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