author | marks |
Thu, 29 Nov 2007 07:47:57 -0800 | |
changeset 5545 | 62533366078f |
parent 5498 | 334b476844ca |
child 5642 | 504c84876fda |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
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 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
3461 | 22 |
* Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
4144
068f395736ad
6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents:
3912
diff
changeset
|
26 |
/* Portions Copyright 2007 Jeremy Teo */ |
068f395736ad
6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents:
3912
diff
changeset
|
27 |
|
789 | 28 |
#pragma ident "%Z%%M% %I% %E% SMI" |
29 |
||
30 |
#include <sys/types.h> |
|
31 |
#include <sys/param.h> |
|
32 |
#include <sys/time.h> |
|
33 |
#include <sys/systm.h> |
|
34 |
#include <sys/sysmacros.h> |
|
35 |
#include <sys/resource.h> |
|
36 |
#include <sys/vfs.h> |
|
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
37 |
#include <sys/vfs_opreg.h> |
789 | 38 |
#include <sys/vnode.h> |
39 |
#include <sys/file.h> |
|
40 |
#include <sys/stat.h> |
|
41 |
#include <sys/kmem.h> |
|
42 |
#include <sys/taskq.h> |
|
43 |
#include <sys/uio.h> |
|
44 |
#include <sys/vmsystm.h> |
|
45 |
#include <sys/atomic.h> |
|
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
46 |
#include <sys/vm.h> |
789 | 47 |
#include <vm/seg_vn.h> |
48 |
#include <vm/pvn.h> |
|
49 |
#include <vm/as.h> |
|
50 |
#include <sys/mman.h> |
|
51 |
#include <sys/pathname.h> |
|
52 |
#include <sys/cmn_err.h> |
|
53 |
#include <sys/errno.h> |
|
54 |
#include <sys/unistd.h> |
|
55 |
#include <sys/zfs_dir.h> |
|
56 |
#include <sys/zfs_acl.h> |
|
57 |
#include <sys/zfs_ioctl.h> |
|
58 |
#include <sys/fs/zfs.h> |
|
59 |
#include <sys/dmu.h> |
|
60 |
#include <sys/spa.h> |
|
61 |
#include <sys/txg.h> |
|
62 |
#include <sys/dbuf.h> |
|
63 |
#include <sys/zap.h> |
|
64 |
#include <sys/dirent.h> |
|
65 |
#include <sys/policy.h> |
|
66 |
#include <sys/sunddi.h> |
|
67 |
#include <sys/filio.h> |
|
68 |
#include "fs/fs_subr.h" |
|
69 |
#include <sys/zfs_ctldir.h> |
|
5331 | 70 |
#include <sys/zfs_fuid.h> |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1472
diff
changeset
|
71 |
#include <sys/dnlc.h> |
1669 | 72 |
#include <sys/zfs_rlock.h> |
5331 | 73 |
#include <sys/extdirent.h> |
74 |
#include <sys/kidmap.h> |
|
75 |
#include <sys/cred_impl.h> |
|
789 | 76 |
|
77 |
/* |
|
78 |
* Programming rules. |
|
79 |
* |
|
80 |
* Each vnode op performs some logical unit of work. To do this, the ZPL must |
|
81 |
* properly lock its in-core state, create a DMU transaction, do the work, |
|
82 |
* record this work in the intent log (ZIL), commit the DMU transaction, |
|
5331 | 83 |
* and wait for the intent log to commit if it is a synchronous operation. |
84 |
* Moreover, the vnode ops must work in both normal and log replay context. |
|
789 | 85 |
* The ordering of events is important to avoid deadlocks and references |
86 |
* to freed memory. The example below illustrates the following Big Rules: |
|
87 |
* |
|
88 |
* (1) A check must be made in each zfs thread for a mounted file system. |
|
5367 | 89 |
* This is done avoiding races using ZFS_ENTER(zfsvfs). |
90 |
* A ZFS_EXIT(zfsvfs) is needed before all returns. Any znodes |
|
91 |
* must be checked with ZFS_VERIFY_ZP(zp). Both of these macros |
|
92 |
* can return EIO from the calling function. |
|
789 | 93 |
* |
94 |
* (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
|
95 |
* (if necessary) and ZFS_EXIT(). This is for 3 reasons: |
789 | 96 |
* First, if it's the last reference, the vnode/znode |
97 |
* can be freed, so the zp may point to freed memory. Second, the last |
|
98 |
* reference will call zfs_zinactive(), which may induce a lot of work -- |
|
1669 | 99 |
* pushing cached pages (which acquires range locks) and syncing out |
789 | 100 |
* cached atime changes. Third, zfs_zinactive() may require a new tx, |
101 |
* which could deadlock the system if you were already holding one. |
|
102 |
* |
|
1757 | 103 |
* (3) All range locks must be grabbed before calling dmu_tx_assign(), |
104 |
* as they can span dmu_tx_assign() calls. |
|
105 |
* |
|
106 |
* (4) Always pass zfsvfs->z_assign as the second argument to dmu_tx_assign(). |
|
789 | 107 |
* In normal operation, this will be TXG_NOWAIT. During ZIL replay, |
108 |
* it will be a specific txg. Either way, dmu_tx_assign() never blocks. |
|
109 |
* This is critical because we don't want to block while holding locks. |
|
110 |
* Note, in particular, that if a lock is sometimes acquired before |
|
111 |
* the tx assigns, and sometimes after (e.g. z_lock), then failing to |
|
112 |
* use a non-blocking assign can deadlock the system. The scenario: |
|
113 |
* |
|
114 |
* Thread A has grabbed a lock before calling dmu_tx_assign(). |
|
115 |
* Thread B is in an already-assigned tx, and blocks for this lock. |
|
116 |
* Thread A calls dmu_tx_assign(TXG_WAIT) and blocks in txg_wait_open() |
|
117 |
* forever, because the previous txg can't quiesce until B's tx commits. |
|
118 |
* |
|
119 |
* 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
|
120 |
* then drop all locks, call dmu_tx_wait(), and try again. |
789 | 121 |
* |
1757 | 122 |
* (5) If the operation succeeded, generate the intent log entry for it |
789 | 123 |
* before dropping locks. This ensures that the ordering of events |
124 |
* in the intent log matches the order in which they actually occurred. |
|
125 |
* |
|
1757 | 126 |
* (6) At the end of each vnode op, the DMU tx must always commit, |
789 | 127 |
* regardless of whether there were any errors. |
128 |
* |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
129 |
* (7) After dropping all locks, invoke zil_commit(zilog, seq, foid) |
789 | 130 |
* to ensure that synchronous semantics are provided when necessary. |
131 |
* |
|
132 |
* In general, this is how things should be ordered in each vnode op: |
|
133 |
* |
|
134 |
* ZFS_ENTER(zfsvfs); // exit if unmounted |
|
135 |
* top: |
|
136 |
* zfs_dirent_lock(&dl, ...) // lock directory entry (may VN_HOLD()) |
|
137 |
* rw_enter(...); // grab any other locks you need |
|
138 |
* tx = dmu_tx_create(...); // get DMU tx |
|
139 |
* dmu_tx_hold_*(); // hold each object you might modify |
|
140 |
* error = dmu_tx_assign(tx, zfsvfs->z_assign); // try to assign |
|
141 |
* if (error) { |
|
142 |
* rw_exit(...); // drop locks |
|
143 |
* zfs_dirent_unlock(dl); // unlock directory entry |
|
144 |
* VN_RELE(...); // release held vnodes |
|
145 |
* if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
146 |
* dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
147 |
* dmu_tx_abort(tx); |
789 | 148 |
* goto top; |
149 |
* } |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
150 |
* dmu_tx_abort(tx); // abort DMU tx |
789 | 151 |
* ZFS_EXIT(zfsvfs); // finished in zfs |
152 |
* return (error); // really out of space |
|
153 |
* } |
|
154 |
* error = do_real_work(); // do whatever this VOP does |
|
155 |
* 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
|
156 |
* zfs_log_*(...); // on success, make ZIL entry |
789 | 157 |
* dmu_tx_commit(tx); // commit DMU tx -- error or not |
158 |
* rw_exit(...); // drop locks |
|
159 |
* zfs_dirent_unlock(dl); // unlock directory entry |
|
160 |
* 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
|
161 |
* zil_commit(zilog, seq, foid); // synchronous when necessary |
789 | 162 |
* ZFS_EXIT(zfsvfs); // finished in zfs |
163 |
* return (error); // done, report error |
|
164 |
*/ |
|
5367 | 165 |
|
789 | 166 |
/* ARGSUSED */ |
167 |
static int |
|
5331 | 168 |
zfs_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct) |
789 | 169 |
{ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
170 |
znode_t *zp = VTOZ(*vpp); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
171 |
|
5331 | 172 |
if ((flag & FWRITE) && (zp->z_phys->zp_flags & ZFS_APPENDONLY) && |
173 |
((flag & FAPPEND) == 0)) { |
|
174 |
return (EPERM); |
|
175 |
} |
|
176 |
||
177 |
if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan && |
|
178 |
ZTOV(zp)->v_type == VREG && |
|
179 |
!(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) && |
|
180 |
zp->z_phys->zp_size > 0) |
|
181 |
if (fs_vscan(*vpp, cr, 0) != 0) |
|
182 |
return (EACCES); |
|
183 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
184 |
/* Keep a count of the synchronous opens in the znode */ |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
185 |
if (flag & (FSYNC | FDSYNC)) |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
186 |
atomic_inc_32(&zp->z_sync_cnt); |
5331 | 187 |
|
789 | 188 |
return (0); |
189 |
} |
|
190 |
||
191 |
/* ARGSUSED */ |
|
192 |
static int |
|
5331 | 193 |
zfs_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr, |
194 |
caller_context_t *ct) |
|
789 | 195 |
{ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
196 |
znode_t *zp = VTOZ(vp); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
197 |
|
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
198 |
/* Decrement the synchronous opens in the znode */ |
4339 | 199 |
if ((flag & (FSYNC | FDSYNC)) && (count == 1)) |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
200 |
atomic_dec_32(&zp->z_sync_cnt); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
201 |
|
789 | 202 |
/* |
203 |
* Clean up any locks held by this process on the vp. |
|
204 |
*/ |
|
205 |
cleanlocks(vp, ddi_get_pid(), 0); |
|
206 |
cleanshares(vp, ddi_get_pid()); |
|
207 |
||
5331 | 208 |
if (!zfs_has_ctldir(zp) && zp->z_zfsvfs->z_vscan && |
209 |
ZTOV(zp)->v_type == VREG && |
|
210 |
!(zp->z_phys->zp_flags & ZFS_AV_QUARANTINED) && |
|
211 |
zp->z_phys->zp_size > 0) |
|
212 |
VERIFY(fs_vscan(vp, cr, 1) == 0); |
|
213 |
||
789 | 214 |
return (0); |
215 |
} |
|
216 |
||
217 |
/* |
|
218 |
* Lseek support for finding holes (cmd == _FIO_SEEK_HOLE) and |
|
219 |
* data (cmd == _FIO_SEEK_DATA). "off" is an in/out parameter. |
|
220 |
*/ |
|
221 |
static int |
|
222 |
zfs_holey(vnode_t *vp, int cmd, offset_t *off) |
|
223 |
{ |
|
224 |
znode_t *zp = VTOZ(vp); |
|
225 |
uint64_t noff = (uint64_t)*off; /* new offset */ |
|
226 |
uint64_t file_sz; |
|
227 |
int error; |
|
228 |
boolean_t hole; |
|
229 |
||
230 |
file_sz = zp->z_phys->zp_size; |
|
231 |
if (noff >= file_sz) { |
|
232 |
return (ENXIO); |
|
233 |
} |
|
234 |
||
235 |
if (cmd == _FIO_SEEK_HOLE) |
|
236 |
hole = B_TRUE; |
|
237 |
else |
|
238 |
hole = B_FALSE; |
|
239 |
||
240 |
error = dmu_offset_next(zp->z_zfsvfs->z_os, zp->z_id, hole, &noff); |
|
241 |
||
242 |
/* end of file? */ |
|
243 |
if ((error == ESRCH) || (noff > file_sz)) { |
|
244 |
/* |
|
245 |
* Handle the virtual hole at the end of file. |
|
246 |
*/ |
|
247 |
if (hole) { |
|
248 |
*off = file_sz; |
|
249 |
return (0); |
|
250 |
} |
|
251 |
return (ENXIO); |
|
252 |
} |
|
253 |
||
254 |
if (noff < *off) |
|
255 |
return (error); |
|
256 |
*off = noff; |
|
257 |
return (error); |
|
258 |
} |
|
259 |
||
260 |
/* ARGSUSED */ |
|
261 |
static int |
|
262 |
zfs_ioctl(vnode_t *vp, int com, intptr_t data, int flag, cred_t *cred, |
|
5331 | 263 |
int *rvalp, caller_context_t *ct) |
789 | 264 |
{ |
265 |
offset_t off; |
|
266 |
int error; |
|
267 |
zfsvfs_t *zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
268 |
znode_t *zp; |
789 | 269 |
|
270 |
switch (com) { |
|
4339 | 271 |
case _FIOFFS: |
789 | 272 |
return (zfs_sync(vp->v_vfsp, 0, cred)); |
273 |
||
1544 | 274 |
/* |
275 |
* The following two ioctls are used by bfu. Faking out, |
|
276 |
* necessary to avoid bfu errors. |
|
277 |
*/ |
|
4339 | 278 |
case _FIOGDIO: |
279 |
case _FIOSDIO: |
|
1544 | 280 |
return (0); |
281 |
||
4339 | 282 |
case _FIO_SEEK_DATA: |
283 |
case _FIO_SEEK_HOLE: |
|
789 | 284 |
if (ddi_copyin((void *)data, &off, sizeof (off), flag)) |
285 |
return (EFAULT); |
|
286 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
287 |
zp = VTOZ(vp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
288 |
zfsvfs = zp->z_zfsvfs; |
5367 | 289 |
ZFS_ENTER(zfsvfs); |
290 |
ZFS_VERIFY_ZP(zp); |
|
789 | 291 |
|
292 |
/* offset parameter is in/out */ |
|
293 |
error = zfs_holey(vp, com, &off); |
|
294 |
ZFS_EXIT(zfsvfs); |
|
295 |
if (error) |
|
296 |
return (error); |
|
297 |
if (ddi_copyout(&off, (void *)data, sizeof (off), flag)) |
|
298 |
return (EFAULT); |
|
299 |
return (0); |
|
300 |
} |
|
301 |
return (ENOTTY); |
|
302 |
} |
|
303 |
||
304 |
/* |
|
305 |
* When a file is memory mapped, we must keep the IO data synchronized |
|
306 |
* between the DMU cache and the memory mapped pages. What this means: |
|
307 |
* |
|
308 |
* On Write: If we find a memory mapped page, we write to *both* |
|
309 |
* the page and the dmu buffer. |
|
310 |
* |
|
311 |
* NOTE: We will always "break up" the IO into PAGESIZE uiomoves when |
|
312 |
* the file is memory mapped. |
|
313 |
*/ |
|
314 |
static int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
315 |
mappedwrite(vnode_t *vp, int nbytes, uio_t *uio, dmu_tx_t *tx) |
789 | 316 |
{ |
317 |
znode_t *zp = VTOZ(vp); |
|
318 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
319 |
int64_t start, off; |
|
320 |
int len = nbytes; |
|
321 |
int error = 0; |
|
322 |
||
323 |
start = uio->uio_loffset; |
|
324 |
off = start & PAGEOFFSET; |
|
325 |
for (start &= PAGEMASK; len > 0; start += PAGESIZE) { |
|
326 |
page_t *pp; |
|
327 |
uint64_t bytes = MIN(PAGESIZE - off, len); |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
328 |
uint64_t woff = uio->uio_loffset; |
789 | 329 |
|
330 |
/* |
|
331 |
* We don't want a new page to "appear" in the middle of |
|
332 |
* the file update (because it may not get the write |
|
333 |
* update data), so we grab a lock to block |
|
334 |
* zfs_getpage(). |
|
335 |
*/ |
|
336 |
rw_enter(&zp->z_map_lock, RW_WRITER); |
|
337 |
if (pp = page_lookup(vp, start, SE_SHARED)) { |
|
338 |
caddr_t va; |
|
339 |
||
340 |
rw_exit(&zp->z_map_lock); |
|
341 |
va = ppmapin(pp, PROT_READ | PROT_WRITE, (caddr_t)-1L); |
|
342 |
error = uiomove(va+off, bytes, UIO_WRITE, uio); |
|
343 |
if (error == 0) { |
|
344 |
dmu_write(zfsvfs->z_os, zp->z_id, |
|
345 |
woff, bytes, va+off, tx); |
|
346 |
} |
|
347 |
ppmapout(va); |
|
348 |
page_unlock(pp); |
|
349 |
} else { |
|
350 |
error = dmu_write_uio(zfsvfs->z_os, zp->z_id, |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
351 |
uio, bytes, tx); |
789 | 352 |
rw_exit(&zp->z_map_lock); |
353 |
} |
|
354 |
len -= bytes; |
|
355 |
off = 0; |
|
356 |
if (error) |
|
357 |
break; |
|
358 |
} |
|
359 |
return (error); |
|
360 |
} |
|
361 |
||
362 |
/* |
|
363 |
* When a file is memory mapped, we must keep the IO data synchronized |
|
364 |
* between the DMU cache and the memory mapped pages. What this means: |
|
365 |
* |
|
366 |
* On Read: We "read" preferentially from memory mapped pages, |
|
367 |
* else we default from the dmu buffer. |
|
368 |
* |
|
369 |
* NOTE: We will always "break up" the IO into PAGESIZE uiomoves when |
|
370 |
* the file is memory mapped. |
|
371 |
*/ |
|
372 |
static int |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
373 |
mappedread(vnode_t *vp, int nbytes, uio_t *uio) |
789 | 374 |
{ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
375 |
znode_t *zp = VTOZ(vp); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
376 |
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
|
377 |
int64_t start, off; |
789 | 378 |
int len = nbytes; |
379 |
int error = 0; |
|
380 |
||
381 |
start = uio->uio_loffset; |
|
382 |
off = start & PAGEOFFSET; |
|
383 |
for (start &= PAGEMASK; len > 0; start += PAGESIZE) { |
|
384 |
page_t *pp; |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
385 |
uint64_t bytes = MIN(PAGESIZE - off, len); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
386 |
|
789 | 387 |
if (pp = page_lookup(vp, start, SE_SHARED)) { |
388 |
caddr_t va; |
|
389 |
||
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
390 |
va = ppmapin(pp, PROT_READ, (caddr_t)-1L); |
789 | 391 |
error = uiomove(va + off, bytes, UIO_READ, uio); |
392 |
ppmapout(va); |
|
393 |
page_unlock(pp); |
|
394 |
} else { |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
395 |
error = dmu_read_uio(os, zp->z_id, uio, bytes); |
789 | 396 |
} |
397 |
len -= bytes; |
|
398 |
off = 0; |
|
399 |
if (error) |
|
400 |
break; |
|
401 |
} |
|
402 |
return (error); |
|
403 |
} |
|
404 |
||
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
405 |
offset_t zfs_read_chunk_size = 1024 * 1024; /* Tunable */ |
789 | 406 |
|
407 |
/* |
|
408 |
* Read bytes from specified file into supplied buffer. |
|
409 |
* |
|
410 |
* IN: vp - vnode of file to be read from. |
|
411 |
* uio - structure supplying read location, range info, |
|
412 |
* and return buffer. |
|
413 |
* ioflag - SYNC flags; used to provide FRSYNC semantics. |
|
414 |
* cr - credentials of caller. |
|
5331 | 415 |
* ct - caller context |
789 | 416 |
* |
417 |
* OUT: uio - updated offset and range, buffer filled. |
|
418 |
* |
|
419 |
* RETURN: 0 if success |
|
420 |
* error code if failure |
|
421 |
* |
|
422 |
* Side Effects: |
|
423 |
* vp - atime updated if byte count > 0 |
|
424 |
*/ |
|
425 |
/* ARGSUSED */ |
|
426 |
static int |
|
427 |
zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct) |
|
428 |
{ |
|
429 |
znode_t *zp = VTOZ(vp); |
|
430 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
431 |
objset_t *os; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
432 |
ssize_t n, nbytes; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
433 |
int error; |
1669 | 434 |
rl_t *rl; |
789 | 435 |
|
5367 | 436 |
ZFS_ENTER(zfsvfs); |
437 |
ZFS_VERIFY_ZP(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
438 |
os = zfsvfs->z_os; |
789 | 439 |
|
440 |
/* |
|
441 |
* Validate file offset |
|
442 |
*/ |
|
443 |
if (uio->uio_loffset < (offset_t)0) { |
|
444 |
ZFS_EXIT(zfsvfs); |
|
445 |
return (EINVAL); |
|
446 |
} |
|
447 |
||
448 |
/* |
|
449 |
* Fasttrack empty reads |
|
450 |
*/ |
|
451 |
if (uio->uio_resid == 0) { |
|
452 |
ZFS_EXIT(zfsvfs); |
|
453 |
return (0); |
|
454 |
} |
|
455 |
||
456 |
/* |
|
1669 | 457 |
* Check for mandatory locks |
789 | 458 |
*/ |
459 |
if (MANDMODE((mode_t)zp->z_phys->zp_mode)) { |
|
460 |
if (error = chklock(vp, FREAD, |
|
461 |
uio->uio_loffset, uio->uio_resid, uio->uio_fmode, ct)) { |
|
462 |
ZFS_EXIT(zfsvfs); |
|
463 |
return (error); |
|
464 |
} |
|
465 |
} |
|
466 |
||
467 |
/* |
|
468 |
* If we're in FRSYNC mode, sync out this znode before reading it. |
|
469 |
*/ |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
470 |
if (ioflag & FRSYNC) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
471 |
zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id); |
789 | 472 |
|
473 |
/* |
|
1669 | 474 |
* Lock the range against changes. |
789 | 475 |
*/ |
1669 | 476 |
rl = zfs_range_lock(zp, uio->uio_loffset, uio->uio_resid, RL_READER); |
477 |
||
789 | 478 |
/* |
479 |
* If we are reading past end-of-file we can skip |
|
480 |
* to the end; but we might still need to set atime. |
|
481 |
*/ |
|
482 |
if (uio->uio_loffset >= zp->z_phys->zp_size) { |
|
483 |
error = 0; |
|
484 |
goto out; |
|
485 |
} |
|
486 |
||
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
487 |
ASSERT(uio->uio_loffset < zp->z_phys->zp_size); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
488 |
n = MIN(uio->uio_resid, zp->z_phys->zp_size - uio->uio_loffset); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
489 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
490 |
while (n > 0) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
491 |
nbytes = MIN(n, zfs_read_chunk_size - |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
492 |
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
|
493 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
494 |
if (vn_has_cached_data(vp)) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
495 |
error = mappedread(vp, nbytes, uio); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
496 |
else |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
497 |
error = dmu_read_uio(os, zp->z_id, uio, nbytes); |
1544 | 498 |
if (error) |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
499 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
500 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
501 |
n -= nbytes; |
789 | 502 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
503 |
|
789 | 504 |
out: |
2237 | 505 |
zfs_range_unlock(rl); |
789 | 506 |
|
507 |
ZFS_ACCESSTIME_STAMP(zfsvfs, zp); |
|
508 |
ZFS_EXIT(zfsvfs); |
|
509 |
return (error); |
|
510 |
} |
|
511 |
||
512 |
/* |
|
513 |
* Fault in the pages of the first n bytes specified by the uio structure. |
|
514 |
* 1 byte in each page is touched and the uio struct is unmodified. |
|
515 |
* Any error will exit this routine as this is only a best |
|
516 |
* attempt to get the pages resident. This is a copy of ufs_trans_touch(). |
|
517 |
*/ |
|
518 |
static void |
|
519 |
zfs_prefault_write(ssize_t n, struct uio *uio) |
|
520 |
{ |
|
521 |
struct iovec *iov; |
|
522 |
ulong_t cnt, incr; |
|
523 |
caddr_t p; |
|
524 |
uint8_t tmp; |
|
525 |
||
526 |
iov = uio->uio_iov; |
|
527 |
||
528 |
while (n) { |
|
529 |
cnt = MIN(iov->iov_len, n); |
|
530 |
if (cnt == 0) { |
|
531 |
/* empty iov entry */ |
|
532 |
iov++; |
|
533 |
continue; |
|
534 |
} |
|
535 |
n -= cnt; |
|
536 |
/* |
|
537 |
* touch each page in this segment. |
|
538 |
*/ |
|
539 |
p = iov->iov_base; |
|
540 |
while (cnt) { |
|
541 |
switch (uio->uio_segflg) { |
|
542 |
case UIO_USERSPACE: |
|
543 |
case UIO_USERISPACE: |
|
544 |
if (fuword8(p, &tmp)) |
|
545 |
return; |
|
546 |
break; |
|
547 |
case UIO_SYSSPACE: |
|
548 |
if (kcopy(p, &tmp, 1)) |
|
549 |
return; |
|
550 |
break; |
|
551 |
} |
|
552 |
incr = MIN(cnt, PAGESIZE); |
|
553 |
p += incr; |
|
554 |
cnt -= incr; |
|
555 |
} |
|
556 |
/* |
|
557 |
* touch the last byte in case it straddles a page. |
|
558 |
*/ |
|
559 |
p--; |
|
560 |
switch (uio->uio_segflg) { |
|
561 |
case UIO_USERSPACE: |
|
562 |
case UIO_USERISPACE: |
|
563 |
if (fuword8(p, &tmp)) |
|
564 |
return; |
|
565 |
break; |
|
566 |
case UIO_SYSSPACE: |
|
567 |
if (kcopy(p, &tmp, 1)) |
|
568 |
return; |
|
569 |
break; |
|
570 |
} |
|
571 |
iov++; |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
/* |
|
576 |
* Write the bytes to a file. |
|
577 |
* |
|
578 |
* IN: vp - vnode of file to be written to. |
|
579 |
* uio - structure supplying write location, range info, |
|
580 |
* and data buffer. |
|
581 |
* ioflag - FAPPEND flag set if in append mode. |
|
582 |
* cr - credentials of caller. |
|
5331 | 583 |
* ct - caller context (NFS/CIFS fem monitor only) |
789 | 584 |
* |
585 |
* OUT: uio - updated offset and range. |
|
586 |
* |
|
587 |
* RETURN: 0 if success |
|
588 |
* error code if failure |
|
589 |
* |
|
590 |
* Timestamps: |
|
591 |
* vp - ctime|mtime updated if byte count > 0 |
|
592 |
*/ |
|
593 |
/* ARGSUSED */ |
|
594 |
static int |
|
595 |
zfs_write(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct) |
|
596 |
{ |
|
597 |
znode_t *zp = VTOZ(vp); |
|
598 |
rlim64_t limit = uio->uio_llimit; |
|
599 |
ssize_t start_resid = uio->uio_resid; |
|
600 |
ssize_t tx_bytes; |
|
601 |
uint64_t end_size; |
|
602 |
dmu_tx_t *tx; |
|
603 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
604 |
zilog_t *zilog; |
789 | 605 |
offset_t woff; |
606 |
ssize_t n, nbytes; |
|
1669 | 607 |
rl_t *rl; |
789 | 608 |
int max_blksz = zfsvfs->z_max_blksz; |
5331 | 609 |
uint64_t pflags = zp->z_phys->zp_flags; |
1669 | 610 |
int error; |
789 | 611 |
|
612 |
/* |
|
5331 | 613 |
* If immutable or not appending then return EPERM |
614 |
*/ |
|
615 |
if ((pflags & (ZFS_IMMUTABLE | ZFS_READONLY)) || |
|
616 |
((pflags & ZFS_APPENDONLY) && !(ioflag & FAPPEND) && |
|
617 |
(uio->uio_loffset < zp->z_phys->zp_size))) |
|
618 |
return (EPERM); |
|
619 |
||
620 |
/* |
|
789 | 621 |
* Fasttrack empty write |
622 |
*/ |
|
1669 | 623 |
n = start_resid; |
789 | 624 |
if (n == 0) |
625 |
return (0); |
|
626 |
||
1669 | 627 |
if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T) |
628 |
limit = MAXOFFSET_T; |
|
629 |
||
5367 | 630 |
ZFS_ENTER(zfsvfs); |
631 |
ZFS_VERIFY_ZP(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
632 |
zilog = zfsvfs->z_log; |
789 | 633 |
|
634 |
/* |
|
2237 | 635 |
* Pre-fault the pages to ensure slow (eg NFS) pages |
1669 | 636 |
* don't hold up txg. |
789 | 637 |
*/ |
2237 | 638 |
zfs_prefault_write(n, uio); |
789 | 639 |
|
640 |
/* |
|
641 |
* If in append mode, set the io offset pointer to eof. |
|
642 |
*/ |
|
1669 | 643 |
if (ioflag & FAPPEND) { |
644 |
/* |
|
645 |
* Range lock for a file append: |
|
646 |
* The value for the start of range will be determined by |
|
647 |
* zfs_range_lock() (to guarantee append semantics). |
|
648 |
* If this write will cause the block size to increase, |
|
649 |
* zfs_range_lock() will lock the entire file, so we must |
|
650 |
* later reduce the range after we grow the block size. |
|
651 |
*/ |
|
652 |
rl = zfs_range_lock(zp, 0, n, RL_APPEND); |
|
653 |
if (rl->r_len == UINT64_MAX) { |
|
654 |
/* overlocked, zp_size can't change */ |
|
655 |
woff = uio->uio_loffset = zp->z_phys->zp_size; |
|
656 |
} else { |
|
657 |
woff = uio->uio_loffset = rl->r_off; |
|
658 |
} |
|
789 | 659 |
} else { |
660 |
woff = uio->uio_loffset; |
|
661 |
/* |
|
662 |
* Validate file offset |
|
663 |
*/ |
|
664 |
if (woff < 0) { |
|
665 |
ZFS_EXIT(zfsvfs); |
|
666 |
return (EINVAL); |
|
667 |
} |
|
668 |
||
669 |
/* |
|
1669 | 670 |
* If we need to grow the block size then zfs_range_lock() |
671 |
* will lock a wider range than we request here. |
|
672 |
* Later after growing the block size we reduce the range. |
|
789 | 673 |
*/ |
1669 | 674 |
rl = zfs_range_lock(zp, woff, n, RL_WRITER); |
789 | 675 |
} |
676 |
||
677 |
if (woff >= limit) { |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
678 |
zfs_range_unlock(rl); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
679 |
ZFS_EXIT(zfsvfs); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
680 |
return (EFBIG); |
789 | 681 |
} |
682 |
||
683 |
if ((woff + n) > limit || woff > (limit - n)) |
|
684 |
n = limit - woff; |
|
685 |
||
686 |
/* |
|
1669 | 687 |
* Check for mandatory locks |
789 | 688 |
*/ |
689 |
if (MANDMODE((mode_t)zp->z_phys->zp_mode) && |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
690 |
(error = chklock(vp, FWRITE, woff, n, uio->uio_fmode, ct)) != 0) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
691 |
zfs_range_unlock(rl); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
692 |
ZFS_EXIT(zfsvfs); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
693 |
return (error); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
694 |
} |
1669 | 695 |
end_size = MAX(zp->z_phys->zp_size, woff + n); |
789 | 696 |
|
1669 | 697 |
/* |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
698 |
* 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
|
699 |
* 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
|
700 |
* and allows us to do more fine-grained space accounting. |
789 | 701 |
*/ |
702 |
while (n > 0) { |
|
703 |
/* |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
704 |
* Start a transaction. |
789 | 705 |
*/ |
706 |
woff = uio->uio_loffset; |
|
707 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
708 |
dmu_tx_hold_bonus(tx, zp->z_id); |
|
709 |
dmu_tx_hold_write(tx, zp->z_id, woff, MIN(n, max_blksz)); |
|
710 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
|
711 |
if (error) { |
|
712 |
if (error == ERESTART && |
|
713 |
zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
714 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
715 |
dmu_tx_abort(tx); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
716 |
continue; |
789 | 717 |
} |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
718 |
dmu_tx_abort(tx); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
719 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
720 |
} |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
721 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
722 |
/* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
723 |
* 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
|
724 |
* 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
|
725 |
* 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
|
726 |
* 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
|
727 |
*/ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
728 |
if (rl->r_len == UINT64_MAX) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
729 |
uint64_t new_blksz; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
730 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
731 |
if (zp->z_blksz > max_blksz) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
732 |
ASSERT(!ISP2(zp->z_blksz)); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
733 |
new_blksz = MIN(end_size, SPA_MAXBLOCKSIZE); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
734 |
} else { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
735 |
new_blksz = MIN(end_size, max_blksz); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
736 |
} |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
737 |
zfs_grow_blocksize(zp, new_blksz, tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
738 |
zfs_range_reduce(rl, woff, n); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
739 |
} |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
740 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
741 |
/* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
742 |
* 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
|
743 |
* Perhaps we should use SPA_MAXBLOCKSIZE chunks? |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
744 |
*/ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
745 |
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
|
746 |
rw_enter(&zp->z_map_lock, RW_READER); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
747 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
748 |
tx_bytes = uio->uio_resid; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
749 |
if (vn_has_cached_data(vp)) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
750 |
rw_exit(&zp->z_map_lock); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
751 |
error = mappedwrite(vp, nbytes, uio, tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
752 |
} else { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
753 |
error = dmu_write_uio(zfsvfs->z_os, zp->z_id, |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
754 |
uio, nbytes, tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
755 |
rw_exit(&zp->z_map_lock); |
789 | 756 |
} |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
757 |
tx_bytes -= uio->uio_resid; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
758 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
759 |
/* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
760 |
* 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
|
761 |
* 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
|
762 |
*/ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
763 |
if (tx_bytes == 0) { |
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3638
diff
changeset
|
764 |
dmu_tx_commit(tx); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
765 |
ASSERT(error != 0); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
766 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
767 |
} |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
768 |
|
789 | 769 |
/* |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
770 |
* 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
|
771 |
* 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
|
772 |
* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
773 |
* 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
|
774 |
* 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
|
775 |
* to another app after the partial write is committed. |
5331 | 776 |
* |
777 |
* Note: we don't call zfs_fuid_map_id() here because |
|
778 |
* user 0 is not an ephemeral uid. |
|
789 | 779 |
*/ |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
780 |
mutex_enter(&zp->z_acl_lock); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
781 |
if ((zp->z_phys->zp_mode & (S_IXUSR | (S_IXUSR >> 3) | |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
782 |
(S_IXUSR >> 6))) != 0 && |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
783 |
(zp->z_phys->zp_mode & (S_ISUID | S_ISGID)) != 0 && |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
784 |
secpolicy_vnode_setid_retain(cr, |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
785 |
(zp->z_phys->zp_mode & S_ISUID) != 0 && |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
786 |
zp->z_phys->zp_uid == 0) != 0) { |
4339 | 787 |
zp->z_phys->zp_mode &= ~(S_ISUID | S_ISGID); |
3638
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 |
mutex_exit(&zp->z_acl_lock); |
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 |
/* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
792 |
* Update time stamp. NOTE: This marks the bonus buffer as |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
793 |
* dirty, so we don't have to do it again for zp_size. |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
794 |
*/ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
795 |
zfs_time_stamper(zp, CONTENT_MODIFIED, tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
796 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
797 |
/* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
798 |
* 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
|
799 |
* account for possible concurrent updates. |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
800 |
*/ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
801 |
while ((end_size = zp->z_phys->zp_size) < uio->uio_loffset) |
789 | 802 |
(void) atomic_cas_64(&zp->z_phys->zp_size, end_size, |
803 |
uio->uio_loffset); |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
804 |
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
|
805 |
dmu_tx_commit(tx); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
806 |
|
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
807 |
if (error != 0) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
808 |
break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
809 |
ASSERT(tx_bytes == nbytes); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
810 |
n -= nbytes; |
789 | 811 |
} |
812 |
||
2237 | 813 |
zfs_range_unlock(rl); |
789 | 814 |
|
815 |
/* |
|
816 |
* If we're in replay mode, or we made no progress, return error. |
|
817 |
* Otherwise, it's at least a partial write, so it's successful. |
|
818 |
*/ |
|
819 |
if (zfsvfs->z_assign >= TXG_INITIAL || uio->uio_resid == start_resid) { |
|
820 |
ZFS_EXIT(zfsvfs); |
|
821 |
return (error); |
|
822 |
} |
|
823 |
||
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
824 |
if (ioflag & (FSYNC | FDSYNC)) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
825 |
zil_commit(zilog, zp->z_last_itx, zp->z_id); |
789 | 826 |
|
827 |
ZFS_EXIT(zfsvfs); |
|
828 |
return (0); |
|
829 |
} |
|
830 |
||
2237 | 831 |
void |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
832 |
zfs_get_done(dmu_buf_t *db, void *vzgd) |
2237 | 833 |
{ |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
834 |
zgd_t *zgd = (zgd_t *)vzgd; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
835 |
rl_t *rl = zgd->zgd_rl; |
2237 | 836 |
vnode_t *vp = ZTOV(rl->r_zp); |
837 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
838 |
dmu_buf_rele(db, vzgd); |
2237 | 839 |
zfs_range_unlock(rl); |
840 |
VN_RELE(vp); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
841 |
zil_add_vdev(zgd->zgd_zilog, DVA_GET_VDEV(BP_IDENTITY(zgd->zgd_bp))); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
842 |
kmem_free(zgd, sizeof (zgd_t)); |
2237 | 843 |
} |
844 |
||
789 | 845 |
/* |
846 |
* Get data to generate a TX_WRITE intent log record. |
|
847 |
*/ |
|
848 |
int |
|
2237 | 849 |
zfs_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio) |
789 | 850 |
{ |
851 |
zfsvfs_t *zfsvfs = arg; |
|
852 |
objset_t *os = zfsvfs->z_os; |
|
853 |
znode_t *zp; |
|
854 |
uint64_t off = lr->lr_offset; |
|
2237 | 855 |
dmu_buf_t *db; |
1669 | 856 |
rl_t *rl; |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
857 |
zgd_t *zgd; |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
858 |
int dlen = lr->lr_length; /* length of user data */ |
789 | 859 |
int error = 0; |
860 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
861 |
ASSERT(zio); |
789 | 862 |
ASSERT(dlen != 0); |
863 |
||
864 |
/* |
|
1669 | 865 |
* Nothing to do if the file has been removed |
789 | 866 |
*/ |
867 |
if (zfs_zget(zfsvfs, lr->lr_foid, &zp) != 0) |
|
868 |
return (ENOENT); |
|
3461 | 869 |
if (zp->z_unlinked) { |
789 | 870 |
VN_RELE(ZTOV(zp)); |
871 |
return (ENOENT); |
|
872 |
} |
|
873 |
||
874 |
/* |
|
875 |
* Write records come in two flavors: immediate and indirect. |
|
876 |
* For small writes it's cheaper to store the data with the |
|
877 |
* log record (immediate); for large writes it's cheaper to |
|
878 |
* sync the data and get a pointer to it (indirect) so that |
|
879 |
* we don't have to write the data twice. |
|
880 |
*/ |
|
1669 | 881 |
if (buf != NULL) { /* immediate write */ |
882 |
rl = zfs_range_lock(zp, off, dlen, RL_READER); |
|
883 |
/* test for truncation needs to be done while range locked */ |
|
884 |
if (off >= zp->z_phys->zp_size) { |
|
885 |
error = ENOENT; |
|
886 |
goto out; |
|
887 |
} |
|
2449
6adc99f24a96
6452420 zfs_get_data() of page data panics when blocksize is less than pagesize
maybee
parents:
2391
diff
changeset
|
888 |
VERIFY(0 == dmu_read(os, lr->lr_foid, off, dlen, buf)); |
1669 | 889 |
} else { /* indirect write */ |
890 |
uint64_t boff; /* block starting offset */ |
|
891 |
||
789 | 892 |
/* |
1669 | 893 |
* Have to lock the whole block to ensure when it's |
894 |
* written out and it's checksum is being calculated |
|
895 |
* that no one can change the data. We need to re-check |
|
896 |
* blocksize after we get the lock in case it's changed! |
|
789 | 897 |
*/ |
1669 | 898 |
for (;;) { |
1941
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
899 |
if (ISP2(zp->z_blksz)) { |
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
900 |
boff = P2ALIGN_TYPED(off, zp->z_blksz, |
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
901 |
uint64_t); |
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
902 |
} else { |
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
903 |
boff = 0; |
1843b345392c
6422565 Data corruption possible with range lock for dmu_sync()
perrin
parents:
1878
diff
changeset
|
904 |
} |
1669 | 905 |
dlen = zp->z_blksz; |
906 |
rl = zfs_range_lock(zp, boff, dlen, RL_READER); |
|
907 |
if (zp->z_blksz == dlen) |
|
908 |
break; |
|
2237 | 909 |
zfs_range_unlock(rl); |
1669 | 910 |
} |
911 |
/* test for truncation needs to be done while range locked */ |
|
912 |
if (off >= zp->z_phys->zp_size) { |
|
913 |
error = ENOENT; |
|
914 |
goto out; |
|
915 |
} |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
916 |
zgd = (zgd_t *)kmem_alloc(sizeof (zgd_t), KM_SLEEP); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
917 |
zgd->zgd_rl = rl; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
918 |
zgd->zgd_zilog = zfsvfs->z_log; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
919 |
zgd->zgd_bp = &lr->lr_blkptr; |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
920 |
VERIFY(0 == dmu_buf_hold(os, lr->lr_foid, boff, zgd, &db)); |
2237 | 921 |
ASSERT(boff == db->db_offset); |
922 |
lr->lr_blkoff = off - boff; |
|
923 |
error = dmu_sync(zio, db, &lr->lr_blkptr, |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
924 |
lr->lr_common.lrc_txg, zfs_get_done, zgd); |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
925 |
ASSERT((error && error != EINPROGRESS) || |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
926 |
lr->lr_length <= zp->z_blksz); |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
927 |
if (error == 0) { |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
928 |
zil_add_vdev(zfsvfs->z_log, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
929 |
DVA_GET_VDEV(BP_IDENTITY(&lr->lr_blkptr))); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
930 |
} |
2237 | 931 |
/* |
932 |
* If we get EINPROGRESS, then we need to wait for a |
|
933 |
* write IO initiated by dmu_sync() to complete before |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
934 |
* we can release this dbuf. We will finish everything |
2237 | 935 |
* up in the zfs_get_done() callback. |
936 |
*/ |
|
937 |
if (error == EINPROGRESS) |
|
938 |
return (0); |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
939 |
dmu_buf_rele(db, zgd); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2796
diff
changeset
|
940 |
kmem_free(zgd, sizeof (zgd_t)); |
789 | 941 |
} |
1669 | 942 |
out: |
2237 | 943 |
zfs_range_unlock(rl); |
789 | 944 |
VN_RELE(ZTOV(zp)); |
945 |
return (error); |
|
946 |
} |
|
947 |
||
948 |
/*ARGSUSED*/ |
|
949 |
static int |
|
5331 | 950 |
zfs_access(vnode_t *vp, int mode, int flag, cred_t *cr, |
951 |
caller_context_t *ct) |
|
789 | 952 |
{ |
953 |
znode_t *zp = VTOZ(vp); |
|
954 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
955 |
int error; |
|
956 |
||
5367 | 957 |
ZFS_ENTER(zfsvfs); |
958 |
ZFS_VERIFY_ZP(zp); |
|
5331 | 959 |
|
960 |
if (flag & V_ACE_MASK) |
|
961 |
error = zfs_zaccess(zp, mode, flag, B_FALSE, cr); |
|
962 |
else |
|
963 |
error = zfs_zaccess_rwx(zp, mode, flag, cr); |
|
964 |
||
789 | 965 |
ZFS_EXIT(zfsvfs); |
966 |
return (error); |
|
967 |
} |
|
968 |
||
969 |
/* |
|
970 |
* Lookup an entry in a directory, or an extended attribute directory. |
|
971 |
* If it exists, return a held vnode reference for it. |
|
972 |
* |
|
973 |
* IN: dvp - vnode of directory to search. |
|
974 |
* nm - name of entry to lookup. |
|
975 |
* pnp - full pathname to lookup [UNUSED]. |
|
976 |
* flags - LOOKUP_XATTR set if looking for an attribute. |
|
977 |
* rdir - root directory vnode [UNUSED]. |
|
978 |
* cr - credentials of caller. |
|
5331 | 979 |
* ct - caller context |
980 |
* direntflags - directory lookup flags |
|
981 |
* realpnp - returned pathname. |
|
789 | 982 |
* |
983 |
* OUT: vpp - vnode of located entry, NULL if not found. |
|
984 |
* |
|
985 |
* RETURN: 0 if success |
|
986 |
* error code if failure |
|
987 |
* |
|
988 |
* Timestamps: |
|
989 |
* NA |
|
990 |
*/ |
|
991 |
/* ARGSUSED */ |
|
992 |
static int |
|
993 |
zfs_lookup(vnode_t *dvp, char *nm, vnode_t **vpp, struct pathname *pnp, |
|
5331 | 994 |
int flags, vnode_t *rdir, cred_t *cr, caller_context_t *ct, |
995 |
int *direntflags, pathname_t *realpnp) |
|
789 | 996 |
{ |
997 |
znode_t *zdp = VTOZ(dvp); |
|
998 |
zfsvfs_t *zfsvfs = zdp->z_zfsvfs; |
|
999 |
int error; |
|
1000 |
||
5367 | 1001 |
ZFS_ENTER(zfsvfs); |
1002 |
ZFS_VERIFY_ZP(zdp); |
|
789 | 1003 |
|
1004 |
*vpp = NULL; |
|
1005 |
||
1006 |
if (flags & LOOKUP_XATTR) { |
|
1007 |
/* |
|
3234 | 1008 |
* If the xattr property is off, refuse the lookup request. |
1009 |
*/ |
|
1010 |
if (!(zfsvfs->z_vfs->vfs_flag & VFS_XATTR)) { |
|
1011 |
ZFS_EXIT(zfsvfs); |
|
1012 |
return (EINVAL); |
|
1013 |
} |
|
1014 |
||
1015 |
/* |
|
789 | 1016 |
* We don't allow recursive attributes.. |
1017 |
* Maybe someday we will. |
|
1018 |
*/ |
|
1019 |
if (zdp->z_phys->zp_flags & ZFS_XATTR) { |
|
1020 |
ZFS_EXIT(zfsvfs); |
|
1021 |
return (EINVAL); |
|
1022 |
} |
|
1023 |
||
3280
e93ccc27c51d
6492686 NFSv4 client got EACCES over ZFS when trying to OPENATTR without createdir
ck153898
parents:
3271
diff
changeset
|
1024 |
if (error = zfs_get_xattrdir(VTOZ(dvp), vpp, cr, flags)) { |
789 | 1025 |
ZFS_EXIT(zfsvfs); |
1026 |
return (error); |
|
1027 |
} |
|
1028 |
||
1029 |
/* |
|
1030 |
* Do we have permission to get into attribute directory? |
|
1031 |
*/ |
|
1032 |
||
5331 | 1033 |
if (error = zfs_zaccess(VTOZ(*vpp), ACE_EXECUTE, 0, |
1034 |
B_FALSE, cr)) { |
|
789 | 1035 |
VN_RELE(*vpp); |
5331 | 1036 |
*vpp = NULL; |
789 | 1037 |
} |
1038 |
||
1039 |
ZFS_EXIT(zfsvfs); |
|
1040 |
return (error); |
|
1041 |
} |
|
1042 |
||
1512 | 1043 |
if (dvp->v_type != VDIR) { |
1044 |
ZFS_EXIT(zfsvfs); |
|
1460
299d0ee75ed4
6371285 panic when nfs lookup operation attempted on plain file
marks
parents:
1417
diff
changeset
|
1045 |
return (ENOTDIR); |
1512 | 1046 |
} |
1460
299d0ee75ed4
6371285 panic when nfs lookup operation attempted on plain file
marks
parents:
1417
diff
changeset
|
1047 |
|
789 | 1048 |
/* |
1049 |
* Check accessibility of directory. |
|
1050 |
*/ |
|
1051 |
||
5331 | 1052 |
if (error = zfs_zaccess(zdp, ACE_EXECUTE, 0, B_FALSE, cr)) { |
789 | 1053 |
ZFS_EXIT(zfsvfs); |
1054 |
return (error); |
|
1055 |
} |
|
1056 |
||
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
1057 |
if (zfsvfs->z_utf8 && u8_validate(nm, strlen(nm), |
5331 | 1058 |
NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
1059 |
ZFS_EXIT(zfsvfs); |
|
1060 |
return (EILSEQ); |
|
1061 |
} |
|
1062 |
||
1063 |
error = zfs_dirlook(zdp, nm, vpp, flags, direntflags, realpnp); |
|
1064 |
if (error == 0) { |
|
789 | 1065 |
/* |
1066 |
* Convert device special files |
|
1067 |
*/ |
|
1068 |
if (IS_DEVVP(*vpp)) { |
|
1069 |
vnode_t *svp; |
|
1070 |
||
1071 |
svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); |
|
1072 |
VN_RELE(*vpp); |
|
1073 |
if (svp == NULL) |
|
1074 |
error = ENOSYS; |
|
1075 |
else |
|
1076 |
*vpp = svp; |
|
1077 |
} |
|
1078 |
} |
|
1079 |
||
1080 |
ZFS_EXIT(zfsvfs); |
|
1081 |
return (error); |
|
1082 |
} |
|
1083 |
||
1084 |
/* |
|
1085 |
* Attempt to create a new entry in a directory. If the entry |
|
1086 |
* already exists, truncate the file if permissible, else return |
|
1087 |
* an error. Return the vp of the created or trunc'd file. |
|
1088 |
* |
|
1089 |
* IN: dvp - vnode of directory to put new file entry in. |
|
1090 |
* name - name of new file entry. |
|
1091 |
* vap - attributes of new file. |
|
1092 |
* excl - flag indicating exclusive or non-exclusive mode. |
|
1093 |
* mode - mode to open file with. |
|
1094 |
* cr - credentials of caller. |
|
1095 |
* flag - large file flag [UNUSED]. |
|
5331 | 1096 |
* ct - caller context |
1097 |
* vsecp - ACL to be set |
|
789 | 1098 |
* |
1099 |
* OUT: vpp - vnode of created or trunc'd entry. |
|
1100 |
* |
|
1101 |
* RETURN: 0 if success |
|
1102 |
* error code if failure |
|
1103 |
* |
|
1104 |
* Timestamps: |
|
1105 |
* dvp - ctime|mtime updated if new entry created |
|
1106 |
* vp - ctime|mtime always, atime if new |
|
1107 |
*/ |
|
5331 | 1108 |
|
789 | 1109 |
/* ARGSUSED */ |
1110 |
static int |
|
1111 |
zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl, |
|
5331 | 1112 |
int mode, vnode_t **vpp, cred_t *cr, int flag, caller_context_t *ct, |
1113 |
vsecattr_t *vsecp) |
|
789 | 1114 |
{ |
1115 |
znode_t *zp, *dzp = VTOZ(dvp); |
|
1116 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1117 |
zilog_t *zilog; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1118 |
objset_t *os; |
789 | 1119 |
zfs_dirlock_t *dl; |
1120 |
dmu_tx_t *tx; |
|
1121 |
int error; |
|
5331 | 1122 |
zfs_acl_t *aclp = NULL; |
1123 |
zfs_fuid_info_t *fuidp = NULL; |
|
1124 |
||
1125 |
/* |
|
1126 |
* If we have an ephemeral id, ACL, or XVATTR then |
|
1127 |
* make sure file system is at proper version |
|
1128 |
*/ |
|
1129 |
||
1130 |
if (zfsvfs->z_use_fuids == B_FALSE && |
|
1131 |
(vsecp || (vap->va_mask & AT_XVATTR) || |
|
1132 |
IS_EPHEMERAL(crgetuid(cr)) || IS_EPHEMERAL(crgetgid(cr)))) |
|
1133 |
return (EINVAL); |
|
789 | 1134 |
|
5367 | 1135 |
ZFS_ENTER(zfsvfs); |
1136 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1137 |
os = zfsvfs->z_os; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1138 |
zilog = zfsvfs->z_log; |
789 | 1139 |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
1140 |
if (zfsvfs->z_utf8 && u8_validate(name, strlen(name), |
5331 | 1141 |
NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
1142 |
ZFS_EXIT(zfsvfs); |
|
1143 |
return (EILSEQ); |
|
1144 |
} |
|
1145 |
||
1146 |
if (vap->va_mask & AT_XVATTR) { |
|
1147 |
if ((error = secpolicy_xvattr((xvattr_t *)vap, |
|
1148 |
crgetuid(cr), cr, vap->va_type)) != 0) { |
|
1149 |
ZFS_EXIT(zfsvfs); |
|
1150 |
return (error); |
|
1151 |
} |
|
1152 |
} |
|
789 | 1153 |
top: |
1154 |
*vpp = NULL; |
|
1155 |
||
1156 |
if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr)) |
|
1157 |
vap->va_mode &= ~VSVTX; |
|
1158 |
||
1159 |
if (*name == '\0') { |
|
1160 |
/* |
|
1161 |
* Null component name refers to the directory itself. |
|
1162 |
*/ |
|
1163 |
VN_HOLD(dvp); |
|
1164 |
zp = dzp; |
|
1165 |
dl = NULL; |
|
1166 |
error = 0; |
|
1167 |
} else { |
|
1168 |
/* possible VN_HOLD(zp) */ |
|
5331 | 1169 |
int zflg = 0; |
1170 |
||
1171 |
if (flag & FIGNORECASE) |
|
1172 |
zflg |= ZCILOOK; |
|
1173 |
||
1174 |
error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, |
|
1175 |
NULL, NULL); |
|
1176 |
if (error) { |
|
789 | 1177 |
if (strcmp(name, "..") == 0) |
1178 |
error = EISDIR; |
|
1179 |
ZFS_EXIT(zfsvfs); |
|
5331 | 1180 |
if (aclp) |
1181 |
zfs_acl_free(aclp); |
|
789 | 1182 |
return (error); |
1183 |
} |
|
1184 |
} |
|
5331 | 1185 |
if (vsecp && aclp == NULL) { |
1186 |
error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp); |
|
1187 |
if (error) { |
|
1188 |
ZFS_EXIT(zfsvfs); |
|
1189 |
if (dl) |
|
1190 |
zfs_dirent_unlock(dl); |
|
1191 |
return (error); |
|
1192 |
} |
|
1193 |
} |
|
789 | 1194 |
|
1195 |
if (zp == NULL) { |
|
5331 | 1196 |
uint64_t txtype; |
1197 |
||
789 | 1198 |
/* |
1199 |
* Create a new file object and update the directory |
|
1200 |
* to reference it. |
|
1201 |
*/ |
|
5331 | 1202 |
if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) { |
789 | 1203 |
goto out; |
1204 |
} |
|
1205 |
||
1206 |
/* |
|
1207 |
* We only support the creation of regular files in |
|
1208 |
* extended attribute directories. |
|
1209 |
*/ |
|
1210 |
if ((dzp->z_phys->zp_flags & ZFS_XATTR) && |
|
1211 |
(vap->va_type != VREG)) { |
|
1212 |
error = EINVAL; |
|
1213 |
goto out; |
|
1214 |
} |
|
1215 |
||
1216 |
tx = dmu_tx_create(os); |
|
1217 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
5331 | 1218 |
if (zfsvfs->z_fuid_obj == 0) { |
1219 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
1220 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, |
|
1221 |
SPA_MAXBLOCKSIZE); |
|
1222 |
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL); |
|
1223 |
} else { |
|
1224 |
dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj); |
|
1225 |
dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0, |
|
1226 |
SPA_MAXBLOCKSIZE); |
|
1227 |
} |
|
789 | 1228 |
dmu_tx_hold_bonus(tx, dzp->z_id); |
1544 | 1229 |
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name); |
5331 | 1230 |
if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp) { |
789 | 1231 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, |
1232 |
0, SPA_MAXBLOCKSIZE); |
|
5331 | 1233 |
} |
789 | 1234 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
1235 |
if (error) { |
|
1236 |
zfs_dirent_unlock(dl); |
|
1237 |
if (error == ERESTART && |
|
1238 |
zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1239 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1240 |
dmu_tx_abort(tx); |
789 | 1241 |
goto top; |
1242 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1243 |
dmu_tx_abort(tx); |
789 | 1244 |
ZFS_EXIT(zfsvfs); |
5331 | 1245 |
if (aclp) |
1246 |
zfs_acl_free(aclp); |
|
789 | 1247 |
return (error); |
1248 |
} |
|
5446 | 1249 |
zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp); |
789 | 1250 |
(void) zfs_link_create(dl, zp, tx, ZNEW); |
5331 | 1251 |
txtype = zfs_log_create_txtype(Z_FILE, vsecp, vap); |
1252 |
if (flag & FIGNORECASE) |
|
1253 |
txtype |= TX_CI; |
|
1254 |
zfs_log_create(zilog, tx, txtype, dzp, zp, name, |
|
1255 |
vsecp, fuidp, vap); |
|
1256 |
if (fuidp) |
|
1257 |
zfs_fuid_info_free(fuidp); |
|
789 | 1258 |
dmu_tx_commit(tx); |
1259 |
} else { |
|
5331 | 1260 |
int aflags = (flag & FAPPEND) ? V_APPEND : 0; |
1261 |
||
789 | 1262 |
/* |
1263 |
* A directory entry already exists for this name. |
|
1264 |
*/ |
|
1265 |
/* |
|
1266 |
* Can't truncate an existing file if in exclusive mode. |
|
1267 |
*/ |
|
1268 |
if (excl == EXCL) { |
|
1269 |
error = EEXIST; |
|
1270 |
goto out; |
|
1271 |
} |
|
1272 |
/* |
|
1273 |
* Can't open a directory for writing. |
|
1274 |
*/ |
|
1275 |
if ((ZTOV(zp)->v_type == VDIR) && (mode & S_IWRITE)) { |
|
1276 |
error = EISDIR; |
|
1277 |
goto out; |
|
1278 |
} |
|
1279 |
/* |
|
1280 |
* Verify requested access to file. |
|
1281 |
*/ |
|
5331 | 1282 |
if (mode && (error = zfs_zaccess_rwx(zp, mode, aflags, cr))) { |
789 | 1283 |
goto out; |
1284 |
} |
|
1285 |
||
1286 |
mutex_enter(&dzp->z_lock); |
|
1287 |
dzp->z_seq++; |
|
1288 |
mutex_exit(&dzp->z_lock); |
|
1289 |
||
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1290 |
/* |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1291 |
* Truncate regular files if requested. |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1292 |
*/ |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1293 |
if ((ZTOV(zp)->v_type == VREG) && |
789 | 1294 |
(vap->va_mask & AT_SIZE) && (vap->va_size == 0)) { |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1295 |
error = zfs_freesp(zp, 0, 0, mode, TRUE); |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1296 |
if (error == ERESTART && |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1297 |
zfsvfs->z_assign == TXG_NOWAIT) { |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1298 |
/* NB: we already did dmu_tx_wait() */ |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1299 |
zfs_dirent_unlock(dl); |
2365
2745d773b6bd
6447452 re-creating zfs files can lead to failure to unmount
perrin
parents:
2237
diff
changeset
|
1300 |
VN_RELE(ZTOV(zp)); |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
1301 |
goto top; |
789 | 1302 |
} |
4863 | 1303 |
|
1304 |
if (error == 0) { |
|
5331 | 1305 |
vnevent_create(ZTOV(zp), ct); |
4863 | 1306 |
} |
789 | 1307 |
} |
1308 |
} |
|
1309 |
out: |
|
1310 |
||
1311 |
if (dl) |
|
1312 |
zfs_dirent_unlock(dl); |
|
1313 |
||
1314 |
if (error) { |
|
1315 |
if (zp) |
|
1316 |
VN_RELE(ZTOV(zp)); |
|
1317 |
} else { |
|
1318 |
*vpp = ZTOV(zp); |
|
1319 |
/* |
|
1320 |
* If vnode is for a device return a specfs vnode instead. |
|
1321 |
*/ |
|
1322 |
if (IS_DEVVP(*vpp)) { |
|
1323 |
struct vnode *svp; |
|
1324 |
||
1325 |
svp = specvp(*vpp, (*vpp)->v_rdev, (*vpp)->v_type, cr); |
|
1326 |
VN_RELE(*vpp); |
|
1327 |
if (svp == NULL) { |
|
1328 |
error = ENOSYS; |
|
1329 |
} |
|
1330 |
*vpp = svp; |
|
1331 |
} |
|
1332 |
} |
|
5331 | 1333 |
if (aclp) |
1334 |
zfs_acl_free(aclp); |
|
789 | 1335 |
|
1336 |
ZFS_EXIT(zfsvfs); |
|
1337 |
return (error); |
|
1338 |
} |
|
1339 |
||
1340 |
/* |
|
1341 |
* Remove an entry from a directory. |
|
1342 |
* |
|
1343 |
* IN: dvp - vnode of directory to remove entry from. |
|
1344 |
* name - name of entry to remove. |
|
1345 |
* cr - credentials of caller. |
|
5331 | 1346 |
* ct - caller context |
1347 |
* flags - case flags |
|
789 | 1348 |
* |
1349 |
* RETURN: 0 if success |
|
1350 |
* error code if failure |
|
1351 |
* |
|
1352 |
* Timestamps: |
|
1353 |
* dvp - ctime|mtime |
|
1354 |
* vp - ctime (if nlink > 0) |
|
1355 |
*/ |
|
5331 | 1356 |
/*ARGSUSED*/ |
789 | 1357 |
static int |
5331 | 1358 |
zfs_remove(vnode_t *dvp, char *name, cred_t *cr, caller_context_t *ct, |
1359 |
int flags) |
|
789 | 1360 |
{ |
1361 |
znode_t *zp, *dzp = VTOZ(dvp); |
|
1362 |
znode_t *xzp = NULL; |
|
1363 |
vnode_t *vp; |
|
1364 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1365 |
zilog_t *zilog; |
789 | 1366 |
uint64_t acl_obj, xattr_obj; |
1367 |
zfs_dirlock_t *dl; |
|
1368 |
dmu_tx_t *tx; |
|
3461 | 1369 |
boolean_t may_delete_now, delete_now = FALSE; |
1370 |
boolean_t unlinked; |
|
5331 | 1371 |
uint64_t txtype; |
1372 |
pathname_t *realnmp = NULL; |
|
1373 |
pathname_t realnm; |
|
789 | 1374 |
int error; |
5331 | 1375 |
int zflg = ZEXISTS; |
789 | 1376 |
|
5367 | 1377 |
ZFS_ENTER(zfsvfs); |
1378 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1379 |
zilog = zfsvfs->z_log; |
789 | 1380 |
|
5331 | 1381 |
if (flags & FIGNORECASE) { |
1382 |
zflg |= ZCILOOK; |
|
1383 |
pn_alloc(&realnm); |
|
1384 |
realnmp = &realnm; |
|
1385 |
} |
|
1386 |
||
789 | 1387 |
top: |
1388 |
/* |
|
1389 |
* Attempt to lock directory; fail if entry doesn't exist. |
|
1390 |
*/ |
|
5331 | 1391 |
if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, |
1392 |
NULL, realnmp)) { |
|
1393 |
if (realnmp) |
|
1394 |
pn_free(realnmp); |
|
789 | 1395 |
ZFS_EXIT(zfsvfs); |
1396 |
return (error); |
|
1397 |
} |
|
1398 |
||
1399 |
vp = ZTOV(zp); |
|
1400 |
||
1401 |
if (error = zfs_zaccess_delete(dzp, zp, cr)) { |
|
1402 |
goto out; |
|
1403 |
} |
|
1404 |
||
1405 |
/* |
|
1406 |
* Need to use rmdir for removing directories. |
|
1407 |
*/ |
|
1408 |
if (vp->v_type == VDIR) { |
|
1409 |
error = EPERM; |
|
1410 |
goto out; |
|
1411 |
} |
|
1412 |
||
5331 | 1413 |
vnevent_remove(vp, dvp, name, ct); |
1414 |
||
1415 |
if (realnmp) |
|
1416 |
dnlc_remove(dvp, realnmp->pn_path); |
|
1417 |
else |
|
1418 |
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
|
1419 |
|
789 | 1420 |
mutex_enter(&vp->v_lock); |
1421 |
may_delete_now = vp->v_count == 1 && !vn_has_cached_data(vp); |
|
1422 |
mutex_exit(&vp->v_lock); |
|
1423 |
||
1424 |
/* |
|
3461 | 1425 |
* We may delete the znode now, or we may put it in the unlinked set; |
789 | 1426 |
* it depends on whether we're the last link, and on whether there are |
1427 |
* other holds on the vnode. So we dmu_tx_hold() the right things to |
|
1428 |
* allow for either case. |
|
1429 |
*/ |
|
1430 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
1544 | 1431 |
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name); |
789 | 1432 |
dmu_tx_hold_bonus(tx, zp->z_id); |
1433 |
if (may_delete_now) |
|
1434 |
dmu_tx_hold_free(tx, zp->z_id, 0, DMU_OBJECT_END); |
|
1435 |
||
1436 |
/* are there any extended attributes? */ |
|
1437 |
if ((xattr_obj = zp->z_phys->zp_xattr) != 0) { |
|
1438 |
/* XXX - do we need this if we are deleting? */ |
|
1439 |
dmu_tx_hold_bonus(tx, xattr_obj); |
|
1440 |
} |
|
1441 |
||
1442 |
/* are there any additional acls */ |
|
1443 |
if ((acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj) != 0 && |
|
1444 |
may_delete_now) |
|
1445 |
dmu_tx_hold_free(tx, acl_obj, 0, DMU_OBJECT_END); |
|
1446 |
||
1447 |
/* charge as an update -- would be nice not to charge at all */ |
|
3461 | 1448 |
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL); |
789 | 1449 |
|
1450 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
|
1451 |
if (error) { |
|
1452 |
zfs_dirent_unlock(dl); |
|
1453 |
VN_RELE(vp); |
|
1454 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1455 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1456 |
dmu_tx_abort(tx); |
789 | 1457 |
goto top; |
1458 |
} |
|
5331 | 1459 |
if (realnmp) |
1460 |
pn_free(realnmp); |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1461 |
dmu_tx_abort(tx); |
789 | 1462 |
ZFS_EXIT(zfsvfs); |
1463 |
return (error); |
|
1464 |
} |
|
1465 |
||
1466 |
/* |
|
1467 |
* Remove the directory entry. |
|
1468 |
*/ |
|
5331 | 1469 |
error = zfs_link_destroy(dl, zp, tx, zflg, &unlinked); |
789 | 1470 |
|
1471 |
if (error) { |
|
1472 |
dmu_tx_commit(tx); |
|
1473 |
goto out; |
|
1474 |
} |
|
1475 |
||
3461 | 1476 |
if (unlinked) { |
789 | 1477 |
mutex_enter(&vp->v_lock); |
1478 |
delete_now = may_delete_now && |
|
1479 |
vp->v_count == 1 && !vn_has_cached_data(vp) && |
|
1480 |
zp->z_phys->zp_xattr == xattr_obj && |
|
1481 |
zp->z_phys->zp_acl.z_acl_extern_obj == acl_obj; |
|
1482 |
mutex_exit(&vp->v_lock); |
|
1483 |
} |
|
1484 |
||
1485 |
if (delete_now) { |
|
1486 |
if (zp->z_phys->zp_xattr) { |
|
1487 |
error = zfs_zget(zfsvfs, zp->z_phys->zp_xattr, &xzp); |
|
1488 |
ASSERT3U(error, ==, 0); |
|
1489 |
ASSERT3U(xzp->z_phys->zp_links, ==, 2); |
|
1490 |
dmu_buf_will_dirty(xzp->z_dbuf, tx); |
|
1491 |
mutex_enter(&xzp->z_lock); |
|
3461 | 1492 |
xzp->z_unlinked = 1; |
789 | 1493 |
xzp->z_phys->zp_links = 0; |
1494 |
mutex_exit(&xzp->z_lock); |
|
3461 | 1495 |
zfs_unlinked_add(xzp, tx); |
789 | 1496 |
zp->z_phys->zp_xattr = 0; /* probably unnecessary */ |
1497 |
} |
|
1498 |
mutex_enter(&zp->z_lock); |
|
1499 |
mutex_enter(&vp->v_lock); |
|
1500 |
vp->v_count--; |
|
1501 |
ASSERT3U(vp->v_count, ==, 0); |
|
1502 |
mutex_exit(&vp->v_lock); |
|
1503 |
mutex_exit(&zp->z_lock); |
|
1504 |
zfs_znode_delete(zp, tx); |
|
1505 |
VFS_RELE(zfsvfs->z_vfs); |
|
3461 | 1506 |
} else if (unlinked) { |
1507 |
zfs_unlinked_add(zp, tx); |
|
789 | 1508 |
} |
1509 |
||
5331 | 1510 |
txtype = TX_REMOVE; |
1511 |
if (flags & FIGNORECASE) |
|
1512 |
txtype |= TX_CI; |
|
1513 |
zfs_log_remove(zilog, tx, txtype, dzp, name); |
|
789 | 1514 |
|
1515 |
dmu_tx_commit(tx); |
|
1516 |
out: |
|
5331 | 1517 |
if (realnmp) |
1518 |
pn_free(realnmp); |
|
1519 |
||
789 | 1520 |
zfs_dirent_unlock(dl); |
1521 |
||
1522 |
if (!delete_now) { |
|
1523 |
VN_RELE(vp); |
|
1524 |
} else if (xzp) { |
|
1525 |
/* this rele delayed to prevent nesting transactions */ |
|
1526 |
VN_RELE(ZTOV(xzp)); |
|
1527 |
} |
|
1528 |
||
1529 |
ZFS_EXIT(zfsvfs); |
|
1530 |
return (error); |
|
1531 |
} |
|
1532 |
||
1533 |
/* |
|
1534 |
* Create a new directory and insert it into dvp using the name |
|
1535 |
* provided. Return a pointer to the inserted directory. |
|
1536 |
* |
|
1537 |
* IN: dvp - vnode of directory to add subdir to. |
|
1538 |
* dirname - name of new directory. |
|
1539 |
* vap - attributes of new directory. |
|
1540 |
* cr - credentials of caller. |
|
5331 | 1541 |
* ct - caller context |
1542 |
* vsecp - ACL to be set |
|
789 | 1543 |
* |
1544 |
* OUT: vpp - vnode of created directory. |
|
1545 |
* |
|
1546 |
* RETURN: 0 if success |
|
1547 |
* error code if failure |
|
1548 |
* |
|
1549 |
* Timestamps: |
|
1550 |
* dvp - ctime|mtime updated |
|
1551 |
* vp - ctime|mtime|atime updated |
|
1552 |
*/ |
|
5331 | 1553 |
/*ARGSUSED*/ |
789 | 1554 |
static int |
5331 | 1555 |
zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr, |
1556 |
caller_context_t *ct, int flags, vsecattr_t *vsecp) |
|
789 | 1557 |
{ |
1558 |
znode_t *zp, *dzp = VTOZ(dvp); |
|
1559 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1560 |
zilog_t *zilog; |
789 | 1561 |
zfs_dirlock_t *dl; |
5331 | 1562 |
uint64_t txtype; |
789 | 1563 |
dmu_tx_t *tx; |
1564 |
int error; |
|
5331 | 1565 |
zfs_acl_t *aclp = NULL; |
1566 |
zfs_fuid_info_t *fuidp = NULL; |
|
1567 |
int zf = ZNEW; |
|
789 | 1568 |
|
1569 |
ASSERT(vap->va_type == VDIR); |
|
1570 |
||
5331 | 1571 |
/* |
1572 |
* If we have an ephemeral id, ACL, or XVATTR then |
|
1573 |
* make sure file system is at proper version |
|
1574 |
*/ |
|
1575 |
||
1576 |
if (zfsvfs->z_use_fuids == B_FALSE && |
|
1577 |
(vsecp || (vap->va_mask & AT_XVATTR) || IS_EPHEMERAL(crgetuid(cr))|| |
|
1578 |
IS_EPHEMERAL(crgetgid(cr)))) |
|
1579 |
return (EINVAL); |
|
1580 |
||
5367 | 1581 |
ZFS_ENTER(zfsvfs); |
1582 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1583 |
zilog = zfsvfs->z_log; |
789 | 1584 |
|
1585 |
if (dzp->z_phys->zp_flags & ZFS_XATTR) { |
|
1586 |
ZFS_EXIT(zfsvfs); |
|
1587 |
return (EINVAL); |
|
1588 |
} |
|
5331 | 1589 |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
1590 |
if (zfsvfs->z_utf8 && u8_validate(dirname, |
5331 | 1591 |
strlen(dirname), NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
1592 |
ZFS_EXIT(zfsvfs); |
|
1593 |
return (EILSEQ); |
|
1594 |
} |
|
1595 |
if (flags & FIGNORECASE) |
|
1596 |
zf |= ZCILOOK; |
|
1597 |
||
1598 |
if (vap->va_mask & AT_XVATTR) |
|
1599 |
if ((error = secpolicy_xvattr((xvattr_t *)vap, |
|
1600 |
crgetuid(cr), cr, vap->va_type)) != 0) { |
|
1601 |
ZFS_EXIT(zfsvfs); |
|
1602 |
return (error); |
|
1603 |
} |
|
789 | 1604 |
|
1605 |
/* |
|
1606 |
* First make sure the new directory doesn't exist. |
|
1607 |
*/ |
|
5331 | 1608 |
top: |
1609 |
*vpp = NULL; |
|
1610 |
||
1611 |
if (error = zfs_dirent_lock(&dl, dzp, dirname, &zp, zf, |
|
1612 |
NULL, NULL)) { |
|
789 | 1613 |
ZFS_EXIT(zfsvfs); |
1614 |
return (error); |
|
1615 |
} |
|
1616 |
||
5331 | 1617 |
if (error = zfs_zaccess(dzp, ACE_ADD_SUBDIRECTORY, 0, B_FALSE, cr)) { |
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
|
1618 |
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
|
1619 |
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
|
1620 |
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
|
1621 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
1622 |
|
5331 | 1623 |
if (vsecp && aclp == NULL) { |
1624 |
error = zfs_vsec_2_aclp(zfsvfs, vap->va_type, vsecp, &aclp); |
|
1625 |
if (error) { |
|
1626 |
zfs_dirent_unlock(dl); |
|
1627 |
ZFS_EXIT(zfsvfs); |
|
1628 |
return (error); |
|
1629 |
} |
|
1630 |
} |
|
789 | 1631 |
/* |
1632 |
* Add a new entry to the directory. |
|
1633 |
*/ |
|
1634 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
1544 | 1635 |
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, dirname); |
1636 |
dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL); |
|
5331 | 1637 |
if (zfsvfs->z_fuid_obj == 0) { |
1638 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
1639 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, |
|
1640 |
SPA_MAXBLOCKSIZE); |
|
1641 |
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL); |
|
1642 |
} else { |
|
1643 |
dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj); |
|
1644 |
dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0, |
|
1645 |
SPA_MAXBLOCKSIZE); |
|
1646 |
} |
|
1647 |
if ((dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) || aclp) |
|
789 | 1648 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, |
1649 |
0, SPA_MAXBLOCKSIZE); |
|
1650 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
|
1651 |
if (error) { |
|
1652 |
zfs_dirent_unlock(dl); |
|
1653 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1654 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1655 |
dmu_tx_abort(tx); |
789 | 1656 |
goto top; |
1657 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1658 |
dmu_tx_abort(tx); |
789 | 1659 |
ZFS_EXIT(zfsvfs); |
5331 | 1660 |
if (aclp) |
1661 |
zfs_acl_free(aclp); |
|
789 | 1662 |
return (error); |
1663 |
} |
|
1664 |
||
1665 |
/* |
|
1666 |
* Create new node. |
|
1667 |
*/ |
|
5446 | 1668 |
zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, aclp, &fuidp); |
5331 | 1669 |
|
1670 |
if (aclp) |
|
1671 |
zfs_acl_free(aclp); |
|
789 | 1672 |
|
1673 |
/* |
|
1674 |
* Now put new name in parent dir. |
|
1675 |
*/ |
|
1676 |
(void) zfs_link_create(dl, zp, tx, ZNEW); |
|
1677 |
||
1678 |
*vpp = ZTOV(zp); |
|
1679 |
||
5331 | 1680 |
txtype = zfs_log_create_txtype(Z_DIR, vsecp, vap); |
1681 |
if (flags & FIGNORECASE) |
|
1682 |
txtype |= TX_CI; |
|
1683 |
zfs_log_create(zilog, tx, txtype, dzp, zp, dirname, vsecp, fuidp, vap); |
|
1684 |
||
1685 |
if (fuidp) |
|
1686 |
zfs_fuid_info_free(fuidp); |
|
789 | 1687 |
dmu_tx_commit(tx); |
1688 |
||
1689 |
zfs_dirent_unlock(dl); |
|
1690 |
||
1691 |
ZFS_EXIT(zfsvfs); |
|
1692 |
return (0); |
|
1693 |
} |
|
1694 |
||
1695 |
/* |
|
1696 |
* Remove a directory subdir entry. If the current working |
|
1697 |
* directory is the same as the subdir to be removed, the |
|
1698 |
* remove will fail. |
|
1699 |
* |
|
1700 |
* IN: dvp - vnode of directory to remove from. |
|
1701 |
* name - name of directory to be removed. |
|
1702 |
* cwd - vnode of current working directory. |
|
1703 |
* cr - credentials of caller. |
|
5331 | 1704 |
* ct - caller context |
1705 |
* flags - case flags |
|
789 | 1706 |
* |
1707 |
* RETURN: 0 if success |
|
1708 |
* error code if failure |
|
1709 |
* |
|
1710 |
* Timestamps: |
|
1711 |
* dvp - ctime|mtime updated |
|
1712 |
*/ |
|
5331 | 1713 |
/*ARGSUSED*/ |
789 | 1714 |
static int |
5331 | 1715 |
zfs_rmdir(vnode_t *dvp, char *name, vnode_t *cwd, cred_t *cr, |
1716 |
caller_context_t *ct, int flags) |
|
789 | 1717 |
{ |
1718 |
znode_t *dzp = VTOZ(dvp); |
|
1719 |
znode_t *zp; |
|
1720 |
vnode_t *vp; |
|
1721 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1722 |
zilog_t *zilog; |
789 | 1723 |
zfs_dirlock_t *dl; |
1724 |
dmu_tx_t *tx; |
|
1725 |
int error; |
|
5331 | 1726 |
int zflg = ZEXISTS; |
789 | 1727 |
|
5367 | 1728 |
ZFS_ENTER(zfsvfs); |
1729 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
1730 |
zilog = zfsvfs->z_log; |
789 | 1731 |
|
5331 | 1732 |
if (flags & FIGNORECASE) |
1733 |
zflg |= ZCILOOK; |
|
789 | 1734 |
top: |
1735 |
zp = NULL; |
|
1736 |
||
1737 |
/* |
|
1738 |
* Attempt to lock directory; fail if entry doesn't exist. |
|
1739 |
*/ |
|
5331 | 1740 |
if (error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, |
1741 |
NULL, NULL)) { |
|
789 | 1742 |
ZFS_EXIT(zfsvfs); |
1743 |
return (error); |
|
1744 |
} |
|
1745 |
||
1746 |
vp = ZTOV(zp); |
|
1747 |
||
1748 |
if (error = zfs_zaccess_delete(dzp, zp, cr)) { |
|
1749 |
goto out; |
|
1750 |
} |
|
1751 |
||
1752 |
if (vp->v_type != VDIR) { |
|
1753 |
error = ENOTDIR; |
|
1754 |
goto out; |
|
1755 |
} |
|
1756 |
||
1757 |
if (vp == cwd) { |
|
1758 |
error = EINVAL; |
|
1759 |
goto out; |
|
1760 |
} |
|
1761 |
||
5331 | 1762 |
vnevent_rmdir(vp, dvp, name, ct); |
789 | 1763 |
|
1764 |
/* |
|
3897
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3638
diff
changeset
|
1765 |
* 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
|
1766 |
* 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
|
1767 |
*/ |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3638
diff
changeset
|
1768 |
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
|
1769 |
|
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3638
diff
changeset
|
1770 |
/* |
278bade789ba
6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents:
3638
diff
changeset
|
1771 |
* Grab a lock on the parent pointer to make sure we play well |
789 | 1772 |
* with the treewalk and directory rename code. |
1773 |
*/ |
|
1774 |
rw_enter(&zp->z_parent_lock, RW_WRITER); |
|
1775 |
||
1776 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
1544 | 1777 |
dmu_tx_hold_zap(tx, dzp->z_id, FALSE, name); |
789 | 1778 |
dmu_tx_hold_bonus(tx, zp->z_id); |
3461 | 1779 |
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL); |
789 | 1780 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
1781 |
if (error) { |
|
1782 |
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
|
1783 |
rw_exit(&zp->z_name_lock); |
789 | 1784 |
zfs_dirent_unlock(dl); |
1785 |
VN_RELE(vp); |
|
1786 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1787 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1788 |
dmu_tx_abort(tx); |
789 | 1789 |
goto top; |
1790 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
1791 |
dmu_tx_abort(tx); |
789 | 1792 |
ZFS_EXIT(zfsvfs); |
1793 |
return (error); |
|
1794 |
} |
|
1795 |
||
5331 | 1796 |
error = zfs_link_destroy(dl, zp, tx, zflg, NULL); |
1797 |
||
1798 |
if (error == 0) { |
|
1799 |
uint64_t txtype = TX_RMDIR; |
|
1800 |
if (flags & FIGNORECASE) |
|
1801 |
txtype |= TX_CI; |
|
1802 |
zfs_log_remove(zilog, tx, txtype, dzp, name); |
|
1803 |
} |
|
789 | 1804 |
|
1805 |
dmu_tx_commit(tx); |
|
1806 |
||
1807 |
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
|
1808 |
rw_exit(&zp->z_name_lock); |
789 | 1809 |
out: |
1810 |
zfs_dirent_unlock(dl); |
|
1811 |
||
1812 |
VN_RELE(vp); |
|
1813 |
||
1814 |
ZFS_EXIT(zfsvfs); |
|
1815 |
return (error); |
|
1816 |
} |
|
1817 |
||
1818 |
/* |
|
1819 |
* Read as many directory entries as will fit into the provided |
|
1820 |
* buffer from the given directory cursor position (specified in |
|
1821 |
* the uio structure. |
|
1822 |
* |
|
1823 |
* IN: vp - vnode of directory to read. |
|
1824 |
* uio - structure supplying read location, range info, |
|
1825 |
* and return buffer. |
|
1826 |
* cr - credentials of caller. |
|
5331 | 1827 |
* ct - caller context |
1828 |
* flags - case flags |
|
789 | 1829 |
* |
1830 |
* OUT: uio - updated offset and range, buffer filled. |
|
1831 |
* eofp - set to true if end-of-file detected. |
|
1832 |
* |
|
1833 |
* RETURN: 0 if success |
|
1834 |
* error code if failure |
|
1835 |
* |
|
1836 |
* Timestamps: |
|
1837 |
* vp - atime updated |
|
1838 |
* |
|
1839 |
* Note that the low 4 bits of the cookie returned by zap is always zero. |
|
1840 |
* This allows us to use the low range for "special" directory entries: |
|
1841 |
* We use 0 for '.', and 1 for '..'. If this is the root of the filesystem, |
|
1842 |
* we use the offset 2 for the '.zfs' directory. |
|
1843 |
*/ |
|
1844 |
/* ARGSUSED */ |
|
1845 |
static int |
|
5331 | 1846 |
zfs_readdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp, |
1847 |
caller_context_t *ct, int flags) |
|
789 | 1848 |
{ |
1849 |
znode_t *zp = VTOZ(vp); |
|
1850 |
iovec_t *iovp; |
|
5331 | 1851 |
edirent_t *eodp; |
789 | 1852 |
dirent64_t *odp; |
1853 |
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
|
1854 |
objset_t *os; |
789 | 1855 |
caddr_t outbuf; |
1856 |
size_t bufsize; |
|
1857 |
zap_cursor_t zc; |
|
1858 |
zap_attribute_t zap; |
|
1859 |
uint_t bytes_wanted; |
|
1860 |
uint64_t offset; /* must be unsigned; checks for < 1 */ |
|
1861 |
int local_eof; |
|
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1862 |
int outcount; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1863 |
int error; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1864 |
uint8_t prefetch; |
789 | 1865 |
|
5367 | 1866 |
ZFS_ENTER(zfsvfs); |
1867 |
ZFS_VERIFY_ZP(zp); |
|
789 | 1868 |
|
1869 |
/* |
|
1870 |
* If we are not given an eof variable, |
|
1871 |
* use a local one. |
|
1872 |
*/ |
|
1873 |
if (eofp == NULL) |
|
1874 |
eofp = &local_eof; |
|
1875 |
||
1876 |
/* |
|
1877 |
* Check for valid iov_len. |
|
1878 |
*/ |
|
1879 |
if (uio->uio_iov->iov_len <= 0) { |
|
1880 |
ZFS_EXIT(zfsvfs); |
|
1881 |
return (EINVAL); |
|
1882 |
} |
|
1883 |
||
1884 |
/* |
|
1885 |
* Quit if directory has been removed (posix) |
|
1886 |
*/ |
|
3461 | 1887 |
if ((*eofp = zp->z_unlinked) != 0) { |
789 | 1888 |
ZFS_EXIT(zfsvfs); |
1889 |
return (0); |
|
1890 |
} |
|
1891 |
||
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1892 |
error = 0; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1893 |
os = zfsvfs->z_os; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1894 |
offset = uio->uio_loffset; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1895 |
prefetch = zp->z_zn_prefetch; |
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1896 |
|
789 | 1897 |
/* |
1898 |
* Initialize the iterator cursor. |
|
1899 |
*/ |
|
1900 |
if (offset <= 3) { |
|
1901 |
/* |
|
1902 |
* Start iteration from the beginning of the directory. |
|
1903 |
*/ |
|
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1904 |
zap_cursor_init(&zc, os, zp->z_id); |
789 | 1905 |
} else { |
1906 |
/* |
|
1907 |
* The offset is a serialized cursor. |
|
1908 |
*/ |
|
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
1909 |
zap_cursor_init_serialized(&zc, os, zp->z_id, offset); |
789 | 1910 |
} |
1911 |
||
1912 |
/* |
|
1913 |
* Get space to change directory entries into fs independent format. |
|
1914 |
*/ |
|
1915 |
iovp = uio->uio_iov; |
|
1916 |
bytes_wanted = iovp->iov_len; |
|
1917 |
if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) { |
|
1918 |
bufsize = bytes_wanted; |
|
1919 |
outbuf = kmem_alloc(bufsize, KM_SLEEP); |
|
1920 |
odp = (struct dirent64 *)outbuf; |
|
1921 |
} else { |
|
1922 |
bufsize = bytes_wanted; |
|
1923 |
odp = (struct dirent64 *)iovp->iov_base; |
|
1924 |
} |
|
5331 | 1925 |
eodp = (struct edirent *)odp; |
789 | 1926 |
|
1927 |
/* |
|
1928 |
* Transform to file-system independent format |
|
1929 |
*/ |
|
1930 |
outcount = 0; |
|
1931 |
while (outcount < bytes_wanted) { |
|
3912 | 1932 |
ino64_t objnum; |
1933 |
ushort_t reclen; |
|
1934 |
off64_t *next; |
|
1935 |
||
789 | 1936 |
/* |
1937 |
* Special case `.', `..', and `.zfs'. |
|
1938 |
*/ |
|
1939 |
if (offset == 0) { |
|
1940 |
(void) strcpy(zap.za_name, "."); |
|
5331 | 1941 |
zap.za_normalization_conflict = 0; |
3912 | 1942 |
objnum = zp->z_id; |
789 | 1943 |
} else if (offset == 1) { |
1944 |
(void) strcpy(zap.za_name, ".."); |
|
5331 | 1945 |
zap.za_normalization_conflict = 0; |
3912 | 1946 |
objnum = zp->z_phys->zp_parent; |
789 | 1947 |
} else if (offset == 2 && zfs_show_ctldir(zp)) { |
1948 |
(void) strcpy(zap.za_name, ZFS_CTLDIR_NAME); |
|
5331 | 1949 |
zap.za_normalization_conflict = 0; |
3912 | 1950 |
objnum = ZFSCTL_INO_ROOT; |
789 | 1951 |
} else { |
1952 |
/* |
|
1953 |
* Grab next entry. |
|
1954 |
*/ |
|
1955 |
if (error = zap_cursor_retrieve(&zc, &zap)) { |
|
1956 |
if ((*eofp = (error == ENOENT)) != 0) |
|
1957 |
break; |
|
1958 |
else |
|
1959 |
goto update; |
|
1960 |
} |
|
1961 |
||
1962 |
if (zap.za_integer_length != 8 || |
|
1963 |
zap.za_num_integers != 1) { |
|
1964 |
cmn_err(CE_WARN, "zap_readdir: bad directory " |
|
1965 |
"entry, obj = %lld, offset = %lld\n", |
|
1966 |
(u_longlong_t)zp->z_id, |
|
1967 |
(u_longlong_t)offset); |
|
1968 |
error = ENXIO; |
|
1969 |
goto update; |
|
1970 |
} |
|
3912 | 1971 |
|
1972 |
objnum = ZFS_DIRENT_OBJ(zap.za_first_integer); |
|
1973 |
/* |
|
1974 |
* MacOS X can extract the object type here such as: |
|
1975 |
* uint8_t type = ZFS_DIRENT_TYPE(zap.za_first_integer); |
|
1976 |
*/ |
|
789 | 1977 |
} |
5331 | 1978 |
|
1979 |
if (flags & V_RDDIR_ENTFLAGS) |
|
1980 |
reclen = EDIRENT_RECLEN(strlen(zap.za_name)); |
|
1981 |
else |
|
1982 |
reclen = DIRENT64_RECLEN(strlen(zap.za_name)); |
|
789 | 1983 |
|
1984 |
/* |
|
1985 |
* Will this entry fit in the buffer? |
|
1986 |
*/ |
|
3912 | 1987 |
if (outcount + reclen > bufsize) { |
789 | 1988 |
/* |
1989 |
* Did we manage to fit anything in the buffer? |
|
1990 |
*/ |
|
1991 |
if (!outcount) { |
|
1992 |
error = EINVAL; |
|
1993 |
goto update; |
|
1994 |
} |
|
1995 |
break; |
|
1996 |
} |
|
5331 | 1997 |
if (flags & V_RDDIR_ENTFLAGS) { |
1998 |
/* |
|
1999 |
* Add extended flag entry: |
|
2000 |
*/ |
|
2001 |
eodp->ed_ino = objnum; |
|
2002 |
eodp->ed_reclen = reclen; |
|
2003 |
/* NOTE: ed_off is the offset for the *next* entry */ |
|
2004 |
next = &(eodp->ed_off); |
|
2005 |
eodp->ed_eflags = zap.za_normalization_conflict ? |
|
2006 |
ED_CASE_CONFLICT : 0; |
|
2007 |
(void) strncpy(eodp->ed_name, zap.za_name, |
|
2008 |
EDIRENT_NAMELEN(reclen)); |
|
2009 |
eodp = (edirent_t *)((intptr_t)eodp + reclen); |
|
2010 |
} else { |
|
2011 |
/* |
|
2012 |
* Add normal entry: |
|
2013 |
*/ |
|
2014 |
odp->d_ino = objnum; |
|
2015 |
odp->d_reclen = reclen; |
|
2016 |
/* NOTE: d_off is the offset for the *next* entry */ |
|
2017 |
next = &(odp->d_off); |
|
2018 |
(void) strncpy(odp->d_name, zap.za_name, |
|
2019 |
DIRENT64_NAMELEN(reclen)); |
|
2020 |
odp = (dirent64_t *)((intptr_t)odp + reclen); |
|
2021 |
} |
|
3912 | 2022 |
outcount += reclen; |
789 | 2023 |
|
2024 |
ASSERT(outcount <= bufsize); |
|
2025 |
||
2026 |
/* Prefetch znode */ |
|
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
2027 |
if (prefetch) |
3912 | 2028 |
dmu_prefetch(os, objnum, 0, 0); |
789 | 2029 |
|
2030 |
/* |
|
2031 |
* Move to the next entry, fill in the previous offset. |
|
2032 |
*/ |
|
2033 |
if (offset > 2 || (offset == 2 && !zfs_show_ctldir(zp))) { |
|
2034 |
zap_cursor_advance(&zc); |
|
2035 |
offset = zap_cursor_serialize(&zc); |
|
2036 |
} else { |
|
2037 |
offset += 1; |
|
2038 |
} |
|
2039 |
*next = offset; |
|
2040 |
} |
|
869
dc133b87dfb3
6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents:
789
diff
changeset
|
2041 |
zp->z_zn_prefetch = B_FALSE; /* a lookup will re-enable pre-fetching */ |
789 | 2042 |
|
2043 |
if (uio->uio_segflg == UIO_SYSSPACE && uio->uio_iovcnt == 1) { |
|
2044 |
iovp->iov_base += outcount; |
|
2045 |
iovp->iov_len -= outcount; |
|
2046 |
uio->uio_resid -= outcount; |
|
2047 |
} else if (error = uiomove(outbuf, (long)outcount, UIO_READ, uio)) { |
|
2048 |
/* |
|
2049 |
* Reset the pointer. |
|
2050 |
*/ |
|
2051 |
offset = uio->uio_loffset; |
|
2052 |
} |
|
2053 |
||
2054 |
update: |
|
885
d925b21dba78
6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents:
869
diff
changeset
|
2055 |
zap_cursor_fini(&zc); |
789 | 2056 |
if (uio->uio_segflg != UIO_SYSSPACE || uio->uio_iovcnt != 1) |
2057 |
kmem_free(outbuf, bufsize); |
|
2058 |
||
2059 |
if (error == ENOENT) |
|
2060 |
error = 0; |
|
2061 |
||
2062 |
ZFS_ACCESSTIME_STAMP(zfsvfs, zp); |
|
2063 |
||
2064 |
uio->uio_loffset = offset; |
|
2065 |
ZFS_EXIT(zfsvfs); |
|
2066 |
return (error); |
|
2067 |
} |
|
2068 |
||
4720
8edc0d2e6f3f
6535160 Lock contention on zl_lock from zil_commit
fr157268
parents:
4709
diff
changeset
|
2069 |
ulong_t zfs_fsync_sync_cnt = 4; |
8edc0d2e6f3f
6535160 Lock contention on zl_lock from zil_commit
fr157268
parents:
4709
diff
changeset
|
2070 |
|
789 | 2071 |
static int |
5331 | 2072 |
zfs_fsync(vnode_t *vp, int syncflag, cred_t *cr, caller_context_t *ct) |
789 | 2073 |
{ |
2074 |
znode_t *zp = VTOZ(vp); |
|
2075 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
2076 |
||
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
2077 |
/* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
2078 |
* 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
|
2079 |
* 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
|
2080 |
* 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
|
2081 |
* 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
|
2082 |
*/ |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
2083 |
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
|
2084 |
(vp->v_type == VREG) && !(IS_SWAPVP(vp))) |
5331 | 2085 |
(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
|
2086 |
|
4720
8edc0d2e6f3f
6535160 Lock contention on zl_lock from zil_commit
fr157268
parents:
4709
diff
changeset
|
2087 |
(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
|
2088 |
|
5367 | 2089 |
ZFS_ENTER(zfsvfs); |
2090 |
ZFS_VERIFY_ZP(zp); |
|
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
2091 |
zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id); |
789 | 2092 |
ZFS_EXIT(zfsvfs); |
2093 |
return (0); |
|
2094 |
} |
|
2095 |
||
5331 | 2096 |
|
789 | 2097 |
/* |
2098 |
* Get the requested file attributes and place them in the provided |
|
2099 |
* vattr structure. |
|
2100 |
* |
|
2101 |
* IN: vp - vnode of file. |
|
2102 |
* vap - va_mask identifies requested attributes. |
|
5331 | 2103 |
* If AT_XVATTR set, then optional attrs are requested |
2104 |
* flags - ATTR_NOACLCHECK (CIFS server context) |
|
789 | 2105 |
* cr - credentials of caller. |
5331 | 2106 |
* ct - caller context |
789 | 2107 |
* |
2108 |
* OUT: vap - attribute values. |
|
2109 |
* |
|
2110 |
* RETURN: 0 (always succeeds) |
|
2111 |
*/ |
|
2112 |
/* ARGSUSED */ |
|
2113 |
static int |
|
5331 | 2114 |
zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, |
2115 |
caller_context_t *ct) |
|
789 | 2116 |
{ |
2117 |
znode_t *zp = VTOZ(vp); |
|
2118 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2119 |
znode_phys_t *pzp; |
5331 | 2120 |
int error = 0; |
4543 | 2121 |
uint64_t links; |
5331 | 2122 |
xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */ |
2123 |
xoptattr_t *xoap = NULL; |
|
2124 |
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; |
|
789 | 2125 |
|
5367 | 2126 |
ZFS_ENTER(zfsvfs); |
2127 |
ZFS_VERIFY_ZP(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2128 |
pzp = zp->z_phys; |
789 | 2129 |
|
5331 | 2130 |
mutex_enter(&zp->z_lock); |
2131 |
||
2132 |
/* |
|
2133 |
* If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES. |
|
2134 |
* Also, if we are the owner don't bother, since owner should |
|
2135 |
* always be allowed to read basic attributes of file. |
|
2136 |
*/ |
|
2137 |
if (!(pzp->zp_flags & ZFS_ACL_TRIVIAL) && |
|
2138 |
(pzp->zp_uid != crgetuid(cr))) { |
|
2139 |
if (error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0, |
|
2140 |
skipaclchk, cr)) { |
|
2141 |
mutex_exit(&zp->z_lock); |
|
2142 |
ZFS_EXIT(zfsvfs); |
|
2143 |
return (error); |
|
2144 |
} |
|
2145 |
} |
|
2146 |
||
789 | 2147 |
/* |
2148 |
* Return all attributes. It's cheaper to provide the answer |
|
2149 |
* than to determine whether we were asked the question. |
|
2150 |
*/ |
|
2151 |
||
2152 |
vap->va_type = vp->v_type; |
|
2153 |
vap->va_mode = pzp->zp_mode & MODEMASK; |
|
5331 | 2154 |
zfs_fuid_map_ids(zp, &vap->va_uid, &vap->va_gid); |
789 | 2155 |
vap->va_fsid = zp->z_zfsvfs->z_vfs->vfs_dev; |
2156 |
vap->va_nodeid = zp->z_id; |
|
4543 | 2157 |
if ((vp->v_flag & VROOT) && zfs_show_ctldir(zp)) |
2158 |
links = pzp->zp_links + 1; |
|
2159 |
else |
|
2160 |
links = pzp->zp_links; |
|
2161 |
vap->va_nlink = MIN(links, UINT32_MAX); /* nlink_t limit! */ |
|
789 | 2162 |
vap->va_size = pzp->zp_size; |
1816
8c14b56c8515
6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents:
1773
diff
changeset
|
2163 |
vap->va_rdev = vp->v_rdev; |
789 | 2164 |
vap->va_seq = zp->z_seq; |
2165 |
||
5331 | 2166 |
/* |
2167 |
* Add in any requested optional attributes and the create time. |
|
2168 |
* Also set the corresponding bits in the returned attribute bitmap. |
|
2169 |
*/ |
|
2170 |
if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) { |
|
2171 |
if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) { |
|
2172 |
xoap->xoa_archive = |
|
2173 |
((pzp->zp_flags & ZFS_ARCHIVE) != 0); |
|
2174 |
XVA_SET_RTN(xvap, XAT_ARCHIVE); |
|
2175 |
} |
|
2176 |
||
2177 |
if (XVA_ISSET_REQ(xvap, XAT_READONLY)) { |
|
2178 |
xoap->xoa_readonly = |
|
2179 |
((pzp->zp_flags & ZFS_READONLY) != 0); |
|
2180 |
XVA_SET_RTN(xvap, XAT_READONLY); |
|
2181 |
} |
|
2182 |
||
2183 |
if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) { |
|
2184 |
xoap->xoa_system = |
|
2185 |
((pzp->zp_flags & ZFS_SYSTEM) != 0); |
|
2186 |
XVA_SET_RTN(xvap, XAT_SYSTEM); |
|
2187 |
} |
|
2188 |
||
2189 |
if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) { |
|
2190 |
xoap->xoa_hidden = |
|
2191 |
((pzp->zp_flags & ZFS_HIDDEN) != 0); |
|
2192 |
XVA_SET_RTN(xvap, XAT_HIDDEN); |
|
2193 |
} |
|
2194 |
||
2195 |
if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) { |
|
2196 |
xoap->xoa_nounlink = |
|
2197 |
((pzp->zp_flags & ZFS_NOUNLINK) != 0); |
|
2198 |
XVA_SET_RTN(xvap, XAT_NOUNLINK); |
|
2199 |
} |
|
2200 |
||
2201 |
if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) { |
|
2202 |
xoap->xoa_immutable = |
|
2203 |
((pzp->zp_flags & ZFS_IMMUTABLE) != 0); |
|
2204 |
XVA_SET_RTN(xvap, XAT_IMMUTABLE); |
|
2205 |
} |
|
2206 |
||
2207 |
if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) { |
|
2208 |
xoap->xoa_appendonly = |
|
2209 |
((pzp->zp_flags & ZFS_APPENDONLY) != 0); |
|
2210 |
XVA_SET_RTN(xvap, XAT_APPENDONLY); |
|
2211 |
} |
|
2212 |
||
2213 |
if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) { |
|
2214 |
xoap->xoa_nodump = |
|
2215 |
((pzp->zp_flags & ZFS_NODUMP) != 0); |
|
2216 |
XVA_SET_RTN(xvap, XAT_NODUMP); |
|
2217 |
} |
|
2218 |
||
2219 |
if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) { |
|
2220 |
xoap->xoa_opaque = |
|
2221 |
((pzp->zp_flags & ZFS_OPAQUE) != 0); |
|
2222 |
XVA_SET_RTN(xvap, XAT_OPAQUE); |
|
2223 |
} |
|
2224 |
||
2225 |
if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) { |
|
2226 |
xoap->xoa_av_quarantined = |
|
2227 |
((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0); |
|
2228 |
XVA_SET_RTN(xvap, XAT_AV_QUARANTINED); |
|
2229 |
} |
|
2230 |
||
2231 |
if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) { |
|
2232 |
xoap->xoa_av_modified = |
|
2233 |
((pzp->zp_flags & ZFS_AV_MODIFIED) != 0); |
|
2234 |
XVA_SET_RTN(xvap, XAT_AV_MODIFIED); |
|
2235 |
} |
|
2236 |
||
2237 |
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) && |
|
2238 |
vp->v_type == VREG && |
|
2239 |
(pzp->zp_flags & ZFS_BONUS_SCANSTAMP)) { |
|
2240 |
size_t len; |
|
2241 |
dmu_object_info_t doi; |
|
2242 |
||
2243 |
/* |
|
2244 |
* Only VREG files have anti-virus scanstamps, so we |
|
2245 |
* won't conflict with symlinks in the bonus buffer. |
|
2246 |
*/ |
|
2247 |
dmu_object_info_from_db(zp->z_dbuf, &doi); |
|
2248 |
len = sizeof (xoap->xoa_av_scanstamp) + |
|
2249 |
sizeof (znode_phys_t); |
|
2250 |
if (len <= doi.doi_bonus_size) { |
|
2251 |
/* |
|
2252 |
* pzp points to the start of the |
|
2253 |
* znode_phys_t. pzp + 1 points to the |
|
2254 |
* first byte after the znode_phys_t. |
|
2255 |
*/ |
|
2256 |
(void) memcpy(xoap->xoa_av_scanstamp, |
|
2257 |
pzp + 1, |
|
2258 |
sizeof (xoap->xoa_av_scanstamp)); |
|
2259 |
XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP); |
|
2260 |
} |
|
2261 |
} |
|
2262 |
||
2263 |
if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) { |
|
2264 |
ZFS_TIME_DECODE(&xoap->xoa_createtime, pzp->zp_crtime); |
|
2265 |
XVA_SET_RTN(xvap, XAT_CREATETIME); |
|
2266 |
} |
|
2267 |
} |
|
2268 |
||
789 | 2269 |
ZFS_TIME_DECODE(&vap->va_atime, pzp->zp_atime); |
2270 |
ZFS_TIME_DECODE(&vap->va_mtime, pzp->zp_mtime); |
|
2271 |
ZFS_TIME_DECODE(&vap->va_ctime, pzp->zp_ctime); |
|
2272 |
||
2273 |
mutex_exit(&zp->z_lock); |
|
2274 |
||
2275 |
dmu_object_size_from_db(zp->z_dbuf, &vap->va_blksize, &vap->va_nblocks); |
|
2276 |
||
2277 |
if (zp->z_blksz == 0) { |
|
2278 |
/* |
|
2279 |
* Block size hasn't been set; suggest maximal I/O transfers. |
|
2280 |
*/ |
|
2281 |
vap->va_blksize = zfsvfs->z_max_blksz; |
|
2282 |
} |
|
2283 |
||
2284 |
ZFS_EXIT(zfsvfs); |
|
2285 |
return (0); |
|
2286 |
} |
|
2287 |
||
2288 |
/* |
|
2289 |
* Set the file attributes to the values contained in the |
|
2290 |
* vattr structure. |
|
2291 |
* |
|
2292 |
* IN: vp - vnode of file to be modified. |
|
2293 |
* vap - new attribute values. |
|
5331 | 2294 |
* If AT_XVATTR set, then optional attrs are being set |
789 | 2295 |
* flags - ATTR_UTIME set if non-default time values provided. |
5331 | 2296 |
* - ATTR_NOACLCHECK (CIFS context only). |
789 | 2297 |
* cr - credentials of caller. |
5331 | 2298 |
* ct - caller context |
789 | 2299 |
* |
2300 |
* RETURN: 0 if success |
|
2301 |
* error code if failure |
|
2302 |
* |
|
2303 |
* Timestamps: |
|
2304 |
* vp - ctime updated, mtime updated if size changed. |
|
2305 |
*/ |
|
2306 |
/* ARGSUSED */ |
|
2307 |
static int |
|
2308 |
zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr, |
|
2309 |
caller_context_t *ct) |
|
2310 |
{ |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2311 |
znode_t *zp = VTOZ(vp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2312 |
znode_phys_t *pzp; |
789 | 2313 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2314 |
zilog_t *zilog; |
789 | 2315 |
dmu_tx_t *tx; |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2316 |
vattr_t oldva; |
789 | 2317 |
uint_t mask = vap->va_mask; |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2318 |
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
|
2319 |
int trim_mask = 0; |
789 | 2320 |
uint64_t new_mode; |
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
|
2321 |
znode_t *attrzp; |
789 | 2322 |
int need_policy = FALSE; |
2323 |
int err; |
|
5331 | 2324 |
zfs_fuid_info_t *fuidp = NULL; |
2325 |
xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */ |
|
2326 |
xoptattr_t *xoap; |
|
2327 |
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; |
|
789 | 2328 |
|
2329 |
if (mask == 0) |
|
2330 |
return (0); |
|
2331 |
||
2332 |
if (mask & AT_NOSET) |
|
2333 |
return (EINVAL); |
|
2334 |
||
5367 | 2335 |
ZFS_ENTER(zfsvfs); |
2336 |
ZFS_VERIFY_ZP(zp); |
|
5331 | 2337 |
|
2338 |
pzp = zp->z_phys; |
|
2339 |
zilog = zfsvfs->z_log; |
|
2340 |
||
2341 |
/* |
|
2342 |
* Make sure that if we have ephemeral uid/gid or xvattr specified |
|
2343 |
* that file system is at proper version level |
|
2344 |
*/ |
|
2345 |
||
2346 |
if (zfsvfs->z_use_fuids == B_FALSE && |
|
2347 |
(((mask & AT_UID) && IS_EPHEMERAL(vap->va_uid)) || |
|
2348 |
((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
|
2349 |
(mask & AT_XVATTR))) { |
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2350 |
ZFS_EXIT(zfsvfs); |
5331 | 2351 |
return (EINVAL); |
5386
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2352 |
} |
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2353 |
|
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2354 |
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
|
2355 |
ZFS_EXIT(zfsvfs); |
789 | 2356 |
return (EISDIR); |
5386
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2357 |
} |
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2358 |
|
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2359 |
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
|
2360 |
ZFS_EXIT(zfsvfs); |
1308
997e6a49c409
6362908 nfsv4-test: RENAME does not check PERM with NFSv4/ZFS
marks
parents:
1298
diff
changeset
|
2361 |
return (EINVAL); |
5386
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2362 |
} |
1308
997e6a49c409
6362908 nfsv4-test: RENAME does not check PERM with NFSv4/ZFS
marks
parents:
1298
diff
changeset
|
2363 |
|
5331 | 2364 |
/* |
2365 |
* If this is an xvattr_t, then get a pointer to the structure of |
|
2366 |
* optional attributes. If this is NULL, then we have a vattr_t. |
|
2367 |
*/ |
|
2368 |
xoap = xva_getxoptattr(xvap); |
|
2369 |
||
2370 |
/* |
|
2371 |
* Immutable files can only alter immutable bit and atime |
|
2372 |
*/ |
|
2373 |
if ((pzp->zp_flags & ZFS_IMMUTABLE) && |
|
2374 |
((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
|
2375 |
((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
|
2376 |
ZFS_EXIT(zfsvfs); |
5331 | 2377 |
return (EPERM); |
5386
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2378 |
} |
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2379 |
|
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2380 |
if ((mask & AT_SIZE) && (pzp->zp_flags & ZFS_READONLY)) { |
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2381 |
ZFS_EXIT(zfsvfs); |
5331 | 2382 |
return (EPERM); |
5386
fa920350a914
6623402 command hang during 'zfs unmount -a' after run CIFS test cases
timh
parents:
5367
diff
changeset
|
2383 |
} |
789 | 2384 |
|
2385 |
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
|
2386 |
attrzp = NULL; |
789 | 2387 |
|
2388 |
if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) { |
|
2389 |
ZFS_EXIT(zfsvfs); |
|
2390 |
return (EROFS); |
|
2391 |
} |
|
2392 |
||
2393 |
/* |
|
2394 |
* First validate permissions |
|
2395 |
*/ |
|
2396 |
||
2397 |
if (mask & AT_SIZE) { |
|
5331 | 2398 |
err = zfs_zaccess(zp, ACE_WRITE_DATA, 0, skipaclchk, cr); |
789 | 2399 |
if (err) { |
2400 |
ZFS_EXIT(zfsvfs); |
|
2401 |
return (err); |
|
2402 |
} |
|
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2403 |
/* |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2404 |
* XXX - Note, we are not providing any open |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2405 |
* mode flags here (like FNDELAY), so we may |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2406 |
* block if there are locks present... this |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2407 |
* should be addressed in openat(). |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2408 |
*/ |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2409 |
do { |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2410 |
err = zfs_freesp(zp, vap->va_size, 0, 0, FALSE); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
2411 |
/* NB: we already did dmu_tx_wait() if necessary */ |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2412 |
} while (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT); |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2413 |
if (err) { |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2414 |
ZFS_EXIT(zfsvfs); |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2415 |
return (err); |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2416 |
} |
789 | 2417 |
} |
2418 |
||
5331 | 2419 |
if (mask & (AT_ATIME|AT_MTIME) || |
2420 |
((mask & AT_XVATTR) && (XVA_ISSET_REQ(xvap, XAT_HIDDEN) || |
|
2421 |
XVA_ISSET_REQ(xvap, XAT_READONLY) || |
|
2422 |
XVA_ISSET_REQ(xvap, XAT_ARCHIVE) || |
|
2423 |
XVA_ISSET_REQ(xvap, XAT_CREATETIME) || |
|
2424 |
XVA_ISSET_REQ(xvap, XAT_SYSTEM)))) |
|
2425 |
need_policy = zfs_zaccess(zp, ACE_WRITE_ATTRIBUTES, 0, |
|
2426 |
skipaclchk, cr); |
|
789 | 2427 |
|
2428 |
if (mask & (AT_UID|AT_GID)) { |
|
2429 |
int idmask = (mask & (AT_UID|AT_GID)); |
|
2430 |
int take_owner; |
|
2431 |
int take_group; |
|
2432 |
||
2433 |
/* |
|
913
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2434 |
* 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
|
2435 |
* 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
|
2436 |
*/ |
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2437 |
|
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2438 |
if (!(mask & AT_MODE)) |
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2439 |
vap->va_mode = pzp->zp_mode; |
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2440 |
|
e99aef503251
6299353 chown(2) fails to clear SUID/SGID bits on ZFS.
marks
parents:
905
diff
changeset
|
2441 |
/* |
789 | 2442 |
* Take ownership or chgrp to group we are a member of |
2443 |
*/ |
|
2444 |
||
2445 |
take_owner = (mask & AT_UID) && (vap->va_uid == crgetuid(cr)); |
|
5331 | 2446 |
take_group = (mask & AT_GID) && |
2447 |
zfs_groupmember(zfsvfs, vap->va_gid, cr); |
|
789 | 2448 |
|
2449 |
/* |
|
2450 |
* If both AT_UID and AT_GID are set then take_owner and |
|
2451 |
* take_group must both be set in order to allow taking |
|
2452 |
* ownership. |
|
2453 |
* |
|
2454 |
* Otherwise, send the check through secpolicy_vnode_setattr() |
|
2455 |
* |
|
2456 |
*/ |
|
2457 |
||
2458 |
if (((idmask == (AT_UID|AT_GID)) && take_owner && take_group) || |
|
2459 |
((idmask == AT_UID) && take_owner) || |
|
2460 |
((idmask == AT_GID) && take_group)) { |
|
5331 | 2461 |
if (zfs_zaccess(zp, ACE_WRITE_OWNER, 0, |
2462 |
skipaclchk, cr) == 0) { |
|
789 | 2463 |
/* |
2464 |
* Remove setuid/setgid for non-privileged users |
|
2465 |
*/ |
|
1115 | 2466 |
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
|
2467 |
trim_mask = (mask & (AT_UID|AT_GID)); |
789 | 2468 |
} else { |
2469 |
need_policy = TRUE; |
|
2470 |
} |
|
2471 |
} else { |
|
2472 |
need_policy = TRUE; |
|
2473 |
} |
|
2474 |
} |
|
2475 |
||
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
|
2476 |
mutex_enter(&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
|
2477 |
oldva.va_mode = pzp->zp_mode; |
5331 | 2478 |
zfs_fuid_map_ids(zp, &oldva.va_uid, &oldva.va_gid); |
2479 |
if (mask & AT_XVATTR) { |
|
2480 |
if ((need_policy == FALSE) && |
|
2481 |
(XVA_ISSET_REQ(xvap, XAT_APPENDONLY) && |
|
2482 |
xoap->xoa_appendonly != |
|
2483 |
((pzp->zp_flags & ZFS_APPENDONLY) != 0)) || |
|
2484 |
(XVA_ISSET_REQ(xvap, XAT_NOUNLINK) && |
|
2485 |
xoap->xoa_nounlink != |
|
2486 |
((pzp->zp_flags & ZFS_NOUNLINK) != 0)) || |
|
2487 |
(XVA_ISSET_REQ(xvap, XAT_IMMUTABLE) && |
|
2488 |
xoap->xoa_immutable != |
|
2489 |
((pzp->zp_flags & ZFS_IMMUTABLE) != 0)) || |
|
2490 |
(XVA_ISSET_REQ(xvap, XAT_NODUMP) && |
|
2491 |
xoap->xoa_nodump != |
|
2492 |
((pzp->zp_flags & ZFS_NODUMP) != 0)) || |
|
2493 |
(XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED) && |
|
2494 |
xoap->xoa_av_modified != |
|
2495 |
((pzp->zp_flags & ZFS_AV_MODIFIED) != 0)) || |
|
5545
62533366078f
6623426 if immutable is set on a directory, unsetting all attributes fails
marks
parents:
5498
diff
changeset
|
2496 |
((XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED) && |
62533366078f
6623426 if immutable is set on a directory, unsetting all attributes fails
marks
parents:
5498
diff
changeset
|
2497 |
((vp->v_type != VREG && xoap->xoa_av_quarantined) || |
5331 | 2498 |
xoap->xoa_av_quarantined != |
5545
62533366078f
6623426 if immutable is set on a directory, unsetting all attributes fails
marks
parents:
5498
diff
changeset
|
2499 |
((pzp->zp_flags & ZFS_AV_QUARANTINED) != 0)))) || |
5331 | 2500 |
(XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) || |
2501 |
(XVA_ISSET_REQ(xvap, XAT_OPAQUE))) { |
|
2502 |
need_policy = TRUE; |
|
2503 |
} |
|
2504 |
} |
|
2505 |
||
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
|
2506 |
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
|
2507 |
|
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
|
2508 |
if (mask & AT_MODE) { |
5331 | 2509 |
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
|
2510 |
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
|
2511 |
&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
|
2512 |
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
|
2513 |
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
|
2514 |
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
|
2515 |
} |
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
|
2516 |
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
|
2517 |
} 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
|
2518 |
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
|
2519 |
} |
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
|
2520 |
} |
789 | 2521 |
|
2522 |
if (need_policy) { |
|
1115 | 2523 |
/* |
2524 |
* 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
|
2525 |
* 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
|
2526 |
* 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
|
2527 |
* UID|GID and or MODE from mask so that |
1115 | 2528 |
* secpolicy_vnode_setattr() doesn't revoke it. |
2529 |
*/ |
|
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
|
2530 |
|
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
|
2531 |
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
|
2532 |
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
|
2533 |
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
|
2534 |
} |
789 | 2535 |
err = secpolicy_vnode_setattr(cr, vp, vap, &oldva, flags, |
5331 | 2536 |
(int (*)(void *, int, cred_t *))zfs_zaccess_unix, zp); |
789 | 2537 |
if (err) { |
2538 |
ZFS_EXIT(zfsvfs); |
|
2539 |
return (err); |
|
2540 |
} |
|
1115 | 2541 |
|
2542 |
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
|
2543 |
vap->va_mask |= saved_mask; |
789 | 2544 |
} |
2545 |
||
2546 |
/* |
|
2547 |
* secpolicy_vnode_setattr, or take ownership may have |
|
2548 |
* changed va_mask |
|
2549 |
*/ |
|
2550 |
mask = vap->va_mask; |
|
2551 |
||
2552 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
2553 |
dmu_tx_hold_bonus(tx, zp->z_id); |
|
5331 | 2554 |
if (zfsvfs->z_fuid_obj == 0) { |
2555 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
2556 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, |
|
2557 |
SPA_MAXBLOCKSIZE); |
|
2558 |
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL); |
|
2559 |
} else { |
|
2560 |
dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj); |
|
2561 |
dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0, |
|
2562 |
SPA_MAXBLOCKSIZE); |
|
2563 |
} |
|
789 | 2564 |
|
2565 |
if (mask & AT_MODE) { |
|
1576
0364d1928a7f
6380036 zfs does not clear S_ISUID and S_ISGID bits on successful writes
marks
parents:
1544
diff
changeset
|
2566 |
uint64_t pmode = pzp->zp_mode; |
0364d1928a7f
6380036 zfs does not clear S_ISUID and S_ISGID bits on successful writes
marks
parents:
1544
diff
changeset
|
2567 |
|
0364d1928a7f
6380036 zfs does not clear S_ISUID and S_ISGID bits on successful writes
marks
parents:
1544
diff
changeset
|
2568 |
new_mode = (pmode & S_IFMT) | (vap->va_mode & ~S_IFMT); |
789 | 2569 |
|
5331 | 2570 |
if (pzp->zp_acl.z_acl_extern_obj) { |
2571 |
/* Are we upgrading ACL from old V0 format to new V1 */ |
|
2572 |
if (zfsvfs->z_version <= ZPL_VERSION_FUID && |
|
2573 |
pzp->zp_acl.z_acl_version == |
|
2574 |
ZFS_ACL_VERSION_INITIAL) { |
|
2575 |
dmu_tx_hold_free(tx, |
|
2576 |
pzp->zp_acl.z_acl_extern_obj, 0, |
|
2577 |
DMU_OBJECT_END); |
|
2578 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, |
|
2579 |
0, sizeof (zfs_object_ace_t) * 2048 + 6); |
|
2580 |
} else { |
|
2581 |
dmu_tx_hold_write(tx, |
|
2582 |
pzp->zp_acl.z_acl_extern_obj, 0, |
|
2583 |
SPA_MAXBLOCKSIZE); |
|
2584 |
} |
|
2585 |
} else { |
|
789 | 2586 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, |
5331 | 2587 |
0, sizeof (zfs_object_ace_t) * 2048 + 6); |
2588 |
} |
|
789 | 2589 |
} |
2590 |
||
5331 | 2591 |
if ((mask & (AT_UID | AT_GID)) && pzp->zp_xattr != 0) { |
2592 |
err = zfs_zget(zp->z_zfsvfs, pzp->zp_xattr, &attrzp); |
|
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
|
2593 |
if (err) { |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2594 |
dmu_tx_abort(tx); |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2595 |
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
|
2596 |
return (err); |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2597 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2598 |
dmu_tx_hold_bonus(tx, attrzp->z_id); |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2599 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2600 |
|
789 | 2601 |
err = dmu_tx_assign(tx, zfsvfs->z_assign); |
2602 |
if (err) { |
|
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
|
2603 |
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
|
2604 |
VN_RELE(ZTOV(attrzp)); |
789 | 2605 |
if (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
2606 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
2607 |
dmu_tx_abort(tx); |
789 | 2608 |
goto top; |
2609 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
2610 |
dmu_tx_abort(tx); |
789 | 2611 |
ZFS_EXIT(zfsvfs); |
2612 |
return (err); |
|
2613 |
} |
|
2614 |
||
2615 |
dmu_buf_will_dirty(zp->z_dbuf, tx); |
|
2616 |
||
2617 |
/* |
|
2618 |
* Set each attribute requested. |
|
2619 |
* We group settings according to the locks they need to acquire. |
|
2620 |
* |
|
2621 |
* Note: you cannot set ctime directly, although it will be |
|
2622 |
* updated as a side-effect of calling this function. |
|
2623 |
*/ |
|
2624 |
||
2625 |
mutex_enter(&zp->z_lock); |
|
2626 |
||
2627 |
if (mask & AT_MODE) { |
|
2628 |
err = zfs_acl_chmod_setattr(zp, new_mode, tx); |
|
2629 |
ASSERT3U(err, ==, 0); |
|
2630 |
} |
|
2631 |
||
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
|
2632 |
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
|
2633 |
mutex_enter(&attrzp->z_lock); |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2634 |
|
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2635 |
if (mask & AT_UID) { |
5331 | 2636 |
pzp->zp_uid = zfs_fuid_create(zfsvfs, |
2637 |
vap->va_uid, ZFS_OWNER, tx, &fuidp); |
|
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
|
2638 |
if (attrzp) { |
5331 | 2639 |
attrzp->z_phys->zp_uid = zfs_fuid_create(zfsvfs, |
2640 |
vap->va_uid, ZFS_OWNER, tx, &fuidp); |
|
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
|
2641 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2642 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2643 |
|
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2644 |
if (mask & AT_GID) { |
5331 | 2645 |
pzp->zp_gid = zfs_fuid_create(zfsvfs, vap->va_gid, |
2646 |
ZFS_GROUP, tx, &fuidp); |
|
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
|
2647 |
if (attrzp) |
5331 | 2648 |
attrzp->z_phys->zp_gid = zfs_fuid_create(zfsvfs, |
2649 |
vap->va_gid, ZFS_GROUP, tx, &fuidp); |
|
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
|
2650 |
} |
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2651 |
|
64215f768e86
6354804 The file's ACL was changed when cp it from one ZFS file system to another one.
marks
parents:
1141
diff
changeset
|
2652 |
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
|
2653 |
mutex_exit(&attrzp->z_lock); |
789 | 2654 |
|
2655 |
if (mask & AT_ATIME) |
|
2656 |
ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime); |
|
2657 |
||
2658 |
if (mask & AT_MTIME) |
|
2659 |
ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime); |
|
2660 |
||
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2661 |
if (mask & AT_SIZE) |
789 | 2662 |
zfs_time_stamper_locked(zp, CONTENT_MODIFIED, tx); |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2663 |
else if (mask != 0) |
789 | 2664 |
zfs_time_stamper_locked(zp, STATE_CHANGED, tx); |
5331 | 2665 |
/* |
2666 |
* Do this after setting timestamps to prevent timestamp |
|
2667 |
* update from toggling bit |
|
2668 |
*/ |
|
2669 |
||
2670 |
if (xoap && (mask & AT_XVATTR)) { |
|
2671 |
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) { |
|
2672 |
size_t len; |
|
2673 |
dmu_object_info_t doi; |
|
2674 |
||
2675 |
ASSERT(vp->v_type == VREG); |
|
2676 |
||
2677 |
/* Grow the bonus buffer if necessary. */ |
|
2678 |
dmu_object_info_from_db(zp->z_dbuf, &doi); |
|
2679 |
len = sizeof (xoap->xoa_av_scanstamp) + |
|
2680 |
sizeof (znode_phys_t); |
|
2681 |
if (len > doi.doi_bonus_size) |
|
2682 |
VERIFY(dmu_set_bonus(zp->z_dbuf, len, tx) == 0); |
|
2683 |
} |
|
2684 |
zfs_xvattr_set(zp, xvap); |
|
2685 |
} |
|
789 | 2686 |
|
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
2687 |
if (mask != 0) |
5331 | 2688 |
zfs_log_setattr(zilog, tx, TX_SETATTR, zp, vap, mask, fuidp); |
2689 |
||
2690 |
if (fuidp) |
|
2691 |
zfs_fuid_info_free(fuidp); |
|
789 | 2692 |
mutex_exit(&zp->z_lock); |
2693 |
||
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
|
2694 |
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
|
2695 |
VN_RELE(ZTOV(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
|
2696 |
|
789 | 2697 |
dmu_tx_commit(tx); |
2698 |
||
2699 |
ZFS_EXIT(zfsvfs); |
|
2700 |
return (err); |
|
2701 |
} |
|
2702 |
||
3271 | 2703 |
typedef struct zfs_zlock { |
2704 |
krwlock_t *zl_rwlock; /* lock we acquired */ |
|
2705 |
znode_t *zl_znode; /* znode we held */ |
|
2706 |
struct zfs_zlock *zl_next; /* next in list */ |
|
2707 |
} zfs_zlock_t; |
|
2708 |
||
2709 |
/* |
|
2710 |
* Drop locks and release vnodes that were held by zfs_rename_lock(). |
|
2711 |
*/ |
|
2712 |
static void |
|
2713 |
zfs_rename_unlock(zfs_zlock_t **zlpp) |
|
2714 |
{ |
|
2715 |
zfs_zlock_t *zl; |
|
2716 |
||
2717 |
while ((zl = *zlpp) != NULL) { |
|
2718 |
if (zl->zl_znode != NULL) |
|
2719 |
VN_RELE(ZTOV(zl->zl_znode)); |
|
2720 |
rw_exit(zl->zl_rwlock); |
|
2721 |
*zlpp = zl->zl_next; |
|
2722 |
kmem_free(zl, sizeof (*zl)); |
|
2723 |
} |
|
2724 |
} |
|
2725 |
||
789 | 2726 |
/* |
2727 |
* Search back through the directory tree, using the ".." entries. |
|
2728 |
* Lock each directory in the chain to prevent concurrent renames. |
|
2729 |
* Fail any attempt to move a directory into one of its own descendants. |
|
2730 |
* XXX - z_parent_lock can overlap with map or grow locks |
|
2731 |
*/ |
|
2732 |
static int |
|
2733 |
zfs_rename_lock(znode_t *szp, znode_t *tdzp, znode_t *sdzp, zfs_zlock_t **zlpp) |
|
2734 |
{ |
|
2735 |
zfs_zlock_t *zl; |
|
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
2736 |
znode_t *zp = tdzp; |
789 | 2737 |
uint64_t rootid = zp->z_zfsvfs->z_root; |
2738 |
uint64_t *oidp = &zp->z_id; |
|
2739 |
krwlock_t *rwlp = &szp->z_parent_lock; |
|
2740 |
krw_t rw = RW_WRITER; |
|
2741 |
||
2742 |
/* |
|
2743 |
* First pass write-locks szp and compares to zp->z_id. |
|
2744 |
* Later passes read-lock zp and compare to zp->z_parent. |
|
2745 |
*/ |
|
2746 |
do { |
|
3271 | 2747 |
if (!rw_tryenter(rwlp, rw)) { |
2748 |
/* |
|
2749 |
* Another thread is renaming in this path. |
|
2750 |
* Note that if we are a WRITER, we don't have any |
|
2751 |
* parent_locks held yet. |
|
2752 |
*/ |
|
2753 |
if (rw == RW_READER && zp->z_id > szp->z_id) { |
|
2754 |
/* |
|
2755 |
* Drop our locks and restart |
|
2756 |
*/ |
|
2757 |
zfs_rename_unlock(&zl); |
|
2758 |
*zlpp = NULL; |
|
2759 |
zp = tdzp; |
|
2760 |
oidp = &zp->z_id; |
|
2761 |
rwlp = &szp->z_parent_lock; |
|
2762 |
rw = RW_WRITER; |
|
2763 |
continue; |
|
2764 |
} else { |
|
2765 |
/* |
|
2766 |
* Wait for other thread to drop its locks |
|
2767 |
*/ |
|
2768 |
rw_enter(rwlp, rw); |
|
2769 |
} |
|
2770 |
} |
|
2771 |
||
789 | 2772 |
zl = kmem_alloc(sizeof (*zl), KM_SLEEP); |
2773 |
zl->zl_rwlock = rwlp; |
|
2774 |
zl->zl_znode = NULL; |
|
2775 |
zl->zl_next = *zlpp; |
|
2776 |
*zlpp = zl; |
|
2777 |
||
2778 |
if (*oidp == szp->z_id) /* We're a descendant of szp */ |
|
2779 |
return (EINVAL); |
|
2780 |
||
2781 |
if (*oidp == rootid) /* We've hit the top */ |
|
2782 |
return (0); |
|
2783 |
||
2784 |
if (rw == RW_READER) { /* i.e. not the first pass */ |
|
2785 |
int error = zfs_zget(zp->z_zfsvfs, *oidp, &zp); |
|
2786 |
if (error) |
|
2787 |
return (error); |
|
2788 |
zl->zl_znode = zp; |
|
2789 |
} |
|
2790 |
oidp = &zp->z_phys->zp_parent; |
|
2791 |
rwlp = &zp->z_parent_lock; |
|
2792 |
rw = RW_READER; |
|
2793 |
||
2794 |
} while (zp->z_id != sdzp->z_id); |
|
2795 |
||
2796 |
return (0); |
|
2797 |
} |
|
2798 |
||
2799 |
/* |
|
2800 |
* Move an entry from the provided source directory to the target |
|
2801 |
* directory. Change the entry name as indicated. |
|
2802 |
* |
|
2803 |
* IN: sdvp - Source directory containing the "old entry". |
|
2804 |
* snm - Old entry name. |
|
2805 |
* tdvp - Target directory to contain the "new entry". |
|
2806 |
* tnm - New entry name. |
|
2807 |
* cr - credentials of caller. |
|
5331 | 2808 |
* ct - caller context |
2809 |
* flags - case flags |
|
789 | 2810 |
* |
2811 |
* RETURN: 0 if success |
|
2812 |
* error code if failure |
|
2813 |
* |
|
2814 |
* Timestamps: |
|
2815 |
* sdvp,tdvp - ctime|mtime updated |
|
2816 |
*/ |
|
5331 | 2817 |
/*ARGSUSED*/ |
789 | 2818 |
static int |
5331 | 2819 |
zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr, |
2820 |
caller_context_t *ct, int flags) |
|
789 | 2821 |
{ |
2822 |
znode_t *tdzp, *szp, *tzp; |
|
2823 |
znode_t *sdzp = VTOZ(sdvp); |
|
2824 |
zfsvfs_t *zfsvfs = sdzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2825 |
zilog_t *zilog; |
789 | 2826 |
vnode_t *realvp; |
2827 |
zfs_dirlock_t *sdl, *tdl; |
|
2828 |
dmu_tx_t *tx; |
|
2829 |
zfs_zlock_t *zl; |
|
5331 | 2830 |
int cmp, serr, terr; |
2831 |
int error = 0; |
|
2832 |
int zflg = 0; |
|
789 | 2833 |
|
5367 | 2834 |
ZFS_ENTER(zfsvfs); |
2835 |
ZFS_VERIFY_ZP(sdzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
2836 |
zilog = zfsvfs->z_log; |
789 | 2837 |
|
2838 |
/* |
|
2839 |
* Make sure we have the real vp for the target directory. |
|
2840 |
*/ |
|
5331 | 2841 |
if (VOP_REALVP(tdvp, &realvp, ct) == 0) |
789 | 2842 |
tdvp = realvp; |
2843 |
||
2844 |
if (tdvp->v_vfsp != sdvp->v_vfsp) { |
|
2845 |
ZFS_EXIT(zfsvfs); |
|
2846 |
return (EXDEV); |
|
2847 |
} |
|
2848 |
||
2849 |
tdzp = VTOZ(tdvp); |
|
5367 | 2850 |
ZFS_VERIFY_ZP(tdzp); |
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
2851 |
if (zfsvfs->z_utf8 && u8_validate(tnm, |
5331 | 2852 |
strlen(tnm), NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
2853 |
ZFS_EXIT(zfsvfs); |
|
2854 |
return (EILSEQ); |
|
2855 |
} |
|
2856 |
||
2857 |
if (flags & FIGNORECASE) |
|
2858 |
zflg |= ZCILOOK; |
|
2859 |
||
789 | 2860 |
top: |
2861 |
szp = NULL; |
|
2862 |
tzp = NULL; |
|
2863 |
zl = NULL; |
|
2864 |
||
2865 |
/* |
|
2866 |
* This is to prevent the creation of links into attribute space |
|
2867 |
* by renaming a linked file into/outof an attribute directory. |
|
2868 |
* See the comment in zfs_link() for why this is considered bad. |
|
2869 |
*/ |
|
2870 |
if ((tdzp->z_phys->zp_flags & ZFS_XATTR) != |
|
2871 |
(sdzp->z_phys->zp_flags & ZFS_XATTR)) { |
|
2872 |
ZFS_EXIT(zfsvfs); |
|
2873 |
return (EINVAL); |
|
2874 |
} |
|
2875 |
||
2876 |
/* |
|
2877 |
* Lock source and target directory entries. To prevent deadlock, |
|
2878 |
* a lock ordering must be defined. We lock the directory with |
|
2879 |
* the smallest object id first, or if it's a tie, the one with |
|
2880 |
* the lexically first name. |
|
2881 |
*/ |
|
2882 |
if (sdzp->z_id < tdzp->z_id) { |
|
2883 |
cmp = -1; |
|
2884 |
} else if (sdzp->z_id > tdzp->z_id) { |
|
2885 |
cmp = 1; |
|
2886 |
} else { |
|
5331 | 2887 |
/* |
2888 |
* First compare the two name arguments without |
|
2889 |
* considering any case folding. |
|
2890 |
*/ |
|
2891 |
int nofold = (zfsvfs->z_norm & ~U8_TEXTPREP_TOUPPER); |
|
2892 |
||
2893 |
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
|
2894 |
ASSERT(error == 0 || !zfsvfs->z_utf8); |
789 | 2895 |
if (cmp == 0) { |
2896 |
/* |
|
2897 |
* POSIX: "If the old argument and the new argument |
|
2898 |
* both refer to links to the same existing file, |
|
2899 |
* the rename() function shall return successfully |
|
2900 |
* and perform no other action." |
|
2901 |
*/ |
|
2902 |
ZFS_EXIT(zfsvfs); |
|
2903 |
return (0); |
|
2904 |
} |
|
5331 | 2905 |
/* |
2906 |
* If the file system is case-folding, then we may |
|
2907 |
* have some more checking to do. A case-folding file |
|
2908 |
* system is either supporting mixed case sensitivity |
|
2909 |
* access or is completely case-insensitive. Note |
|
2910 |
* that the file system is always case preserving. |
|
2911 |
* |
|
2912 |
* In mixed sensitivity mode case sensitive behavior |
|
2913 |
* is the default. FIGNORECASE must be used to |
|
2914 |
* explicitly request case insensitive behavior. |
|
2915 |
* |
|
2916 |
* If the source and target names provided differ only |
|
2917 |
* by case (e.g., a request to rename 'tim' to 'Tim'), |
|
2918 |
* we will treat this as a special case in the |
|
2919 |
* case-insensitive mode: as long as the source name |
|
2920 |
* is an exact match, we will allow this to proceed as |
|
2921 |
* a name-change request. |
|
2922 |
*/ |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
2923 |
if ((zfsvfs->z_case == ZFS_CASE_INSENSITIVE || |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
2924 |
(zfsvfs->z_case == ZFS_CASE_MIXED && |
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
2925 |
flags & FIGNORECASE)) && |
5331 | 2926 |
u8_strcmp(snm, tnm, 0, zfsvfs->z_norm, U8_UNICODE_LATEST, |
2927 |
&error) == 0) { |
|
2928 |
/* |
|
2929 |
* case preserving rename request, require exact |
|
2930 |
* name matches |
|
2931 |
*/ |
|
2932 |
zflg |= ZCIEXACT; |
|
2933 |
zflg &= ~ZCILOOK; |
|
2934 |
} |
|
789 | 2935 |
} |
5331 | 2936 |
|
789 | 2937 |
if (cmp < 0) { |
5331 | 2938 |
serr = zfs_dirent_lock(&sdl, sdzp, snm, &szp, |
2939 |
ZEXISTS | zflg, NULL, NULL); |
|
2940 |
terr = zfs_dirent_lock(&tdl, |
|
2941 |
tdzp, tnm, &tzp, ZRENAMING | zflg, NULL, NULL); |
|
789 | 2942 |
} else { |
5331 | 2943 |
terr = zfs_dirent_lock(&tdl, |
2944 |
tdzp, tnm, &tzp, zflg, NULL, NULL); |
|
2945 |
serr = zfs_dirent_lock(&sdl, |
|
2946 |
sdzp, snm, &szp, ZEXISTS | ZRENAMING | zflg, |
|
2947 |
NULL, NULL); |
|
789 | 2948 |
} |
2949 |
||
2950 |
if (serr) { |
|
2951 |
/* |
|
2952 |
* Source entry invalid or not there. |
|
2953 |
*/ |
|
2954 |
if (!terr) { |
|
2955 |
zfs_dirent_unlock(tdl); |
|
2956 |
if (tzp) |
|
2957 |
VN_RELE(ZTOV(tzp)); |
|
2958 |
} |
|
2959 |
if (strcmp(snm, "..") == 0) |
|
2960 |
serr = EINVAL; |
|
2961 |
ZFS_EXIT(zfsvfs); |
|
2962 |
return (serr); |
|
2963 |
} |
|
2964 |
if (terr) { |
|
2965 |
zfs_dirent_unlock(sdl); |
|
2966 |
VN_RELE(ZTOV(szp)); |
|
2967 |
if (strcmp(tnm, "..") == 0) |
|
2968 |
terr = EINVAL; |
|
2969 |
ZFS_EXIT(zfsvfs); |
|
2970 |
return (terr); |
|
2971 |
} |
|
2972 |
||
2973 |
/* |
|
2974 |
* Must have write access at the source to remove the old entry |
|
2975 |
* and write access at the target to create the new entry. |
|
2976 |
* Note that if target and source are the same, this can be |
|
2977 |
* done in a single check. |
|
2978 |
*/ |
|
2979 |
||
2980 |
if (error = zfs_zaccess_rename(sdzp, szp, tdzp, tzp, cr)) |
|
2981 |
goto out; |
|
2982 |
||
2983 |
if (ZTOV(szp)->v_type == VDIR) { |
|
2984 |
/* |
|
2985 |
* Check to make sure rename is valid. |
|
2986 |
* Can't do a move like this: /usr/a/b to /usr/a/b/c/d |
|
2987 |
*/ |
|
2988 |
if (error = zfs_rename_lock(szp, tdzp, sdzp, &zl)) |
|
2989 |
goto out; |
|
2990 |
} |
|
2991 |
||
2992 |
/* |
|
2993 |
* Does target exist? |
|
2994 |
*/ |
|
2995 |
if (tzp) { |
|
2996 |
/* |
|
2997 |
* Source and target must be the same type. |
|
2998 |
*/ |
|
2999 |
if (ZTOV(szp)->v_type == VDIR) { |
|
3000 |
if (ZTOV(tzp)->v_type != VDIR) { |
|
3001 |
error = ENOTDIR; |
|
3002 |
goto out; |
|
3003 |
} |
|
3004 |
} else { |
|
3005 |
if (ZTOV(tzp)->v_type == VDIR) { |
|
3006 |
error = EISDIR; |
|
3007 |
goto out; |
|
3008 |
} |
|
3009 |
} |
|
3010 |
/* |
|
3011 |
* POSIX dictates that when the source and target |
|
3012 |
* entries refer to the same file object, rename |
|
3013 |
* must do nothing and exit without error. |
|
3014 |
*/ |
|
3015 |
if (szp->z_id == tzp->z_id) { |
|
3016 |
error = 0; |
|
3017 |
goto out; |
|
3018 |
} |
|
3019 |
} |
|
3020 |
||
5331 | 3021 |
vnevent_rename_src(ZTOV(szp), sdvp, snm, ct); |
789 | 3022 |
if (tzp) |
5331 | 3023 |
vnevent_rename_dest(ZTOV(tzp), tdvp, tnm, ct); |
4863 | 3024 |
|
3025 |
/* |
|
3026 |
* notify the target directory if it is not the same |
|
3027 |
* as source directory. |
|
3028 |
*/ |
|
3029 |
if (tdvp != sdvp) { |
|
5331 | 3030 |
vnevent_rename_dest_dir(tdvp, ct); |
4863 | 3031 |
} |
789 | 3032 |
|
3033 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
3034 |
dmu_tx_hold_bonus(tx, szp->z_id); /* nlink changes */ |
|
3035 |
dmu_tx_hold_bonus(tx, sdzp->z_id); /* nlink changes */ |
|
1544 | 3036 |
dmu_tx_hold_zap(tx, sdzp->z_id, FALSE, snm); |
3037 |
dmu_tx_hold_zap(tx, tdzp->z_id, TRUE, tnm); |
|
3038 |
if (sdzp != tdzp) |
|
789 | 3039 |
dmu_tx_hold_bonus(tx, tdzp->z_id); /* nlink changes */ |
1544 | 3040 |
if (tzp) |
3041 |
dmu_tx_hold_bonus(tx, tzp->z_id); /* parent changes */ |
|
3461 | 3042 |
dmu_tx_hold_zap(tx, zfsvfs->z_unlinkedobj, FALSE, NULL); |
789 | 3043 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
3044 |
if (error) { |
|
3045 |
if (zl != NULL) |
|
3046 |
zfs_rename_unlock(&zl); |
|
3047 |
zfs_dirent_unlock(sdl); |
|
3048 |
zfs_dirent_unlock(tdl); |
|
3049 |
VN_RELE(ZTOV(szp)); |
|
3050 |
if (tzp) |
|
3051 |
VN_RELE(ZTOV(tzp)); |
|
3052 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3053 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3054 |
dmu_tx_abort(tx); |
789 | 3055 |
goto top; |
3056 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3057 |
dmu_tx_abort(tx); |
789 | 3058 |
ZFS_EXIT(zfsvfs); |
3059 |
return (error); |
|
3060 |
} |
|
3061 |
||
3062 |
if (tzp) /* Attempt to remove the existing target */ |
|
5331 | 3063 |
error = zfs_link_destroy(tdl, tzp, tx, zflg, NULL); |
789 | 3064 |
|
3065 |
if (error == 0) { |
|
3066 |
error = zfs_link_create(tdl, szp, tx, ZRENAMING); |
|
3067 |
if (error == 0) { |
|
5331 | 3068 |
szp->z_phys->zp_flags |= ZFS_AV_MODIFIED; |
3069 |
||
789 | 3070 |
error = zfs_link_destroy(sdl, szp, tx, ZRENAMING, NULL); |
3071 |
ASSERT(error == 0); |
|
5331 | 3072 |
|
3073 |
zfs_log_rename(zilog, tx, |
|
3074 |
TX_RENAME | (flags & FIGNORECASE ? TX_CI : 0), |
|
3075 |
sdzp, sdl->dl_name, tdzp, tdl->dl_name, szp); |
|
789 | 3076 |
} |
3077 |
} |
|
3078 |
||
3079 |
dmu_tx_commit(tx); |
|
3080 |
out: |
|
3081 |
if (zl != NULL) |
|
3082 |
zfs_rename_unlock(&zl); |
|
3083 |
||
3084 |
zfs_dirent_unlock(sdl); |
|
3085 |
zfs_dirent_unlock(tdl); |
|
3086 |
||
3087 |
VN_RELE(ZTOV(szp)); |
|
3088 |
if (tzp) |
|
3089 |
VN_RELE(ZTOV(tzp)); |
|
3090 |
||
3091 |
ZFS_EXIT(zfsvfs); |
|
3092 |
return (error); |
|
3093 |
} |
|
3094 |
||
3095 |
/* |
|
3096 |
* Insert the indicated symbolic reference entry into the directory. |
|
3097 |
* |
|
3098 |
* IN: dvp - Directory to contain new symbolic link. |
|
3099 |
* link - Name for new symlink entry. |
|
3100 |
* vap - Attributes of new entry. |
|
3101 |
* target - Target path of new symlink. |
|
3102 |
* cr - credentials of caller. |
|
5331 | 3103 |
* ct - caller context |
3104 |
* flags - case flags |
|
789 | 3105 |
* |
3106 |
* RETURN: 0 if success |
|
3107 |
* error code if failure |
|
3108 |
* |
|
3109 |
* Timestamps: |
|
3110 |
* dvp - ctime|mtime updated |
|
3111 |
*/ |
|
5331 | 3112 |
/*ARGSUSED*/ |
789 | 3113 |
static int |
5331 | 3114 |
zfs_symlink(vnode_t *dvp, char *name, vattr_t *vap, char *link, cred_t *cr, |
3115 |
caller_context_t *ct, int flags) |
|
789 | 3116 |
{ |
3117 |
znode_t *zp, *dzp = VTOZ(dvp); |
|
3118 |
zfs_dirlock_t *dl; |
|
3119 |
dmu_tx_t *tx; |
|
3120 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3121 |
zilog_t *zilog; |
789 | 3122 |
int len = strlen(link); |
3123 |
int error; |
|
5331 | 3124 |
int zflg = ZNEW; |
3125 |
zfs_fuid_info_t *fuidp = NULL; |
|
789 | 3126 |
|
3127 |
ASSERT(vap->va_type == VLNK); |
|
3128 |
||
5367 | 3129 |
ZFS_ENTER(zfsvfs); |
3130 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3131 |
zilog = zfsvfs->z_log; |
5331 | 3132 |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
3133 |
if (zfsvfs->z_utf8 && u8_validate(name, strlen(name), |
5331 | 3134 |
NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
3135 |
ZFS_EXIT(zfsvfs); |
|
3136 |
return (EILSEQ); |
|
3137 |
} |
|
3138 |
if (flags & FIGNORECASE) |
|
3139 |
zflg |= ZCILOOK; |
|
789 | 3140 |
top: |
5331 | 3141 |
if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) { |
789 | 3142 |
ZFS_EXIT(zfsvfs); |
3143 |
return (error); |
|
3144 |
} |
|
3145 |
||
3146 |
if (len > MAXPATHLEN) { |
|
3147 |
ZFS_EXIT(zfsvfs); |
|
3148 |
return (ENAMETOOLONG); |
|
3149 |
} |
|
3150 |
||
3151 |
/* |
|
3152 |
* Attempt to lock directory; fail if entry already exists. |
|
3153 |
*/ |
|
5331 | 3154 |
error = zfs_dirent_lock(&dl, dzp, name, &zp, zflg, NULL, NULL); |
3155 |
if (error) { |
|
789 | 3156 |
ZFS_EXIT(zfsvfs); |
3157 |
return (error); |
|
3158 |
} |
|
3159 |
||
3160 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
3161 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, MAX(1, len)); |
|
3162 |
dmu_tx_hold_bonus(tx, dzp->z_id); |
|
1544 | 3163 |
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name); |
789 | 3164 |
if (dzp->z_phys->zp_flags & ZFS_INHERIT_ACE) |
3165 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, SPA_MAXBLOCKSIZE); |
|
5331 | 3166 |
if (zfsvfs->z_fuid_obj == 0) { |
3167 |
dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); |
|
3168 |
dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, |
|
3169 |
SPA_MAXBLOCKSIZE); |
|
3170 |
dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, FALSE, NULL); |
|
3171 |
} else { |
|
3172 |
dmu_tx_hold_bonus(tx, zfsvfs->z_fuid_obj); |
|
3173 |
dmu_tx_hold_write(tx, zfsvfs->z_fuid_obj, 0, |
|
3174 |
SPA_MAXBLOCKSIZE); |
|
3175 |
} |
|
789 | 3176 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
3177 |
if (error) { |
|
3178 |
zfs_dirent_unlock(dl); |
|
3179 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3180 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3181 |
dmu_tx_abort(tx); |
789 | 3182 |
goto top; |
3183 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3184 |
dmu_tx_abort(tx); |
789 | 3185 |
ZFS_EXIT(zfsvfs); |
3186 |
return (error); |
|
3187 |
} |
|
3188 |
||
3189 |
dmu_buf_will_dirty(dzp->z_dbuf, tx); |
|
3190 |
||
3191 |
/* |
|
3192 |
* Create a new object for the symlink. |
|
3193 |
* Put the link content into bonus buffer if it will fit; |
|
3194 |
* otherwise, store it just like any other file data. |
|
3195 |
*/ |
|
3196 |
if (sizeof (znode_phys_t) + len <= dmu_bonus_max()) { |
|
5446 | 3197 |
zfs_mknode(dzp, vap, tx, cr, 0, &zp, len, NULL, &fuidp); |
789 | 3198 |
if (len != 0) |
3199 |
bcopy(link, zp->z_phys + 1, len); |
|
3200 |
} else { |
|
3201 |
dmu_buf_t *dbp; |
|
1669 | 3202 |
|
5446 | 3203 |
zfs_mknode(dzp, vap, tx, cr, 0, &zp, 0, NULL, &fuidp); |
1669 | 3204 |
/* |
3205 |
* Nothing can access the znode yet so no locking needed |
|
3206 |
* for growing the znode's blocksize. |
|
3207 |
*/ |
|
3208 |
zfs_grow_blocksize(zp, len, tx); |
|
789 | 3209 |
|
5446 | 3210 |
VERIFY(0 == dmu_buf_hold(zfsvfs->z_os, |
3211 |
zp->z_id, 0, FTAG, &dbp)); |
|
789 | 3212 |
dmu_buf_will_dirty(dbp, tx); |
3213 |
||
3214 |
ASSERT3U(len, <=, dbp->db_size); |
|
3215 |
bcopy(link, dbp->db_data, len); |
|
1544 | 3216 |
dmu_buf_rele(dbp, FTAG); |
789 | 3217 |
} |
3218 |
zp->z_phys->zp_size = len; |
|
3219 |
||
3220 |
/* |
|
3221 |
* Insert the new object into the directory. |
|
3222 |
*/ |
|
3223 |
(void) zfs_link_create(dl, zp, tx, ZNEW); |
|
3224 |
out: |
|
5331 | 3225 |
if (error == 0) { |
3226 |
uint64_t txtype = TX_SYMLINK; |
|
3227 |
if (flags & FIGNORECASE) |
|
3228 |
txtype |= TX_CI; |
|
3229 |
zfs_log_symlink(zilog, tx, txtype, dzp, zp, name, link); |
|
3230 |
} |
|
3231 |
if (fuidp) |
|
3232 |
zfs_fuid_info_free(fuidp); |
|
789 | 3233 |
|
3234 |
dmu_tx_commit(tx); |
|
3235 |
||
3236 |
zfs_dirent_unlock(dl); |
|
3237 |
||
3238 |
VN_RELE(ZTOV(zp)); |
|
3239 |
||
3240 |
ZFS_EXIT(zfsvfs); |
|
3241 |
return (error); |
|
3242 |
} |
|
3243 |
||
3244 |
/* |
|
3245 |
* Return, in the buffer contained in the provided uio structure, |
|
3246 |
* the symbolic path referred to by vp. |
|
3247 |
* |
|
3248 |
* IN: vp - vnode of symbolic link. |
|
3249 |
* uoip - structure to contain the link path. |
|
3250 |
* cr - credentials of caller. |
|
5331 | 3251 |
* ct - caller context |
789 | 3252 |
* |
3253 |
* OUT: uio - structure to contain the link path. |
|
3254 |
* |
|
3255 |
* RETURN: 0 if success |
|
3256 |
* error code if failure |
|
3257 |
* |
|
3258 |
* Timestamps: |
|
3259 |
* vp - atime updated |
|
3260 |
*/ |
|
3261 |
/* ARGSUSED */ |
|
3262 |
static int |
|
5331 | 3263 |
zfs_readlink(vnode_t *vp, uio_t *uio, cred_t *cr, caller_context_t *ct) |
789 | 3264 |
{ |
3265 |
znode_t *zp = VTOZ(vp); |
|
3266 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3267 |
size_t bufsz; |
|
3268 |
int error; |
|
3269 |
||
5367 | 3270 |
ZFS_ENTER(zfsvfs); |
3271 |
ZFS_VERIFY_ZP(zp); |
|
789 | 3272 |
|
3273 |
bufsz = (size_t)zp->z_phys->zp_size; |
|
3274 |
if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) { |
|
3275 |
error = uiomove(zp->z_phys + 1, |
|
3276 |
MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio); |
|
3277 |
} else { |
|
1544 | 3278 |
dmu_buf_t *dbp; |
3279 |
error = dmu_buf_hold(zfsvfs->z_os, zp->z_id, 0, FTAG, &dbp); |
|
3280 |
if (error) { |
|
789 | 3281 |
ZFS_EXIT(zfsvfs); |
3282 |
return (error); |
|
3283 |
} |
|
3284 |
error = uiomove(dbp->db_data, |
|
3285 |
MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio); |
|
1544 | 3286 |
dmu_buf_rele(dbp, FTAG); |
789 | 3287 |
} |
3288 |
||
3289 |
ZFS_ACCESSTIME_STAMP(zfsvfs, zp); |
|
3290 |
ZFS_EXIT(zfsvfs); |
|
3291 |
return (error); |
|
3292 |
} |
|
3293 |
||
3294 |
/* |
|
3295 |
* Insert a new entry into directory tdvp referencing svp. |
|
3296 |
* |
|
3297 |
* IN: tdvp - Directory to contain new entry. |
|
3298 |
* svp - vnode of new entry. |
|
3299 |
* name - name of new entry. |
|
3300 |
* cr - credentials of caller. |
|
5331 | 3301 |
* ct - caller context |
789 | 3302 |
* |
3303 |
* RETURN: 0 if success |
|
3304 |
* error code if failure |
|
3305 |
* |
|
3306 |
* Timestamps: |
|
3307 |
* tdvp - ctime|mtime updated |
|
3308 |
* svp - ctime updated |
|
3309 |
*/ |
|
3310 |
/* ARGSUSED */ |
|
3311 |
static int |
|
5331 | 3312 |
zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr, |
3313 |
caller_context_t *ct, int flags) |
|
789 | 3314 |
{ |
3315 |
znode_t *dzp = VTOZ(tdvp); |
|
3316 |
znode_t *tzp, *szp; |
|
3317 |
zfsvfs_t *zfsvfs = dzp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3318 |
zilog_t *zilog; |
789 | 3319 |
zfs_dirlock_t *dl; |
3320 |
dmu_tx_t *tx; |
|
3321 |
vnode_t *realvp; |
|
3322 |
int error; |
|
5331 | 3323 |
int zf = ZNEW; |
3324 |
uid_t owner; |
|
789 | 3325 |
|
3326 |
ASSERT(tdvp->v_type == VDIR); |
|
3327 |
||
5367 | 3328 |
ZFS_ENTER(zfsvfs); |
3329 |
ZFS_VERIFY_ZP(dzp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3330 |
zilog = zfsvfs->z_log; |
789 | 3331 |
|
5331 | 3332 |
if (VOP_REALVP(svp, &realvp, ct) == 0) |
789 | 3333 |
svp = realvp; |
3334 |
||
3335 |
if (svp->v_vfsp != tdvp->v_vfsp) { |
|
3336 |
ZFS_EXIT(zfsvfs); |
|
3337 |
return (EXDEV); |
|
3338 |
} |
|
5367 | 3339 |
szp = VTOZ(svp); |
3340 |
ZFS_VERIFY_ZP(szp); |
|
789 | 3341 |
|
5498
334b476844ca
6622831 normalization properties are not preserved by "zfs send"
timh
parents:
5446
diff
changeset
|
3342 |
if (zfsvfs->z_utf8 && u8_validate(name, |
5331 | 3343 |
strlen(name), NULL, U8_VALIDATE_ENTIRE, &error) < 0) { |
3344 |
ZFS_EXIT(zfsvfs); |
|
3345 |
return (EILSEQ); |
|
3346 |
} |
|
3347 |
if (flags & FIGNORECASE) |
|
3348 |
zf |= ZCILOOK; |
|
3349 |
||
789 | 3350 |
top: |
3351 |
/* |
|
3352 |
* We do not support links between attributes and non-attributes |
|
3353 |
* because of the potential security risk of creating links |
|
3354 |
* into "normal" file space in order to circumvent restrictions |
|
3355 |
* imposed in attribute space. |
|
3356 |
*/ |
|
3357 |
if ((szp->z_phys->zp_flags & ZFS_XATTR) != |
|
3358 |
(dzp->z_phys->zp_flags & ZFS_XATTR)) { |
|
3359 |
ZFS_EXIT(zfsvfs); |
|
3360 |
return (EINVAL); |
|
3361 |
} |
|
3362 |
||
3363 |
/* |
|
3364 |
* POSIX dictates that we return EPERM here. |
|
3365 |
* Better choices include ENOTSUP or EISDIR. |
|
3366 |
*/ |
|
3367 |
if (svp->v_type == VDIR) { |
|
3368 |
ZFS_EXIT(zfsvfs); |
|
3369 |
return (EPERM); |
|
3370 |
} |
|
3371 |
||
5331 | 3372 |
zfs_fuid_map_id(zfsvfs, szp->z_phys->zp_uid, ZFS_OWNER, &owner); |
3373 |
if (owner != crgetuid(cr) && |
|
789 | 3374 |
secpolicy_basic_link(cr) != 0) { |
3375 |
ZFS_EXIT(zfsvfs); |
|
3376 |
return (EPERM); |
|
3377 |
} |
|
3378 |
||
5331 | 3379 |
if (error = zfs_zaccess(dzp, ACE_ADD_FILE, 0, B_FALSE, cr)) { |
789 | 3380 |
ZFS_EXIT(zfsvfs); |
3381 |
return (error); |
|
3382 |
} |
|
3383 |
||
3384 |
/* |
|
3385 |
* Attempt to lock directory; fail if entry already exists. |
|
3386 |
*/ |
|
5331 | 3387 |
error = zfs_dirent_lock(&dl, dzp, name, &tzp, zf, NULL, NULL); |
3388 |
if (error) { |
|
789 | 3389 |
ZFS_EXIT(zfsvfs); |
3390 |
return (error); |
|
3391 |
} |
|
3392 |
||
3393 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
3394 |
dmu_tx_hold_bonus(tx, szp->z_id); |
|
1544 | 3395 |
dmu_tx_hold_zap(tx, dzp->z_id, TRUE, name); |
789 | 3396 |
error = dmu_tx_assign(tx, zfsvfs->z_assign); |
3397 |
if (error) { |
|
3398 |
zfs_dirent_unlock(dl); |
|
3399 |
if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3400 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3401 |
dmu_tx_abort(tx); |
789 | 3402 |
goto top; |
3403 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3404 |
dmu_tx_abort(tx); |
789 | 3405 |
ZFS_EXIT(zfsvfs); |
3406 |
return (error); |
|
3407 |
} |
|
3408 |
||
3409 |
error = zfs_link_create(dl, szp, tx, 0); |
|
3410 |
||
5331 | 3411 |
if (error == 0) { |
3412 |
uint64_t txtype = TX_LINK; |
|
3413 |
if (flags & FIGNORECASE) |
|
3414 |
txtype |= TX_CI; |
|
3415 |
zfs_log_link(zilog, tx, txtype, dzp, szp, name); |
|
3416 |
} |
|
789 | 3417 |
|
3418 |
dmu_tx_commit(tx); |
|
3419 |
||
3420 |
zfs_dirent_unlock(dl); |
|
3421 |
||
4863 | 3422 |
if (error == 0) { |
5331 | 3423 |
vnevent_link(svp, ct); |
4863 | 3424 |
} |
3425 |
||
789 | 3426 |
ZFS_EXIT(zfsvfs); |
3427 |
return (error); |
|
3428 |
} |
|
3429 |
||
3430 |
/* |
|
3431 |
* zfs_null_putapage() is used when the file system has been force |
|
3432 |
* unmounted. It just drops the pages. |
|
3433 |
*/ |
|
3434 |
/* ARGSUSED */ |
|
3435 |
static int |
|
3436 |
zfs_null_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp, |
|
3437 |
size_t *lenp, int flags, cred_t *cr) |
|
3438 |
{ |
|
3439 |
pvn_write_done(pp, B_INVAL|B_FORCE|B_ERROR); |
|
3440 |
return (0); |
|
3441 |
} |
|
3442 |
||
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3443 |
/* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3444 |
* 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
|
3445 |
* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3446 |
* 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
|
3447 |
* pp - page to push. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3448 |
* flags - additional flags. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3449 |
* cr - credentials of caller. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3450 |
* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3451 |
* OUT: offp - start of range pushed. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3452 |
* lenp - len of range pushed. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3453 |
* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3454 |
* RETURN: 0 if success |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3455 |
* error code if failure |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3456 |
* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3457 |
* 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
|
3458 |
* 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
|
3459 |
* unlocked. |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3460 |
*/ |
789 | 3461 |
/* ARGSUSED */ |
3462 |
static int |
|
3463 |
zfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp, |
|
3464 |
size_t *lenp, int flags, cred_t *cr) |
|
3465 |
{ |
|
3466 |
znode_t *zp = VTOZ(vp); |
|
3467 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3468 |
zilog_t *zilog = zfsvfs->z_log; |
|
3469 |
dmu_tx_t *tx; |
|
1669 | 3470 |
rl_t *rl; |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3471 |
u_offset_t off, koff; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3472 |
size_t len, klen; |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3473 |
uint64_t filesz; |
789 | 3474 |
int err; |
3475 |
||
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3476 |
filesz = zp->z_phys->zp_size; |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3477 |
off = pp->p_offset; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3478 |
len = PAGESIZE; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3479 |
/* |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3480 |
* If our blocksize is bigger than the page size, try to kluster |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3481 |
* muiltiple pages so that we write a full block (thus avoiding |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3482 |
* a read-modify-write). |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3483 |
*/ |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3484 |
if (off < filesz && zp->z_blksz > PAGESIZE) { |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3485 |
if (!ISP2(zp->z_blksz)) { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3486 |
/* Only one block in the file. */ |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3487 |
klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3488 |
koff = 0; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3489 |
} else { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3490 |
klen = zp->z_blksz; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3491 |
koff = P2ALIGN(off, (u_offset_t)klen); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3492 |
} |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3493 |
ASSERT(koff <= filesz); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3494 |
if (koff + klen > filesz) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3495 |
klen = P2ROUNDUP(filesz - koff, (uint64_t)PAGESIZE); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3496 |
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
|
3497 |
} |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3498 |
ASSERT3U(btop(len), ==, btopr(len)); |
789 | 3499 |
top: |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3500 |
rl = zfs_range_lock(zp, off, len, RL_WRITER); |
1819 | 3501 |
/* |
3502 |
* Can't push pages past end-of-file. |
|
3503 |
*/ |
|
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3504 |
filesz = zp->z_phys->zp_size; |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3505 |
if (off >= filesz) { |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3506 |
/* ignore all pages */ |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3507 |
err = 0; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3508 |
goto out; |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3509 |
} else if (off + len > filesz) { |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3510 |
int npages = btopr(filesz - off); |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3511 |
page_t *trunc; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3512 |
|
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3513 |
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
|
3514 |
/* 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
|
3515 |
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
|
3516 |
pvn_write_done(trunc, flags); |
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3517 |
len = filesz - off; |
1819 | 3518 |
} |
789 | 3519 |
|
3520 |
tx = dmu_tx_create(zfsvfs->z_os); |
|
3521 |
dmu_tx_hold_write(tx, zp->z_id, off, len); |
|
3522 |
dmu_tx_hold_bonus(tx, zp->z_id); |
|
3523 |
err = dmu_tx_assign(tx, zfsvfs->z_assign); |
|
3524 |
if (err != 0) { |
|
3525 |
if (err == ERESTART && zfsvfs->z_assign == TXG_NOWAIT) { |
|
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3526 |
zfs_range_unlock(rl); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3527 |
dmu_tx_wait(tx); |
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3528 |
dmu_tx_abort(tx); |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3529 |
err = 0; |
789 | 3530 |
goto top; |
3531 |
} |
|
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
3532 |
dmu_tx_abort(tx); |
789 | 3533 |
goto out; |
3534 |
} |
|
3535 |
||
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3536 |
if (zp->z_blksz <= PAGESIZE) { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3537 |
caddr_t va = ppmapin(pp, PROT_READ, (caddr_t)-1); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3538 |
ASSERT3U(len, <=, PAGESIZE); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3539 |
dmu_write(zfsvfs->z_os, zp->z_id, off, len, va, tx); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3540 |
ppmapout(va); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3541 |
} else { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3542 |
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
|
3543 |
} |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3544 |
|
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3545 |
if (err == 0) { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3546 |
zfs_time_stamper(zp, CONTENT_MODIFIED, tx); |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3461
diff
changeset
|
3547 |
zfs_log_write(zilog, 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
|
3548 |
dmu_tx_commit(tx); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3549 |
} |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3550 |
|
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3551 |
out: |
2237 | 3552 |
zfs_range_unlock(rl); |
4709
dc10a713d1a0
6453407 rm a file when the root file system is at its quota limit reports ENOSPC
maybee
parents:
4543
diff
changeset
|
3553 |
pvn_write_done(pp, (err ? B_ERROR : 0) | flags); |
789 | 3554 |
if (offp) |
3555 |
*offp = off; |
|
3556 |
if (lenp) |
|
3557 |
*lenp = len; |
|
3558 |
||
3559 |
return (err); |
|
3560 |
} |
|
3561 |
||
3562 |
/* |
|
3563 |
* Copy the portion of the file indicated from pages into the file. |
|
3564 |
* The pages are stored in a page list attached to the files vnode. |
|
3565 |
* |
|
3566 |
* IN: vp - vnode of file to push page data to. |
|
3567 |
* off - position in file to put data. |
|
3568 |
* len - amount of data to write. |
|
3569 |
* flags - flags to control the operation. |
|
3570 |
* cr - credentials of caller. |
|
5331 | 3571 |
* ct - caller context. |
789 | 3572 |
* |
3573 |
* RETURN: 0 if success |
|
3574 |
* error code if failure |
|
3575 |
* |
|
3576 |
* Timestamps: |
|
3577 |
* vp - ctime|mtime updated |
|
3578 |
*/ |
|
5331 | 3579 |
/*ARGSUSED*/ |
789 | 3580 |
static int |
5331 | 3581 |
zfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr, |
3582 |
caller_context_t *ct) |
|
789 | 3583 |
{ |
3584 |
znode_t *zp = VTOZ(vp); |
|
3585 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3586 |
page_t *pp; |
|
3587 |
size_t io_len; |
|
3588 |
u_offset_t io_off; |
|
1669 | 3589 |
uint64_t filesz; |
789 | 3590 |
int error = 0; |
3591 |
||
5367 | 3592 |
ZFS_ENTER(zfsvfs); |
3593 |
ZFS_VERIFY_ZP(zp); |
|
789 | 3594 |
|
3595 |
if (len == 0) { |
|
3596 |
/* |
|
3597 |
* Search the entire vp list for pages >= off. |
|
3598 |
*/ |
|
3599 |
error = pvn_vplist_dirty(vp, (u_offset_t)off, zfs_putapage, |
|
3600 |
flags, cr); |
|
1472 | 3601 |
goto out; |
789 | 3602 |
} |
3603 |
||
1669 | 3604 |
filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */ |
3605 |
if (off > filesz) { |
|
789 | 3606 |
/* past end of file */ |
3607 |
ZFS_EXIT(zfsvfs); |
|
3608 |
return (0); |
|
3609 |
} |
|
3610 |
||
1669 | 3611 |
len = MIN(len, filesz - off); |
789 | 3612 |
|
1472 | 3613 |
for (io_off = off; io_off < off + len; io_off += io_len) { |
789 | 3614 |
if ((flags & B_INVAL) || ((flags & B_ASYNC) == 0)) { |
1669 | 3615 |
pp = page_lookup(vp, io_off, |
4339 | 3616 |
(flags & (B_INVAL | B_FREE)) ? SE_EXCL : SE_SHARED); |
789 | 3617 |
} else { |
3618 |
pp = page_lookup_nowait(vp, io_off, |
|
4339 | 3619 |
(flags & B_FREE) ? SE_EXCL : SE_SHARED); |
789 | 3620 |
} |
3621 |
||
3622 |
if (pp != NULL && pvn_getdirty(pp, flags)) { |
|
3623 |
int err; |
|
3624 |
||
3625 |
/* |
|
3626 |
* Found a dirty page to push |
|
3627 |
*/ |
|
1669 | 3628 |
err = zfs_putapage(vp, pp, &io_off, &io_len, flags, cr); |
3629 |
if (err) |
|
789 | 3630 |
error = err; |
3631 |
} else { |
|
3632 |
io_len = PAGESIZE; |
|
3633 |
} |
|
3634 |
} |
|
1472 | 3635 |
out: |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
3636 |
if ((flags & B_ASYNC) == 0) |
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2597
diff
changeset
|
3637 |
zil_commit(zfsvfs->z_log, UINT64_MAX, zp->z_id); |
789 | 3638 |
ZFS_EXIT(zfsvfs); |
3639 |
return (error); |
|
3640 |
} |
|
3641 |
||
5331 | 3642 |
/*ARGSUSED*/ |
789 | 3643 |
void |
5331 | 3644 |
zfs_inactive(vnode_t *vp, cred_t *cr, caller_context_t *ct) |
789 | 3645 |
{ |
3646 |
znode_t *zp = VTOZ(vp); |
|
3647 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3648 |
int error; |
|
3649 |
||
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3650 |
rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER); |
5446 | 3651 |
if (zp->z_dbuf == NULL) { |
3652 |
/* |
|
3653 |
* This fs has been unmounted, or we did |
|
3654 |
* zfs_suspend/resume and it no longer exists. |
|
3655 |
*/ |
|
789 | 3656 |
if (vn_has_cached_data(vp)) { |
3657 |
(void) pvn_vplist_dirty(vp, 0, zfs_null_putapage, |
|
3658 |
B_INVAL, cr); |
|
3659 |
} |
|
3660 |
||
1544 | 3661 |
mutex_enter(&zp->z_lock); |
789 | 3662 |
vp->v_count = 0; /* count arrives as 1 */ |
5446 | 3663 |
mutex_exit(&zp->z_lock); |
3664 |
zfs_znode_free(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3665 |
rw_exit(&zfsvfs->z_teardown_inactive_lock); |
789 | 3666 |
VFS_RELE(zfsvfs->z_vfs); |
3667 |
return; |
|
3668 |
} |
|
3669 |
||
3670 |
/* |
|
3671 |
* Attempt to push any data in the page cache. If this fails |
|
3672 |
* we will get kicked out later in zfs_zinactive(). |
|
3673 |
*/ |
|
1298 | 3674 |
if (vn_has_cached_data(vp)) { |
3675 |
(void) pvn_vplist_dirty(vp, 0, zfs_putapage, B_INVAL|B_ASYNC, |
|
3676 |
cr); |
|
3677 |
} |
|
789 | 3678 |
|
3461 | 3679 |
if (zp->z_atime_dirty && zp->z_unlinked == 0) { |
789 | 3680 |
dmu_tx_t *tx = dmu_tx_create(zfsvfs->z_os); |
3681 |
||
3682 |
dmu_tx_hold_bonus(tx, zp->z_id); |
|
3683 |
error = dmu_tx_assign(tx, TXG_WAIT); |
|
3684 |
if (error) { |
|
3685 |
dmu_tx_abort(tx); |
|
3686 |
} else { |
|
3687 |
dmu_buf_will_dirty(zp->z_dbuf, tx); |
|
3688 |
mutex_enter(&zp->z_lock); |
|
3689 |
zp->z_atime_dirty = 0; |
|
3690 |
mutex_exit(&zp->z_lock); |
|
3691 |
dmu_tx_commit(tx); |
|
3692 |
} |
|
3693 |
} |
|
3694 |
||
3695 |
zfs_zinactive(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
3696 |
rw_exit(&zfsvfs->z_teardown_inactive_lock); |
789 | 3697 |
} |
3698 |
||
3699 |
/* |
|
3700 |
* Bounds-check the seek operation. |
|
3701 |
* |
|
3702 |
* IN: vp - vnode seeking within |
|
3703 |
* ooff - old file offset |
|
3704 |
* noffp - pointer to new file offset |
|
5331 | 3705 |
* ct - caller context |
789 | 3706 |
* |
3707 |
* RETURN: 0 if success |
|
3708 |
* EINVAL if new offset invalid |
|
3709 |
*/ |
|
3710 |
/* ARGSUSED */ |
|
3711 |
static int |
|
5331 | 3712 |
zfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp, |
3713 |
caller_context_t *ct) |
|
789 | 3714 |
{ |
3715 |
if (vp->v_type == VDIR) |
|
3716 |
return (0); |
|
3717 |
return ((*noffp < 0 || *noffp > MAXOFFSET_T) ? EINVAL : 0); |
|
3718 |
} |
|
3719 |
||
3720 |
/* |
|
3721 |
* Pre-filter the generic locking function to trap attempts to place |
|
3722 |
* a mandatory lock on a memory mapped file. |
|
3723 |
*/ |
|
3724 |
static int |
|
3725 |
zfs_frlock(vnode_t *vp, int cmd, flock64_t *bfp, int flag, offset_t offset, |
|
5331 | 3726 |
flk_callback_t *flk_cbp, cred_t *cr, caller_context_t *ct) |
789 | 3727 |
{ |
3728 |
znode_t *zp = VTOZ(vp); |
|
3729 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3730 |
int error; |
|
3731 |
||
5367 | 3732 |
ZFS_ENTER(zfsvfs); |
3733 |
ZFS_VERIFY_ZP(zp); |
|
789 | 3734 |
|
3735 |
/* |
|
1544 | 3736 |
* We are following the UFS semantics with respect to mapcnt |
3737 |
* here: If we see that the file is mapped already, then we will |
|
3738 |
* return an error, but we don't worry about races between this |
|
3739 |
* function and zfs_map(). |
|
789 | 3740 |
*/ |
1544 | 3741 |
if (zp->z_mapcnt > 0 && MANDMODE((mode_t)zp->z_phys->zp_mode)) { |
789 | 3742 |
ZFS_EXIT(zfsvfs); |
3743 |
return (EAGAIN); |
|
3744 |
} |
|
5331 | 3745 |
error = fs_frlock(vp, cmd, bfp, flag, offset, flk_cbp, cr, ct); |
789 | 3746 |
ZFS_EXIT(zfsvfs); |
3747 |
return (error); |
|
3748 |
} |
|
3749 |
||
3750 |
/* |
|
3751 |
* If we can't find a page in the cache, we will create a new page |
|
3752 |
* and fill it with file data. For efficiency, we may try to fill |
|
1669 | 3753 |
* multiple pages at once (klustering). |
789 | 3754 |
*/ |
3755 |
static int |
|
3756 |
zfs_fillpage(vnode_t *vp, u_offset_t off, struct seg *seg, |
|
3757 |
caddr_t addr, page_t *pl[], size_t plsz, enum seg_rw rw) |
|
3758 |
{ |
|
3759 |
znode_t *zp = VTOZ(vp); |
|
3760 |
page_t *pp, *cur_pp; |
|
3761 |
objset_t *os = zp->z_zfsvfs->z_os; |
|
3762 |
caddr_t va; |
|
3763 |
u_offset_t io_off, total; |
|
3764 |
uint64_t oid = zp->z_id; |
|
3765 |
size_t io_len; |
|
1669 | 3766 |
uint64_t filesz; |
789 | 3767 |
int err; |
3768 |
||
3769 |
/* |
|
3770 |
* If we are only asking for a single page don't bother klustering. |
|
3771 |
*/ |
|
1669 | 3772 |
filesz = zp->z_phys->zp_size; /* get consistent copy of zp_size */ |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3773 |
if (off >= filesz) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3774 |
return (EFAULT); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3775 |
if (plsz == PAGESIZE || zp->z_blksz <= PAGESIZE) { |
789 | 3776 |
io_off = off; |
3777 |
io_len = PAGESIZE; |
|
3778 |
pp = page_create_va(vp, io_off, io_len, PG_WAIT, seg, addr); |
|
3779 |
} else { |
|
3780 |
/* |
|
3781 |
* Try to fill a kluster of pages (a blocks worth). |
|
3782 |
*/ |
|
3783 |
size_t klen; |
|
3784 |
u_offset_t koff; |
|
3785 |
||
3786 |
if (!ISP2(zp->z_blksz)) { |
|
3787 |
/* Only one block in the file. */ |
|
3788 |
klen = P2ROUNDUP((ulong_t)zp->z_blksz, PAGESIZE); |
|
3789 |
koff = 0; |
|
3790 |
} else { |
|
3131
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3791 |
/* |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3792 |
* It would be ideal to align our offset to the |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3793 |
* blocksize but doing so has resulted in some |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3794 |
* strange application crashes. For now, we |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3795 |
* leave the offset as is and only adjust the |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3796 |
* length if we are off the end of the file. |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3797 |
*/ |
ef325e37ab22
6471359 zfs_fillpage() when faulting aligns on the range size within the file, getting the wrong large page
gw25295
parents:
3063
diff
changeset
|
3798 |
koff = off; |
789 | 3799 |
klen = plsz; |
3800 |
} |
|
1819 | 3801 |
ASSERT(koff <= filesz); |
3802 |
if (koff + klen > filesz) |
|
3803 |
klen = P2ROUNDUP(filesz, (uint64_t)PAGESIZE) - koff; |
|
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3804 |
ASSERT3U(off, >=, koff); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3805 |
ASSERT3U(off, <, koff + klen); |
789 | 3806 |
pp = pvn_read_kluster(vp, off, seg, addr, &io_off, |
4339 | 3807 |
&io_len, koff, klen, 0); |
789 | 3808 |
} |
3809 |
if (pp == NULL) { |
|
3810 |
/* |
|
3811 |
* Some other thread entered the page before us. |
|
3812 |
* Return to zfs_getpage to retry the lookup. |
|
3813 |
*/ |
|
3814 |
*pl = NULL; |
|
3815 |
return (0); |
|
3816 |
} |
|
3817 |
||
3818 |
/* |
|
3819 |
* Fill the pages in the kluster. |
|
3820 |
*/ |
|
3821 |
cur_pp = pp; |
|
3822 |
for (total = io_off + io_len; io_off < total; io_off += PAGESIZE) { |
|
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2638
diff
changeset
|
3823 |
ASSERT3U(io_off, ==, cur_pp->p_offset); |
789 | 3824 |
va = ppmapin(cur_pp, PROT_READ | PROT_WRITE, (caddr_t)-1); |
1544 | 3825 |
err = dmu_read(os, oid, io_off, PAGESIZE, va); |
789 | 3826 |
ppmapout(va); |
3827 |
if (err) { |
|
3828 |
/* On error, toss the entire kluster */ |
|
3829 |
pvn_read_done(pp, B_ERROR); |
|
3830 |
return (err); |
|
3831 |
} |
|
3832 |
cur_pp = cur_pp->p_next; |
|
3833 |
} |
|
3834 |
out: |
|
3835 |
/* |
|
3836 |
* Fill in the page list array from the kluster. If |
|
3837 |
* there are too many pages in the kluster, return |
|
3838 |
* as many pages as possible starting from the desired |
|
3839 |
* offset `off'. |
|
3840 |
* NOTE: the page list will always be null terminated. |
|
3841 |
*/ |
|
3842 |
pvn_plist_init(pp, pl, plsz, off, io_len, rw); |
|
3843 |
||
3844 |
return (0); |
|
3845 |
} |
|
3846 |
||
3847 |
/* |
|
3848 |
* Return pointers to the pages for the file region [off, off + len] |
|
3849 |
* in the pl array. If plsz is greater than len, this function may |
|
3850 |
* also return page pointers from before or after the specified |
|
3851 |
* region (i.e. some region [off', off' + plsz]). These additional |
|
3852 |
* pages are only returned if they are already in the cache, or were |
|
3853 |
* created as part of a klustered read. |
|
3854 |
* |
|
3855 |
* IN: vp - vnode of file to get data from. |
|
3856 |
* off - position in file to get data from. |
|
3857 |
* len - amount of data to retrieve. |
|
3858 |
* plsz - length of provided page list. |
|
3859 |
* seg - segment to obtain pages for. |
|
3860 |
* addr - virtual address of fault. |
|
3861 |
* rw - mode of created pages. |
|
3862 |
* cr - credentials of caller. |
|
5331 | 3863 |
* ct - caller context. |
789 | 3864 |
* |
3865 |
* OUT: protp - protection mode of created pages. |
|
3866 |
* pl - list of pages created. |
|
3867 |
* |
|
3868 |
* RETURN: 0 if success |
|
3869 |
* error code if failure |
|
3870 |
* |
|
3871 |
* Timestamps: |
|
3872 |
* vp - atime updated |
|
3873 |
*/ |
|
3874 |
/* ARGSUSED */ |
|
3875 |
static int |
|
3876 |
zfs_getpage(vnode_t *vp, offset_t off, size_t len, uint_t *protp, |
|
3877 |
page_t *pl[], size_t plsz, struct seg *seg, caddr_t addr, |
|
5331 | 3878 |
enum seg_rw rw, cred_t *cr, caller_context_t *ct) |
789 | 3879 |
{ |
3880 |
znode_t *zp = VTOZ(vp); |
|
3881 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
3882 |
page_t *pp, **pl0 = pl; |
|
2752
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3883 |
int need_unlock = 0, err = 0; |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3884 |
offset_t orig_off; |
789 | 3885 |
|
5367 | 3886 |
ZFS_ENTER(zfsvfs); |
3887 |
ZFS_VERIFY_ZP(zp); |
|
789 | 3888 |
|
3889 |
if (protp) |
|
3890 |
*protp = PROT_ALL; |
|
3891 |
||
3892 |
/* no faultahead (for now) */ |
|
3893 |
if (pl == NULL) { |
|
3894 |
ZFS_EXIT(zfsvfs); |
|
3895 |
return (0); |
|
3896 |
} |
|
3897 |
||
3898 |
/* can't fault past EOF */ |
|
3899 |
if (off >= zp->z_phys->zp_size) { |
|
3900 |
ZFS_EXIT(zfsvfs); |
|
3901 |
return (EFAULT); |
|
3902 |
} |
|
2752
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3903 |
orig_off = off; |
789 | 3904 |
|
3905 |
/* |
|
3906 |
* If we already own the lock, then we must be page faulting |
|
3907 |
* in the middle of a write to this file (i.e., we are writing |
|
3908 |
* to this file using data from a mapped region of the file). |
|
3909 |
*/ |
|
2752
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3910 |
if (rw_owner(&zp->z_map_lock) != curthread) { |
789 | 3911 |
rw_enter(&zp->z_map_lock, RW_WRITER); |
3912 |
need_unlock = TRUE; |
|
3913 |
} |
|
3914 |
||
3915 |
/* |
|
3916 |
* Loop through the requested range [off, off + len] looking |
|
3917 |
* for pages. If we don't find a page, we will need to create |
|
3918 |
* a new page and fill it with data from the file. |
|
3919 |
*/ |
|
3920 |
while (len > 0) { |
|
3921 |
if (plsz < PAGESIZE) |
|
3922 |
break; |
|
3923 |
if (pp = page_lookup(vp, off, SE_SHARED)) { |
|
3924 |
*pl++ = pp; |
|
3925 |
off += PAGESIZE; |
|
3926 |
addr += PAGESIZE; |
|
3927 |
len -= PAGESIZE; |
|
3928 |
plsz -= PAGESIZE; |
|
3929 |
} else { |
|
3930 |
err = zfs_fillpage(vp, off, seg, addr, pl, plsz, rw); |
|
2752
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3931 |
if (err) |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3932 |
goto out; |
789 | 3933 |
/* |
3934 |
* klustering may have changed our region |
|
3935 |
* to be block aligned. |
|
3936 |
*/ |
|
3937 |
if (((pp = *pl) != 0) && (off != pp->p_offset)) { |
|
3938 |
int delta = off - pp->p_offset; |
|
3939 |
len += delta; |
|
3940 |
off -= delta; |
|
3941 |
addr -= delta; |
|
3942 |
} |
|
3943 |
while (*pl) { |
|
3944 |
pl++; |
|
3945 |
off += PAGESIZE; |
|
3946 |
addr += PAGESIZE; |
|
3947 |
plsz -= PAGESIZE; |
|
3948 |
if (len > PAGESIZE) |
|
3949 |
len -= PAGESIZE; |
|
3950 |
else |
|
3951 |
len = 0; |
|
3952 |
} |
|
3953 |
} |
|
3954 |
} |
|
3955 |
||
3956 |
/* |
|
3957 |
* Fill out the page array with any pages already in the cache. |
|
3958 |
*/ |
|
3959 |
while (plsz > 0) { |
|
3960 |
pp = page_lookup_nowait(vp, off, SE_SHARED); |
|
3961 |
if (pp == NULL) |
|
3962 |
break; |
|
3963 |
*pl++ = pp; |
|
3964 |
off += PAGESIZE; |
|
3965 |
plsz -= PAGESIZE; |
|
3966 |
} |
|
3967 |
||
3968 |
ZFS_ACCESSTIME_STAMP(zfsvfs, zp); |
|
3969 |
out: |
|
2752
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3970 |
/* |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3971 |
* We can't grab the range lock for the page as reader which would |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3972 |
* stop truncation as this leads to deadlock. So we need to recheck |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3973 |
* the file size. |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3974 |
*/ |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3975 |
if (orig_off >= zp->z_phys->zp_size) |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3976 |
err = EFAULT; |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3977 |
if (err) { |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3978 |
/* |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3979 |
* 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
|
3980 |
*/ |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3981 |
while (pl > pl0) |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3982 |
page_unlock(*--pl); |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3983 |
} |
2b25a96fc433
6438702 error handling in zfs_getpage() can trigger "page not locked" panic
perrin
parents:
2688
diff
changeset
|
3984 |
|
789 | 3985 |
*pl = NULL; |
3986 |
||
3987 |
if (need_unlock) |
|
3988 |
rw_exit(&zp->z_map_lock); |
|
3989 |
||
3990 |
ZFS_EXIT(zfsvfs); |
|
3991 |
return (err); |
|
3992 |
} |
|
3993 |
||
1544 | 3994 |
/* |
3995 |
* Request a memory map for a section of a file. This code interacts |
|
3996 |
* with common code and the VM system as follows: |
|
3997 |
* |
|
3998 |
* common code calls mmap(), which ends up in smmap_common() |
|
3999 |
* |
|
4000 |
* this calls VOP_MAP(), which takes you into (say) zfs |
|
4001 |
* |
|
4002 |
* zfs_map() calls as_map(), passing segvn_create() as the callback |
|
4003 |
* |
|
4004 |
* segvn_create() creates the new segment and calls VOP_ADDMAP() |
|
4005 |
* |
|
4006 |
* zfs_addmap() updates z_mapcnt |
|
4007 |
*/ |
|
5331 | 4008 |
/*ARGSUSED*/ |
789 | 4009 |
static int |
4010 |
zfs_map(vnode_t *vp, offset_t off, struct as *as, caddr_t *addrp, |
|
5331 | 4011 |
size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr, |
4012 |
caller_context_t *ct) |
|
789 | 4013 |
{ |
4014 |
znode_t *zp = VTOZ(vp); |
|
4015 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
4016 |
segvn_crargs_t vn_a; |
|
4017 |
int error; |
|
4018 |
||
5331 | 4019 |
if ((prot & PROT_WRITE) && |
4020 |
(zp->z_phys->zp_flags & (ZFS_IMMUTABLE | ZFS_READONLY | |
|
4021 |
ZFS_APPENDONLY))) |
|
4022 |
return (EPERM); |
|
4023 |
||
5367 | 4024 |
ZFS_ENTER(zfsvfs); |
4025 |
ZFS_VERIFY_ZP(zp); |
|
789 | 4026 |
|
4027 |
if (vp->v_flag & VNOMAP) { |
|
4028 |
ZFS_EXIT(zfsvfs); |
|
4029 |
return (ENOSYS); |
|
4030 |
} |
|
4031 |
||
4032 |
if (off < 0 || len > MAXOFFSET_T - off) { |
|
4033 |
ZFS_EXIT(zfsvfs); |
|
4034 |
return (ENXIO); |
|
4035 |
} |
|
4036 |
||
4037 |
if (vp->v_type != VREG) { |
|
4038 |
ZFS_EXIT(zfsvfs); |
|
4039 |
return (ENODEV); |
|
4040 |
} |
|
4041 |
||
4042 |
/* |
|
4043 |
* If file is locked, disallow mapping. |
|
4044 |
*/ |
|
1544 | 4045 |
if (MANDMODE((mode_t)zp->z_phys->zp_mode) && vn_has_flocks(vp)) { |
4046 |
ZFS_EXIT(zfsvfs); |
|
4047 |
return (EAGAIN); |
|
789 | 4048 |
} |
4049 |
||
4050 |
as_rangelock(as); |
|
4051 |
if ((flags & MAP_FIXED) == 0) { |
|
4052 |
map_addr(addrp, len, off, 1, flags); |
|
4053 |
if (*addrp == NULL) { |
|
4054 |
as_rangeunlock(as); |
|
4055 |
ZFS_EXIT(zfsvfs); |
|
4056 |
return (ENOMEM); |
|
4057 |
} |
|
4058 |
} else { |
|
4059 |
/* |
|
4060 |
* User specified address - blow away any previous mappings |
|
4061 |
*/ |
|
4062 |
(void) as_unmap(as, *addrp, len); |
|
4063 |
} |
|
4064 |
||
4065 |
vn_a.vp = vp; |
|
4066 |
vn_a.offset = (u_offset_t)off; |
|
4067 |
vn_a.type = flags & MAP_TYPE; |
|
4068 |
vn_a.prot = prot; |
|
4069 |
vn_a.maxprot = maxprot; |
|
4070 |
vn_a.cred = cr; |
|
4071 |
vn_a.amp = NULL; |
|
4072 |
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
|
4073 |
vn_a.szc = 0; |
fa316336e215
6377034 setting physmem in /etc/system does not have desired effect on x86
kchow
parents:
1394
diff
changeset
|
4074 |
vn_a.lgrp_mem_policy_flags = 0; |
789 | 4075 |
|
4076 |
error = as_map(as, *addrp, len, segvn_create, &vn_a); |
|
4077 |
||
4078 |
as_rangeunlock(as); |
|
4079 |
ZFS_EXIT(zfsvfs); |
|
4080 |
return (error); |
|
4081 |
} |
|
4082 |
||
4083 |
/* ARGSUSED */ |
|
4084 |
static int |
|
4085 |
zfs_addmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr, |
|
5331 | 4086 |
size_t len, uchar_t prot, uchar_t maxprot, uint_t flags, cred_t *cr, |
4087 |
caller_context_t *ct) |
|
789 | 4088 |
{ |
1544 | 4089 |
uint64_t pages = btopr(len); |
4090 |
||
4091 |
atomic_add_64(&VTOZ(vp)->z_mapcnt, pages); |
|
789 | 4092 |
return (0); |
4093 |
} |
|
4094 |
||
1773
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4095 |
/* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4096 |
* 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
|
4097 |
* 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
|
4098 |
* 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
|
4099 |
* 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
|
4100 |
* 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
|
4101 |
* 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
|
4102 |
* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4103 |
* open() |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4104 |
* mmap() |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4105 |
* <modify memory> |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4106 |
* munmap() |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4107 |
* close() |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4108 |
* <time lapse> |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4109 |
* putpage() via fsflush |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4110 |
* |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4111 |
* 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
|
4112 |
* 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
|
4113 |
* 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
|
4114 |
* torn down. |
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4115 |
*/ |
789 | 4116 |
/* ARGSUSED */ |
4117 |
static int |
|
4118 |
zfs_delmap(vnode_t *vp, offset_t off, struct as *as, caddr_t addr, |
|
5331 | 4119 |
size_t len, uint_t prot, uint_t maxprot, uint_t flags, cred_t *cr, |
4120 |
caller_context_t *ct) |
|
789 | 4121 |
{ |
1544 | 4122 |
uint64_t pages = btopr(len); |
4123 |
||
4124 |
ASSERT3U(VTOZ(vp)->z_mapcnt, >=, pages); |
|
4125 |
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
|
4126 |
|
d6e4f2855c14
6407791 bringover into ZFS results in s. files newer than extracted source
eschrock
parents:
1757
diff
changeset
|
4127 |
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
|
4128 |
vn_has_cached_data(vp)) |
5331 | 4129 |
(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
|
4130 |
|
789 | 4131 |
return (0); |
4132 |
} |
|
4133 |
||
4134 |
/* |
|
4135 |
* Free or allocate space in a file. Currently, this function only |
|
4136 |
* supports the `F_FREESP' command. However, this command is somewhat |
|
4137 |
* misnamed, as its functionality includes the ability to allocate as |
|
4138 |
* well as free space. |
|
4139 |
* |
|
4140 |
* IN: vp - vnode of file to free data in. |
|
4141 |
* cmd - action to take (only F_FREESP supported). |
|
4142 |
* bfp - section of file to free/alloc. |
|
4143 |
* flag - current file open mode flags. |
|
4144 |
* offset - current file offset. |
|
4145 |
* cr - credentials of caller [UNUSED]. |
|
5331 | 4146 |
* ct - caller context. |
789 | 4147 |
* |
4148 |
* RETURN: 0 if success |
|
4149 |
* error code if failure |
|
4150 |
* |
|
4151 |
* Timestamps: |
|
4152 |
* vp - ctime|mtime updated |
|
4153 |
*/ |
|
4154 |
/* ARGSUSED */ |
|
4155 |
static int |
|
4156 |
zfs_space(vnode_t *vp, int cmd, flock64_t *bfp, int flag, |
|
4157 |
offset_t offset, cred_t *cr, caller_context_t *ct) |
|
4158 |
{ |
|
4159 |
znode_t *zp = VTOZ(vp); |
|
4160 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
4161 |
uint64_t off, len; |
|
4162 |
int error; |
|
4163 |
||
5367 | 4164 |
ZFS_ENTER(zfsvfs); |
4165 |
ZFS_VERIFY_ZP(zp); |
|
789 | 4166 |
|
4167 |
top: |
|
4168 |
if (cmd != F_FREESP) { |
|
4169 |
ZFS_EXIT(zfsvfs); |
|
4170 |
return (EINVAL); |
|
4171 |
} |
|
4172 |
||
4173 |
if (error = convoff(vp, bfp, 0, offset)) { |
|
4174 |
ZFS_EXIT(zfsvfs); |
|
4175 |
return (error); |
|
4176 |
} |
|
4177 |
||
4178 |
if (bfp->l_len < 0) { |
|
4179 |
ZFS_EXIT(zfsvfs); |
|
4180 |
return (EINVAL); |
|
4181 |
} |
|
4182 |
||
4183 |
off = bfp->l_start; |
|
1669 | 4184 |
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
|
4185 |
|
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
4186 |
do { |
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
4187 |
error = zfs_freesp(zp, off, len, flag, TRUE); |
2113
0510bb40c993
6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents:
1941
diff
changeset
|
4188 |
/* NB: we already did dmu_tx_wait() if necessary */ |
1878
c22df0f5603f
6413573 deadlock between fsflush() and zfs_create()
maybee
parents:
1819
diff
changeset
|
4189 |
} while (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT); |
789 | 4190 |
|
4191 |
ZFS_EXIT(zfsvfs); |
|
4192 |
return (error); |
|
4193 |
} |
|
4194 |
||
5331 | 4195 |
/*ARGSUSED*/ |
789 | 4196 |
static int |
5331 | 4197 |
zfs_fid(vnode_t *vp, fid_t *fidp, caller_context_t *ct) |
789 | 4198 |
{ |
4199 |
znode_t *zp = VTOZ(vp); |
|
4200 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
4201 |
uint32_t gen; |
789 | 4202 |
uint64_t object = zp->z_id; |
4203 |
zfid_short_t *zfid; |
|
4204 |
int size, i; |
|
4205 |
||
5367 | 4206 |
ZFS_ENTER(zfsvfs); |
4207 |
ZFS_VERIFY_ZP(zp); |
|
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
4863
diff
changeset
|
4208 |
gen = (uint32_t)zp->z_gen; |
789 | 4209 |
|
4210 |
size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN; |
|
4211 |
if (fidp->fid_len < size) { |
|
4212 |
fidp->fid_len = size; |
|
1512 | 4213 |
ZFS_EXIT(zfsvfs); |
789 | 4214 |
return (ENOSPC); |
4215 |
} |
|
4216 |
||
4217 |
zfid = (zfid_short_t *)fidp; |
|
4218 |
||
4219 |
zfid->zf_len = size; |
|
4220 |
||
4221 |
for (i = 0; i < sizeof (zfid->zf_object); i++) |
|
4222 |
zfid->zf_object[i] = (uint8_t)(object >> (8 * i)); |
|
4223 |
||
4224 |
/* Must have a non-zero generation number to distinguish from .zfs */ |
|
4225 |
if (gen == 0) |
|
4226 |
gen = 1; |
|
4227 |
for (i = 0; i < sizeof (zfid->zf_gen); i++) |
|
4228 |
zfid->zf_gen[i] = (uint8_t)(gen >> (8 * i)); |
|
4229 |
||
4230 |
if (size == LONG_FID_LEN) { |
|
4231 |
uint64_t objsetid = dmu_objset_id(zfsvfs->z_os); |
|
4232 |
zfid_long_t *zlfid; |
|
4233 |
||
4234 |
zlfid = (zfid_long_t *)fidp; |
|
4235 |
||
4236 |
for (i = 0; i < sizeof (zlfid->zf_setid); i++) |
|
4237 |
zlfid->zf_setid[i] = (uint8_t)(objsetid >> (8 * i)); |
|
4238 |
||
4239 |
/* XXX - this should be the generation number for the objset */ |
|
4240 |
for (i = 0; i < sizeof (zlfid->zf_setgen); i++) |
|
4241 |
zlfid->zf_setgen[i] = 0; |
|
4242 |
} |
|
4243 |
||
4244 |
ZFS_EXIT(zfsvfs); |
|
4245 |
return (0); |
|
4246 |
} |
|
4247 |
||
4248 |
static int |
|
5331 | 4249 |
zfs_pathconf(vnode_t *vp, int cmd, ulong_t *valp, cred_t *cr, |
4250 |
caller_context_t *ct) |
|
789 | 4251 |
{ |
4252 |
znode_t *zp, *xzp; |
|
4253 |
zfsvfs_t *zfsvfs; |
|
4254 |
zfs_dirlock_t *dl; |
|
4255 |
int error; |
|
4256 |
||
4257 |
switch (cmd) { |
|
4258 |
case _PC_LINK_MAX: |
|
4259 |
*valp = ULONG_MAX; |
|
4260 |
return (0); |
|
4261 |
||
4262 |
case _PC_FILESIZEBITS: |
|
4263 |
*valp = 64; |
|
4264 |
return (0); |
|
4265 |
||
4266 |
case _PC_XATTR_EXISTS: |
|
4267 |
zp = VTOZ(vp); |
|
4268 |
zfsvfs = zp->z_zfsvfs; |
|
5367 | 4269 |
ZFS_ENTER(zfsvfs); |
4270 |
ZFS_VERIFY_ZP(zp); |
|
789 | 4271 |
*valp = 0; |
4272 |
error = zfs_dirent_lock(&dl, zp, "", &xzp, |
|
5331 | 4273 |
ZXATTR | ZEXISTS | ZSHARED, NULL, NULL); |
789 | 4274 |
if (error == 0) { |
4275 |
zfs_dirent_unlock(dl); |
|
4276 |
if (!zfs_dirempty(xzp)) |
|
4277 |
*valp = 1; |
|
4278 |
VN_RELE(ZTOV(xzp)); |
|
4279 |
} else if (error == ENOENT) { |
|
4280 |
/* |
|
4281 |
* If there aren't extended attributes, it's the |
|
4282 |
* same as having zero of them. |
|
4283 |
*/ |
|
4284 |
error = 0; |
|
4285 |
} |
|
4286 |
ZFS_EXIT(zfsvfs); |
|
4287 |
return (error); |
|
4288 |
||
5331 | 4289 |
case _PC_SATTR_ENABLED: |
4290 |
case _PC_SATTR_EXISTS: |
|
4291 |
*valp = vfs_has_feature(vp->v_vfsp, VFSFT_XVATTR) && |
|
4292 |
(vp->v_type == VREG || vp->v_type == VDIR); |
|
4293 |
return (0); |
|
4294 |
||
789 | 4295 |
case _PC_ACL_ENABLED: |
4296 |
*valp = _ACL_ACE_ENABLED; |
|
4297 |
return (0); |
|
4298 |
||
4299 |
case _PC_MIN_HOLE_SIZE: |
|
4300 |
*valp = (ulong_t)SPA_MINBLOCKSIZE; |
|
4301 |
return (0); |
|
4302 |
||
4303 |
default: |
|
5331 | 4304 |
return (fs_pathconf(vp, cmd, valp, cr, ct)); |
789 | 4305 |
} |
4306 |
} |
|
4307 |
||
4308 |
/*ARGSUSED*/ |
|
4309 |
static int |
|
5331 | 4310 |
zfs_getsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr, |
4311 |
caller_context_t *ct) |
|
789 | 4312 |
{ |
4313 |
znode_t *zp = VTOZ(vp); |
|
4314 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
4315 |
int error; |
|
5331 | 4316 |
boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; |
789 | 4317 |
|
5367 | 4318 |
ZFS_ENTER(zfsvfs); |
4319 |
ZFS_VERIFY_ZP(zp); |
|
5331 | 4320 |
error = zfs_getacl(zp, vsecp, skipaclchk, cr); |
789 | 4321 |
ZFS_EXIT(zfsvfs); |
4322 |
||
4323 |
return (error); |
|
4324 |
} |
|
4325 |
||
4326 |
/*ARGSUSED*/ |
|
4327 |
static int |
|
5331 | 4328 |
zfs_setsecattr(vnode_t *vp, vsecattr_t *vsecp, int flag, cred_t *cr, |
4329 |
caller_context_t *ct) |
|
789 | 4330 |
{ |
4331 |
znode_t *zp = VTOZ(vp); |
|
4332 |
zfsvfs_t *zfsvfs = zp->z_zfsvfs; |
|
4333 |
int error; |
|
5331 | 4334 |
boolean_t skipaclchk = (flag & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE; |
789 | 4335 |
|
5367 | 4336 |
ZFS_ENTER(zfsvfs); |
4337 |
ZFS_VERIFY_ZP(zp); |
|
5331 | 4338 |
error = zfs_setacl(zp, vsecp, skipaclchk, cr); |
789 | 4339 |
ZFS_EXIT(zfsvfs); |
4340 |
return (error); |
|
4341 |
} |
|
4342 |
||
4343 |
/* |
|
4344 |
* Predeclare these here so that the compiler assumes that |
|
4345 |
* this is an "old style" function declaration that does |
|
4346 |
* not include arguments => we won't get type mismatch errors |
|
4347 |
* in the initializations that follow. |
|
4348 |
*/ |
|
4349 |
static int zfs_inval(); |
|
4350 |
static int zfs_isdir(); |
|
4351 |
||
4352 |
static int |
|
4353 |
zfs_inval() |
|
4354 |
{ |
|
4355 |
return (EINVAL); |
|
4356 |
} |
|
4357 |
||
4358 |
static int |
|
4359 |
zfs_isdir() |
|
4360 |
{ |
|
4361 |
return (EISDIR); |
|
4362 |
} |
|
4363 |
/* |
|
4364 |
* Directory vnode operations template |
|
4365 |
*/ |
|
4366 |
vnodeops_t *zfs_dvnodeops; |
|
4367 |
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
|
4368 |
VOPNAME_OPEN, { .vop_open = zfs_open }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4369 |
VOPNAME_CLOSE, { .vop_close = zfs_close }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4370 |
VOPNAME_READ, { .error = zfs_isdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4371 |
VOPNAME_WRITE, { .error = zfs_isdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4372 |
VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4373 |
VOPNAME_GETATTR, { .vop_getattr = zfs_getattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4374 |
VOPNAME_SETATTR, { .vop_setattr = zfs_setattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4375 |
VOPNAME_ACCESS, { .vop_access = zfs_access }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4376 |
VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4377 |
VOPNAME_CREATE, { .vop_create = zfs_create }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4378 |
VOPNAME_REMOVE, { .vop_remove = zfs_remove }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4379 |
VOPNAME_LINK, { .vop_link = zfs_link }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4380 |
VOPNAME_RENAME, { .vop_rename = zfs_rename }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4381 |
VOPNAME_MKDIR, { .vop_mkdir = zfs_mkdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4382 |
VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4383 |
VOPNAME_READDIR, { .vop_readdir = zfs_readdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4384 |
VOPNAME_SYMLINK, { .vop_symlink = zfs_symlink }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4385 |
VOPNAME_FSYNC, { .vop_fsync = zfs_fsync }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4386 |
VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4387 |
VOPNAME_FID, { .vop_fid = zfs_fid }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4388 |
VOPNAME_SEEK, { .vop_seek = zfs_seek }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4389 |
VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4390 |
VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4391 |
VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr }, |
4863 | 4392 |
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
|
4393 |
NULL, NULL |
789 | 4394 |
}; |
4395 |
||
4396 |
/* |
|
4397 |
* Regular file vnode operations template |
|
4398 |
*/ |
|
4399 |
vnodeops_t *zfs_fvnodeops; |
|
4400 |
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
|
4401 |
VOPNAME_OPEN, { .vop_open = zfs_open }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4402 |
VOPNAME_CLOSE, { .vop_close = zfs_close }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4403 |
VOPNAME_READ, { .vop_read = zfs_read }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4404 |
VOPNAME_WRITE, { .vop_write = zfs_write }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4405 |
VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4406 |
VOPNAME_GETATTR, { .vop_getattr = zfs_getattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4407 |
VOPNAME_SETATTR, { .vop_setattr = zfs_setattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4408 |
VOPNAME_ACCESS, { .vop_access = zfs_access }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4409 |
VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4410 |
VOPNAME_RENAME, { .vop_rename = zfs_rename }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4411 |
VOPNAME_FSYNC, { .vop_fsync = zfs_fsync }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4412 |
VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4413 |
VOPNAME_FID, { .vop_fid = zfs_fid }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4414 |
VOPNAME_SEEK, { .vop_seek = zfs_seek }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4415 |
VOPNAME_FRLOCK, { .vop_frlock = zfs_frlock }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4416 |
VOPNAME_SPACE, { .vop_space = zfs_space }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4417 |
VOPNAME_GETPAGE, { .vop_getpage = zfs_getpage }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4418 |
VOPNAME_PUTPAGE, { .vop_putpage = zfs_putpage }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4419 |
VOPNAME_MAP, { .vop_map = zfs_map }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4420 |
VOPNAME_ADDMAP, { .vop_addmap = zfs_addmap }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4421 |
VOPNAME_DELMAP, { .vop_delmap = zfs_delmap }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4422 |
VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4423 |
VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4424 |
VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4425 |
VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4426 |
NULL, NULL |
789 | 4427 |
}; |
4428 |
||
4429 |
/* |
|
4430 |
* Symbolic link vnode operations template |
|
4431 |
*/ |
|
4432 |
vnodeops_t *zfs_symvnodeops; |
|
4433 |
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
|
4434 |
VOPNAME_GETATTR, { .vop_getattr = zfs_getattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4435 |
VOPNAME_SETATTR, { .vop_setattr = zfs_setattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4436 |
VOPNAME_ACCESS, { .vop_access = zfs_access }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4437 |
VOPNAME_RENAME, { .vop_rename = zfs_rename }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4438 |
VOPNAME_READLINK, { .vop_readlink = zfs_readlink }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4439 |
VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4440 |
VOPNAME_FID, { .vop_fid = zfs_fid }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4441 |
VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4442 |
VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4443 |
NULL, NULL |
789 | 4444 |
}; |
4445 |
||
4446 |
/* |
|
4447 |
* Extended attribute directory vnode operations template |
|
4448 |
* This template is identical to the directory vnodes |
|
4449 |
* operation template except for restricted operations: |
|
4450 |
* VOP_MKDIR() |
|
4451 |
* VOP_SYMLINK() |
|
4452 |
* Note that there are other restrictions embedded in: |
|
4453 |
* zfs_create() - restrict type to VREG |
|
4454 |
* zfs_link() - no links into/out of attribute space |
|
4455 |
* zfs_rename() - no moves into/out of attribute space |
|
4456 |
*/ |
|
4457 |
vnodeops_t *zfs_xdvnodeops; |
|
4458 |
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
|
4459 |
VOPNAME_OPEN, { .vop_open = zfs_open }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4460 |
VOPNAME_CLOSE, { .vop_close = zfs_close }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4461 |
VOPNAME_IOCTL, { .vop_ioctl = zfs_ioctl }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4462 |
VOPNAME_GETATTR, { .vop_getattr = zfs_getattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4463 |
VOPNAME_SETATTR, { .vop_setattr = zfs_setattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4464 |
VOPNAME_ACCESS, { .vop_access = zfs_access }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4465 |
VOPNAME_LOOKUP, { .vop_lookup = zfs_lookup }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4466 |
VOPNAME_CREATE, { .vop_create = zfs_create }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4467 |
VOPNAME_REMOVE, { .vop_remove = zfs_remove }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4468 |
VOPNAME_LINK, { .vop_link = zfs_link }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4469 |
VOPNAME_RENAME, { .vop_rename = zfs_rename }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4470 |
VOPNAME_MKDIR, { .error = zfs_inval }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4471 |
VOPNAME_RMDIR, { .vop_rmdir = zfs_rmdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4472 |
VOPNAME_READDIR, { .vop_readdir = zfs_readdir }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4473 |
VOPNAME_SYMLINK, { .error = zfs_inval }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4474 |
VOPNAME_FSYNC, { .vop_fsync = zfs_fsync }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4475 |
VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4476 |
VOPNAME_FID, { .vop_fid = zfs_fid }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4477 |
VOPNAME_SEEK, { .vop_seek = zfs_seek }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4478 |
VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4479 |
VOPNAME_GETSECATTR, { .vop_getsecattr = zfs_getsecattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4480 |
VOPNAME_SETSECATTR, { .vop_setsecattr = zfs_setsecattr }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4481 |
VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4482 |
NULL, NULL |
789 | 4483 |
}; |
4484 |
||
4485 |
/* |
|
4486 |
* Error vnode operations template |
|
4487 |
*/ |
|
4488 |
vnodeops_t *zfs_evnodeops; |
|
4489 |
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
|
4490 |
VOPNAME_INACTIVE, { .vop_inactive = zfs_inactive }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4491 |
VOPNAME_PATHCONF, { .vop_pathconf = zfs_pathconf }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3897
diff
changeset
|
4492 |
NULL, NULL |
789 | 4493 |
}; |