usr/src/uts/common/fs/zfs/zfs_vnops.c
author Chris Kirby <Chris.Kirby@oracle.com>
Thu, 10 Jun 2010 15:46:47 -0600
changeset 12605 6790e683d5a5
parent 12421 d38fccc4d212
child 12620 12fcd99a642d
permissions -rw-r--r--
6959846 DMU traverse prefetch size should be a global tunable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1460
299d0ee75ed4 6371285 panic when nfs lookup operation attempted on plain file
marks
parents: 1417
diff changeset
     5
 * Common Development and Distribution License (the "License").
299d0ee75ed4 6371285 panic when nfs lookup operation attempted on plain file
marks
parents: 1417
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
4144
068f395736ad 6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents: 3912
diff changeset
    25
/* Portions Copyright 2007 Jeremy Teo */
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
    26
/* Portions Copyright 2010 Robert Milkowski */
4144
068f395736ad 6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents: 3912
diff changeset
    27
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/systm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/sysmacros.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/vfs.h>
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
    35
#include <sys/vfs_opreg.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/vnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/taskq.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/vmsystm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/atomic.h>
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
    44
#include <sys/vm.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <vm/seg_vn.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <vm/pvn.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <vm/as.h>
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
    48
#include <vm/kpm.h>
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
    49
#include <vm/seg_kpm.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/mman.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include <sys/unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <sys/zfs_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
#include <sys/zfs_acl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#include <sys/zfs_ioctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
#include <sys/dmu.h>
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
    60
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#include <sys/txg.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#include <sys/dbuf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
#include <sys/zap.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
    65
#include <sys/sa.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
#include <sys/dirent.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
#include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
#include <sys/filio.h>
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
    70
#include <sys/sid.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
#include "fs/fs_subr.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
#include <sys/zfs_ctldir.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    73
#include <sys/zfs_fuid.h>
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
    74
#include <sys/zfs_sa.h>
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 1472
diff changeset
    75
#include <sys/dnlc.h>
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
    76
#include <sys/zfs_rlock.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    77
#include <sys/extdirent.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    78
#include <sys/kidmap.h>
11134
8aa0c4ca6639 PSARC 2009/542 Increase the maximum value of NGROUPS_MAX to 1024
Casper H.S. Dik <Casper.Dik@Sun.COM>
parents: 11083
diff changeset
    79
#include <sys/cred.h>
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
    80
#include <sys/attr.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 * Programming rules.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
 * Each vnode op performs some logical unit of work.  To do this, the ZPL must
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
 * properly lock its in-core state, create a DMU transaction, do the work,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
 * record this work in the intent log (ZIL), commit the DMU transaction,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    88
 * and wait for the intent log to commit if it is a synchronous operation.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    89
 * Moreover, the vnode ops must work in both normal and log replay context.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
 * The ordering of events is important to avoid deadlocks and references
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
 * to freed memory.  The example below illustrates the following Big Rules:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
 *  (1) A check must be made in each zfs thread for a mounted file system.
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    94
 *	This is done avoiding races using ZFS_ENTER(zfsvfs).
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    95
 *      A ZFS_EXIT(zfsvfs) is needed before all returns.  Any znodes
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    96
 *      must be checked with ZFS_VERIFY_ZP(zp).  Both of these macros
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    97
 *      can return EIO from the calling function.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
 *  (2)	VN_RELE() should always be the last thing except for zil_commit()
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   100
 *	(if necessary) and ZFS_EXIT(). This is for 3 reasons:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
 *	First, if it's the last reference, the vnode/znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
 *	can be freed, so the zp may point to freed memory.  Second, the last
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
 *	reference will call zfs_zinactive(), which may induce a lot of work --
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   104
 *	pushing cached pages (which acquires range locks) and syncing out
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
 *	cached atime changes.  Third, zfs_zinactive() may require a new tx,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
 *	which could deadlock the system if you were already holding one.
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   107
 *	If you must call VN_RELE() within a tx then use VN_RELE_ASYNC().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
 *
1757
fe91f3ab3083 6405008 Reboot hung after a stress test
perrin
parents: 1669
diff changeset
   109
 *  (3)	All range locks must be grabbed before calling dmu_tx_assign(),
fe91f3ab3083 6405008 Reboot hung after a stress test
perrin
parents: 1669
diff changeset
   110
 *	as they can span dmu_tx_assign() calls.
fe91f3ab3083 6405008 Reboot hung after a stress test
perrin
parents: 1669
diff changeset
   111
 *
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   112
 *  (4)	Always pass TXG_NOWAIT as the second argument to dmu_tx_assign().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
 *	This is critical because we don't want to block while holding locks.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
 *	Note, in particular, that if a lock is sometimes acquired before
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
 *	the tx assigns, and sometimes after (e.g. z_lock), then failing to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
 *	use a non-blocking assign can deadlock the system.  The scenario:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
 *	Thread A has grabbed a lock before calling dmu_tx_assign().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
 *	Thread B is in an already-assigned tx, and blocks for this lock.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
 *	Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
 *	forever, because the previous txg can't quiesce until B's tx commits.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
 *	If dmu_tx_assign() returns ERESTART and zfsvfs->z_assign is TXG_NOWAIT,
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   124
 *	then drop all locks, call dmu_tx_wait(), and try again.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
 *
1757
fe91f3ab3083 6405008 Reboot hung after a stress test
perrin
parents: 1669
diff changeset
   126
 *  (5)	If the operation succeeded, generate the intent log entry for it
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
 *	before dropping locks.  This ensures that the ordering of events
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
 *	in the intent log matches the order in which they actually occurred.
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   129
 *      During ZIL replay the zfs_log_* functions will update the sequence
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   130
 *	number to indicate the zil transaction has replayed.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
 *
1757
fe91f3ab3083 6405008 Reboot hung after a stress test
perrin
parents: 1669
diff changeset
   132
 *  (6)	At the end of each vnode op, the DMU tx must always commit,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
 *	regardless of whether there were any errors.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
 *
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   135
 *  (7)	After dropping all locks, invoke zil_commit(zilog, seq, foid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
 *	to ensure that synchronous semantics are provided when necessary.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
 * In general, this is how things should be ordered in each vnode op:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
 *	ZFS_ENTER(zfsvfs);		// exit if unmounted
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
 * top:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
 *	zfs_dirent_lock(&dl, ...)	// lock directory entry (may VN_HOLD())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
 *	rw_enter(...);			// grab any other locks you need
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
 *	tx = dmu_tx_create(...);	// get DMU tx
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
 *	dmu_tx_hold_*();		// hold each object you might modify
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   146
 *	error = dmu_tx_assign(tx, TXG_NOWAIT);	// try to assign
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
 *	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
 *		rw_exit(...);		// drop locks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
 *		zfs_dirent_unlock(dl);	// unlock directory entry
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
 *		VN_RELE(...);		// release held vnodes
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   151
 *		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   152
 *			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   153
 *			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
 *			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
 *		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   156
 *		dmu_tx_abort(tx);	// abort DMU tx
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
 *		ZFS_EXIT(zfsvfs);	// finished in zfs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
 *		return (error);		// really out of space
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
 *	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
 *	error = do_real_work();		// do whatever this VOP does
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
 *	if (error == 0)
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   162
 *		zfs_log_*(...);		// on success, make ZIL entry
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
 *	dmu_tx_commit(tx);		// commit DMU tx -- error or not
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
 *	rw_exit(...);			// drop locks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
 *	zfs_dirent_unlock(dl);		// unlock directory entry
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
 *	VN_RELE(...);			// release held vnodes
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   167
 *	zil_commit(zilog, seq, foid);	// synchronous when necessary
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
 *	ZFS_EXIT(zfsvfs);		// finished in zfs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
 *	return (error);			// done, report error
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
 */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   171
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   174
zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   176
	znode_t	*zp = VTOZ(*vpp);
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   177
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   178
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   179
	ZFS_ENTER(zfsvfs);
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   180
	ZFS_VERIFY_ZP(zp);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   181
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   182
	if ((flag & FWRITE) && (zp->z_pflags & ZFS_APPENDONLY) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   183
	    ((flag & FAPPEND) == 0)) {
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   184
		ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   185
		return (EPERM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   186
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   187
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   188
	if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   189
	    ZTOV(zp)->v_type == VREG &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   190
	    !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0) {
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   191
		if (fs_vscan(*vpp, cr, 0) != 0) {
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   192
			ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   193
			return (EACCES);
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   194
		}
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   195
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   196
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   197
	/* Keep a count of the synchronous opens in the znode */
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   198
	if (flag & (FSYNC | FDSYNC))
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   199
		atomic_inc_32(&zp->z_sync_cnt);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   200
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   201
	ZFS_EXIT(zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   207
zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   208
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
{
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   210
	znode_t	*zp = VTOZ(vp);
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   211
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   212
9909
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   213
	/*
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   214
	 * Clean up any locks held by this process on the vp.
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   215
	 */
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   216
	cleanlocks(vp, ddi_get_pid(), 0);
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   217
	cleanshares(vp, ddi_get_pid());
aa280f585a3e 6790232 zfs related assertion failure: vp->v_filocks == 0L, file: ../../common/fs/vnode.c, line: 2344
Chris Kirby <chris.kirby@sun.com>
parents: 9774
diff changeset
   218
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   219
	ZFS_ENTER(zfsvfs);
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   220
	ZFS_VERIFY_ZP(zp);
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   221
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   222
	/* Decrement the synchronous opens in the znode */
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   223
	if ((flag & (FSYNC | FDSYNC)) && (count == 1))
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   224
		atomic_dec_32(&zp->z_sync_cnt);
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   225
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   226
	if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   227
	    ZTOV(zp)->v_type == VREG &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   228
	    !(zp->z_pflags & ZFS_AV_QUARANTINED) && zp->z_size > 0)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   229
		VERIFY(fs_vscan(vp, cr, 1) == 0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   230
7844
effed23820ae 6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7757
diff changeset
   231
	ZFS_EXIT(zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
 * Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
 * data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
zfs_holey(vnode_t *vp, int cmd, offset_t *off)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
	znode_t	*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
	uint64_t noff = (uint64_t)*off; /* new offset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	uint64_t file_sz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	boolean_t hole;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   248
	file_sz = zp->z_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
	if (noff >= file_sz)  {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	if (cmd == _FIO_SEEK_HOLE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
		hole = B_TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
		hole = B_FALSE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
	error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	/* end of file? */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
	if ((error == ESRCH) || (noff > file_sz)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
		 * Handle the virtual hole at the end of file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
		if (hole) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
			*off = file_sz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	if (noff < *off)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	*off = noff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   281
    int *rvalp, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
	offset_t off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	zfsvfs_t *zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   286
	znode_t *zp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	switch (com) {
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   289
	case _FIOFFS:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		return (zfs_sync(vp->v_vfsp, 0, cred));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   292
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   293
		 * The following two ioctls are used by bfu.  Faking out,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   294
		 * necessary to avoid bfu errors.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   295
		 */
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   296
	case _FIOGDIO:
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   297
	case _FIOSDIO:
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   298
		return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
   299
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   300
	case _FIO_SEEK_DATA:
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
   301
	case _FIO_SEEK_HOLE:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		if (ddi_copyin((void *)data, &off, sizeof (off), flag))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
			return (EFAULT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   305
		zp = VTOZ(vp);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   306
		zfsvfs = zp->z_zfsvfs;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   307
		ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   308
		ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
		/* offset parameter is in/out */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
		error = zfs_holey(vp, com, &off);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		if (ddi_copyout(&off, (void *)data, sizeof (off), flag))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
			return (EFAULT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	return (ENOTTY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
/*
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   323
 * Utility functions to map and unmap a single physical page.  These
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   324
 * are used to manage the mappable copies of ZFS file data, and therefore
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   325
 * do not update ref/mod bits.
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   326
 */
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   327
caddr_t
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   328
zfs_map_page(page_t *pp, enum seg_rw rw)
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   329
{
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   330
	if (kpm_enable)
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   331
		return (hat_kpm_mapin(pp, 0));
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   332
	ASSERT(rw == S_READ || rw == S_WRITE);
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   333
	return (ppmapin(pp, PROT_READ | ((rw == S_WRITE) ? PROT_WRITE : 0),
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   334
	    (caddr_t)-1));
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   335
}
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   336
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   337
void
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   338
zfs_unmap_page(page_t *pp, caddr_t addr)
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   339
{
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   340
	if (kpm_enable) {
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   341
		hat_kpm_mapout(pp, 0, addr);
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   342
	} else {
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   343
		ppmapout(addr);
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   344
	}
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   345
}
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   346
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   347
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
 * When a file is memory mapped, we must keep the IO data synchronized
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
 * between the DMU cache and the memory mapped pages.  What this means:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
 * On Write:	If we find a memory mapped page, we write to *both*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
 *		the page and the dmu buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
 */
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   354
static void
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   355
update_pages(vnode_t *vp, int64_t start, int len, objset_t *os, uint64_t oid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
{
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   357
	int64_t	off;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   358
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	off = start & PAGEOFFSET;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
	for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		page_t *pp;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   362
		uint64_t nbytes = MIN(PAGESIZE - off, len);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   363
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
		if (pp = page_lookup(vp, start, SE_SHARED)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
			caddr_t va;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   367
			va = zfs_map_page(pp, S_WRITE);
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9412
diff changeset
   368
			(void) dmu_read(os, oid, start+off, nbytes, va+off,
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9412
diff changeset
   369
			    DMU_READ_PREFETCH);
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   370
			zfs_unmap_page(pp, va);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
			page_unlock(pp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
		}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   373
		len -= nbytes;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
		off = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
 * When a file is memory mapped, we must keep the IO data synchronized
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
 * between the DMU cache and the memory mapped pages.  What this means:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
 * On Read:	We "read" preferentially from memory mapped pages,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
 *		else we default from the dmu buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
 * NOTE: We will always "break up" the IO into PAGESIZE uiomoves when
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
 *	the file is memory mapped.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
static int
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   389
mappedread(vnode_t *vp, int nbytes, uio_t *uio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
{
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   391
	znode_t *zp = VTOZ(vp);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   392
	objset_t *os = zp->z_zfsvfs->z_os;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   393
	int64_t	start, off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	int len = nbytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
	int error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
	start = uio->uio_loffset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
	off = start & PAGEOFFSET;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
	for (start &= PAGEMASK; len > 0; start += PAGESIZE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
		page_t *pp;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   401
		uint64_t bytes = MIN(PAGESIZE - off, len);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   402
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
		if (pp = page_lookup(vp, start, SE_SHARED)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
			caddr_t va;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   406
			va = zfs_map_page(pp, S_READ);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
			error = uiomove(va + off, bytes, UIO_READ, uio);
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
   408
			zfs_unmap_page(pp, va);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
			page_unlock(pp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
		} else {
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   411
			error = dmu_read_uio(os, zp->z_id, uio, bytes);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
		len -= bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
		off = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
		if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   421
offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
 * Read bytes from specified file into supplied buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
 *	IN:	vp	- vnode of file to be read from.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
 *		uio	- structure supplying read location, range info,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
 *			  and return buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
 *		ioflag	- SYNC flags; used to provide FRSYNC semantics.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   431
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
 *	OUT:	uio	- updated offset and range, buffer filled.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
 * Side Effects:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
 *	vp - atime updated if byte count > 0
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   447
	objset_t	*os;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   448
	ssize_t		n, nbytes;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   449
	int		error;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   450
	rl_t		*rl;
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   451
	xuio_t		*xuio = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   453
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   454
	ZFS_VERIFY_ZP(zp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   455
	os = zfsvfs->z_os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   457
	if (zp->z_pflags & ZFS_AV_QUARANTINED) {
5929
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
   458
		ZFS_EXIT(zfsvfs);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
   459
		return (EACCES);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
   460
	}
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
   461
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	 * Validate file offset
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
	if (uio->uio_loffset < (offset_t)0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
	 * Fasttrack empty reads
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	if (uio->uio_resid == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
	/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   479
	 * Check for mandatory locks
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   481
	if (MANDMODE(zp->z_mode)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
		if (error = chklock(vp, FREAD,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
		    uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	 * If we're in FRSYNC mode, sync out this znode before reading it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
	 */
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
   492
	if (ioflag & FRSYNC || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   493
		zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
	/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   496
	 * Lock the range against changes.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   498
	rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   499
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	 * If we are reading past end-of-file we can skip
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	 * to the end; but we might still need to set atime.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   504
	if (uio->uio_loffset >= zp->z_size) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
		error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   509
	ASSERT(uio->uio_loffset < zp->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   510
	n = MIN(uio->uio_resid, zp->z_size - uio->uio_loffset);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   511
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   512
	if ((uio->uio_extflg == UIO_XUIO) &&
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   513
	    (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY)) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   514
		int nblk;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   515
		int blksz = zp->z_blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   516
		uint64_t offset = uio->uio_loffset;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   517
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   518
		xuio = (xuio_t *)uio;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   519
		if ((ISP2(blksz))) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   520
			nblk = (P2ROUNDUP(offset + n, blksz) - P2ALIGN(offset,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   521
			    blksz)) / blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   522
		} else {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   523
			ASSERT(offset + n <= blksz);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   524
			nblk = 1;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   525
		}
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
   526
		(void) dmu_xuio_init(xuio, nblk);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   527
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   528
		if (vn_has_cached_data(vp)) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   529
			/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   530
			 * For simplicity, we always allocate a full buffer
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   531
			 * even if we only expect to read a portion of a block.
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   532
			 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   533
			while (--nblk >= 0) {
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
   534
				(void) dmu_xuio_add(xuio,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   535
				    dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   536
				    blksz), 0, blksz);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   537
			}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   538
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   539
	}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   540
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   541
	while (n > 0) {
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   542
		nbytes = MIN(n, zfs_read_chunk_size -
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   543
		    P2PHASE(uio->uio_loffset, zfs_read_chunk_size));
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   544
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   545
		if (vn_has_cached_data(vp))
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   546
			error = mappedread(vp, nbytes, uio);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   547
		else
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   548
			error = dmu_read_uio(os, zp->z_id, uio, nbytes);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
   549
		if (error) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
   550
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
   551
			if (error == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
   552
				error = EIO;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   553
			break;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
   554
		}
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   555
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   556
		n -= nbytes;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
out:
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   559
	zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
	ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
 * Write the bytes to a file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
 *	IN:	vp	- vnode of file to be written to.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
 *		uio	- structure supplying write location, range info,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
 *			  and data buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
 *		ioflag	- FAPPEND flag set if in append mode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   574
 *		ct	- caller context (NFS/CIFS fem monitor only)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
 *	OUT:	uio	- updated offset and range.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
 *	vp - ctime|mtime updated if byte count > 0
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   584
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
	rlim64_t	limit = uio->uio_llimit;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	ssize_t		start_resid = uio->uio_resid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	ssize_t		tx_bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	uint64_t	end_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   596
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	offset_t	woff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
	ssize_t		n, nbytes;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   599
	rl_t		*rl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
	int		max_blksz = zfsvfs->z_max_blksz;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   601
	int		error;
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   602
	arc_buf_t	*abuf;
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   603
	iovec_t		*aiov;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   604
	xuio_t		*xuio = NULL;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   605
	int		i_iov = 0;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   606
	int		iovcnt = uio->uio_iovcnt;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   607
	iovec_t		*iovp = uio->uio_iov;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   608
	int		write_eof;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   609
	int		count = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   610
	sa_bulk_attr_t	bulk[4];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   611
	uint64_t	mtime[2], ctime[2];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
	 * Fasttrack empty write
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
	 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   616
	n = start_resid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
	if (n == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   620
	if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   621
		limit = MAXOFFSET_T;
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   622
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   623
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   624
	ZFS_VERIFY_ZP(zp);
6743
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   625
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   626
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   627
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   628
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   629
	    &zp->z_size, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   630
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   631
	    &zp->z_pflags, 8);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   632
6743
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   633
	/*
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   634
	 * If immutable or not appending then return EPERM
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   635
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   636
	if ((zp->z_pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) ||
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   637
	    ((zp->z_pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   638
	    (uio->uio_loffset < zp->z_size))) {
6743
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   639
		ZFS_EXIT(zfsvfs);
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   640
		return (EPERM);
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   641
	}
5176703cbaff 6703554 panic with ZFS and Greenplum: BAD TRAP: type=e (#pf Page fault)
marks
parents: 6492
diff changeset
   642
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
   643
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	/*
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   646
	 * Validate file offset
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   647
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   648
	woff = ioflag & FAPPEND ? zp->z_size : uio->uio_loffset;
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   649
	if (woff < 0) {
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   650
		ZFS_EXIT(zfsvfs);
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   651
		return (EINVAL);
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   652
	}
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   653
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   654
	/*
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   655
	 * Check for mandatory locks before calling zfs_range_lock()
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   656
	 * in order to prevent a deadlock with locks set via fcntl().
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   657
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   658
	if (MANDMODE((mode_t)zp->z_mode) &&
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   659
	    (error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) {
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   660
		ZFS_EXIT(zfsvfs);
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   661
		return (error);
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   662
	}
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   663
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   664
	/*
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   665
	 * Pre-fault the pages to ensure slow (eg NFS) pages
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   666
	 * don't hold up txg.
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   667
	 * Skip this if uio contains loaned arc_buf.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
	 */
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   669
	if ((uio->uio_extflg == UIO_XUIO) &&
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   670
	    (((xuio_t *)uio)->xu_type == UIOTYPE_ZEROCOPY))
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   671
		xuio = (xuio_t *)uio;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   672
	else
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   673
		uio_prefaultpages(n, uio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
	 * If in append mode, set the io offset pointer to eof.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
	 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   678
	if (ioflag & FAPPEND) {
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   679
		/*
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   680
		 * Obtain an appending range lock to guarantee file append
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   681
		 * semantics.  We reset the write offset once we have the lock.
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   682
		 */
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   683
		rl = zfs_range_lock(zp, 0, n, RL_APPEND);
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   684
		woff = rl->r_off;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   685
		if (rl->r_len == UINT64_MAX) {
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   686
			/*
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   687
			 * We overlocked the file because this write will cause
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   688
			 * the file block size to increase.
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   689
			 * Note that zp_size cannot change with this lock held.
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   690
			 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   691
			woff = zp->z_size;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   692
		}
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   693
		uio->uio_loffset = woff;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
		/*
11083
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   696
		 * Note that if the file block size will change as a result of
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   697
		 * this write, then this range lock will lock the entire file
f5064cfdf092 6876139 writev - gABI test case hangs with ZFS filesystem
William Gorrell <william.gorrell@sun.com>
parents: 10945
diff changeset
   698
		 * so that we can re-write the block safely.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
		 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   700
		rl = zfs_range_lock(zp, woff, n, RL_WRITER);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
	if (woff >= limit) {
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   704
		zfs_range_unlock(rl);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   705
		ZFS_EXIT(zfsvfs);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   706
		return (EFBIG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
	if ((woff + n) > limit || woff > (limit - n))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
		n = limit - woff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   712
	/* Will this write extend the file length? */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   713
	write_eof = (woff + n > zp->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   714
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   715
	end_size = MAX(zp->z_size, woff + n);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   717
	/*
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   718
	 * Write the file in reasonable size chunks.  Each chunk is written
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   719
	 * in a separate transaction; this keeps the intent log records small
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   720
	 * and allows us to do more fine-grained space accounting.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
	while (n > 0) {
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   723
		abuf = NULL;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   724
		woff = uio->uio_loffset;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   725
again:
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   726
		if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   727
		    zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   728
			if (abuf != NULL)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   729
				dmu_return_arcbuf(abuf);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
   730
			error = EDQUOT;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
   731
			break;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
   732
		}
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   733
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   734
		if (xuio && abuf == NULL) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   735
			ASSERT(i_iov < iovcnt);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   736
			aiov = &iovp[i_iov];
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   737
			abuf = dmu_xuio_arcbuf(xuio, i_iov);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   738
			dmu_xuio_clear(xuio, i_iov);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   739
			DTRACE_PROBE3(zfs_cp_write, int, i_iov,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   740
			    iovec_t *, aiov, arc_buf_t *, abuf);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   741
			ASSERT((aiov->iov_base == abuf->b_data) ||
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   742
			    ((char *)aiov->iov_base - (char *)abuf->b_data +
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   743
			    aiov->iov_len == arc_buf_size(abuf)));
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   744
			i_iov++;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   745
		} else if (abuf == NULL && n >= max_blksz &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   746
		    woff >= zp->z_size &&
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   747
		    P2PHASE(woff, max_blksz) == 0 &&
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   748
		    zp->z_blksz == max_blksz) {
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   749
			/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   750
			 * This write covers a full block.  "Borrow" a buffer
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   751
			 * from the dmu so that we can fill it before we enter
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   752
			 * a transaction.  This avoids the possibility of
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   753
			 * holding up the transaction if the data copy hangs
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   754
			 * up on a pagefault (e.g., from an NFS server mapping).
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   755
			 */
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   756
			size_t cbytes;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   757
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   758
			abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   759
			    max_blksz);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   760
			ASSERT(abuf != NULL);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   761
			ASSERT(arc_buf_size(abuf) == max_blksz);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   762
			if (error = uiocopy(abuf->b_data, max_blksz,
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   763
			    UIO_WRITE, uio, &cbytes)) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   764
				dmu_return_arcbuf(abuf);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   765
				break;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   766
			}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   767
			ASSERT(cbytes == max_blksz);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   768
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   769
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   770
		/*
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   771
		 * Start a transaction.
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   772
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
		tx = dmu_tx_create(zfsvfs->z_os);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   774
		dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
		dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   776
		zfs_sa_upgrade_txholds(tx, zp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   777
		error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
		if (error) {
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   779
			if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   780
				dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   781
				dmu_tx_abort(tx);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   782
				goto again;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
			}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
   784
			dmu_tx_abort(tx);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   785
			if (abuf != NULL)
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   786
				dmu_return_arcbuf(abuf);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   787
			break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   788
		}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   789
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   790
		/*
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   791
		 * If zfs_range_lock() over-locked we grow the blocksize
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   792
		 * and then reduce the lock range.  This will only happen
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   793
		 * on the first iteration since zfs_range_reduce() will
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   794
		 * shrink down r_len to the appropriate size.
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   795
		 */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   796
		if (rl->r_len == UINT64_MAX) {
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   797
			uint64_t new_blksz;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   798
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   799
			if (zp->z_blksz > max_blksz) {
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   800
				ASSERT(!ISP2(zp->z_blksz));
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   801
				new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   802
			} else {
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   803
				new_blksz = MIN(end_size, max_blksz);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   804
			}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   805
			zfs_grow_blocksize(zp, new_blksz, tx);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   806
			zfs_range_reduce(rl, woff, n);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   807
		}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   808
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   809
		/*
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   810
		 * XXX - should we really limit each write to z_max_blksz?
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   811
		 * Perhaps we should use SPA_MAXBLOCKSIZE chunks?
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   812
		 */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   813
		nbytes = MIN(n, max_blksz - P2PHASE(woff, max_blksz));
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   814
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   815
		if (abuf == NULL) {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   816
			tx_bytes = uio->uio_resid;
12123
bb40732a982e 6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents: 12079
diff changeset
   817
			error = dmu_write_uio_dbuf(sa_get_db(zp->z_sa_hdl),
bb40732a982e 6572591 meta dnode lookup causes bucket lock contention in dbuf hash
Tim Haley <Tim.Haley@Sun.COM>
parents: 12079
diff changeset
   818
			    uio, nbytes, tx);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   819
			tx_bytes -= uio->uio_resid;
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   820
		} else {
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   821
			tx_bytes = nbytes;
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   822
			ASSERT(xuio == NULL || tx_bytes == aiov->iov_len);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   823
			/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   824
			 * If this is not a full block write, but we are
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   825
			 * extending the file past EOF and this data starts
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   826
			 * block-aligned, use assign_arcbuf().  Otherwise,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   827
			 * write via dmu_write().
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   828
			 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   829
			if (tx_bytes < max_blksz && (!write_eof ||
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   830
			    aiov->iov_base != abuf->b_data)) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   831
				ASSERT(xuio);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   832
				dmu_write(zfsvfs->z_os, zp->z_id, woff,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   833
				    aiov->iov_len, aiov->iov_base, tx);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   834
				dmu_return_arcbuf(abuf);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   835
				xuio_stat_wbuf_copied();
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   836
			} else {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   837
				ASSERT(xuio || tx_bytes == max_blksz);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   838
				dmu_assign_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   839
				    woff, abuf, tx);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
   840
			}
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   841
			ASSERT(tx_bytes <= uio->uio_resid);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   842
			uioskip(uio, tx_bytes);
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   843
		}
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   844
		if (tx_bytes && vn_has_cached_data(vp)) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   845
			update_pages(vp, woff,
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
   846
			    tx_bytes, zfsvfs->z_os, zp->z_id);
9412
4aefd8704ce0 6717022 ZFS DMU needs zero-copy support
Aleksandr Guzovskiy <Aleksandr.Guzovskiy@Sun.COM>
parents: 9396
diff changeset
   847
		}
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   848
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   849
		/*
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   850
		 * If we made no progress, we're done.  If we made even
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   851
		 * partial progress, update the znode and ZIL accordingly.
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   852
		 */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   853
		if (tx_bytes == 0) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   854
			(void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   855
			    (void *)&zp->z_size, sizeof (uint64_t), tx);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
   856
			dmu_tx_commit(tx);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   857
			ASSERT(error != 0);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   858
			break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   859
		}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   860
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
		/*
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   862
		 * Clear Set-UID/Set-GID bits on successful write if not
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   863
		 * privileged and at least one of the excute bits is set.
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   864
		 *
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   865
		 * It would be nice to to this after all writes have
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   866
		 * been done, but that would still expose the ISUID/ISGID
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   867
		 * to another app after the partial write is committed.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   868
		 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
		 */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   870
		mutex_enter(&zp->z_acl_lock);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   871
		if ((zp->z_mode & (S_IXUSR | (S_IXUSR >> 3) |
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   872
		    (S_IXUSR >> 6))) != 0 &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   873
		    (zp->z_mode & (S_ISUID | S_ISGID)) != 0 &&
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   874
		    secpolicy_vnode_setid_retain(cr,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   875
		    (zp->z_mode & S_ISUID) != 0 && zp->z_uid == 0) != 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   876
			uint64_t newmode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   877
			zp->z_mode &= ~(S_ISUID | S_ISGID);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   878
			newmode = zp->z_mode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   879
			(void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   880
			    (void *)&newmode, sizeof (uint64_t), tx);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   881
		}
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   882
		mutex_exit(&zp->z_acl_lock);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   883
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   884
		zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   885
		    B_TRUE);
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   886
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   887
		/*
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   888
		 * Update the file size (zp_size) if it has changed;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   889
		 * account for possible concurrent updates.
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   890
		 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   891
		while ((end_size = zp->z_size) < uio->uio_loffset) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   892
			(void) atomic_cas_64(&zp->z_size, end_size,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
			    uio->uio_loffset);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   894
			ASSERT(error == 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   895
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   896
		error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
   897
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   898
		zfs_log_write(zilog, tx, TX_WRITE, zp, woff, tx_bytes, ioflag);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   899
		dmu_tx_commit(tx);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   900
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   901
		if (error != 0)
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   902
			break;
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   903
		ASSERT(tx_bytes == nbytes);
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
   904
		n -= nbytes;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   907
	zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
	 * If we're in replay mode, or we made no progress, return error.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
	 * Otherwise, it's at least a partial write, so it's successful.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
	 */
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
   913
	if (zfsvfs->z_replay || uio->uio_resid == start_resid) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
   918
	if (ioflag & (FSYNC | FDSYNC) ||
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
   919
	    zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
   920
		zil_commit(zilog, zp->z_last_itx, zp->z_id);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   926
void
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   927
zfs_get_done(zgd_t *zgd, int error)
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   928
{
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   929
	znode_t *zp = zgd->zgd_private;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   930
	objset_t *os = zp->z_zfsvfs->z_os;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   931
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   932
	if (zgd->zgd_db)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   933
		dmu_buf_rele(zgd->zgd_db, zgd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   934
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   935
	zfs_range_unlock(zgd->zgd_rl);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   936
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   937
	/*
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   938
	 * Release the vnode asynchronously as we currently have the
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   939
	 * txg stopped from syncing.
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   940
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   941
	VN_RELE_ASYNC(ZTOV(zp), dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   942
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   943
	if (error == 0 && zgd->zgd_bp)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   944
		zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   945
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   946
	kmem_free(zgd, sizeof (zgd_t));
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   947
}
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   948
10209
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
   949
#ifdef DEBUG
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
   950
static int zil_fault_io = 0;
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
   951
#endif
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
   952
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
 * Get data to generate a TX_WRITE intent log record.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
int
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   957
zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
	zfsvfs_t *zfsvfs = arg;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
	objset_t *os = zfsvfs->z_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
	znode_t *zp;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   962
	uint64_t object = lr->lr_foid;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   963
	uint64_t offset = lr->lr_offset;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   964
	uint64_t size = lr->lr_length;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   965
	blkptr_t *bp = &lr->lr_blkptr;
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
   966
	dmu_buf_t *db;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2796
diff changeset
   967
	zgd_t *zgd;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
	int error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   970
	ASSERT(zio != NULL);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   971
	ASSERT(size != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
	/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   974
	 * Nothing to do if the file has been removed
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   976
	if (zfs_zget(zfsvfs, object, &zp) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
		return (ENOENT);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
   978
	if (zp->z_unlinked) {
9321
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   979
		/*
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   980
		 * Release the vnode asynchronously as we currently have the
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   981
		 * txg stopped from syncing.
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   982
		 */
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   983
		VN_RELE_ASYNC(ZTOV(zp),
dca349c475c1 6591646 Hang while trying to enter a txg while holding a txg open
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9265
diff changeset
   984
		    dsl_pool_vnrele_taskq(dmu_objset_pool(os)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   988
	zgd = (zgd_t *)kmem_zalloc(sizeof (zgd_t), KM_SLEEP);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   989
	zgd->zgd_zilog = zfsvfs->z_log;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   990
	zgd->zgd_private = zp;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
   991
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
	 * Write records come in two flavors: immediate and indirect.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
	 * For small writes it's cheaper to store the data with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	 * log record (immediate); for large writes it's cheaper to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	 * sync the data and get a pointer to it (indirect) so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
	 * we don't have to write the data twice.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
	 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
   999
	if (buf != NULL) { /* immediate write */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1000
		zgd->zgd_rl = zfs_range_lock(zp, offset, size, RL_READER);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1001
		/* test for truncation needs to be done while range locked */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1002
		if (offset >= zp->z_size) {
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1003
			error = ENOENT;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1004
		} else {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1005
			error = dmu_read(os, object, offset, size, buf,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1006
			    DMU_READ_NO_PREFETCH);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1007
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1008
		ASSERT(error == 0 || error == ENOENT);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1009
	} else { /* indirect write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
		/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1011
		 * Have to lock the whole block to ensure when it's
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1012
		 * written out and it's checksum is being calculated
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1013
		 * that no one can change the data. We need to re-check
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1014
		 * blocksize after we get the lock in case it's changed!
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
		 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1016
		for (;;) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1017
			uint64_t blkoff;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1018
			size = zp->z_blksz;
10945
b3afbf06f20d 6897933 zfs_get_data: assertion failed: db->db_offset == offset
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10922
diff changeset
  1019
			blkoff = ISP2(size) ? P2PHASE(offset, size) : offset;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1020
			offset -= blkoff;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1021
			zgd->zgd_rl = zfs_range_lock(zp, offset, size,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1022
			    RL_READER);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1023
			if (zp->z_blksz == size)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1024
				break;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1025
			offset += blkoff;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1026
			zfs_range_unlock(zgd->zgd_rl);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1027
		}
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1028
		/* test for truncation needs to be done while range locked */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1029
		if (lr->lr_offset >= zp->z_size)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  1030
			error = ENOENT;
10209
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1031
#ifdef DEBUG
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1032
		if (zil_fault_io) {
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1033
			error = EIO;
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1034
			zil_fault_io = 0;
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1035
		}
91f47f0e7728 6830541 zfs_get_data trips on a verify
Mark J Musante <Mark.Musante@Sun.COM>
parents: 10143
diff changeset
  1036
#endif
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1037
		if (error == 0)
12285
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 12218
diff changeset
  1038
			error = dmu_buf_hold(os, object, offset, zgd, &db,
d736d62dcca2 6944833 Avoid prefetching dbufs in dmu_sync() path
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 12218
diff changeset
  1039
			    DMU_READ_NO_PREFETCH);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1040
10800
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10793
diff changeset
  1041
		if (error == 0) {
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1042
			zgd->zgd_db = db;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1043
			zgd->zgd_bp = bp;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1044
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1045
			ASSERT(db->db_offset == offset);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1046
			ASSERT(db->db_size == size);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1047
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1048
			error = dmu_sync(zio, lr->lr_common.lrc_txg,
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1049
			    zfs_get_done, zgd);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1050
			ASSERT(error || lr->lr_length <= zp->z_blksz);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1051
10800
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10793
diff changeset
  1052
			/*
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1053
			 * On success, we need to wait for the write I/O
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1054
			 * initiated by dmu_sync() to complete before we can
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1055
			 * release this dbuf.  We will finish everything up
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1056
			 * in the zfs_get_done() callback.
10800
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10793
diff changeset
  1057
			 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1058
			if (error == 0)
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1059
				return (0);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1060
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1061
			if (error == EALREADY) {
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1062
				lr->lr_common.lrc_txtype = TX_WRITE2;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1063
				error = 0;
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1064
			}
10800
469478b180d9 6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10793
diff changeset
  1065
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1067
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1068
	zfs_get_done(zgd, error);
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10896
diff changeset
  1069
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1075
zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1076
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1082
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1083
	ZFS_VERIFY_ZP(zp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1084
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1085
	if (flag & V_ACE_MASK)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1086
		error = zfs_zaccess(zp, mode, flag, B_FALSE, cr);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1087
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1088
		error = zfs_zaccess_rwx(zp, mode, flag, cr);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1089
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
/*
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1095
 * If vnode is for a device return a specfs vnode instead.
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1096
 */
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1097
static int
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1098
specvp_check(vnode_t **vpp, cred_t *cr)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1099
{
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1100
	int error = 0;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1101
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1102
	if (IS_DEVVP(*vpp)) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1103
		struct vnode *svp;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1104
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1105
		svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1106
		VN_RELE(*vpp);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1107
		if (svp == NULL)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1108
			error = ENOSYS;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1109
		*vpp = svp;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1110
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1111
	return (error);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1112
}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1113
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1114
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1115
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
 * Lookup an entry in a directory, or an extended attribute directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
 * If it exists, return a held vnode reference for it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
 *	IN:	dvp	- vnode of directory to search.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
 *		nm	- name of entry to lookup.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
 *		pnp	- full pathname to lookup [UNUSED].
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
 *		flags	- LOOKUP_XATTR set if looking for an attribute.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
 *		rdir	- root directory vnode [UNUSED].
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1125
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1126
 *		direntflags - directory lookup flags
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1127
 *		realpnp - returned pathname.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1128
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
 *	OUT:	vpp	- vnode of located entry, NULL if not found.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
 *	NA
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1140
    int flags, vnode_t *rdir, cred_t *cr,  caller_context_t *ct,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1141
    int *direntflags, pathname_t *realpnp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
	znode_t *zdp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
	zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1145
	int	error = 0;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1146
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1147
	/* fast path */
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1148
	if (!(flags & (LOOKUP_XATTR | FIGNORECASE))) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1149
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1150
		if (dvp->v_type != VDIR) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1151
			return (ENOTDIR);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1152
		} else if (zdp->z_sa_hdl == NULL) {
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1153
			return (EIO);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1154
		}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1155
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1156
		if (nm[0] == 0 || (nm[0] == '.' && nm[1] == '\0')) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1157
			error = zfs_fastaccesschk_execute(zdp, cr);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1158
			if (!error) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1159
				*vpp = dvp;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1160
				VN_HOLD(*vpp);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1161
				return (0);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1162
			}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1163
			return (error);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1164
		} else {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1165
			vnode_t *tvp = dnlc_lookup(dvp, nm);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1166
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1167
			if (tvp) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1168
				error = zfs_fastaccesschk_execute(zdp, cr);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1169
				if (error) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1170
					VN_RELE(tvp);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1171
					return (error);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1172
				}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1173
				if (tvp == DNLC_NO_VNODE) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1174
					VN_RELE(tvp);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1175
					return (ENOENT);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1176
				} else {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1177
					*vpp = tvp;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1178
					return (specvp_check(vpp, cr));
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1179
				}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1180
			}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1181
		}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1182
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1183
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1184
	DTRACE_PROBE2(zfs__fastpath__lookup__miss, vnode_t *, dvp, char *, nm);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1186
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1187
	ZFS_VERIFY_ZP(zdp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
	*vpp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
	if (flags & LOOKUP_XATTR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
		/*
3234
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1193
		 * If the xattr property is off, refuse the lookup request.
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1194
		 */
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1195
		if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) {
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1196
			ZFS_EXIT(zfsvfs);
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1197
			return (EINVAL);
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1198
		}
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1199
28b36f7bbd7e PSARC/2006/638 noxattr ZFS property
ck153898
parents: 3131
diff changeset
  1200
		/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
		 * We don't allow recursive attributes..
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
		 * Maybe someday we will.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
		 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1204
		if (zdp->z_pflags & ZFS_XATTR) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
			return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
3280
e93ccc27c51d 6492686 NFSv4 client got EACCES over ZFS when trying to OPENATTR without createdir
ck153898
parents: 3271
diff changeset
  1209
		if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
		 * Do we have permission to get into attribute directory?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1218
		if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1219
		    B_FALSE, cr)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
			VN_RELE(*vpp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1221
			*vpp = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
1512
dad2d74ca2cb 6391609 zfs_fid() missing ZFS_EXIT()
ek110237
parents: 1484
diff changeset
  1228
	if (dvp->v_type != VDIR) {
dad2d74ca2cb 6391609 zfs_fid() missing ZFS_EXIT()
ek110237
parents: 1484
diff changeset
  1229
		ZFS_EXIT(zfsvfs);
1460
299d0ee75ed4 6371285 panic when nfs lookup operation attempted on plain file
marks
parents: 1417
diff changeset
  1230
		return (ENOTDIR);
1512
dad2d74ca2cb 6391609 zfs_fid() missing ZFS_EXIT()
ek110237
parents: 1484
diff changeset
  1231
	}
1460
299d0ee75ed4 6371285 panic when nfs lookup operation attempted on plain file
marks
parents: 1417
diff changeset
  1232
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	 * Check accessibility of directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1237
	if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1242
	if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm),
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1243
	    NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1244
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1245
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1246
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1247
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1248
	error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp);
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1249
	if (error == 0)
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1250
		error = specvp_check(vpp, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1257
 * Attempt to create a new entry in a directory.  If the entry
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1258
 * already exists, truncate the file if permissible, else return
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
 * an error.  Return the vp of the created or trunc'd file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
 *	IN:	dvp	- vnode of directory to put new file entry in.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
 *		name	- name of new file entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
 *		vap	- attributes of new file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
 *		excl	- flag indicating exclusive or non-exclusive mode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
 *		mode	- mode to open file with.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
 *		cr	- credentials of caller.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
 *		flag	- large file flag [UNUSED].
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1268
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1269
 *		vsecp 	- ACL to be set
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
 *	OUT:	vpp	- vnode of created or trunc'd entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1273
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
 *	dvp - ctime|mtime updated if new entry created
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
 *	 vp - ctime|mtime always, atime if new
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1280
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1281
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1282
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1283
zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1284
    int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1285
    vsecattr_t *vsecp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1286
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1287
	znode_t		*zp, *dzp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1288
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1289
	zilog_t		*zilog;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1290
	objset_t	*os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1291
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1292
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1293
	int		error;
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1294
	ksid_t		*ksid;
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1295
	uid_t		uid;
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1296
	gid_t		gid = crgetgid(cr);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1297
	zfs_acl_ids_t   acl_ids;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1298
	boolean_t	fuid_dirtied;
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1299
	boolean_t	have_acl = B_FALSE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1300
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1301
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1302
	 * If we have an ephemeral id, ACL, or XVATTR then
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1303
	 * make sure file system is at proper version
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1304
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1305
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1306
	ksid = crgetsid(cr, KSID_OWNER);
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1307
	if (ksid)
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1308
		uid = ksid_getid(ksid);
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1309
	else
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1310
		uid = crgetuid(cr);
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1311
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1312
	if (zfsvfs->z_use_fuids == B_FALSE &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1313
	    (vsecp || (vap->va_mask & AT_XVATTR) ||
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1314
	    IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1315
		return (EINVAL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1316
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1317
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1318
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1319
	os = zfsvfs->z_os;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1320
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1322
	if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1323
	    NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1324
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1325
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1326
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1327
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1328
	if (vap->va_mask & AT_XVATTR) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1329
		if ((error = secpolicy_xvattr((xvattr_t *)vap,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1330
		    crgetuid(cr), cr, vap->va_type)) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1331
			ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1332
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1333
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1334
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1335
top:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1336
	*vpp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
	if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
		vap->va_mode &= ~VSVTX;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
	if (*name == '\0') {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
		 * Null component name refers to the directory itself.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1345
		VN_HOLD(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1346
		zp = dzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1347
		dl = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1348
		error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1349
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1350
		/* possible VN_HOLD(zp) */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1351
		int zflg = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1352
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1353
		if (flag & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1354
			zflg |= ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1355
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1356
		error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1357
		    NULL, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1358
		if (error) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
			if (strcmp(name, "..") == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1360
				error = EISDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1363
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1364
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1365
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1366
	if (zp == NULL) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1367
		uint64_t txtype;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1368
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1369
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1370
		 * Create a new file object and update the directory
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
		 * to reference it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
		 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1373
		if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
		 * We only support the creation of regular files in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
		 * extended attribute directories.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
		 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1381
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1382
		if ((dzp->z_pflags & ZFS_XATTR) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1383
		    (vap->va_type != VREG)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1384
			error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1386
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1388
		if (!have_acl && (error = zfs_acl_ids_create(dzp, 0, vap,
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1389
		    cr, vsecp, &acl_ids)) != 0)
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1390
			goto out;
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1391
		have_acl = B_TRUE;
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1392
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1393
		if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1394
			zfs_acl_ids_free(&acl_ids);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1395
			error = EDQUOT;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1396
			goto out;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1397
		}
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1398
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1399
		tx = dmu_tx_create(os);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1400
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1401
		dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1402
		    ZFS_SA_BASE_ATTR_SIZE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1403
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1404
		fuid_dirtied = zfsvfs->z_fuid_dirty;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1405
		if (fuid_dirtied)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1406
			zfs_fuid_txhold(zfsvfs, tx);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  1407
		dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1408
		dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1409
		if (!zfsvfs->z_use_sa &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1410
		    acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
			dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1412
			    0, acl_ids.z_aclp->z_acl_bytes);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1413
		}
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1414
		error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
			zfs_dirent_unlock(dl);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1417
			if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1418
				dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1419
				dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
				goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
			}
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1422
			zfs_acl_ids_free(&acl_ids);
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1423
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
		}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1427
		zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1428
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1429
		if (fuid_dirtied)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1430
			zfs_fuid_sync(zfsvfs, tx);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1431
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
		(void) zfs_link_create(dl, zp, tx, ZNEW);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1433
		txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1434
		if (flag & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1435
			txtype |= TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1436
		zfs_log_create(zilog, tx, txtype, dzp, zp, name,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1437
		    vsecp, acl_ids.z_fuidp, vap);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1438
		zfs_acl_ids_free(&acl_ids);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1439
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1441
		int aflags = (flag & FAPPEND) ? V_APPEND : 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1442
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1444
		 * A directory entry already exists for this name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1445
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1446
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1447
		 * Can't truncate an existing file if in exclusive mode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1448
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1449
		if (excl == EXCL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1450
			error = EEXIST;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
		 * Can't open a directory for writing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1455
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1456
		if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1457
			error = EISDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1458
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1460
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1461
		 * Verify requested access to file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1462
		 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1463
		if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1467
		mutex_enter(&dzp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1468
		dzp->z_seq++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1469
		mutex_exit(&dzp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1470
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  1471
		/*
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  1472
		 * Truncate regular files if requested.
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  1473
		 */
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  1474
		if ((ZTOV(zp)->v_type == VREG) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
		    (vap->va_mask & AT_SIZE) && (vap->va_size == 0)) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1476
			/* we can't hold any locks when calling zfs_freesp() */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1477
			zfs_dirent_unlock(dl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1478
			dl = NULL;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  1479
			error = zfs_freesp(zp, 0, 0, mode, TRUE);
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  1480
			if (error == 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1481
				vnevent_create(ZTOV(zp), ct);
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  1482
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1484
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
out:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
	if (dl)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
		zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
		if (zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
			VN_RELE(ZTOV(zp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
		*vpp = ZTOV(zp);
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  1495
		error = specvp_check(vpp, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1498
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1499
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1500
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1503
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
 * Remove an entry from a directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
 *	IN:	dvp	- vnode of directory to remove entry from.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
 *		name	- name of entry to remove.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1511
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1512
 *		flags	- case flags
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
 *	dvp - ctime|mtime
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
 *	 vp - ctime (if nlink > 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1520
 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1521
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1522
uint64_t null_xattr = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1523
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1524
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1526
zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1527
    int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1529
	znode_t		*zp, *dzp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1530
	znode_t		*xzp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1531
	vnode_t		*vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1532
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1533
	zilog_t		*zilog;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1534
	uint64_t	acl_obj, xattr_obj = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1535
	uint64_t 	xattr_obj_unlinked = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1536
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1537
	dmu_tx_t	*tx;
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1538
	boolean_t	may_delete_now, delete_now = FALSE;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1539
	boolean_t	unlinked, toobig = FALSE;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1540
	uint64_t	txtype;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1541
	pathname_t	*realnmp = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1542
	pathname_t	realnm;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1543
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1544
	int		zflg = ZEXISTS;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1545
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1546
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1547
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1548
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1549
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1550
	if (flags & FIGNORECASE) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1551
		zflg |= ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1552
		pn_alloc(&realnm);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1553
		realnmp = &realnm;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1554
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1555
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1556
top:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1557
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
	 * Attempt to lock directory; fail if entry doesn't exist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1560
	if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1561
	    NULL, realnmp)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1562
		if (realnmp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1563
			pn_free(realnmp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
	vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
	if (error = zfs_zaccess_delete(dzp, zp, cr)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
	 * Need to use rmdir for removing directories.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	if (vp->v_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
		error = EPERM;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1582
	vnevent_remove(vp, dvp, name, ct);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1583
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1584
	if (realnmp)
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6180
diff changeset
  1585
		dnlc_remove(dvp, realnmp->pn_buf);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1586
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1587
		dnlc_remove(dvp, name);
1484
d330e98f8ed7 6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents: 1472
diff changeset
  1588
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
	mutex_enter(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
	may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
	mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
	/*
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1594
	 * We may delete the znode now, or we may put it in the unlinked set;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
	 * it depends on whether we're the last link, and on whether there are
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
	 * other holds on the vnode.  So we dmu_tx_hold() the right things to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
	 * allow for either case.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
	tx = dmu_tx_create(zfsvfs->z_os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  1600
	dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1601
	dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1602
	zfs_sa_upgrade_txholds(tx, zp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1603
	zfs_sa_upgrade_txholds(tx, dzp);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1604
	if (may_delete_now) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1605
		toobig =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1606
		    zp->z_size > zp->z_blksz * DMU_MAX_DELETEBLKCNT;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1607
		/* if the file is too big, only hold_free a token amount */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1608
		dmu_tx_hold_free(tx, zp->z_id, 0,
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1609
		    (toobig ? DMU_MAX_ACCESS : DMU_OBJECT_END));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1610
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
	/* are there any extended attributes? */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1613
	error = sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1614
	    &xattr_obj, sizeof (xattr_obj));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1615
	if (xattr_obj) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1616
		error = zfs_zget(zfsvfs, xattr_obj, &xzp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1617
		ASSERT3U(error, ==, 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1618
		dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1619
		dmu_tx_hold_sa(tx, xzp->z_sa_hdl, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
	/* are there any additional acls */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1623
	if ((acl_obj = ZFS_EXTERNAL_ACL(zp)) != 0 && may_delete_now)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
		dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
	/* charge as an update -- would be nice not to charge at all */
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1627
	dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1629
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
		zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
		VN_RELE(vp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1633
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1634
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1635
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1638
		if (realnmp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1639
			pn_free(realnmp);
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1640
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
	 * Remove the directory entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1648
	error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1649
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1651
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1653
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1655
	if (unlinked) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1656
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1657
		mutex_enter(&vp->v_lock);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1658
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1659
		(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1660
		    &xattr_obj_unlinked, sizeof (xattr_obj_unlinked));
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  1661
		delete_now = may_delete_now && !toobig &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1662
		    vp->v_count == 1 && !vn_has_cached_data(vp) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1663
		    xattr_obj == xattr_obj_unlinked && ZFS_EXTERNAL_ACL(zp) ==
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1664
		    acl_obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1665
		mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1666
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1668
	if (delete_now) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1669
		if (xattr_obj_unlinked) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1670
			ASSERT3U(xzp->z_links, ==, 2);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1671
			mutex_enter(&xzp->z_lock);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1672
			xzp->z_unlinked = 1;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1673
			xzp->z_links = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1674
			error = sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1675
			    &xzp->z_links, sizeof (xzp->z_links), tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1676
			ASSERT3U(error,  ==,  0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
			mutex_exit(&xzp->z_lock);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1678
			zfs_unlinked_add(xzp, tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1679
			if (zp->z_is_sa)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1680
				error = sa_remove(zp->z_sa_hdl,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1681
				    SA_ZPL_XATTR(zfsvfs), tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1682
			else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1683
				error = sa_update(zp->z_sa_hdl,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1684
				    SA_ZPL_XATTR(zfsvfs), &null_xattr,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1685
				    sizeof (uint64_t), tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1686
			ASSERT3U(error, ==, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
		mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
		mutex_enter(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
		vp->v_count--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
		ASSERT3U(vp->v_count, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
		mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
		zfs_znode_delete(zp, tx);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1695
	} else if (unlinked) {
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1696
		zfs_unlinked_add(zp, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1697
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1699
	txtype = TX_REMOVE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1700
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1701
		txtype |= TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1702
	zfs_log_remove(zilog, tx, txtype, dzp, name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1704
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
out:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1706
	if (realnmp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1707
		pn_free(realnmp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1708
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1709
	zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12164
diff changeset
  1711
	if (!delete_now)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1712
		VN_RELE(vp);
12178
93ec1371f750 6939983 assertion failed: zap_count(os, DMU_USERUSED_OBJECT, &count) != 0||count == 0, in dsl_dataset.c
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12164
diff changeset
  1713
	if (xzp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1714
		VN_RELE(ZTOV(xzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1716
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1717
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1718
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
 * Create a new directory and insert it into dvp using the name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1725
 * provided.  Return a pointer to the inserted directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1726
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
 *	IN:	dvp	- vnode of directory to add subdir to.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1728
 *		dirname	- name of new directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1729
 *		vap	- attributes of new directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1730
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1731
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1732
 *		vsecp	- ACL to be set
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1734
 *	OUT:	vpp	- vnode of created directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1738
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
 *	dvp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1741
 *	 vp - ctime|mtime|atime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1743
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1744
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1745
zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1746
    caller_context_t *ct, int flags, vsecattr_t *vsecp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1747
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
	znode_t		*zp, *dzp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1749
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1750
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1751
	zfs_dirlock_t	*dl;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1752
	uint64_t	txtype;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1753
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1754
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1755
	int		zf = ZNEW;
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1756
	ksid_t		*ksid;
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1757
	uid_t		uid;
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1758
	gid_t		gid = crgetgid(cr);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1759
	zfs_acl_ids_t   acl_ids;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1760
	boolean_t	fuid_dirtied;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1762
	ASSERT(vap->va_type == VDIR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1764
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1765
	 * If we have an ephemeral id, ACL, or XVATTR then
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1766
	 * make sure file system is at proper version
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1767
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1768
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1769
	ksid = crgetsid(cr, KSID_OWNER);
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1770
	if (ksid)
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1771
		uid = ksid_getid(ksid);
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1772
	else
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1773
		uid = crgetuid(cr);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1774
	if (zfsvfs->z_use_fuids == B_FALSE &&
7847
3b5331e410c6 6754013 ZFS should always use KSID_OWNER when it's set
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7844
diff changeset
  1775
	    (vsecp || (vap->va_mask & AT_XVATTR) ||
7876
c8456365db46 6760970 zfs_mkdir falsely returns EINVAL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 7847
diff changeset
  1776
	    IS_EPHEMERAL(uid) || IS_EPHEMERAL(gid)))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1777
		return (EINVAL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1778
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1779
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1780
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1781
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1783
	if (dzp->z_pflags & ZFS_XATTR) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1787
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1788
	if (zfsvfs->z_utf8 && u8_validate(dirname,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1789
	    strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1790
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1791
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1792
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1793
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1794
		zf |= ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1795
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1796
	if (vap->va_mask & AT_XVATTR) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1797
		if ((error = secpolicy_xvattr((xvattr_t *)vap,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1798
		    crgetuid(cr), cr, vap->va_type)) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1799
			ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1800
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1801
		}
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1802
	}
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1803
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1804
	if ((error = zfs_acl_ids_create(dzp, 0, vap, cr,
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1805
	    vsecp, &acl_ids)) != 0) {
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1806
		ZFS_EXIT(zfsvfs);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1807
		return (error);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1808
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1809
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
	 * First make sure the new directory doesn't exist.
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1811
	 *
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1812
	 * Existence is checked first to make sure we don't return
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1813
	 * EACCES instead of EEXIST which can cause some applications
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1814
	 * to fail.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1816
top:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1817
	*vpp = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1818
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1819
	if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1820
	    NULL, NULL)) {
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1821
		zfs_acl_ids_free(&acl_ids);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1826
	if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) {
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1827
		zfs_acl_ids_free(&acl_ids);
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  1828
		zfs_dirent_unlock(dl);
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  1829
		ZFS_EXIT(zfsvfs);
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  1830
		return (error);
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  1831
	}
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  1832
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1833
	if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  1834
		zfs_acl_ids_free(&acl_ids);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1835
		zfs_dirent_unlock(dl);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1836
		ZFS_EXIT(zfsvfs);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1837
		return (EDQUOT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1838
	}
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1839
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
	 * Add a new entry to the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
	tx = dmu_tx_create(zfsvfs->z_os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  1844
	dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  1845
	dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1846
	fuid_dirtied = zfsvfs->z_fuid_dirty;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1847
	if (fuid_dirtied)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  1848
		zfs_fuid_txhold(zfsvfs, tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1849
	if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1850
		dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1851
		    acl_ids.z_aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1852
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1853
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1854
	dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1855
	    ZFS_SA_BASE_ATTR_SIZE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1856
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1857
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
		zfs_dirent_unlock(dl);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1860
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1861
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1862
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
		}
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  1865
		zfs_acl_ids_free(&acl_ids);
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1866
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
	 * Create new node.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1874
	zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1875
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1876
	if (fuid_dirtied)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1877
		zfs_fuid_sync(zfsvfs, tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1878
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
	 * Now put new name in parent dir.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1881
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
	(void) zfs_link_create(dl, zp, tx, ZNEW);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
	*vpp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1886
	txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1887
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1888
		txtype |= TX_CI;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1889
	zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1890
	    acl_ids.z_fuidp, vap);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1891
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  1892
	zfs_acl_ids_free(&acl_ids);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1893
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
	zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1898
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1899
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  1900
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1901
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1903
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1904
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1905
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1906
 * Remove a directory subdir entry.  If the current working
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1907
 * directory is the same as the subdir to be removed, the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
 * remove will fail.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1909
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1910
 *	IN:	dvp	- vnode of directory to remove from.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1911
 *		name	- name of directory to be removed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1912
 *		cwd	- vnode of current working directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1913
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1914
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1915
 *		flags	- case flags
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1916
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1917
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1918
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1919
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1920
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1921
 *	dvp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1922
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1923
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1924
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1925
zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1926
    caller_context_t *ct, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
	znode_t		*dzp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
	znode_t		*zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
	vnode_t		*vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1932
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1933
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1934
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1935
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1936
	int		zflg = ZEXISTS;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1938
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1939
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  1940
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1941
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1942
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1943
		zflg |= ZCILOOK;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1944
top:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1945
	zp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1946
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1947
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
	 * Attempt to lock directory; fail if entry doesn't exist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1949
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1950
	if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1951
	    NULL, NULL)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1952
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1953
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1954
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1955
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1956
	vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1957
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1958
	if (error = zfs_zaccess_delete(dzp, zp, cr)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1959
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1960
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1961
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1962
	if (vp->v_type != VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1963
		error = ENOTDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1964
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1965
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1966
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1967
	if (vp == cwd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1968
		error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1969
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1972
	vnevent_rmdir(vp, dvp, name, ct);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1973
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1974
	/*
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1975
	 * Grab a lock on the directory to make sure that noone is
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1976
	 * trying to add (or lookup) entries while we are removing it.
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1977
	 */
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1978
	rw_enter(&zp->z_name_lock, RW_WRITER);
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1979
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1980
	/*
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1981
	 * Grab a lock on the parent pointer to make sure we play well
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1982
	 * with the treewalk and directory rename code.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1983
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
	rw_enter(&zp->z_parent_lock, RW_WRITER);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1985
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1986
	tx = dmu_tx_create(zfsvfs->z_os);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  1987
	dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1988
	dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  1989
	dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1990
	zfs_sa_upgrade_txholds(tx, zp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  1991
	zfs_sa_upgrade_txholds(tx, dzp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1992
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
		rw_exit(&zp->z_parent_lock);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  1995
		rw_exit(&zp->z_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
		zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
		VN_RELE(vp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  1998
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  1999
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  2000
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  2003
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2004
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2008
	error = zfs_link_destroy(dl, zp, tx, zflg, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2009
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2010
	if (error == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2011
		uint64_t txtype = TX_RMDIR;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2012
		if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2013
			txtype |= TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2014
		zfs_log_remove(zilog, tx, txtype, dzp, name);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2015
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2016
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2017
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2018
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2019
	rw_exit(&zp->z_parent_lock);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3638
diff changeset
  2020
	rw_exit(&zp->z_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
out:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
	zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
	VN_RELE(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2026
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2027
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2028
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2034
 * Read as many directory entries as will fit into the provided
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2035
 * buffer from the given directory cursor position (specified in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2036
 * the uio structure.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2037
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2038
 *	IN:	vp	- vnode of directory to read.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2039
 *		uio	- structure supplying read location, range info,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2040
 *			  and return buffer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2041
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2042
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2043
 *		flags	- case flags
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2044
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2045
 *	OUT:	uio	- updated offset and range, buffer filled.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2046
 *		eofp	- set to true if end-of-file detected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2047
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2048
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2049
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2050
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2051
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
 *	vp - atime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2053
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2054
 * Note that the low 4 bits of the cookie returned by zap is always zero.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
 * This allows us to use the low range for "special" directory entries:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
 * We use 0 for '.', and 1 for '..'.  If this is the root of the filesystem,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2057
 * we use the offset 2 for the '.zfs' directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2059
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2060
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2061
zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2062
    caller_context_t *ct, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2063
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2064
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2065
	iovec_t		*iovp;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2066
	edirent_t	*eodp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2067
	dirent64_t	*odp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2068
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2069
	objset_t	*os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2070
	caddr_t		outbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2071
	size_t		bufsize;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
	zap_cursor_t	zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2073
	zap_attribute_t	zap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2074
	uint_t		bytes_wanted;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2075
	uint64_t	offset; /* must be unsigned; checks for < 1 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2076
	uint64_t	parent;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2077
	int		local_eof;
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2078
	int		outcount;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2079
	int		error;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2080
	uint8_t		prefetch;
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2081
	boolean_t	check_sysattrs;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2083
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2084
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2086
	if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2087
	    &parent, sizeof (parent))) != 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2088
		ZFS_EXIT(zfsvfs);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2089
		return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2090
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2091
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
	 * If we are not given an eof variable,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2094
	 * use a local one.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2095
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2096
	if (eofp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2097
		eofp = &local_eof;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2098
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2099
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2100
	 * Check for valid iov_len.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2101
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2102
	if (uio->uio_iov->iov_len <= 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2104
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2105
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2106
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2107
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
	 * Quit if directory has been removed (posix)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
	 */
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  2110
	if ((*eofp = zp->z_unlinked) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2111
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2115
	error = 0;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2116
	os = zfsvfs->z_os;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2117
	offset = uio->uio_loffset;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2118
	prefetch = zp->z_zn_prefetch;
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2119
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2120
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
	 * Initialize the iterator cursor.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2122
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
	if (offset <= 3) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2125
		 * Start iteration from the beginning of the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2126
		 */
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2127
		zap_cursor_init(&zc, os, zp->z_id);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2128
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
		 * The offset is a serialized cursor.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
		 */
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2132
		zap_cursor_init_serialized(&zc, os, zp->z_id, offset);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
	 * Get space to change directory entries into fs independent format.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
	iovp = uio->uio_iov;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2139
	bytes_wanted = iovp->iov_len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
	if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
		bufsize = bytes_wanted;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
		outbuf = kmem_alloc(bufsize, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
		odp = (struct dirent64 *)outbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
		bufsize = bytes_wanted;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2146
		odp = (struct dirent64 *)iovp->iov_base;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2147
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2148
	eodp = (struct edirent *)odp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2150
	/*
7757
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  2151
	 * If this VFS supports the system attribute view interface; and
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  2152
	 * we're looking at an extended attribute directory; and we care
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  2153
	 * about normalization conflicts on this vfs; then we must check
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  2154
	 * for normalization conflicts with the sysattr name space.
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2155
	 */
7757
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  2156
	check_sysattrs = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2157
	    (vp->v_flag & V_XATTRDIR) && zfsvfs->z_norm &&
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2158
	    (flags & V_RDDIR_ENTFLAGS);
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2159
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2160
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
	 * Transform to file-system independent format
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2163
	outcount = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2164
	while (outcount < bytes_wanted) {
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2165
		ino64_t objnum;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2166
		ushort_t reclen;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2167
		off64_t *next;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2168
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2170
		 * Special case `.', `..', and `.zfs'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2171
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2172
		if (offset == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2173
			(void) strcpy(zap.za_name, ".");
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2174
			zap.za_normalization_conflict = 0;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2175
			objnum = zp->z_id;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
		} else if (offset == 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
			(void) strcpy(zap.za_name, "..");
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2178
			zap.za_normalization_conflict = 0;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2179
			objnum = parent;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
		} else if (offset == 2 && zfs_show_ctldir(zp)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
			(void) strcpy(zap.za_name, ZFS_CTLDIR_NAME);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2182
			zap.za_normalization_conflict = 0;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2183
			objnum = ZFSCTL_INO_ROOT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
			 * Grab next entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
			if (error = zap_cursor_retrieve(&zc, &zap)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
				if ((*eofp = (error == ENOENT)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
					break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
				else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2192
					goto update;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
			if (zap.za_integer_length != 8 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
			    zap.za_num_integers != 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
				cmn_err(CE_WARN, "zap_readdir: bad directory "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
				    "entry, obj = %lld, offset = %lld\n",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2199
				    (u_longlong_t)zp->z_id,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
				    (u_longlong_t)offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
				error = ENXIO;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
				goto update;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
			}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2204
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2205
			objnum = ZFS_DIRENT_OBJ(zap.za_first_integer);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2206
			/*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2207
			 * MacOS X can extract the object type here such as:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2208
			 * uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2209
			 */
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2210
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2211
			if (check_sysattrs && !zap.za_normalization_conflict) {
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2212
				zap.za_normalization_conflict =
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2213
				    xattr_sysattr_casechk(zap.za_name);
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5642
diff changeset
  2214
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2216
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2217
		if (flags & V_RDDIR_ACCFILTER) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2218
			/*
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2219
			 * If we have no access at all, don't include
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2220
			 * this entry in the returned information
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2221
			 */
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2222
			znode_t	*ezp;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2223
			if (zfs_zget(zp->z_zfsvfs, objnum, &ezp) != 0)
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2224
				goto skip_entry;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2225
			if (!zfs_has_access(ezp, cr)) {
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2226
				VN_RELE(ZTOV(ezp));
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2227
				goto skip_entry;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2228
			}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2229
			VN_RELE(ZTOV(ezp));
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2230
		}
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2231
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2232
		if (flags & V_RDDIR_ENTFLAGS)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2233
			reclen = EDIRENT_RECLEN(strlen(zap.za_name));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2234
		else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2235
			reclen = DIRENT64_RECLEN(strlen(zap.za_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
		 * Will this entry fit in the buffer?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
		 */
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2240
		if (outcount + reclen > bufsize) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
			 * Did we manage to fit anything in the buffer?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2244
			if (!outcount) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
				goto update;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2250
		if (flags & V_RDDIR_ENTFLAGS) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2251
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2252
			 * Add extended flag entry:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2253
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2254
			eodp->ed_ino = objnum;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2255
			eodp->ed_reclen = reclen;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2256
			/* NOTE: ed_off is the offset for the *next* entry */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2257
			next = &(eodp->ed_off);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2258
			eodp->ed_eflags = zap.za_normalization_conflict ?
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2259
			    ED_CASE_CONFLICT : 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2260
			(void) strncpy(eodp->ed_name, zap.za_name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2261
			    EDIRENT_NAMELEN(reclen));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2262
			eodp = (edirent_t *)((intptr_t)eodp + reclen);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2263
		} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2264
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2265
			 * Add normal entry:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2266
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2267
			odp->d_ino = objnum;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2268
			odp->d_reclen = reclen;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2269
			/* NOTE: d_off is the offset for the *next* entry */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2270
			next = &(odp->d_off);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2271
			(void) strncpy(odp->d_name, zap.za_name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2272
			    DIRENT64_NAMELEN(reclen));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2273
			odp = (dirent64_t *)((intptr_t)odp + reclen);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2274
		}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2275
		outcount += reclen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2277
		ASSERT(outcount <= bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
		/* Prefetch znode */
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2280
		if (prefetch)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3898
diff changeset
  2281
			dmu_prefetch(os, objnum, 0, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2282
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  2283
	skip_entry:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2284
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2285
		 * Move to the next entry, fill in the previous offset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2287
		if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2288
			zap_cursor_advance(&zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2289
			offset = zap_cursor_serialize(&zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2290
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2291
			offset += 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2292
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2293
		*next = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
	}
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
  2295
	zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
	if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2298
		iovp->iov_base += outcount;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2299
		iovp->iov_len -= outcount;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2300
		uio->uio_resid -= outcount;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2301
	} else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2302
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2303
		 * Reset the pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2304
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2305
		offset = uio->uio_loffset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2307
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2308
update:
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 869
diff changeset
  2309
	zap_cursor_fini(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
	if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
		kmem_free(outbuf, bufsize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2312
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2313
	if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2314
		error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2315
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2316
	ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2317
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2318
	uio->uio_loffset = offset;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2320
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2321
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2322
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4709
diff changeset
  2323
ulong_t zfs_fsync_sync_cnt = 4;
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4709
diff changeset
  2324
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2325
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2326
zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
	znode_t	*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2330
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2331
	/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2332
	 * Regardless of whether this is required for standards conformance,
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2333
	 * this is the logical behavior when fsync() is called on a file with
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2334
	 * dirty pages.  We use B_ASYNC since the ZIL transactions are already
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2335
	 * going to be pushed out as part of the zil_commit().
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2336
	 */
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2337
	if (vn_has_cached_data(vp) && !(syncflag & FNODSYNC) &&
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2338
	    (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2339
		(void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr, ct);
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  2340
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4709
diff changeset
  2341
	(void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4709
diff changeset
  2342
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2343
	if (zfsvfs->z_os->os_sync != ZFS_SYNC_DISABLED) {
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2344
		ZFS_ENTER(zfsvfs);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2345
		ZFS_VERIFY_ZP(zp);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2346
		zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2347
		ZFS_EXIT(zfsvfs);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  2348
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2349
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2350
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2351
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2352
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
 * Get the requested file attributes and place them in the provided
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
 * vattr structure.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2356
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2357
 *	IN:	vp	- vnode of file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2358
 *		vap	- va_mask identifies requested attributes.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2359
 *			  If AT_XVATTR set, then optional attrs are requested
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2360
 *		flags	- ATTR_NOACLCHECK (CIFS server context)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2362
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2364
 *	OUT:	vap	- attribute values.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
 *	RETURN:	0 (always succeeds)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2367
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2370
zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2371
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2375
	int	error = 0;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4339
diff changeset
  2376
	uint64_t links;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2377
	uint64_t mtime[2], ctime[2];
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2378
	xvattr_t *xvap = (xvattr_t *)vap;	/* vap may be an xvattr_t * */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2379
	xoptattr_t *xoap = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2380
	boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2381
	sa_bulk_attr_t bulk[2];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2382
	int count = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2384
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2385
	ZFS_VERIFY_ZP(zp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2386
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2387
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2388
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2389
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2390
	if ((error = sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) != 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2391
		ZFS_EXIT(zfsvfs);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2392
		return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2393
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2394
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2395
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2396
	 * If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2397
	 * Also, if we are the owner don't bother, since owner should
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2398
	 * always be allowed to read basic attributes of file.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2399
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2400
	if (!(zp->z_pflags & ZFS_ACL_TRIVIAL) && (zp->z_uid != crgetuid(cr))) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2401
		if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2402
		    skipaclchk, cr)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2403
			ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2404
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2405
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2406
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2407
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2408
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
	 * Return all attributes.  It's cheaper to provide the answer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2410
	 * than to determine whether we were asked the question.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2411
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2412
9774
0bb234ab2287 6788152 ZFS panic deadlock: cycle in blocking chain via zfs_zget
Ray Hassan <Ray.Hassan@Sun.COM>
parents: 9749
diff changeset
  2413
	mutex_enter(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2414
	vap->va_type = vp->v_type;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2415
	vap->va_mode = zp->z_mode & MODEMASK;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2416
	vap->va_uid = zp->z_uid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2417
	vap->va_gid = zp->z_gid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2418
	vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2419
	vap->va_nodeid = zp->z_id;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4339
diff changeset
  2420
	if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp))
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2421
		links = zp->z_links + 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4339
diff changeset
  2422
	else
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2423
		links = zp->z_links;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4339
diff changeset
  2424
	vap->va_nlink = MIN(links, UINT32_MAX);	/* nlink_t limit! */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2425
	vap->va_size = zp->z_size;
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1773
diff changeset
  2426
	vap->va_rdev = vp->v_rdev;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2427
	vap->va_seq = zp->z_seq;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2429
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2430
	 * Add in any requested optional attributes and the create time.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2431
	 * Also set the corresponding bits in the returned attribute bitmap.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2432
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2433
	if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2434
		if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2435
			xoap->xoa_archive =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2436
			    ((zp->z_pflags & ZFS_ARCHIVE) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2437
			XVA_SET_RTN(xvap, XAT_ARCHIVE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2438
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2439
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2440
		if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2441
			xoap->xoa_readonly =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2442
			    ((zp->z_pflags & ZFS_READONLY) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2443
			XVA_SET_RTN(xvap, XAT_READONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2444
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2445
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2446
		if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2447
			xoap->xoa_system =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2448
			    ((zp->z_pflags & ZFS_SYSTEM) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2449
			XVA_SET_RTN(xvap, XAT_SYSTEM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2450
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2451
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2452
		if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2453
			xoap->xoa_hidden =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2454
			    ((zp->z_pflags & ZFS_HIDDEN) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2455
			XVA_SET_RTN(xvap, XAT_HIDDEN);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2456
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2457
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2458
		if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2459
			xoap->xoa_nounlink =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2460
			    ((zp->z_pflags & ZFS_NOUNLINK) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2461
			XVA_SET_RTN(xvap, XAT_NOUNLINK);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2462
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2463
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2464
		if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2465
			xoap->xoa_immutable =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2466
			    ((zp->z_pflags & ZFS_IMMUTABLE) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2467
			XVA_SET_RTN(xvap, XAT_IMMUTABLE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2468
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2469
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2470
		if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2471
			xoap->xoa_appendonly =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2472
			    ((zp->z_pflags & ZFS_APPENDONLY) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2473
			XVA_SET_RTN(xvap, XAT_APPENDONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2474
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2475
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2476
		if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2477
			xoap->xoa_nodump =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2478
			    ((zp->z_pflags & ZFS_NODUMP) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2479
			XVA_SET_RTN(xvap, XAT_NODUMP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2480
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2481
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2482
		if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2483
			xoap->xoa_opaque =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2484
			    ((zp->z_pflags & ZFS_OPAQUE) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2485
			XVA_SET_RTN(xvap, XAT_OPAQUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2486
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2487
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2488
		if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2489
			xoap->xoa_av_quarantined =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2490
			    ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2491
			XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2492
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2493
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2494
		if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2495
			xoap->xoa_av_modified =
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2496
			    ((zp->z_pflags & ZFS_AV_MODIFIED) != 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2497
			XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2498
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2499
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2500
		if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2501
		    vp->v_type == VREG) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2502
			zfs_sa_get_scanstamp(zp, xvap);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2503
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2504
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2505
		if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2506
			uint64_t times[2];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2507
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2508
			(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2509
			    times, sizeof (times));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2510
			ZFS_TIME_DECODE(&xoap->xoa_createtime, times);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2511
			XVA_SET_RTN(xvap, XAT_CREATETIME);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2512
		}
10793
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2513
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2514
		if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2515
			xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0);
10793
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2516
			XVA_SET_RTN(xvap, XAT_REPARSE);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2517
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2518
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2519
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2520
	ZFS_TIME_DECODE(&vap->va_atime, zp->z_atime);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2521
	ZFS_TIME_DECODE(&vap->va_mtime, mtime);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2522
	ZFS_TIME_DECODE(&vap->va_ctime, ctime);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2523
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2524
	mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2525
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2526
	sa_object_size(zp->z_sa_hdl, &vap->va_blksize, &vap->va_nblocks);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2528
	if (zp->z_blksz == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2529
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2530
		 * Block size hasn't been set; suggest maximal I/O transfers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2531
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2532
		vap->va_blksize = zfsvfs->z_max_blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2533
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2534
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
 * Set the file attributes to the values contained in the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
 * vattr structure.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
 *	IN:	vp	- vnode of file to be modified.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
 *		vap	- new attribute values.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2545
 *			  If AT_XVATTR set, then optional attrs are being set
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
 *		flags	- ATTR_UTIME set if non-default time values provided.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2547
 *			- ATTR_NOACLCHECK (CIFS context only).
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2549
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2550
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2551
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2552
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2553
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2554
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2555
 *	vp - ctime updated, mtime updated if size changed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2556
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2557
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2558
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2559
zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2560
	caller_context_t *ct)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2561
{
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  2562
	znode_t		*zp = VTOZ(vp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  2564
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
	dmu_tx_t	*tx;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2566
	vattr_t		oldva;
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2567
	xvattr_t	tmpxvattr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
	uint_t		mask = vap->va_mask;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2569
	uint_t		saved_mask;
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2570
	int		trim_mask = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
	uint64_t	new_mode;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2572
	uint64_t	new_uid, new_gid;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2573
	uint64_t	xattr_obj = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2574
	uint64_t	mtime[2], ctime[2];
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  2575
	znode_t		*attrzp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2576
	int		need_policy = FALSE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2577
	int		err, err2;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2578
	zfs_fuid_info_t *fuidp = NULL;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2579
	xvattr_t *xvap = (xvattr_t *)vap;	/* vap may be an xvattr_t * */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2580
	xoptattr_t	*xoap;
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
  2581
	zfs_acl_t	*aclp = NULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2582
	boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2583
	boolean_t	fuid_dirtied = B_FALSE;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2584
	sa_bulk_attr_t	bulk[7], xattr_bulk[7];
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2585
	int		count = 0, xattr_count = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2586
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2587
	if (mask == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2588
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
	if (mask & AT_NOSET)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2593
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2594
	ZFS_VERIFY_ZP(zp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2595
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2596
	zilog = zfsvfs->z_log;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2597
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2598
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2599
	 * Make sure that if we have ephemeral uid/gid or xvattr specified
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2600
	 * that file system is at proper version level
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2601
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2602
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2603
	if (zfsvfs->z_use_fuids == B_FALSE &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2604
	    (((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2605
	    ((mask & AT_GID) && IS_EPHEMERAL(vap->va_gid)) ||
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2606
	    (mask & AT_XVATTR))) {
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2607
		ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2608
		return (EINVAL);
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2609
	}
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2610
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2611
	if (mask & AT_SIZE && vp->v_type == VDIR) {
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2612
		ZFS_EXIT(zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
		return (EISDIR);
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2614
	}
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2615
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2616
	if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO) {
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2617
		ZFS_EXIT(zfsvfs);
1308
997e6a49c409 6362908 nfsv4-test: RENAME does not check PERM with NFSv4/ZFS
marks
parents: 1298
diff changeset
  2618
		return (EINVAL);
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2619
	}
1308
997e6a49c409 6362908 nfsv4-test: RENAME does not check PERM with NFSv4/ZFS
marks
parents: 1298
diff changeset
  2620
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2621
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2622
	 * If this is an xvattr_t, then get a pointer to the structure of
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2623
	 * optional attributes.  If this is NULL, then we have a vattr_t.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2624
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2625
	xoap = xva_getxoptattr(xvap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2626
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2627
	xva_init(&tmpxvattr);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2628
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2629
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2630
	 * Immutable files can only alter immutable bit and atime
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2631
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2632
	if ((zp->z_pflags & ZFS_IMMUTABLE) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2633
	    ((mask & (AT_SIZE|AT_UID|AT_GID|AT_MTIME|AT_MODE)) ||
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2634
	    ((mask & AT_XVATTR) && XVA_ISSET_REQ(xvap, XAT_CREATETIME)))) {
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2635
		ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2636
		return (EPERM);
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2637
	}
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2638
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2639
	if ((mask & AT_SIZE) && (zp->z_pflags & ZFS_READONLY)) {
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2640
		ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2641
		return (EPERM);
5386
fa920350a914 6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents: 5367
diff changeset
  2642
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
6064
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2644
	/*
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2645
	 * Verify timestamps doesn't overflow 32 bits.
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2646
	 * ZFS can handle large timestamps, but 32bit syscalls can't
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2647
	 * handle times greater than 2039.  This check should be removed
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2648
	 * once large timestamps are fully supported.
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2649
	 */
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2650
	if (mask & (AT_ATIME | AT_MTIME)) {
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2651
		if (((mask & AT_ATIME) && TIMESPEC_OVERFLOW(&vap->va_atime)) ||
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2652
		    ((mask & AT_MTIME) && TIMESPEC_OVERFLOW(&vap->va_mtime))) {
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2653
			ZFS_EXIT(zfsvfs);
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2654
			return (EOVERFLOW);
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2655
		}
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2656
	}
45d29804ab93 6629604 ZFS: lstat64() on ZFS file returns EOVERFLOW
marks
parents: 6036
diff changeset
  2657
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2658
top:
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  2659
	attrzp = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9951
diff changeset
  2661
	/* Can this be moved to before the top label? */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2662
	if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2663
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
		return (EROFS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
	 * First validate permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
	if (mask & AT_SIZE) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2672
		err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
		if (err) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
			return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
		}
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2677
		/*
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2678
		 * XXX - Note, we are not providing any open
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2679
		 * mode flags here (like FNDELAY), so we may
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2680
		 * block if there are locks present... this
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2681
		 * should be addressed in openat().
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2682
		 */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  2683
		/* XXX - would it be OK to generate a log record here? */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  2684
		err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2685
		if (err) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2686
			ZFS_EXIT(zfsvfs);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2687
			return (err);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  2688
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2689
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2690
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2691
	if (mask & (AT_ATIME|AT_MTIME) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2692
	    ((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2693
	    XVA_ISSET_REQ(xvap, XAT_READONLY) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2694
	    XVA_ISSET_REQ(xvap, XAT_ARCHIVE) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2695
	    XVA_ISSET_REQ(xvap, XAT_CREATETIME) ||
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2696
	    XVA_ISSET_REQ(xvap, XAT_SYSTEM)))) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2697
		need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2698
		    skipaclchk, cr);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2699
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2700
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2701
	if (mask & (AT_UID|AT_GID)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2702
		int	idmask = (mask & (AT_UID|AT_GID));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2703
		int	take_owner;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2704
		int	take_group;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2706
		/*
913
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2707
		 * NOTE: even if a new mode is being set,
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2708
		 * we may clear S_ISUID/S_ISGID bits.
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2709
		 */
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2710
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2711
		if (!(mask & AT_MODE))
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2712
			vap->va_mode = zp->z_mode;
913
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2713
e99aef503251 6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents: 905
diff changeset
  2714
		/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2715
		 * Take ownership or chgrp to group we are a member of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2716
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
		take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr));
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2719
		take_group = (mask & AT_GID) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2720
		    zfs_groupmember(zfsvfs, vap->va_gid, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
		 * If both AT_UID and AT_GID are set then take_owner and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
		 * take_group must both be set in order to allow taking
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
		 * ownership.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
		 * Otherwise, send the check through secpolicy_vnode_setattr()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
		if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
		    ((idmask == AT_UID) && take_owner) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
		    ((idmask == AT_GID) && take_group)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2734
			if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2735
			    skipaclchk, cr) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2736
				/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2737
				 * Remove setuid/setgid for non-privileged users
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2738
				 */
1115
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2739
				secpolicy_setid_clear(vap, cr);
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2740
				trim_mask = (mask & (AT_UID|AT_GID));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2741
			} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2742
				need_policy =  TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2743
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2744
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2745
			need_policy =  TRUE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2746
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2749
	mutex_enter(&zp->z_lock);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2750
	oldva.va_mode = zp->z_mode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2751
	oldva.va_uid = zp->z_uid;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2752
	oldva.va_gid = zp->z_gid;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2753
	if (mask & AT_XVATTR) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2754
		/*
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2755
		 * Update xvattr mask to include only those attributes
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2756
		 * that are actually changing.
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2757
		 *
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2758
		 * the bits will be restored prior to actually setting
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2759
		 * the attributes so the caller thinks they were set.
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2760
		 */
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2761
		if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2762
			if (xoap->xoa_appendonly !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2763
			    ((zp->z_pflags & ZFS_APPENDONLY) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2764
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2765
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2766
				XVA_CLR_REQ(xvap, XAT_APPENDONLY);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2767
				XVA_SET_REQ(&tmpxvattr, XAT_APPENDONLY);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2768
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2769
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2770
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2771
		if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2772
			if (xoap->xoa_nounlink !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2773
			    ((zp->z_pflags & ZFS_NOUNLINK) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2774
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2775
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2776
				XVA_CLR_REQ(xvap, XAT_NOUNLINK);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2777
				XVA_SET_REQ(&tmpxvattr, XAT_NOUNLINK);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2778
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2779
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2780
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2781
		if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2782
			if (xoap->xoa_immutable !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2783
			    ((zp->z_pflags & ZFS_IMMUTABLE) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2784
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2785
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2786
				XVA_CLR_REQ(xvap, XAT_IMMUTABLE);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2787
				XVA_SET_REQ(&tmpxvattr, XAT_IMMUTABLE);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2788
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2789
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2790
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2791
		if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2792
			if (xoap->xoa_nodump !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2793
			    ((zp->z_pflags & ZFS_NODUMP) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2794
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2795
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2796
				XVA_CLR_REQ(xvap, XAT_NODUMP);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2797
				XVA_SET_REQ(&tmpxvattr, XAT_NODUMP);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2798
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2799
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2800
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2801
		if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2802
			if (xoap->xoa_av_modified !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2803
			    ((zp->z_pflags & ZFS_AV_MODIFIED) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2804
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2805
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2806
				XVA_CLR_REQ(xvap, XAT_AV_MODIFIED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2807
				XVA_SET_REQ(&tmpxvattr, XAT_AV_MODIFIED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2808
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2809
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2810
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2811
		if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2812
			if ((vp->v_type != VREG &&
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2813
			    xoap->xoa_av_quarantined) ||
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2814
			    xoap->xoa_av_quarantined !=
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2815
			    ((zp->z_pflags & ZFS_AV_QUARANTINED) != 0)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2816
				need_policy = TRUE;
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2817
			} else {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2818
				XVA_CLR_REQ(xvap, XAT_AV_QUARANTINED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2819
				XVA_SET_REQ(&tmpxvattr, XAT_AV_QUARANTINED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2820
			}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2821
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2822
10793
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2823
		if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2824
			mutex_exit(&zp->z_lock);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2825
			ZFS_EXIT(zfsvfs);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2826
			return (EPERM);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2827
		}
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10440
diff changeset
  2828
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2829
		if (need_policy == FALSE &&
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2830
		    (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) ||
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  2831
		    XVA_ISSET_REQ(xvap, XAT_OPAQUE))) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2832
			need_policy = TRUE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2833
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2834
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2835
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2836
	mutex_exit(&zp->z_lock);
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2837
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2838
	if (mask & AT_MODE) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2839
		if (zfs_zaccess(zp, ACE_WRITE_ACL, 0, skipaclchk, cr) == 0) {
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2840
			err = secpolicy_setid_setsticky_clear(vp, vap,
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2841
			    &oldva, cr);
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2842
			if (err) {
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2843
				ZFS_EXIT(zfsvfs);
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2844
				return (err);
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2845
			}
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2846
			trim_mask |= AT_MODE;
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2847
		} else {
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2848
			need_policy = TRUE;
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2849
		}
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2850
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2851
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2852
	if (need_policy) {
1115
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2853
		/*
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2854
		 * If trim_mask is set then take ownership
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2855
		 * has been granted or write_acl is present and user
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2856
		 * has the ability to modify mode.  In that case remove
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2857
		 * UID|GID and or MODE from mask so that
1115
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2858
		 * secpolicy_vnode_setattr() doesn't revoke it.
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2859
		 */
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2860
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2861
		if (trim_mask) {
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2862
			saved_mask = vap->va_mask;
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2863
			vap->va_mask &= ~trim_mask;
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2864
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2865
		err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2866
		    (int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2867
		if (err) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2868
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2869
			return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2870
		}
1115
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2871
2b9c0c6b5148 6362068 zfs chown/chgrp doesn't always work
marks
parents: 913
diff changeset
  2872
		if (trim_mask)
2796
95109e1ced2b 6445680 Having write_acl allowed in an ACL doesn't give the ability to set the mode via chmod
marks
parents: 2752
diff changeset
  2873
			vap->va_mask |= saved_mask;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2874
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2876
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2877
	 * secpolicy_vnode_setattr, or take ownership may have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2878
	 * changed va_mask
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2879
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2880
	mask = vap->va_mask;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2881
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2882
	if ((mask & (AT_UID | AT_GID))) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2883
		(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &xattr_obj,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2884
		    sizeof (xattr_obj));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2885
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2886
		if (xattr_obj) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2887
			err = zfs_zget(zp->z_zfsvfs, xattr_obj, &attrzp);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2888
			if (err)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2889
				goto out2;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2890
		}
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2891
		if (mask & AT_UID) {
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2892
			new_uid = zfs_fuid_create(zfsvfs,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2893
			    (uint64_t)vap->va_uid, cr, ZFS_OWNER, &fuidp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2894
			if (vap->va_uid != zp->z_uid &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2895
			    zfs_fuid_overquota(zfsvfs, B_FALSE, new_uid)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2896
				err = EDQUOT;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2897
				goto out2;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2898
			}
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  2899
		}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2900
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2901
		if (mask & AT_GID) {
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2902
			new_gid = zfs_fuid_create(zfsvfs, (uint64_t)vap->va_gid,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2903
			    cr, ZFS_GROUP, &fuidp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2904
			if (new_gid != zp->z_gid &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2905
			    zfs_fuid_overquota(zfsvfs, B_TRUE, new_gid)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2906
				err = EDQUOT;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2907
				goto out2;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2908
			}
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  2909
		}
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  2910
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2911
	tx = dmu_tx_create(zfsvfs->z_os);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2912
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2913
	if (mask & AT_MODE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2914
		uint64_t pmode = zp->z_mode;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2915
		new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2916
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2917
		if (err = zfs_acl_chmod_setattr(zp, &aclp, new_mode))
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2918
			goto out;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2919
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2920
		if (!zp->z_is_sa && ZFS_EXTERNAL_ACL(zp)) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2921
			/*
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2922
			 * Are we upgrading ACL from old V0 format
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2923
			 * to V1 format?
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2924
			 */
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2925
			if (zfsvfs->z_version <= ZPL_VERSION_FUID &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2926
			    ZNODE_ACL_VERSION(zp) ==
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2927
			    ZFS_ACL_VERSION_INITIAL) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2928
				dmu_tx_hold_free(tx,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2929
				    ZFS_EXTERNAL_ACL(zp), 0,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2930
				    DMU_OBJECT_END);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2931
				dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2932
				    0, aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2933
			} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2934
				dmu_tx_hold_write(tx, ZFS_EXTERNAL_ACL(zp), 0,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2935
				    aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2936
			}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2937
		} else if (!zp->z_is_sa && aclp->z_acl_bytes > ZFS_ACE_SPACE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2938
			dmu_tx_hold_write(tx, DMU_NEW_OBJECT,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2939
			    0, aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2940
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2941
		dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2942
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2943
		if ((mask & AT_XVATTR) &&
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2944
		    XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2945
			dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2946
		else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2947
			dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2948
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2949
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2950
	if (attrzp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2951
		dmu_tx_hold_sa(tx, attrzp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2952
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2953
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2954
	fuid_dirtied = zfsvfs->z_fuid_dirty;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2955
	if (fuid_dirtied)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2956
		zfs_fuid_txhold(zfsvfs, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2957
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2958
	zfs_sa_upgrade_txholds(tx, zp);
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  2959
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  2960
	err = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
	if (err) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2962
		if (err == ERESTART)
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  2963
			dmu_tx_wait(tx);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  2964
		goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2965
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2966
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2967
	count = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2968
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2969
	 * Set each attribute requested.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2970
	 * We group settings according to the locks they need to acquire.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2971
	 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2972
	 * Note: you cannot set ctime directly, although it will be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2973
	 * updated as a side-effect of calling this function.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2974
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2976
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2977
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2978
	SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2979
	    &zp->z_pflags, sizeof (zp->z_pflags));
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2980
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2981
	if (attrzp) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2982
		mutex_enter(&attrzp->z_lock);
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2983
		SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2984
		    SA_ZPL_FLAGS(zfsvfs), NULL, &attrzp->z_pflags,
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2985
		    sizeof (attrzp->z_pflags));
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2986
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  2987
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2988
	if (mask & (AT_UID|AT_GID)) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2989
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2990
		if (mask & AT_UID) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2991
			SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2992
			    &new_uid, sizeof (new_uid));
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2993
			zp->z_uid = zfs_fuid_map_id(zfsvfs, new_uid,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2994
			    cr, ZFS_OWNER);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2995
			if (attrzp) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2996
				SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2997
				    SA_ZPL_UID(zfsvfs), NULL, &new_uid,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  2998
				    sizeof (new_uid));
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  2999
				attrzp->z_uid = zp->z_uid;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3000
			}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3001
		}
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3002
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3003
		if (mask & AT_GID) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3004
			SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs),
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3005
			    NULL, &new_gid, sizeof (new_gid));
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3006
			zp->z_gid = zfs_fuid_map_id(zfsvfs, new_gid, cr,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3007
			    ZFS_GROUP);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3008
			if (attrzp) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3009
				SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3010
				    SA_ZPL_GID(zfsvfs), NULL, &new_gid,
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3011
				    sizeof (new_gid));
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3012
				attrzp->z_gid = zp->z_gid;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3013
			}
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3014
		}
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3015
		if (!(mask & AT_MODE)) {
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3016
			SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs),
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3017
			    NULL, &new_mode, sizeof (new_mode));
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3018
			new_mode = zp->z_mode;
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3019
		}
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3020
		err = zfs_acl_chown_setattr(zp);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3021
		ASSERT(err == 0);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3022
		if (attrzp) {
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3023
			err = zfs_acl_chown_setattr(attrzp);
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3024
			ASSERT(err == 0);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3025
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3026
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3027
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
	if (mask & AT_MODE) {
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
  3029
		mutex_enter(&zp->z_acl_lock);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3030
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3031
		    &new_mode, sizeof (new_mode));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3032
		zp->z_mode = new_mode;
12164
0eb8d6741e37 PSARC/2010/029 Improved ACL interoperability
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12123
diff changeset
  3033
		ASSERT3U((uintptr_t)aclp, !=, NULL);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3034
		err = zfs_aclset_common(zp, aclp, cr, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3035
		ASSERT3U(err, ==, 0);
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  3036
		zp->z_acl_cached = aclp;
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  3037
		aclp = NULL;
5824
1d2d522d19b5 6603908 can't change mode if FS/dir is out of quota
marks
parents: 5771
diff changeset
  3038
		mutex_exit(&zp->z_acl_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3040
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3041
	if (attrzp)
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3042
		mutex_exit(&attrzp->z_lock);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3043
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3044
	if (mask & AT_ATIME) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3045
		ZFS_TIME_ENCODE(&vap->va_atime, zp->z_atime);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3046
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3047
		    &zp->z_atime, sizeof (zp->z_atime));
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3048
	}
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3049
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3050
	if (mask & AT_MTIME) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3051
		ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3052
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3053
		    mtime, sizeof (mtime));
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3054
	}
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3055
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  3056
	/* XXX - shouldn't this be done *before* the ATIME/MTIME checks? */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3057
	if (mask & AT_SIZE && !(mask & AT_MTIME)) {
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  3058
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs),
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  3059
		    NULL, mtime, sizeof (mtime));
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3060
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3061
		    &ctime, sizeof (ctime));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3062
		zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3063
		    B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3064
	} else if (mask != 0) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3065
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3066
		    &ctime, sizeof (ctime));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3067
		zfs_tstamp_update_setup(zp, STATE_CHANGED, mtime, ctime,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3068
		    B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3069
		if (attrzp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3070
			SA_ADD_BULK_ATTR(xattr_bulk, xattr_count,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3071
			    SA_ZPL_CTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3072
			    &ctime, sizeof (ctime));
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3073
			zfs_tstamp_update_setup(attrzp, STATE_CHANGED,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3074
			    mtime, ctime, B_TRUE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3075
		}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3076
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3077
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3078
	 * Do this after setting timestamps to prevent timestamp
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3079
	 * update from toggling bit
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3080
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3081
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3082
	if (xoap && (mask & AT_XVATTR)) {
8190
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3083
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3084
		/*
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3085
		 * restore trimmed off masks
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3086
		 * so that return masks can be set for caller.
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3087
		 */
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3088
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3089
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_APPENDONLY)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3090
			XVA_SET_REQ(xvap, XAT_APPENDONLY);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3091
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3092
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_NOUNLINK)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3093
			XVA_SET_REQ(xvap, XAT_NOUNLINK);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3094
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3095
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_IMMUTABLE)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3096
			XVA_SET_REQ(xvap, XAT_IMMUTABLE);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3097
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3098
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_NODUMP)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3099
			XVA_SET_REQ(xvap, XAT_NODUMP);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3100
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3101
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_MODIFIED)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3102
			XVA_SET_REQ(xvap, XAT_AV_MODIFIED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3103
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3104
		if (XVA_ISSET_REQ(&tmpxvattr, XAT_AV_QUARANTINED)) {
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3105
			XVA_SET_REQ(xvap, XAT_AV_QUARANTINED);
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3106
		}
6eeea43ced42 6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8059
diff changeset
  3107
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3108
		if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3109
			ASSERT(vp->v_type == VREG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3110
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3111
		zfs_xvattr_set(zp, xvap, tx);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3112
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3113
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3114
	if (fuid_dirtied)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3115
		zfs_fuid_sync(zfsvfs, tx);
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3116
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  3117
	if (mask != 0)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3118
		zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3119
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3120
	mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3121
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3122
out:
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3123
	if (err == 0 && attrzp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3124
		err2 = sa_bulk_update(attrzp->z_sa_hdl, xattr_bulk,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3125
		    xattr_count, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3126
		ASSERT(err2 == 0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3127
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3128
1231
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3129
	if (attrzp)
64215f768e86 6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents: 1141
diff changeset
  3130
		VN_RELE(ZTOV(attrzp));
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  3131
	if (aclp)
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  3132
		zfs_acl_free(aclp);
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
  3133
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3134
	if (fuidp) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3135
		zfs_fuid_info_free(fuidp);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3136
		fuidp = NULL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3137
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3138
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3139
	if (err) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3140
		dmu_tx_abort(tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3141
		if (err == ERESTART)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3142
			goto top;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3143
	} else {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3144
		err2 = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3145
		dmu_tx_commit(tx);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3146
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3147
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3148
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3149
out2:
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3150
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3151
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3152
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3153
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3154
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3155
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3156
3271
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3157
typedef struct zfs_zlock {
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3158
	krwlock_t	*zl_rwlock;	/* lock we acquired */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3159
	znode_t		*zl_znode;	/* znode we held */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3160
	struct zfs_zlock *zl_next;	/* next in list */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3161
} zfs_zlock_t;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3162
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3163
/*
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3164
 * Drop locks and release vnodes that were held by zfs_rename_lock().
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3165
 */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3166
static void
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3167
zfs_rename_unlock(zfs_zlock_t **zlpp)
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3168
{
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3169
	zfs_zlock_t *zl;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3170
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3171
	while ((zl = *zlpp) != NULL) {
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3172
		if (zl->zl_znode != NULL)
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3173
			VN_RELE(ZTOV(zl->zl_znode));
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3174
		rw_exit(zl->zl_rwlock);
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3175
		*zlpp = zl->zl_next;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3176
		kmem_free(zl, sizeof (*zl));
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3177
	}
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3178
}
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3179
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3180
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3181
 * Search back through the directory tree, using the ".." entries.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3182
 * Lock each directory in the chain to prevent concurrent renames.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3183
 * Fail any attempt to move a directory into one of its own descendants.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3184
 * XXX - z_parent_lock can overlap with map or grow locks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3185
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3186
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3187
zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3188
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3189
	zfs_zlock_t	*zl;
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3461
diff changeset
  3190
	znode_t		*zp = tdzp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3191
	uint64_t	rootid = zp->z_zfsvfs->z_root;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3192
	uint64_t	oidp = zp->z_id;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3193
	krwlock_t	*rwlp = &szp->z_parent_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3194
	krw_t		rw = RW_WRITER;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3196
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3197
	 * First pass write-locks szp and compares to zp->z_id.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3198
	 * Later passes read-lock zp and compare to zp->z_parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3199
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3200
	do {
3271
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3201
		if (!rw_tryenter(rwlp, rw)) {
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3202
			/*
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3203
			 * Another thread is renaming in this path.
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3204
			 * Note that if we are a WRITER, we don't have any
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3205
			 * parent_locks held yet.
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3206
			 */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3207
			if (rw == RW_READER && zp->z_id > szp->z_id) {
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3208
				/*
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3209
				 * Drop our locks and restart
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3210
				 */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3211
				zfs_rename_unlock(&zl);
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3212
				*zlpp = NULL;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3213
				zp = tdzp;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3214
				oidp = zp->z_id;
3271
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3215
				rwlp = &szp->z_parent_lock;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3216
				rw = RW_WRITER;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3217
				continue;
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3218
			} else {
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3219
				/*
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3220
				 * Wait for other thread to drop its locks
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3221
				 */
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3222
				rw_enter(rwlp, rw);
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3223
			}
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3224
		}
bae4d02fdc5b 6502193 race in zfs_rename
maybee
parents: 3234
diff changeset
  3225
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3226
		zl = kmem_alloc(sizeof (*zl), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3227
		zl->zl_rwlock = rwlp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3228
		zl->zl_znode = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3229
		zl->zl_next = *zlpp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3230
		*zlpp = zl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3231
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3232
		if (oidp == szp->z_id)		/* We're a descendant of szp */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3233
			return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3234
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3235
		if (oidp == rootid)		/* We've hit the top */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3236
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3238
		if (rw == RW_READER) {		/* i.e. not the first pass */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3239
			int error = zfs_zget(zp->z_zfsvfs, oidp, &zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3240
			if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3241
				return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3242
			zl->zl_znode = zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3243
		}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3244
		(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(zp->z_zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3245
		    &oidp, sizeof (oidp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3246
		rwlp = &zp->z_parent_lock;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3247
		rw = RW_READER;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3248
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3249
	} while (zp->z_id != sdzp->z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3251
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3252
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3253
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3254
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3255
 * Move an entry from the provided source directory to the target
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3256
 * directory.  Change the entry name as indicated.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3257
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3258
 *	IN:	sdvp	- Source directory containing the "old entry".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3259
 *		snm	- Old entry name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3260
 *		tdvp	- Target directory to contain the "new entry".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3261
 *		tnm	- New entry name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3262
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3263
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3264
 *		flags	- case flags
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3265
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3266
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3267
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3268
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3269
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3270
 *	sdvp,tdvp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3271
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3272
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3273
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3274
zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3275
    caller_context_t *ct, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3276
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3277
	znode_t		*tdzp, *szp, *tzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3278
	znode_t		*sdzp = VTOZ(sdvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3279
	zfsvfs_t	*zfsvfs = sdzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3280
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3281
	vnode_t		*realvp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3282
	zfs_dirlock_t	*sdl, *tdl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3283
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3284
	zfs_zlock_t	*zl;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3285
	int		cmp, serr, terr;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3286
	int		error = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3287
	int		zflg = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3288
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3289
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3290
	ZFS_VERIFY_ZP(sdzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3291
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3292
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3293
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3294
	 * Make sure we have the real vp for the target directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3295
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3296
	if (VOP_REALVP(tdvp, &realvp, ct) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3297
		tdvp = realvp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3298
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3299
	if (tdvp->v_vfsp != sdvp->v_vfsp || zfsctl_is_node(tdvp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3300
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3301
		return (EXDEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3302
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3303
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3304
	tdzp = VTOZ(tdvp);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3305
	ZFS_VERIFY_ZP(tdzp);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3306
	if (zfsvfs->z_utf8 && u8_validate(tnm,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3307
	    strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3308
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3309
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3310
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3311
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3312
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3313
		zflg |= ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3314
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3315
top:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3316
	szp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3317
	tzp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3318
	zl = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3319
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3320
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3321
	 * This is to prevent the creation of links into attribute space
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3322
	 * by renaming a linked file into/outof an attribute directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3323
	 * See the comment in zfs_link() for why this is considered bad.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3324
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3325
	if ((tdzp->z_pflags & ZFS_XATTR) != (sdzp->z_pflags & ZFS_XATTR)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3326
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3327
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3328
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3329
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3330
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3331
	 * Lock source and target directory entries.  To prevent deadlock,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3332
	 * a lock ordering must be defined.  We lock the directory with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3333
	 * the smallest object id first, or if it's a tie, the one with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3334
	 * the lexically first name.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3335
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3336
	if (sdzp->z_id < tdzp->z_id) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3337
		cmp = -1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3338
	} else if (sdzp->z_id > tdzp->z_id) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3339
		cmp = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3340
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3341
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3342
		 * First compare the two name arguments without
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3343
		 * considering any case folding.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3344
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3345
		int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3346
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3347
		cmp = u8_strcmp(snm, tnm, 0, nofold, U8_UNICODE_LATEST, &error);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3348
		ASSERT(error == 0 || !zfsvfs->z_utf8);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3349
		if (cmp == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3350
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3351
			 * POSIX: "If the old argument and the new argument
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3352
			 * both refer to links to the same existing file,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3353
			 * the rename() function shall return successfully
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3354
			 * and perform no other action."
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3355
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3356
			ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3357
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3358
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3359
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3360
		 * If the file system is case-folding, then we may
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3361
		 * have some more checking to do.  A case-folding file
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3362
		 * system is either supporting mixed case sensitivity
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3363
		 * access or is completely case-insensitive.  Note
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3364
		 * that the file system is always case preserving.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3365
		 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3366
		 * In mixed sensitivity mode case sensitive behavior
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3367
		 * is the default.  FIGNORECASE must be used to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3368
		 * explicitly request case insensitive behavior.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3369
		 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3370
		 * If the source and target names provided differ only
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3371
		 * by case (e.g., a request to rename 'tim' to 'Tim'),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3372
		 * we will treat this as a special case in the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3373
		 * case-insensitive mode: as long as the source name
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3374
		 * is an exact match, we will allow this to proceed as
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3375
		 * a name-change request.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3376
		 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3377
		if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE ||
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3378
		    (zfsvfs->z_case == ZFS_CASE_MIXED &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3379
		    flags & FIGNORECASE)) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3380
		    u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3381
		    &error) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3382
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3383
			 * case preserving rename request, require exact
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3384
			 * name matches
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3385
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3386
			zflg |= ZCIEXACT;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3387
			zflg &= ~ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3388
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3390
11321
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3391
	/*
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3392
	 * If the source and destination directories are the same, we should
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3393
	 * grab the z_name_lock of that directory only once.
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3394
	 */
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3395
	if (sdzp == tdzp) {
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3396
		zflg |= ZHAVELOCK;
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3397
		rw_enter(&sdzp->z_name_lock, RW_READER);
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3398
	}
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3399
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3400
	if (cmp < 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3401
		serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3402
		    ZEXISTS | zflg, NULL, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3403
		terr = zfs_dirent_lock(&tdl,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3404
		    tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3405
	} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3406
		terr = zfs_dirent_lock(&tdl,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3407
		    tdzp, tnm, &tzp, zflg, NULL, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3408
		serr = zfs_dirent_lock(&sdl,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3409
		    sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3410
		    NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3411
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3412
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3413
	if (serr) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3414
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3415
		 * Source entry invalid or not there.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3417
		if (!terr) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3418
			zfs_dirent_unlock(tdl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3419
			if (tzp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3420
				VN_RELE(ZTOV(tzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3421
		}
11321
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3422
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3423
		if (sdzp == tdzp)
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3424
			rw_exit(&sdzp->z_name_lock);
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3425
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3426
		if (strcmp(snm, "..") == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3427
			serr = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3428
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3429
		return (serr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3430
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3431
	if (terr) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3432
		zfs_dirent_unlock(sdl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3433
		VN_RELE(ZTOV(szp));
11321
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3434
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3435
		if (sdzp == tdzp)
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3436
			rw_exit(&sdzp->z_name_lock);
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3437
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3438
		if (strcmp(tnm, "..") == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3439
			terr = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3440
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3441
		return (terr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3442
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3444
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3445
	 * Must have write access at the source to remove the old entry
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3446
	 * and write access at the target to create the new entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
	 * Note that if target and source are the same, this can be
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3448
	 * done in a single check.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3449
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3450
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3451
	if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3452
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3453
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3454
	if (ZTOV(szp)->v_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3455
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3456
		 * Check to make sure rename is valid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3457
		 * Can't do a move like this: /usr/a/b to /usr/a/b/c/d
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3458
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3459
		if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3460
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3461
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3462
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3463
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3464
	 * Does target exist?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3465
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3466
	if (tzp) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3467
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3468
		 * Source and target must be the same type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3469
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3470
		if (ZTOV(szp)->v_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3471
			if (ZTOV(tzp)->v_type != VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3472
				error = ENOTDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3473
				goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3474
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3475
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3476
			if (ZTOV(tzp)->v_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3477
				error = EISDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3478
				goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3479
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3480
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3481
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3482
		 * POSIX dictates that when the source and target
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3483
		 * entries refer to the same file object, rename
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3484
		 * must do nothing and exit without error.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3485
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3486
		if (szp->z_id == tzp->z_id) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3487
			error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3488
			goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3489
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3490
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3491
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3492
	vnevent_rename_src(ZTOV(szp), sdvp, snm, ct);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3493
	if (tzp)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3494
		vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct);
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3495
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3496
	/*
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3497
	 * notify the target directory if it is not the same
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3498
	 * as source directory.
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3499
	 */
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3500
	if (tdvp != sdvp) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3501
		vnevent_rename_dest_dir(tdvp, ct);
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3502
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3503
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3504
	tx = dmu_tx_create(zfsvfs->z_os);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3505
	dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3506
	dmu_tx_hold_sa(tx, sdzp->z_sa_hdl, B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  3507
	dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  3508
	dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3509
	if (sdzp != tdzp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3510
		dmu_tx_hold_sa(tx, tdzp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3511
		zfs_sa_upgrade_txholds(tx, tdzp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3512
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3513
	if (tzp) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3514
		dmu_tx_hold_sa(tx, tzp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3515
		zfs_sa_upgrade_txholds(tx, tzp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3516
	}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3517
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3518
	zfs_sa_upgrade_txholds(tx, szp);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  3519
	dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3520
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3521
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3522
		if (zl != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3523
			zfs_rename_unlock(&zl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3524
		zfs_dirent_unlock(sdl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3525
		zfs_dirent_unlock(tdl);
11321
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3526
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3527
		if (sdzp == tdzp)
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3528
			rw_exit(&sdzp->z_name_lock);
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3529
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3530
		VN_RELE(ZTOV(szp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3531
		if (tzp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3532
			VN_RELE(ZTOV(tzp));
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3533
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3534
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3535
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3536
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3537
		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3538
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3539
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3540
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3541
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3542
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3543
	if (tzp)	/* Attempt to remove the existing target */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3544
		error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3545
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3546
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3547
		error = zfs_link_create(tdl, szp, tx, ZRENAMING);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3548
		if (error == 0) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3549
			szp->z_pflags |= ZFS_AV_MODIFIED;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3550
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3551
			error = sa_update(szp->z_sa_hdl, SA_ZPL_FLAGS(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3552
			    (void *)&szp->z_pflags, sizeof (uint64_t), tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3553
			ASSERT3U(error, ==, 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3554
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3555
			error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL);
12413
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3556
			if (error == 0) {
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3557
				zfs_log_rename(zilog, tx, TX_RENAME |
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3558
				    (flags & FIGNORECASE ? TX_CI : 0),
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3559
				    sdzp, sdl->dl_name, tdzp, tdl->dl_name,
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3560
				    szp);
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3561
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3562
				/*
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3563
				 * Update path information for the target vnode
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3564
				 */
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3565
				vn_renamepath(tdvp, ZTOV(szp), tnm,
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3566
				    strlen(tnm));
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3567
			} else {
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3568
				/*
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3569
				 * At this point, we have successfully created
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3570
				 * the target name, but have failed to remove
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3571
				 * the source name.  Since the create was done
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3572
				 * with the ZRENAMING flag, there are
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3573
				 * complications; for one, the link count is
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3574
				 * wrong.  The easiest way to deal with this
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3575
				 * is to remove the newly created target, and
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3576
				 * return the original error.  This must
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3577
				 * succeed; fortunately, it is very unlikely to
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3578
				 * fail, since we just created it.
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3579
				 */
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3580
				VERIFY3U(zfs_link_destroy(tdl, szp, tx,
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3581
				    ZRENAMING, NULL), ==, 0);
72ca7d8ab18e 6894240 zfs has a partially deleted file
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 12394
diff changeset
  3582
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3583
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3584
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3585
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3586
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3587
out:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3588
	if (zl != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3589
		zfs_rename_unlock(&zl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3591
	zfs_dirent_unlock(sdl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3592
	zfs_dirent_unlock(tdl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3593
11321
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3594
	if (sdzp == tdzp)
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3595
		rw_exit(&sdzp->z_name_lock);
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3596
506b7043a14c 6847615 deadlock between zfs_dirent_lock and zfs_rmdir
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11134
diff changeset
  3597
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3598
	VN_RELE(ZTOV(szp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3599
	if (tzp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3600
		VN_RELE(ZTOV(tzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3601
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3602
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3603
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3604
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3605
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3606
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3607
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3609
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3610
 * Insert the indicated symbolic reference entry into the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3611
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3612
 *	IN:	dvp	- Directory to contain new symbolic link.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3613
 *		link	- Name for new symlink entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3614
 *		vap	- Attributes of new entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3615
 *		target	- Target path of new symlink.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3616
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3617
 *		ct	- caller context
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3618
 *		flags	- case flags
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3619
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3620
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3621
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3622
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3623
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3624
 *	dvp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3625
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3626
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3627
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3628
zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3629
    caller_context_t *ct, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3630
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3631
	znode_t		*zp, *dzp = VTOZ(dvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3632
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3633
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3634
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3635
	zilog_t		*zilog;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3636
	uint64_t	len = strlen(link);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3637
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3638
	int		zflg = ZNEW;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3639
	zfs_acl_ids_t	acl_ids;
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3640
	boolean_t	fuid_dirtied;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3641
	uint64_t	txtype = TX_SYMLINK;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3643
	ASSERT(vap->va_type == VLNK);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3644
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3645
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3646
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3647
	zilog = zfsvfs->z_log;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3648
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3649
	if (zfsvfs->z_utf8 && u8_validate(name, strlen(name),
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3650
	    NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3651
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3652
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3653
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3654
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3655
		zflg |= ZCILOOK;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3656
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3657
	if (len > MAXPATHLEN) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3658
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3659
		return (ENAMETOOLONG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3660
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3661
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3662
	if ((error = zfs_acl_ids_create(dzp, 0,
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3663
	    vap, cr, NULL, &acl_ids)) != 0) {
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3664
		ZFS_EXIT(zfsvfs);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3665
		return (error);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3666
	}
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3667
top:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3668
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3669
	 * Attempt to lock directory; fail if entry already exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3670
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3671
	error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3672
	if (error) {
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3673
		zfs_acl_ids_free(&acl_ids);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3674
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3675
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3676
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3677
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3678
	if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3679
		zfs_acl_ids_free(&acl_ids);
12421
d38fccc4d212 6952968 fstest hanging on symlink/06 testcase on nevada, build 140
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12413
diff changeset
  3680
		zfs_dirent_unlock(dl);
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3681
		ZFS_EXIT(zfsvfs);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3682
		return (error);
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3683
	}
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3684
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3685
	if (zfs_acl_ids_overquota(zfsvfs, &acl_ids)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3686
		zfs_acl_ids_free(&acl_ids);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3687
		zfs_dirent_unlock(dl);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3688
		ZFS_EXIT(zfsvfs);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3689
		return (EDQUOT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3690
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3691
	tx = dmu_tx_create(zfsvfs->z_os);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3692
	fuid_dirtied = zfsvfs->z_fuid_dirty;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3693
	dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  3694
	dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3695
	dmu_tx_hold_sa_create(tx, acl_ids.z_aclp->z_acl_bytes +
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3696
	    ZFS_SA_BASE_ATTR_SIZE + len);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3697
	dmu_tx_hold_sa(tx, dzp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3698
	if (!zfsvfs->z_use_sa && acl_ids.z_aclp->z_acl_bytes > ZFS_ACE_SPACE) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3699
		dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3700
		    acl_ids.z_aclp->z_acl_bytes);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3701
	}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3702
	if (fuid_dirtied)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  3703
		zfs_fuid_txhold(zfsvfs, tx);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3704
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3705
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3706
		zfs_dirent_unlock(dl);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3707
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3708
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3709
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3710
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3711
		}
12302
44e9cbdf497d 6946681 System panics in a loop with "pf zfs_fuid_create"
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12294
diff changeset
  3712
		zfs_acl_ids_free(&acl_ids);
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3713
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3714
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3715
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3716
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3717
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3718
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3719
	 * Create a new object for the symlink.
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3720
	 * for version 4 ZPL datsets the symlink will be an SA attribute
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3721
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3722
	zfs_mknode(dzp, vap, tx, cr, 0, &zp, &acl_ids);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3723
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3724
	if (fuid_dirtied)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3725
		zfs_fuid_sync(zfsvfs, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3726
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3727
	if (zp->z_is_sa)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3728
		error = sa_update(zp->z_sa_hdl, SA_ZPL_SYMLINK(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3729
		    link, len, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3730
	else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3731
		zfs_sa_symlink(zp, link, len, tx);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3732
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3733
	zp->z_size = len;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3734
	(void) sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3735
	    &zp->z_size, sizeof (zp->z_size), tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3736
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3737
	 * Insert the new object into the directory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3738
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3739
	(void) zfs_link_create(dl, zp, tx, ZNEW);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3740
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3741
	if (flags & FIGNORECASE)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3742
		txtype |= TX_CI;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3743
	zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3744
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9141
diff changeset
  3745
	zfs_acl_ids_free(&acl_ids);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3746
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3747
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3749
	zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3750
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3751
	VN_RELE(ZTOV(zp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3752
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3753
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3754
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3755
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3756
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3757
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3758
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3759
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3760
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3761
 * Return, in the buffer contained in the provided uio structure,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3762
 * the symbolic path referred to by vp.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3763
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3764
 *	IN:	vp	- vnode of symbolic link.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3765
 *		uoip	- structure to contain the link path.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3766
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3767
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3768
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3769
 *	OUT:	uio	- structure to contain the link path.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3770
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3771
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3772
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3773
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3774
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3775
 *	vp - atime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3776
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3777
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3778
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3779
zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3780
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3781
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3782
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3783
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3784
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3785
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3786
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3787
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3788
	if (zp->z_is_sa)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3789
		error = sa_lookup_uio(zp->z_sa_hdl,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3790
		    SA_ZPL_SYMLINK(zfsvfs), uio);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3791
	else
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3792
		error = zfs_sa_readlink(zp, uio);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3793
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3794
	ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3795
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3796
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3797
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3798
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3799
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3800
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3801
 * Insert a new entry into directory tdvp referencing svp.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3802
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3803
 *	IN:	tdvp	- Directory to contain new entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3804
 *		svp	- vnode of new entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3805
 *		name	- name of new entry.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3806
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3807
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3808
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3809
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3810
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3811
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3812
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3813
 *	tdvp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3814
 *	 svp - ctime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3815
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3816
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3817
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3818
zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3819
    caller_context_t *ct, int flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3820
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3821
	znode_t		*dzp = VTOZ(tdvp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3822
	znode_t		*tzp, *szp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3823
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3824
	zilog_t		*zilog;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3825
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3826
	dmu_tx_t	*tx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3827
	vnode_t		*realvp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3828
	int		error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3829
	int		zf = ZNEW;
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3830
	uint64_t	parent;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3832
	ASSERT(tdvp->v_type == VDIR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3833
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3834
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3835
	ZFS_VERIFY_ZP(dzp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  3836
	zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3837
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3838
	if (VOP_REALVP(svp, &realvp, ct) == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3839
		svp = realvp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3840
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3841
	/*
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3842
	 * POSIX dictates that we return EPERM here.
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3843
	 * Better choices include ENOTSUP or EISDIR.
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3844
	 */
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3845
	if (svp->v_type == VDIR) {
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3846
		ZFS_EXIT(zfsvfs);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3847
		return (EPERM);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3848
	}
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3849
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3850
	if (svp->v_vfsp != tdvp->v_vfsp || zfsctl_is_node(svp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3851
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3852
		return (EXDEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3853
	}
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3854
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3855
	szp = VTOZ(svp);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3856
	ZFS_VERIFY_ZP(szp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3857
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3858
	/* Prevent links to .zfs/shares files */
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3859
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3860
	if ((error = sa_lookup(szp->z_sa_hdl, SA_ZPL_PARENT(zfsvfs),
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3861
	    &parent, sizeof (uint64_t))) != 0) {
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3862
		ZFS_EXIT(zfsvfs);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3863
		return (error);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3864
	}
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3865
	if (parent == zfsvfs->z_shares_dir) {
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3866
		ZFS_EXIT(zfsvfs);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3867
		return (EPERM);
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3868
	}
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3869
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  3870
	if (zfsvfs->z_utf8 && u8_validate(name,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3871
	    strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3872
		ZFS_EXIT(zfsvfs);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3873
		return (EILSEQ);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3874
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3875
	if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3876
		zf |= ZCILOOK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3877
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3878
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3879
	 * We do not support links between attributes and non-attributes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3880
	 * because of the potential security risk of creating links
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3881
	 * into "normal" file space in order to circumvent restrictions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3882
	 * imposed in attribute space.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3883
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3884
	if ((szp->z_pflags & ZFS_XATTR) != (dzp->z_pflags & ZFS_XATTR)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3885
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3886
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3887
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3888
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3889
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3890
	if (szp->z_uid != crgetuid(cr) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3891
	    secpolicy_basic_link(cr) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3892
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3893
		return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3894
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3895
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3896
	if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3897
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3898
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3899
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3900
12079
13822b941977 6939941 problem with moving files in zfs
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11935
diff changeset
  3901
top:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3902
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3903
	 * Attempt to lock directory; fail if entry already exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3904
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3905
	error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3906
	if (error) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3907
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3908
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3909
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3910
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3911
	tx = dmu_tx_create(zfsvfs->z_os);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3912
	dmu_tx_hold_sa(tx, szp->z_sa_hdl, B_FALSE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  3913
	dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3914
	zfs_sa_upgrade_txholds(tx, szp);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  3915
	zfs_sa_upgrade_txholds(tx, dzp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3916
	error = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3917
	if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3918
		zfs_dirent_unlock(dl);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  3919
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3920
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3921
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3922
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3923
		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  3924
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3925
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3926
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3927
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3928
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3929
	error = zfs_link_create(dl, szp, tx, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3930
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3931
	if (error == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3932
		uint64_t txtype = TX_LINK;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3933
		if (flags & FIGNORECASE)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3934
			txtype |= TX_CI;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3935
		zfs_log_link(zilog, tx, txtype, dzp, szp, name);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3936
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3937
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3938
	dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3939
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3940
	zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3941
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3942
	if (error == 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  3943
		vnevent_link(svp, ct);
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3944
	}
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  3945
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3946
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3947
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  3948
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3949
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3950
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3951
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3952
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3953
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3954
 * zfs_null_putapage() is used when the file system has been force
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3955
 * unmounted. It just drops the pages.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3956
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3957
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3958
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3959
zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3960
		size_t *lenp, int flags, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3961
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3962
	pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3963
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3964
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3965
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3966
/*
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3967
 * Push a page out to disk, klustering if possible.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3968
 *
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3969
 *	IN:	vp	- file to push page to.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3970
 *		pp	- page to push.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3971
 *		flags	- additional flags.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3972
 *		cr	- credentials of caller.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3973
 *
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3974
 *	OUT:	offp	- start of range pushed.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3975
 *		lenp	- len of range pushed.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3976
 *
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3977
 *	RETURN:	0 if success
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3978
 *		error code if failure
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3979
 *
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3980
 * NOTE: callers must have locked the page to be pushed.  On
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3981
 * exit, the page (and all other pages in the kluster) must be
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3982
 * unlocked.
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3983
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3984
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3985
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3986
zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3987
		size_t *lenp, int flags, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3988
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3989
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3990
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3991
	dmu_tx_t	*tx;
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3992
	u_offset_t	off, koff;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3993
	size_t		len, klen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3994
	int		err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3995
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3996
	off = pp->p_offset;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3997
	len = PAGESIZE;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3998
	/*
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  3999
	 * If our blocksize is bigger than the page size, try to kluster
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  4000
	 * multiple pages so that we write a full block (thus avoiding
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4001
	 * a read-modify-write).
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4002
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4003
	if (off < zp->z_size && zp->z_blksz > PAGESIZE) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4004
		klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4005
		koff = ISP2(klen) ? P2ALIGN(off, (u_offset_t)klen) : 0;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4006
		ASSERT(koff <= zp->z_size);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4007
		if (koff + klen > zp->z_size)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4008
			klen = P2ROUNDUP(zp->z_size - koff, (uint64_t)PAGESIZE);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4009
		pp = pvn_write_kluster(vp, pp, &off, &len, koff, klen, flags);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4010
	}
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4011
	ASSERT3U(btop(len), ==, btopr(len));
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4012
1819
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1816
diff changeset
  4013
	/*
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1816
diff changeset
  4014
	 * Can't push pages past end-of-file.
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1816
diff changeset
  4015
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4016
	if (off >= zp->z_size) {
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4543
diff changeset
  4017
		/* ignore all pages */
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4018
		err = 0;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4019
		goto out;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4020
	} else if (off + len > zp->z_size) {
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4021
		int npages = btopr(zp->z_size - off);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4022
		page_t *trunc;
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4023
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4024
		page_list_break(&pp, &trunc, npages);
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4543
diff changeset
  4025
		/* ignore pages past end of file */
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4026
		if (trunc)
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4543
diff changeset
  4027
			pvn_write_done(trunc, flags);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4028
		len = zp->z_size - off;
1819
570a79e4d798 6407842 zfs panic when closing a file
maybee
parents: 1816
diff changeset
  4029
	}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  4030
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4031
	if (zfs_owner_overquota(zfsvfs, zp, B_FALSE) ||
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4032
	    zfs_owner_overquota(zfsvfs, zp, B_TRUE)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  4033
		err = EDQUOT;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  4034
		goto out;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9321
diff changeset
  4035
	}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4036
top:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4037
	tx = dmu_tx_create(zfsvfs->z_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4038
	dmu_tx_hold_write(tx, zp->z_id, off, len);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4039
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4040
	dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4041
	zfs_sa_upgrade_txholds(tx, zp);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  4042
	err = dmu_tx_assign(tx, TXG_NOWAIT);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4043
	if (err != 0) {
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 8190
diff changeset
  4044
		if (err == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  4045
			dmu_tx_wait(tx);
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  4046
			dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4047
			goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4048
		}
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1941
diff changeset
  4049
		dmu_tx_abort(tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4050
		goto out;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4051
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4052
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4053
	if (zp->z_blksz <= PAGESIZE) {
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
  4054
		caddr_t va = zfs_map_page(pp, S_READ);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4055
		ASSERT3U(len, <=, PAGESIZE);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4056
		dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx);
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
  4057
		zfs_unmap_page(pp, va);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4058
	} else {
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4059
		err = dmu_write_pages(zfsvfs->z_os, zp->z_id, off, len, pp, tx);
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4060
	}
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4061
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4062
	if (err == 0) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4063
		uint64_t mtime[2], ctime[2];
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  4064
		sa_bulk_attr_t bulk[3];
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4065
		int count = 0;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4066
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4067
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4068
		    &mtime, 16);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4069
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4070
		    &ctime, 16);
12394
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  4071
		SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
557921ce7bf4 6950273 CIFS attributes aren't always updated when timestamps are updated
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12302
diff changeset
  4072
		    &zp->z_pflags, 8);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4073
		zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4074
		    B_TRUE);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4075
		zfs_log_write(zfsvfs->z_log, tx, TX_WRITE, zp, off, len, 0);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4076
	}
9951
a4895b3dd543 6842815 SUNWzfsu package dependency on SUNWPython is not captured
Lin Ling <Lin.Ling@Sun.COM>
parents: 9909
diff changeset
  4077
	dmu_tx_commit(tx);
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4078
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4079
out:
4709
dc10a713d1a0 6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents: 4543
diff changeset
  4080
	pvn_write_done(pp, (err ? B_ERROR : 0) | flags);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4081
	if (offp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4082
		*offp = off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4083
	if (lenp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4084
		*lenp = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4085
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4086
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4087
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4088
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4089
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4090
 * Copy the portion of the file indicated from pages into the file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4091
 * The pages are stored in a page list attached to the files vnode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4092
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4093
 *	IN:	vp	- vnode of file to push page data to.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4094
 *		off	- position in file to put data.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4095
 *		len	- amount of data to write.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4096
 *		flags	- flags to control the operation.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4097
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4098
 *		ct	- caller context.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4099
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4100
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4101
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4102
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4103
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4104
 *	vp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4105
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4106
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4107
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4108
zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4109
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4110
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4111
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4112
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4113
	page_t		*pp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4114
	size_t		io_len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4115
	u_offset_t	io_off;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4116
	uint_t		blksz;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4117
	rl_t		*rl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4118
	int		error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4119
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4120
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4121
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4122
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4123
	/*
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4124
	 * Align this request to the file block size in case we kluster.
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4125
	 * XXX - this can result in pretty aggresive locking, which can
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4126
	 * impact simultanious read/write access.  One option might be
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4127
	 * to break up long requests (len == 0) into block-by-block
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4128
	 * operations to get narrower locking.
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4129
	 */
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4130
	blksz = zp->z_blksz;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4131
	if (ISP2(blksz))
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4132
		io_off = P2ALIGN_TYPED(off, blksz, u_offset_t);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4133
	else
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4134
		io_off = 0;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4135
	if (len > 0 && ISP2(blksz))
9141
d51ab4b3e040 6806627 zfs_putpage gets it backwards
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8845
diff changeset
  4136
		io_len = P2ROUNDUP_TYPED(len + (off - io_off), blksz, size_t);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4137
	else
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4138
		io_len = 0;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4139
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4140
	if (io_len == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4141
		/*
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4142
		 * Search the entire vp list for pages >= io_off.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4143
		 */
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4144
		rl = zfs_range_lock(zp, io_off, UINT64_MAX, RL_WRITER);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4145
		error = pvn_vplist_dirty(vp, io_off, zfs_putapage, flags, cr);
1472
6d54521a5237 6381994 zfs_putpage() serializes I/O unnecessarily
perrin
parents: 1460
diff changeset
  4146
		goto out;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4147
	}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4148
	rl = zfs_range_lock(zp, io_off, io_len, RL_WRITER);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4149
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4150
	if (off > zp->z_size) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4151
		/* past end of file */
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4152
		zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4153
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4154
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4155
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4156
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4157
	len = MIN(io_len, P2ROUNDUP(zp->z_size, PAGESIZE) - io_off);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4158
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4159
	for (off = io_off; io_off < off + len; io_off += io_len) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4160
		if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) {
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  4161
			pp = page_lookup(vp, io_off,
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
  4162
			    (flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4163
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4164
			pp = page_lookup_nowait(vp, io_off,
4339
24b45a78e29e 6561733 ZFS znode z_sync_cnt field is miscounted
perrin
parents: 4144
diff changeset
  4165
			    (flags & B_FREE) ? SE_EXCL : SE_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4166
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4168
		if (pp != NULL && pvn_getdirty(pp, flags)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4169
			int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4171
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4172
			 * Found a dirty page to push
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4173
			 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  4174
			err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  4175
			if (err)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4176
				error = err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4177
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4178
			io_len = PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4179
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4180
	}
1472
6d54521a5237 6381994 zfs_putpage() serializes I/O unnecessarily
perrin
parents: 1460
diff changeset
  4181
out:
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4182
	zfs_range_unlock(rl);
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4183
	if ((flags & B_ASYNC) == 0 || zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
  4184
		zil_commit(zfsvfs->z_log, UINT64_MAX, zp->z_id);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4185
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4186
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4187
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4188
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4189
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4190
void
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4191
zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4192
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4193
	znode_t	*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4194
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4195
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4196
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  4197
	rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4198
	if (zp->z_sa_hdl == NULL) {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5386
diff changeset
  4199
		/*
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5545
diff changeset
  4200
		 * The fs has been unmounted, or we did a
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5545
diff changeset
  4201
		 * suspend/resume and this file no longer exists.
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5386
diff changeset
  4202
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4203
		if (vn_has_cached_data(vp)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4204
			(void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4205
			    B_INVAL, cr);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4206
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4207
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4208
		mutex_enter(&zp->z_lock);
10369
9e765fdb0c01 6832077 zfs_inactive() can clobber v_count
Chris Kirby <chris.kirby@sun.com>
parents: 10209
diff changeset
  4209
		mutex_enter(&vp->v_lock);
9e765fdb0c01 6832077 zfs_inactive() can clobber v_count
Chris Kirby <chris.kirby@sun.com>
parents: 10209
diff changeset
  4210
		ASSERT(vp->v_count == 1);
9e765fdb0c01 6832077 zfs_inactive() can clobber v_count
Chris Kirby <chris.kirby@sun.com>
parents: 10209
diff changeset
  4211
		vp->v_count = 0;
9e765fdb0c01 6832077 zfs_inactive() can clobber v_count
Chris Kirby <chris.kirby@sun.com>
parents: 10209
diff changeset
  4212
		mutex_exit(&vp->v_lock);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5386
diff changeset
  4213
		mutex_exit(&zp->z_lock);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5545
diff changeset
  4214
		rw_exit(&zfsvfs->z_teardown_inactive_lock);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5386
diff changeset
  4215
		zfs_znode_free(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4216
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4217
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4219
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4220
	 * Attempt to push any data in the page cache.  If this fails
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4221
	 * we will get kicked out later in zfs_zinactive().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4222
	 */
1298
1a70f57b62f0 6368181 some memleaks found related to zfs mount
perrin
parents: 1231
diff changeset
  4223
	if (vn_has_cached_data(vp)) {
1a70f57b62f0 6368181 some memleaks found related to zfs mount
perrin
parents: 1231
diff changeset
  4224
		(void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC,
1a70f57b62f0 6368181 some memleaks found related to zfs mount
perrin
parents: 1231
diff changeset
  4225
		    cr);
1a70f57b62f0 6368181 some memleaks found related to zfs mount
perrin
parents: 1231
diff changeset
  4226
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4227
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3280
diff changeset
  4228
	if (zp->z_atime_dirty && zp->z_unlinked == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4229
		dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4230
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4231
		dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4232
		zfs_sa_upgrade_txholds(tx, zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4233
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4234
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4235
			dmu_tx_abort(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4236
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4237
			mutex_enter(&zp->z_lock);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4238
			(void) sa_update(zp->z_sa_hdl, SA_ZPL_ATIME(zfsvfs),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4239
			    (void *)&zp->z_atime, sizeof (zp->z_atime), tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4240
			zp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4241
			mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4242
			dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4243
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4244
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4245
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4246
	zfs_zinactive(zp);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  4247
	rw_exit(&zfsvfs->z_teardown_inactive_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4248
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4250
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4251
 * Bounds-check the seek operation.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4252
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4253
 *	IN:	vp	- vnode seeking within
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4254
 *		ooff	- old file offset
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4255
 *		noffp	- pointer to new file offset
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4256
 *		ct	- caller context
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4257
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4258
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4259
 *		EINVAL if new offset invalid
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4260
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4261
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4262
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4263
zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4264
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4265
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4266
	if (vp->v_type == VDIR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4267
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4268
	return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4269
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4271
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4272
 * Pre-filter the generic locking function to trap attempts to place
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4273
 * a mandatory lock on a memory mapped file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4274
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4275
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4276
zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4277
    flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4278
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4279
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4280
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4281
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4282
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4283
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4284
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4285
	/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4286
	 * We are following the UFS semantics with respect to mapcnt
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4287
	 * here: If we see that the file is mapped already, then we will
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4288
	 * return an error, but we don't worry about races between this
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4289
	 * function and zfs_map().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4290
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4291
	if (zp->z_mapcnt > 0 && MANDMODE(zp->z_mode)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4292
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4293
		return (EAGAIN);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4294
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4295
	ZFS_EXIT(zfsvfs);
10896
007ca67ca400 6793877 lockd can block ZFS force-unmounting on behalf of clients
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10800
diff changeset
  4296
	return (fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4297
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4298
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4299
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4300
 * If we can't find a page in the cache, we will create a new page
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4301
 * and fill it with file data.  For efficiency, we may try to fill
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4302
 * multiple pages at once (klustering) to fill up the supplied page
9265
0ddbce3734dc 6820295 C++ compilation fails on daily.0129 and above
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9179
diff changeset
  4303
 * list.  Note that the pages to be filled are held with an exclusive
0ddbce3734dc 6820295 C++ compilation fails on daily.0129 and above
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9179
diff changeset
  4304
 * lock to prevent access by other threads while they are being filled.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4305
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4306
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4307
zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4308
    caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4309
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4310
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4311
	page_t *pp, *cur_pp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4312
	objset_t *os = zp->z_zfsvfs->z_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4313
	u_offset_t io_off, total;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4314
	size_t io_len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4315
	int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4316
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4317
	if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4318
		/*
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4319
		 * We only have a single page, don't bother klustering
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4320
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4321
		io_off = off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4322
		io_len = PAGESIZE;
9265
0ddbce3734dc 6820295 C++ compilation fails on daily.0129 and above
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9179
diff changeset
  4323
		pp = page_create_va(vp, io_off, io_len,
0ddbce3734dc 6820295 C++ compilation fails on daily.0129 and above
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9179
diff changeset
  4324
		    PG_EXCL | PG_WAIT, seg, addr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4325
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4326
		/*
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4327
		 * Try to find enough pages to fill the page list
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4328
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4329
		pp = pvn_read_kluster(vp, off, seg, addr, &io_off,
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4330
		    &io_len, off, plsz, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4331
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4332
	if (pp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4333
		/*
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4334
		 * The page already exists, nothing to do here.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4335
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4336
		*pl = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4337
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4338
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4340
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4341
	 * Fill the pages in the kluster.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4342
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4343
	cur_pp = pp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4344
	for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4345
		caddr_t va;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4346
2688
12e2ad22b970 6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents: 2638
diff changeset
  4347
		ASSERT3U(io_off, ==, cur_pp->p_offset);
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
  4348
		va = zfs_map_page(cur_pp, S_WRITE);
9512
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9412
diff changeset
  4349
		err = dmu_read(os, zp->z_id, io_off, PAGESIZE, va,
64cafcbcc337 6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 9412
diff changeset
  4350
		    DMU_READ_PREFETCH);
7315
cdba25672122 6735592 "zio" vmem arenas are confusing, not reported separately
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents: 7294
diff changeset
  4351
		zfs_unmap_page(cur_pp, va);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4352
		if (err) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4353
			/* On error, toss the entire kluster */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4354
			pvn_read_done(pp, B_ERROR);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
  4355
			/* convert checksum errors into IO errors */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
  4356
			if (err == ECKSUM)
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 6992
diff changeset
  4357
				err = EIO;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4358
			return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4359
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4360
		cur_pp = cur_pp->p_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4361
	}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4362
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4363
	/*
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4364
	 * Fill in the page list array from the kluster starting
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4365
	 * from the desired offset `off'.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4366
	 * NOTE: the page list will always be null terminated.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4367
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4368
	pvn_plist_init(pp, pl, plsz, off, io_len, rw);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4369
	ASSERT(pl == NULL || (*pl)->p_offset == off);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4370
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4371
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4372
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4373
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4374
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4375
 * Return pointers to the pages for the file region [off, off + len]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4376
 * in the pl array.  If plsz is greater than len, this function may
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4377
 * also return page pointers from after the specified region
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4378
 * (i.e. the region [off, off + plsz]).  These additional pages are
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4379
 * only returned if they are already in the cache, or were created as
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4380
 * part of a klustered read.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4381
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4382
 *	IN:	vp	- vnode of file to get data from.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4383
 *		off	- position in file to get data from.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4384
 *		len	- amount of data to retrieve.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4385
 *		plsz	- length of provided page list.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4386
 *		seg	- segment to obtain pages for.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4387
 *		addr	- virtual address of fault.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4388
 *		rw	- mode of created pages.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4389
 *		cr	- credentials of caller.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4390
 *		ct	- caller context.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4391
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4392
 *	OUT:	protp	- protection mode of created pages.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4393
 *		pl	- list of pages created.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4394
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4395
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4396
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4397
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4398
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4399
 *	vp - atime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4400
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4401
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4402
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4403
zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4404
	page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4405
	enum seg_rw rw, cred_t *cr, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4406
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4407
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4408
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4409
	page_t		**pl0 = pl;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4410
	int		err = 0;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4411
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4412
	/* we do our own caching, faultahead is unnecessary */
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4413
	if (pl == NULL)
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4414
		return (0);
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4415
	else if (len > plsz)
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4416
		len = plsz;
8681
ec4ccb69025b 6800028 Panic in ZFS when running cthon tests
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8636
diff changeset
  4417
	else
ec4ccb69025b 6800028 Panic in ZFS when running cthon tests
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8636
diff changeset
  4418
		len = P2ROUNDUP(len, PAGESIZE);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4419
	ASSERT(plsz >= len);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4420
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4421
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4422
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4423
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4424
	if (protp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4425
		*protp = PROT_ALL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4427
	/*
9265
0ddbce3734dc 6820295 C++ compilation fails on daily.0129 and above
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 9179
diff changeset
  4428
	 * Loop through the requested range [off, off + len) looking
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4429
	 * for pages.  If we don't find a page, we will need to create
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4430
	 * a new page and fill it with data from the file.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4431
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4432
	while (len > 0) {
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4433
		if (*pl = page_lookup(vp, off, SE_SHARED))
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4434
			*(pl+1) = NULL;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4435
		else if (err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw))
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4436
			goto out;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4437
		while (*pl) {
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4438
			ASSERT3U((*pl)->p_offset, ==, off);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4439
			off += PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4440
			addr += PAGESIZE;
8681
ec4ccb69025b 6800028 Panic in ZFS when running cthon tests
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8636
diff changeset
  4441
			if (len > 0) {
ec4ccb69025b 6800028 Panic in ZFS when running cthon tests
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8636
diff changeset
  4442
				ASSERT3U(len, >=, PAGESIZE);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4443
				len -= PAGESIZE;
8681
ec4ccb69025b 6800028 Panic in ZFS when running cthon tests
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8636
diff changeset
  4444
			}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4445
			ASSERT3U(plsz, >=, PAGESIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4446
			plsz -= PAGESIZE;
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4447
			pl++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4448
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4449
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4450
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4451
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4452
	 * Fill out the page array with any pages already in the cache.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4453
	 */
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4454
	while (plsz > 0 &&
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4455
	    (*pl++ = page_lookup_nowait(vp, off, SE_SHARED))) {
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4456
			off += PAGESIZE;
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4457
			plsz -= PAGESIZE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4458
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4459
out:
2752
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4460
	if (err) {
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4461
		/*
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4462
		 * Release any pages we have previously locked.
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4463
		 */
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4464
		while (pl > pl0)
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4465
			page_unlock(*--pl);
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4466
	} else {
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  4467
		ZFS_ACCESSTIME_STAMP(zfsvfs, zp);
2752
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4468
	}
2b25a96fc433 6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents: 2688
diff changeset
  4469
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4470
	*pl = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4471
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4472
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4473
	return (err);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4474
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4475
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4476
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4477
 * Request a memory map for a section of a file.  This code interacts
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4478
 * with common code and the VM system as follows:
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4479
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4480
 *	common code calls mmap(), which ends up in smmap_common()
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4481
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4482
 *	this calls VOP_MAP(), which takes you into (say) zfs
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4483
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4484
 *	zfs_map() calls as_map(), passing segvn_create() as the callback
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4485
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4486
 *	segvn_create() creates the new segment and calls VOP_ADDMAP()
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4487
 *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4488
 *	zfs_addmap() updates z_mapcnt
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4489
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4490
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4491
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4492
zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4493
    size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4494
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4495
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4496
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4497
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4498
	segvn_crargs_t	vn_a;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4499
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4500
5929
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4501
	ZFS_ENTER(zfsvfs);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4502
	ZFS_VERIFY_ZP(zp);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4503
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4504
	if ((prot & PROT_WRITE) && (zp->z_pflags &
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4505
	    (ZFS_IMMUTABLE | ZFS_READONLY | ZFS_APPENDONLY))) {
5929
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4506
		ZFS_EXIT(zfsvfs);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4507
		return (EPERM);
5929
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4508
	}
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4509
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4510
	if ((prot & (PROT_READ | PROT_EXEC)) &&
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4511
	    (zp->z_pflags & ZFS_AV_QUARANTINED)) {
5929
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4512
		ZFS_EXIT(zfsvfs);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4513
		return (EACCES);
07d036def59b 6650101 SNAS: Read access is allowed after stream file is quarantined from CIFS share.
marks
parents: 5824
diff changeset
  4514
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4515
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4516
	if (vp->v_flag & VNOMAP) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4517
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4518
		return (ENOSYS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4519
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4520
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4521
	if (off < 0 || len > MAXOFFSET_T - off) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4522
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4523
		return (ENXIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4524
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4525
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4526
	if (vp->v_type != VREG) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4527
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4528
		return (ENODEV);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4529
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4530
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4531
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4532
	 * If file is locked, disallow mapping.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4533
	 */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4534
	if (MANDMODE(zp->z_mode) && vn_has_flocks(vp)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4535
		ZFS_EXIT(zfsvfs);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4536
		return (EAGAIN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4537
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4538
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4539
	as_rangelock(as);
6036
c98c367c32cb PSARC 2006/123 Mmap compatibility
mec
parents: 5959
diff changeset
  4540
	error = choose_addr(as, addrp, len, off, ADDR_VACALIGN, flags);
c98c367c32cb PSARC 2006/123 Mmap compatibility
mec
parents: 5959
diff changeset
  4541
	if (error != 0) {
c98c367c32cb PSARC 2006/123 Mmap compatibility
mec
parents: 5959
diff changeset
  4542
		as_rangeunlock(as);
c98c367c32cb PSARC 2006/123 Mmap compatibility
mec
parents: 5959
diff changeset
  4543
		ZFS_EXIT(zfsvfs);
c98c367c32cb PSARC 2006/123 Mmap compatibility
mec
parents: 5959
diff changeset
  4544
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4545
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4546
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4547
	vn_a.vp = vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4548
	vn_a.offset = (u_offset_t)off;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4549
	vn_a.type = flags & MAP_TYPE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4550
	vn_a.prot = prot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4551
	vn_a.maxprot = maxprot;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4552
	vn_a.cred = cr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4553
	vn_a.amp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4554
	vn_a.flags = flags & ~MAP_TYPE;
1417
fa316336e215 6377034 setting physmem in /etc/system does not have desired effect on x86
kchow
parents: 1394
diff changeset
  4555
	vn_a.szc = 0;
fa316336e215 6377034 setting physmem in /etc/system does not have desired effect on x86
kchow
parents: 1394
diff changeset
  4556
	vn_a.lgrp_mem_policy_flags = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4557
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4558
	error = as_map(as, *addrp, len, segvn_create, &vn_a);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4559
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4560
	as_rangeunlock(as);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4561
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4562
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4563
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4565
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4566
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4567
zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4568
    size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4569
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4570
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4571
	uint64_t pages = btopr(len);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4572
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4573
	atomic_add_64(&VTOZ(vp)->z_mapcnt, pages);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4574
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4575
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4576
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4577
/*
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4578
 * The reason we push dirty pages as part of zfs_delmap() is so that we get a
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4579
 * more accurate mtime for the associated file.  Since we don't have a way of
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4580
 * detecting when the data was actually modified, we have to resort to
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4581
 * heuristics.  If an explicit msync() is done, then we mark the mtime when the
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4582
 * last page is pushed.  The problem occurs when the msync() call is omitted,
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4583
 * which by far the most common case:
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4584
 *
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4585
 * 	open()
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4586
 * 	mmap()
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4587
 * 	<modify memory>
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4588
 * 	munmap()
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4589
 * 	close()
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4590
 * 	<time lapse>
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4591
 * 	putpage() via fsflush
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4592
 *
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4593
 * If we wait until fsflush to come along, we can have a modification time that
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4594
 * is some arbitrary point in the future.  In order to prevent this in the
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4595
 * common case, we flush pages whenever a (MAP_SHARED, PROT_WRITE) mapping is
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4596
 * torn down.
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4597
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4598
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4599
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4600
zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4601
    size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4602
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4603
{
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4604
	uint64_t pages = btopr(len);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4605
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4606
	ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1512
diff changeset
  4607
	atomic_add_64(&VTOZ(vp)->z_mapcnt, -pages);
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4608
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4609
	if ((flags & MAP_SHARED) && (prot & PROT_WRITE) &&
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4610
	    vn_has_cached_data(vp))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4611
		(void) VOP_PUTPAGE(vp, off, len, B_ASYNC, cr, ct);
1773
d6e4f2855c14 6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents: 1757
diff changeset
  4612
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4613
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4614
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4615
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4616
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4617
 * Free or allocate space in a file.  Currently, this function only
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4618
 * supports the `F_FREESP' command.  However, this command is somewhat
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4619
 * misnamed, as its functionality includes the ability to allocate as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4620
 * well as free space.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4621
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4622
 *	IN:	vp	- vnode of file to free data in.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4623
 *		cmd	- action to take (only F_FREESP supported).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4624
 *		bfp	- section of file to free/alloc.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4625
 *		flag	- current file open mode flags.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4626
 *		offset	- current file offset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4627
 *		cr	- credentials of caller [UNUSED].
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4628
 *		ct	- caller context.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4629
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4630
 *	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4631
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4632
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4633
 * Timestamps:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4634
 *	vp - ctime|mtime updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4635
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4636
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4637
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4638
zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4639
    offset_t offset, cred_t *cr, caller_context_t *ct)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4640
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4641
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4642
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4643
	uint64_t	off, len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4644
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4645
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4646
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4647
	ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4648
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4649
	if (cmd != F_FREESP) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4650
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4651
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4652
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4653
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4654
	if (error = convoff(vp, bfp, 0, offset)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4655
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4656
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4657
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4658
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4659
	if (bfp->l_len < 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4660
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4661
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4662
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4663
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4664
	off = bfp->l_start;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1576
diff changeset
  4665
	len = bfp->l_len; /* 0 means from off to end of file */
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1819
diff changeset
  4666
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6976
diff changeset
  4667
	error = zfs_freesp(zp, off, len, flag, TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4669
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4670
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4671
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4672
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4673
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4674
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4675
zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4676
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4677
	znode_t		*zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4678
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4863
diff changeset
  4679
	uint32_t	gen;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4680
	uint64_t	gen64;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4681
	uint64_t	object = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4682
	zfid_short_t	*zfid;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4683
	int		size, i, error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4684
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4685
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4686
	ZFS_VERIFY_ZP(zp);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4687
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4688
	if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_GEN(zfsvfs),
12218
49ce8ba18d5c 6945935 potential mutex problem in zfs_zaccess_aces_check()
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12178
diff changeset
  4689
	    &gen64, sizeof (uint64_t))) != 0) {
49ce8ba18d5c 6945935 potential mutex problem in zfs_zaccess_aces_check()
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12178
diff changeset
  4690
		ZFS_EXIT(zfsvfs);
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4691
		return (error);
12218
49ce8ba18d5c 6945935 potential mutex problem in zfs_zaccess_aces_check()
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 12178
diff changeset
  4692
	}
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4693
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4694
	gen = (uint32_t)gen64;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4696
	size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4697
	if (fidp->fid_len < size) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4698
		fidp->fid_len = size;
1512
dad2d74ca2cb 6391609 zfs_fid() missing ZFS_EXIT()
ek110237
parents: 1484
diff changeset
  4699
		ZFS_EXIT(zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4700
		return (ENOSPC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4701
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4702
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4703
	zfid = (zfid_short_t *)fidp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4704
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4705
	zfid->zf_len = size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4707
	for (i = 0; i < sizeof (zfid->zf_object); i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4708
		zfid->zf_object[i] = (uint8_t)(object >> (8 * i));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4709
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4710
	/* Must have a non-zero generation number to distinguish from .zfs */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4711
	if (gen == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4712
		gen = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4713
	for (i = 0; i < sizeof (zfid->zf_gen); i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4714
		zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4715
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4716
	if (size == LONG_FID_LEN) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4717
		uint64_t	objsetid = dmu_objset_id(zfsvfs->z_os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4718
		zfid_long_t	*zlfid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4720
		zlfid = (zfid_long_t *)fidp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4722
		for (i = 0; i < sizeof (zlfid->zf_setid); i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4723
			zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4725
		/* XXX - this should be the generation number for the objset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4726
		for (i = 0; i < sizeof (zlfid->zf_setgen); i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4727
			zlfid->zf_setgen[i] = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4728
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4729
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4730
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4731
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4732
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4733
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4734
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4735
zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4736
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4737
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4738
	znode_t		*zp, *xzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4739
	zfsvfs_t	*zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4740
	zfs_dirlock_t	*dl;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4741
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4742
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4743
	switch (cmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4744
	case _PC_LINK_MAX:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4745
		*valp = ULONG_MAX;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4746
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4747
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4748
	case _PC_FILESIZEBITS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4749
		*valp = 64;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4750
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4751
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4752
	case _PC_XATTR_EXISTS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4753
		zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4754
		zfsvfs = zp->z_zfsvfs;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4755
		ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4756
		ZFS_VERIFY_ZP(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4757
		*valp = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4758
		error = zfs_dirent_lock(&dl, zp, "", &xzp,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4759
		    ZXATTR | ZEXISTS | ZSHARED, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4760
		if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4761
			zfs_dirent_unlock(dl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4762
			if (!zfs_dirempty(xzp))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4763
				*valp = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4764
			VN_RELE(ZTOV(xzp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4765
		} else if (error == ENOENT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4766
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4767
			 * If there aren't extended attributes, it's the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4768
			 * same as having zero of them.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4769
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4770
			error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4771
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4772
		ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4773
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4774
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4775
	case _PC_SATTR_ENABLED:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4776
	case _PC_SATTR_EXISTS:
7757
bf4a45ecb669 PSARC/2008/588 VFSFT_SYSATTR_VIEWS
Janice Chang <Janice.Chang@Sun.COM>
parents: 7315
diff changeset
  4777
		*valp = vfs_has_feature(vp->v_vfsp, VFSFT_SYSATTR_VIEWS) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4778
		    (vp->v_type == VREG || vp->v_type == VDIR);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4779
		return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4780
9749
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  4781
	case _PC_ACCESS_FILTERING:
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  4782
		*valp = vfs_has_feature(vp->v_vfsp, VFSFT_ACCESS_FILTER) &&
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  4783
		    vp->v_type == VDIR;
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  4784
		return (0);
105f407a2680 PSARC 2009/246 ZFS support for Access Based Enumeration
Tim Haley <Tim.Haley@Sun.COM>
parents: 9512
diff changeset
  4785
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4786
	case _PC_ACL_ENABLED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4787
		*valp = _ACL_ACE_ENABLED;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4788
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4790
	case _PC_MIN_HOLE_SIZE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4791
		*valp = (ulong_t)SPA_MINBLOCKSIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4792
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4793
10440
ba48e0ae8d55 PSARC 2009/453 futimens, utimensat
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents: 10369
diff changeset
  4794
	case _PC_TIMESTAMP_RESOLUTION:
ba48e0ae8d55 PSARC 2009/453 futimens, utimensat
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents: 10369
diff changeset
  4795
		/* nanosecond timestamp resolution */
ba48e0ae8d55 PSARC 2009/453 futimens, utimensat
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents: 10369
diff changeset
  4796
		*valp = 1L;
ba48e0ae8d55 PSARC 2009/453 futimens, utimensat
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents: 10369
diff changeset
  4797
		return (0);
ba48e0ae8d55 PSARC 2009/453 futimens, utimensat
Roger A. Faulkner <Roger.Faulkner@Sun.COM>
parents: 10369
diff changeset
  4798
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4799
	default:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4800
		return (fs_pathconf(vp, cmd, valp, cr, ct));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4801
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4802
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4803
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4804
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4805
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4806
zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4807
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4808
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4809
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4810
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4811
	int error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4812
	boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4813
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4814
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4815
	ZFS_VERIFY_ZP(zp);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4816
	error = zfs_getacl(zp, vsecp, skipaclchk, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4817
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4819
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4820
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4822
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4823
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4824
zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4825
    caller_context_t *ct)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4826
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4827
	znode_t *zp = VTOZ(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4828
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4829
	int error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4830
	boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4831
	zilog_t	*zilog = zfsvfs->z_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4832
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4833
	ZFS_ENTER(zfsvfs);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4834
	ZFS_VERIFY_ZP(zp);
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4835
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4836
	error = zfs_setacl(zp, vsecp, skipaclchk, cr);
12294
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4837
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4838
	if (zfsvfs->z_os->os_sync == ZFS_SYNC_ALWAYS)
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4839
		zil_commit(zilog, UINT64_MAX, 0);
2a74b443e6b1 PSARC/2010/108 zil synchronicity
Mark J Musante <Mark.Musante@Sun.COM>
parents: 12285
diff changeset
  4840
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4841
	ZFS_EXIT(zfsvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4842
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4843
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4844
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4845
/*
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4846
 * Tunable, both must be a power of 2.
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4847
 *
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4848
 * zcr_blksz_min: the smallest read we may consider to loan out an arcbuf
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4849
 * zcr_blksz_max: if set to less than the file block size, allow loaning out of
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4850
 *                an arcbuf for a partial block read
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4851
 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4852
int zcr_blksz_min = (1 << 10);	/* 1K */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4853
int zcr_blksz_max = (1 << 17);	/* 128K */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4854
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4855
/*ARGSUSED*/
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4856
static int
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4857
zfs_reqzcbuf(vnode_t *vp, enum uio_rw ioflag, xuio_t *xuio, cred_t *cr,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4858
    caller_context_t *ct)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4859
{
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4860
	znode_t	*zp = VTOZ(vp);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4861
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4862
	int max_blksz = zfsvfs->z_max_blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4863
	uio_t *uio = &xuio->xu_uio;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4864
	ssize_t size = uio->uio_resid;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4865
	offset_t offset = uio->uio_loffset;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4866
	int blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4867
	int fullblk, i;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4868
	arc_buf_t *abuf;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4869
	ssize_t maxsize;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4870
	int preamble, postamble;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4871
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4872
	if (xuio->xu_type != UIOTYPE_ZEROCOPY)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4873
		return (EINVAL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4874
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4875
	ZFS_ENTER(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4876
	ZFS_VERIFY_ZP(zp);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4877
	switch (ioflag) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4878
	case UIO_WRITE:
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4879
		/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4880
		 * Loan out an arc_buf for write if write size is bigger than
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4881
		 * max_blksz, and the file's block size is also max_blksz.
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4882
		 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4883
		blksz = max_blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4884
		if (size < blksz || zp->z_blksz != blksz) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4885
			ZFS_EXIT(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4886
			return (EINVAL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4887
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4888
		/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4889
		 * Caller requests buffers for write before knowing where the
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4890
		 * write offset might be (e.g. NFS TCP write).
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4891
		 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4892
		if (offset == -1) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4893
			preamble = 0;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4894
		} else {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4895
			preamble = P2PHASE(offset, blksz);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4896
			if (preamble) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4897
				preamble = blksz - preamble;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4898
				size -= preamble;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4899
			}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4900
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4901
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4902
		postamble = P2PHASE(size, blksz);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4903
		size -= postamble;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4904
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4905
		fullblk = size / blksz;
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
  4906
		(void) dmu_xuio_init(xuio,
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4907
		    (preamble != 0) + fullblk + (postamble != 0));
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4908
		DTRACE_PROBE3(zfs_reqzcbuf_align, int, preamble,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4909
		    int, postamble, int,
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4910
		    (preamble != 0) + fullblk + (postamble != 0));
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4911
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4912
		/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4913
		 * Have to fix iov base/len for partial buffers.  They
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4914
		 * currently represent full arc_buf's.
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4915
		 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4916
		if (preamble) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4917
			/* data begins in the middle of the arc_buf */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4918
			abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4919
			    blksz);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4920
			ASSERT(abuf);
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
  4921
			(void) dmu_xuio_add(xuio, abuf,
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
  4922
			    blksz - preamble, preamble);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4923
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4924
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4925
		for (i = 0; i < fullblk; i++) {
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4926
			abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4927
			    blksz);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4928
			ASSERT(abuf);
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
  4929
			(void) dmu_xuio_add(xuio, abuf, 0, blksz);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4930
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4931
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4932
		if (postamble) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4933
			/* data ends in the middle of the arc_buf */
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4934
			abuf = dmu_request_arcbuf(sa_get_db(zp->z_sa_hdl),
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4935
			    blksz);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4936
			ASSERT(abuf);
11576
b23c42c0c9d6 6893174 avs and other sources are not ss12u1 lint clean
Surya Prakki <Surya.Prakki@Sun.COM>
parents: 11539
diff changeset
  4937
			(void) dmu_xuio_add(xuio, abuf, 0, postamble);
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4938
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4939
		break;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4940
	case UIO_READ:
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4941
		/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4942
		 * Loan out an arc_buf for read if the read size is larger than
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4943
		 * the current file block size.  Block alignment is not
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4944
		 * considered.  Partial arc_buf will be loaned out for read.
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4945
		 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4946
		blksz = zp->z_blksz;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4947
		if (blksz < zcr_blksz_min)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4948
			blksz = zcr_blksz_min;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4949
		if (blksz > zcr_blksz_max)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4950
			blksz = zcr_blksz_max;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4951
		/* avoid potential complexity of dealing with it */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4952
		if (blksz > max_blksz) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4953
			ZFS_EXIT(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4954
			return (EINVAL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4955
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4956
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11576
diff changeset
  4957
		maxsize = zp->z_size - uio->uio_loffset;
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4958
		if (size > maxsize)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4959
			size = maxsize;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4960
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4961
		if (size < blksz || vn_has_cached_data(vp)) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4962
			ZFS_EXIT(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4963
			return (EINVAL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4964
		}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4965
		break;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4966
	default:
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4967
		ZFS_EXIT(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4968
		return (EINVAL);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4969
	}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4970
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4971
	uio->uio_extflg = UIO_XUIO;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4972
	XUIO_XUZC_RW(xuio) = ioflag;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4973
	ZFS_EXIT(zfsvfs);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4974
	return (0);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4975
}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4976
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4977
/*ARGSUSED*/
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4978
static int
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4979
zfs_retzcbuf(vnode_t *vp, xuio_t *xuio, cred_t *cr, caller_context_t *ct)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4980
{
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4981
	int i;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4982
	arc_buf_t *abuf;
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4983
	int ioflag = XUIO_XUZC_RW(xuio);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4984
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4985
	ASSERT(xuio->xu_type == UIOTYPE_ZEROCOPY);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4986
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4987
	i = dmu_xuio_cnt(xuio);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4988
	while (i-- > 0) {
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4989
		abuf = dmu_xuio_arcbuf(xuio, i);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4990
		/*
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4991
		 * if abuf == NULL, it must be a write buffer
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4992
		 * that has been returned in zfs_write().
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4993
		 */
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4994
		if (abuf)
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4995
			dmu_return_arcbuf(abuf);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4996
		ASSERT(abuf || ioflag == UIO_WRITE);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4997
	}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4998
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  4999
	dmu_xuio_fini(xuio);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5000
	return (0);
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5001
}
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5002
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5003
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5004
 * Predeclare these here so that the compiler assumes that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5005
 * this is an "old style" function declaration that does
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5006
 * not include arguments => we won't get type mismatch errors
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5007
 * in the initializations that follow.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5008
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5009
static int zfs_inval();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5010
static int zfs_isdir();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5011
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5012
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5013
zfs_inval()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5014
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5015
	return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5016
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5017
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5018
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5019
zfs_isdir()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5020
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5021
	return (EISDIR);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5022
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5023
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5024
 * Directory vnode operations template
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5025
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5026
vnodeops_t *zfs_dvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5027
const fs_operation_def_t zfs_dvnodeops_template[] = {
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5028
	VOPNAME_OPEN,		{ .vop_open = zfs_open },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5029
	VOPNAME_CLOSE,		{ .vop_close = zfs_close },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5030
	VOPNAME_READ,		{ .error = zfs_isdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5031
	VOPNAME_WRITE,		{ .error = zfs_isdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5032
	VOPNAME_IOCTL,		{ .vop_ioctl = zfs_ioctl },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5033
	VOPNAME_GETATTR,	{ .vop_getattr = zfs_getattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5034
	VOPNAME_SETATTR,	{ .vop_setattr = zfs_setattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5035
	VOPNAME_ACCESS,		{ .vop_access = zfs_access },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5036
	VOPNAME_LOOKUP,		{ .vop_lookup = zfs_lookup },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5037
	VOPNAME_CREATE,		{ .vop_create = zfs_create },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5038
	VOPNAME_REMOVE,		{ .vop_remove = zfs_remove },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5039
	VOPNAME_LINK,		{ .vop_link = zfs_link },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5040
	VOPNAME_RENAME,		{ .vop_rename = zfs_rename },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5041
	VOPNAME_MKDIR,		{ .vop_mkdir = zfs_mkdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5042
	VOPNAME_RMDIR,		{ .vop_rmdir = zfs_rmdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5043
	VOPNAME_READDIR,	{ .vop_readdir = zfs_readdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5044
	VOPNAME_SYMLINK,	{ .vop_symlink = zfs_symlink },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5045
	VOPNAME_FSYNC,		{ .vop_fsync = zfs_fsync },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5046
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5047
	VOPNAME_FID,		{ .vop_fid = zfs_fid },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5048
	VOPNAME_SEEK,		{ .vop_seek = zfs_seek },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5049
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5050
	VOPNAME_GETSECATTR,	{ .vop_getsecattr = zfs_getsecattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5051
	VOPNAME_SETSECATTR,	{ .vop_setsecattr = zfs_setsecattr },
4863
7b14ad153d91 PSARC/2007/027 File Events Notification API
praks
parents: 4813
diff changeset
  5052
	VOPNAME_VNEVENT, 	{ .vop_vnevent = fs_vnevent_support },
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5053
	NULL,			NULL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5054
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5055
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5056
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5057
 * Regular file vnode operations template
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5058
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5059
vnodeops_t *zfs_fvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5060
const fs_operation_def_t zfs_fvnodeops_template[] = {
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5061
	VOPNAME_OPEN,		{ .vop_open = zfs_open },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5062
	VOPNAME_CLOSE,		{ .vop_close = zfs_close },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5063
	VOPNAME_READ,		{ .vop_read = zfs_read },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5064
	VOPNAME_WRITE,		{ .vop_write = zfs_write },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5065
	VOPNAME_IOCTL,		{ .vop_ioctl = zfs_ioctl },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5066
	VOPNAME_GETATTR,	{ .vop_getattr = zfs_getattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5067
	VOPNAME_SETATTR,	{ .vop_setattr = zfs_setattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5068
	VOPNAME_ACCESS,		{ .vop_access = zfs_access },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5069
	VOPNAME_LOOKUP,		{ .vop_lookup = zfs_lookup },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5070
	VOPNAME_RENAME,		{ .vop_rename = zfs_rename },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5071
	VOPNAME_FSYNC,		{ .vop_fsync = zfs_fsync },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5072
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5073
	VOPNAME_FID,		{ .vop_fid = zfs_fid },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5074
	VOPNAME_SEEK,		{ .vop_seek = zfs_seek },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5075
	VOPNAME_FRLOCK,		{ .vop_frlock = zfs_frlock },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5076
	VOPNAME_SPACE,		{ .vop_space = zfs_space },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5077
	VOPNAME_GETPAGE,	{ .vop_getpage = zfs_getpage },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5078
	VOPNAME_PUTPAGE,	{ .vop_putpage = zfs_putpage },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5079
	VOPNAME_MAP,		{ .vop_map = zfs_map },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5080
	VOPNAME_ADDMAP,		{ .vop_addmap = zfs_addmap },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5081
	VOPNAME_DELMAP,		{ .vop_delmap = zfs_delmap },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5082
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5083
	VOPNAME_GETSECATTR,	{ .vop_getsecattr = zfs_getsecattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5084
	VOPNAME_SETSECATTR,	{ .vop_setsecattr = zfs_setsecattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5085
	VOPNAME_VNEVENT,	{ .vop_vnevent = fs_vnevent_support },
11539
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5086
	VOPNAME_REQZCBUF, 	{ .vop_reqzcbuf = zfs_reqzcbuf },
10d35fc3d7fd 6873106 Need a mechanism to share buffers between fs modules
chunli zhang - Sun Microsystems - Irvine United States <Chunli.Zhang@Sun.COM>
parents: 11321
diff changeset
  5087
	VOPNAME_RETZCBUF, 	{ .vop_retzcbuf = zfs_retzcbuf },
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5088
	NULL,			NULL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5089
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5090
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5091
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5092
 * Symbolic link vnode operations template
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5093
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5094
vnodeops_t *zfs_symvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5095
const fs_operation_def_t zfs_symvnodeops_template[] = {
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5096
	VOPNAME_GETATTR,	{ .vop_getattr = zfs_getattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5097
	VOPNAME_SETATTR,	{ .vop_setattr = zfs_setattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5098
	VOPNAME_ACCESS,		{ .vop_access = zfs_access },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5099
	VOPNAME_RENAME,		{ .vop_rename = zfs_rename },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5100
	VOPNAME_READLINK,	{ .vop_readlink = zfs_readlink },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5101
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5102
	VOPNAME_FID,		{ .vop_fid = zfs_fid },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5103
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5104
	VOPNAME_VNEVENT,	{ .vop_vnevent = fs_vnevent_support },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5105
	NULL,			NULL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5106
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5107
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5108
/*
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5109
 * special share hidden files vnode operations template
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5110
 */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5111
vnodeops_t *zfs_sharevnodeops;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5112
const fs_operation_def_t zfs_sharevnodeops_template[] = {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5113
	VOPNAME_GETATTR,	{ .vop_getattr = zfs_getattr },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5114
	VOPNAME_ACCESS,		{ .vop_access = zfs_access },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5115
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5116
	VOPNAME_FID,		{ .vop_fid = zfs_fid },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5117
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5118
	VOPNAME_GETSECATTR,	{ .vop_getsecattr = zfs_getsecattr },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5119
	VOPNAME_SETSECATTR,	{ .vop_setsecattr = zfs_setsecattr },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5120
	VOPNAME_VNEVENT,	{ .vop_vnevent = fs_vnevent_support },
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5121
	NULL,			NULL
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5122
};
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5123
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8681
diff changeset
  5124
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5125
 * Extended attribute directory vnode operations template
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5126
 *	This template is identical to the directory vnodes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5127
 *	operation template except for restricted operations:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5128
 *		VOP_MKDIR()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5129
 *		VOP_SYMLINK()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5130
 * Note that there are other restrictions embedded in:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5131
 *	zfs_create()	- restrict type to VREG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5132
 *	zfs_link()	- no links into/out of attribute space
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5133
 *	zfs_rename()	- no moves into/out of attribute space
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5134
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5135
vnodeops_t *zfs_xdvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5136
const fs_operation_def_t zfs_xdvnodeops_template[] = {
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5137
	VOPNAME_OPEN,		{ .vop_open = zfs_open },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5138
	VOPNAME_CLOSE,		{ .vop_close = zfs_close },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5139
	VOPNAME_IOCTL,		{ .vop_ioctl = zfs_ioctl },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5140
	VOPNAME_GETATTR,	{ .vop_getattr = zfs_getattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5141
	VOPNAME_SETATTR,	{ .vop_setattr = zfs_setattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5142
	VOPNAME_ACCESS,		{ .vop_access = zfs_access },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5143
	VOPNAME_LOOKUP,		{ .vop_lookup = zfs_lookup },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5144
	VOPNAME_CREATE,		{ .vop_create = zfs_create },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5145
	VOPNAME_REMOVE,		{ .vop_remove = zfs_remove },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5146
	VOPNAME_LINK,		{ .vop_link = zfs_link },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5147
	VOPNAME_RENAME,		{ .vop_rename = zfs_rename },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5148
	VOPNAME_MKDIR,		{ .error = zfs_inval },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5149
	VOPNAME_RMDIR,		{ .vop_rmdir = zfs_rmdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5150
	VOPNAME_READDIR,	{ .vop_readdir = zfs_readdir },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5151
	VOPNAME_SYMLINK,	{ .error = zfs_inval },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5152
	VOPNAME_FSYNC,		{ .vop_fsync = zfs_fsync },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5153
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5154
	VOPNAME_FID,		{ .vop_fid = zfs_fid },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5155
	VOPNAME_SEEK,		{ .vop_seek = zfs_seek },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5156
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5157
	VOPNAME_GETSECATTR,	{ .vop_getsecattr = zfs_getsecattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5158
	VOPNAME_SETSECATTR,	{ .vop_setsecattr = zfs_setsecattr },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5159
	VOPNAME_VNEVENT,	{ .vop_vnevent = fs_vnevent_support },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5160
	NULL,			NULL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5161
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5162
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5163
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5164
 * Error vnode operations template
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5165
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5166
vnodeops_t *zfs_evnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5167
const fs_operation_def_t zfs_evnodeops_template[] = {
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5168
	VOPNAME_INACTIVE,	{ .vop_inactive = zfs_inactive },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5169
	VOPNAME_PATHCONF,	{ .vop_pathconf = zfs_pathconf },
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
  5170
	NULL,			NULL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  5171
};