Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/zfs_vfsops.c @ 5331:3047ad28a67b
PSARC/2007/218 caller_context_t in all VOPs
PSARC/2007/227 VFS Feature Registration and ACL on Create
PSARC/2007/244 ZFS Case-insensitive support
PSARC/2007/315 Extensible Attribute Interfaces
PSARC/2007/394 ls(1) new command line options '-/' and '-%': CIFS system attributes support
PSARC/2007/403 Modified Access Checks for CIFS
PSARC/2007/410 Add system attribute support to chmod(1)
PSARC/2007/432 CIFS system attributes support for cp(1), pack(1), unpack(1), compress(1) and uncompress(1)
PSARC/2007/444 Rescind SETTABLE Attribute
PSARC/2007/459 CIFS system attributes support for cpio(1), pax(1), tar(1)
PSARC/2007/546 Update utilities to match CIFS system attributes changes.
PSARC/2007/560 ZFS sharesmb property
4890717 want append-only files
6417428 Case-insensitive file system name lookup to support CIFS
6417435 DOS attributes and additional timestamps to support for CIFS
6417442 File system quarantined and modified attributes to support an integrated Anti-Virus service
6417453 FS boolean property for rejecting/allowing invalid UTF-8 sequences in file names
6473733 RFE: Need support for open-deny modes
6473755 RFE: Need ability to reconcile oplock and delegation conflicts
6494624 sharemgr needs to support CIFS shares better
6546705 All vnode operations need to pass caller_context_t
6546706 Need VOP_SETATTR/VOP_GETATTR to support new, optional attributes
6546893 Solaris system attribute support
6550962 ZFS ACL inheritance needs to be enhanced to support Automatic Inheritance
6553589 RFE: VFS Feature Registration facility
6553770 RFE: ZFS support for ACL-on-CREATE (PSARC 2007/227)
6565581 ls(1) should support file system attributes proposed in PSARC/2007/315
6566784 NTFS streams are not copied along with the files.
6576205 cp(1), pack(1) and compress(1) should support file system attributes proposed in PSARC/2007/315
6578875 RFE: kernel interfaces for nbmand need improvement
6578883 RFE: VOP_SHRLOCK needs additional access types
6578885 chmod(1) should support file system attributes proposed in PSARC/2007/315
6578886 RFE: disallow nbmand state to change on remount
6583349 ACL parser needs to support audit/alarm ACE types
6590347 tar(1) should support filesystem attributes proposed in PSARC/2007/315
6597357 *tar* xv@ doesn't show the hidden directory even though it is restored
6597360 *tar* should re-init xattr info if openat() fails during extraction of and extended attribute
6597368 *tar* cannot restore hard linked extended attributes
6597374 *tar* doesn't display "x " when hard linked attributes are restored
6597375 *tar* extended attribute header off by one
6614861 *cpio* incorrectly archives extended system attributes with -@
6614896 *pax* incorrectly archives extended system attributes with -@
6615225 *tar* incorrectly archives extended system attributes with -@
6617183 CIFS Service - PSARC 2006/715
author | amw |
---|---|
date | Thu, 25 Oct 2007 16:34:29 -0700 |
parents | 6752aa2bd5bc |
children | f0cb3b884d95 |
rev | line source |
---|---|
789 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
5 * Common Development and Distribution License (the "License"). |
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
6 * You may not use this file except in compliance with the License. |
789 | 7 * |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 * or http://www.opensolaris.org/os/licensing. | |
10 * See the License for the specific language governing permissions | |
11 * and limitations under the License. | |
12 * | |
13 * When distributing Covered Code, include this CDDL HEADER in each | |
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 * If applicable, add the following below this CDDL HEADER, with the | |
16 * fields enclosed by brackets "[]" replaced with your own identifying | |
17 * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 * | |
19 * CDDL HEADER END | |
20 */ | |
21 /* | |
3461 | 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
789 | 23 * Use is subject to license terms. |
24 */ | |
25 | |
3246
7a46b8f56ee0
6351954 zfs missing noxattr mount flag (fix keywords)
ck153898
parents:
3234
diff
changeset
|
26 #pragma ident "%Z%%M% %I% %E% SMI" |
789 | 27 |
28 #include <sys/types.h> | |
29 #include <sys/param.h> | |
30 #include <sys/systm.h> | |
31 #include <sys/sysmacros.h> | |
32 #include <sys/kmem.h> | |
33 #include <sys/pathname.h> | |
34 #include <sys/vnode.h> | |
35 #include <sys/vfs.h> | |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
36 #include <sys/vfs_opreg.h> |
789 | 37 #include <sys/mntent.h> |
38 #include <sys/mount.h> | |
39 #include <sys/cmn_err.h> | |
40 #include "fs/fs_subr.h" | |
41 #include <sys/zfs_znode.h> | |
3461 | 42 #include <sys/zfs_dir.h> |
5331 | 43 #include <sys/zfs_i18n.h> |
789 | 44 #include <sys/zil.h> |
45 #include <sys/fs/zfs.h> | |
46 #include <sys/dmu.h> | |
47 #include <sys/dsl_prop.h> | |
3912 | 48 #include <sys/dsl_dataset.h> |
4543 | 49 #include <sys/dsl_deleg.h> |
789 | 50 #include <sys/spa.h> |
51 #include <sys/zap.h> | |
52 #include <sys/varargs.h> | |
53 #include <sys/policy.h> | |
54 #include <sys/atomic.h> | |
55 #include <sys/mkdev.h> | |
56 #include <sys/modctl.h> | |
4543 | 57 #include <sys/refstr.h> |
789 | 58 #include <sys/zfs_ioctl.h> |
59 #include <sys/zfs_ctldir.h> | |
5331 | 60 #include <sys/zfs_fuid.h> |
1544 | 61 #include <sys/bootconf.h> |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
62 #include <sys/sunddi.h> |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
63 #include <sys/dnlc.h> |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
64 #include <sys/dmu_objset.h> |
789 | 65 |
66 int zfsfstype; | |
67 vfsops_t *zfs_vfsops = NULL; | |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
68 static major_t zfs_major; |
789 | 69 static minor_t zfs_minor; |
70 static kmutex_t zfs_dev_mtx; | |
71 | |
72 static int zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr); | |
73 static int zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr); | |
1544 | 74 static int zfs_mountroot(vfs_t *vfsp, enum whymountroot); |
789 | 75 static int zfs_root(vfs_t *vfsp, vnode_t **vpp); |
76 static int zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp); | |
77 static int zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp); | |
78 static void zfs_freevfs(vfs_t *vfsp); | |
79 | |
80 static const fs_operation_def_t zfs_vfsops_template[] = { | |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
81 VFSNAME_MOUNT, { .vfs_mount = zfs_mount }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
82 VFSNAME_MOUNTROOT, { .vfs_mountroot = zfs_mountroot }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
83 VFSNAME_UNMOUNT, { .vfs_unmount = zfs_umount }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
84 VFSNAME_ROOT, { .vfs_root = zfs_root }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
85 VFSNAME_STATVFS, { .vfs_statvfs = zfs_statvfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
86 VFSNAME_SYNC, { .vfs_sync = zfs_sync }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
87 VFSNAME_VGET, { .vfs_vget = zfs_vget }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
88 VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
89 NULL, NULL |
789 | 90 }; |
91 | |
92 static const fs_operation_def_t zfs_vfsops_eio_template[] = { | |
3898
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
93 VFSNAME_FREEVFS, { .vfs_freevfs = zfs_freevfs }, |
c788126f2a20
PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents:
3461
diff
changeset
|
94 NULL, NULL |
789 | 95 }; |
96 | |
97 /* | |
98 * We need to keep a count of active fs's. | |
99 * This is necessary to prevent our module | |
100 * from being unloaded after a umount -f | |
101 */ | |
102 static uint32_t zfs_active_fs_count = 0; | |
103 | |
104 static char *noatime_cancel[] = { MNTOPT_ATIME, NULL }; | |
105 static char *atime_cancel[] = { MNTOPT_NOATIME, NULL }; | |
3234 | 106 static char *noxattr_cancel[] = { MNTOPT_XATTR, NULL }; |
107 static char *xattr_cancel[] = { MNTOPT_NOXATTR, NULL }; | |
789 | 108 |
3234 | 109 /* |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
110 * MO_DEFAULT is not used since the default value is determined |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
111 * by the equivalent property. |
3234 | 112 */ |
789 | 113 static mntopt_t mntopts[] = { |
3234 | 114 { MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, NULL }, |
115 { MNTOPT_XATTR, xattr_cancel, NULL, 0, NULL }, | |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
116 { MNTOPT_NOATIME, noatime_cancel, NULL, 0, NULL }, |
789 | 117 { MNTOPT_ATIME, atime_cancel, NULL, 0, NULL } |
118 }; | |
119 | |
120 static mntopts_t zfs_mntopts = { | |
121 sizeof (mntopts) / sizeof (mntopt_t), | |
122 mntopts | |
123 }; | |
124 | |
125 /*ARGSUSED*/ | |
126 int | |
127 zfs_sync(vfs_t *vfsp, short flag, cred_t *cr) | |
128 { | |
129 /* | |
130 * Data integrity is job one. We don't want a compromised kernel | |
131 * writing to the storage pool, so we never sync during panic. | |
132 */ | |
133 if (panicstr) | |
134 return (0); | |
135 | |
136 /* | |
137 * SYNC_ATTR is used by fsflush() to force old filesystems like UFS | |
138 * to sync metadata, which they would otherwise cache indefinitely. | |
139 * Semantically, the only requirement is that the sync be initiated. | |
140 * The DMU syncs out txgs frequently, so there's nothing to do. | |
141 */ | |
142 if (flag & SYNC_ATTR) | |
143 return (0); | |
144 | |
145 if (vfsp != NULL) { | |
146 /* | |
147 * Sync a specific filesystem. | |
148 */ | |
149 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
150 | |
151 ZFS_ENTER(zfsvfs); | |
152 if (zfsvfs->z_log != NULL) | |
2638
4f583dfeae92
6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents:
2474
diff
changeset
|
153 zil_commit(zfsvfs->z_log, UINT64_MAX, 0); |
789 | 154 else |
155 txg_wait_synced(dmu_objset_pool(zfsvfs->z_os), 0); | |
156 ZFS_EXIT(zfsvfs); | |
157 } else { | |
158 /* | |
159 * Sync all ZFS filesystems. This is what happens when you | |
160 * run sync(1M). Unlike other filesystems, ZFS honors the | |
161 * request by waiting for all pools to commit all dirty data. | |
162 */ | |
163 spa_sync_allpools(); | |
164 } | |
165 | |
166 return (0); | |
167 } | |
168 | |
1544 | 169 static int |
170 zfs_create_unique_device(dev_t *dev) | |
171 { | |
172 major_t new_major; | |
173 | |
174 do { | |
175 ASSERT3U(zfs_minor, <=, MAXMIN32); | |
176 minor_t start = zfs_minor; | |
177 do { | |
178 mutex_enter(&zfs_dev_mtx); | |
179 if (zfs_minor >= MAXMIN32) { | |
180 /* | |
181 * If we're still using the real major | |
182 * keep out of /dev/zfs and /dev/zvol minor | |
183 * number space. If we're using a getudev()'ed | |
184 * major number, we can use all of its minors. | |
185 */ | |
186 if (zfs_major == ddi_name_to_major(ZFS_DRIVER)) | |
187 zfs_minor = ZFS_MIN_MINOR; | |
188 else | |
189 zfs_minor = 0; | |
190 } else { | |
191 zfs_minor++; | |
192 } | |
193 *dev = makedevice(zfs_major, zfs_minor); | |
194 mutex_exit(&zfs_dev_mtx); | |
195 } while (vfs_devismounted(*dev) && zfs_minor != start); | |
196 if (zfs_minor == start) { | |
197 /* | |
198 * We are using all ~262,000 minor numbers for the | |
199 * current major number. Create a new major number. | |
200 */ | |
201 if ((new_major = getudev()) == (major_t)-1) { | |
202 cmn_err(CE_WARN, | |
203 "zfs_mount: Can't get unique major " | |
204 "device number."); | |
205 return (-1); | |
206 } | |
207 mutex_enter(&zfs_dev_mtx); | |
208 zfs_major = new_major; | |
209 zfs_minor = 0; | |
210 | |
211 mutex_exit(&zfs_dev_mtx); | |
212 } else { | |
213 break; | |
214 } | |
215 /* CONSTANTCONDITION */ | |
216 } while (1); | |
217 | |
218 return (0); | |
219 } | |
220 | |
789 | 221 static void |
222 atime_changed_cb(void *arg, uint64_t newval) | |
223 { | |
224 zfsvfs_t *zfsvfs = arg; | |
225 | |
226 if (newval == TRUE) { | |
227 zfsvfs->z_atime = TRUE; | |
228 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME); | |
229 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_ATIME, NULL, 0); | |
230 } else { | |
231 zfsvfs->z_atime = FALSE; | |
232 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_ATIME); | |
233 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOATIME, NULL, 0); | |
234 } | |
235 } | |
236 | |
237 static void | |
3234 | 238 xattr_changed_cb(void *arg, uint64_t newval) |
239 { | |
240 zfsvfs_t *zfsvfs = arg; | |
241 | |
242 if (newval == TRUE) { | |
243 /* XXX locking on vfs_flag? */ | |
244 zfsvfs->z_vfs->vfs_flag |= VFS_XATTR; | |
245 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR); | |
246 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_XATTR, NULL, 0); | |
247 } else { | |
248 /* XXX locking on vfs_flag? */ | |
249 zfsvfs->z_vfs->vfs_flag &= ~VFS_XATTR; | |
250 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_XATTR); | |
251 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOXATTR, NULL, 0); | |
252 } | |
253 } | |
254 | |
255 static void | |
789 | 256 blksz_changed_cb(void *arg, uint64_t newval) |
257 { | |
258 zfsvfs_t *zfsvfs = arg; | |
259 | |
260 if (newval < SPA_MINBLOCKSIZE || | |
261 newval > SPA_MAXBLOCKSIZE || !ISP2(newval)) | |
262 newval = SPA_MAXBLOCKSIZE; | |
263 | |
264 zfsvfs->z_max_blksz = newval; | |
265 zfsvfs->z_vfs->vfs_bsize = newval; | |
266 } | |
267 | |
268 static void | |
269 readonly_changed_cb(void *arg, uint64_t newval) | |
270 { | |
271 zfsvfs_t *zfsvfs = arg; | |
272 | |
273 if (newval) { | |
274 /* XXX locking on vfs_flag? */ | |
275 zfsvfs->z_vfs->vfs_flag |= VFS_RDONLY; | |
276 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RW); | |
277 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RO, NULL, 0); | |
278 } else { | |
279 /* XXX locking on vfs_flag? */ | |
280 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; | |
281 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_RO); | |
282 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_RW, NULL, 0); | |
283 } | |
284 } | |
285 | |
286 static void | |
287 devices_changed_cb(void *arg, uint64_t newval) | |
288 { | |
289 zfsvfs_t *zfsvfs = arg; | |
290 | |
291 if (newval == FALSE) { | |
292 zfsvfs->z_vfs->vfs_flag |= VFS_NODEVICES; | |
293 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES); | |
294 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES, NULL, 0); | |
295 } else { | |
296 zfsvfs->z_vfs->vfs_flag &= ~VFS_NODEVICES; | |
297 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NODEVICES); | |
298 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_DEVICES, NULL, 0); | |
299 } | |
300 } | |
301 | |
302 static void | |
303 setuid_changed_cb(void *arg, uint64_t newval) | |
304 { | |
305 zfsvfs_t *zfsvfs = arg; | |
306 | |
307 if (newval == FALSE) { | |
308 zfsvfs->z_vfs->vfs_flag |= VFS_NOSETUID; | |
309 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_SETUID); | |
310 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID, NULL, 0); | |
311 } else { | |
312 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOSETUID; | |
313 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOSETUID); | |
314 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_SETUID, NULL, 0); | |
315 } | |
316 } | |
317 | |
318 static void | |
319 exec_changed_cb(void *arg, uint64_t newval) | |
320 { | |
321 zfsvfs_t *zfsvfs = arg; | |
322 | |
323 if (newval == FALSE) { | |
324 zfsvfs->z_vfs->vfs_flag |= VFS_NOEXEC; | |
325 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_EXEC); | |
326 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC, NULL, 0); | |
327 } else { | |
328 zfsvfs->z_vfs->vfs_flag &= ~VFS_NOEXEC; | |
329 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NOEXEC); | |
330 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_EXEC, NULL, 0); | |
331 } | |
332 } | |
333 | |
5331 | 334 /* |
335 * The nbmand mount option can be changed at mount time. | |
336 * We can't allow it to be toggled on live file systems or incorrect | |
337 * behavior may be seen from cifs clients | |
338 * | |
339 * This property isn't registered via dsl_prop_register(), but this callback | |
340 * will be called when a file system is first mounted | |
341 */ | |
342 static void | |
343 nbmand_changed_cb(void *arg, uint64_t newval) | |
344 { | |
345 zfsvfs_t *zfsvfs = arg; | |
346 if (newval == FALSE) { | |
347 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND); | |
348 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND, NULL, 0); | |
349 } else { | |
350 vfs_clearmntopt(zfsvfs->z_vfs, MNTOPT_NONBMAND); | |
351 vfs_setmntopt(zfsvfs->z_vfs, MNTOPT_NBMAND, NULL, 0); | |
352 } | |
353 } | |
354 | |
789 | 355 static void |
356 snapdir_changed_cb(void *arg, uint64_t newval) | |
357 { | |
358 zfsvfs_t *zfsvfs = arg; | |
359 | |
360 zfsvfs->z_show_ctldir = newval; | |
361 } | |
362 | |
363 static void | |
5331 | 364 vscan_changed_cb(void *arg, uint64_t newval) |
365 { | |
366 zfsvfs_t *zfsvfs = arg; | |
367 | |
368 zfsvfs->z_vscan = newval; | |
369 } | |
370 | |
371 static void | |
789 | 372 acl_mode_changed_cb(void *arg, uint64_t newval) |
373 { | |
374 zfsvfs_t *zfsvfs = arg; | |
375 | |
376 zfsvfs->z_acl_mode = newval; | |
377 } | |
378 | |
379 static void | |
380 acl_inherit_changed_cb(void *arg, uint64_t newval) | |
381 { | |
382 zfsvfs_t *zfsvfs = arg; | |
383 | |
384 zfsvfs->z_acl_inherit = newval; | |
385 } | |
386 | |
1544 | 387 static int |
5331 | 388 zfs_normalization_set(char *osname, zfsvfs_t *zfsvfs) |
389 { | |
390 uint64_t pval; | |
391 int error; | |
392 | |
393 if (zfsvfs->z_version < ZPL_VERSION_FUID) | |
394 return (0); | |
395 | |
396 error = dsl_prop_get_integer(osname, "normalization", &pval, NULL); | |
397 if (error) | |
398 goto normquit; | |
399 switch ((int)pval) { | |
400 case ZFS_NORMALIZE_NONE: | |
401 break; | |
402 case ZFS_NORMALIZE_C: | |
403 zfsvfs->z_norm |= U8_TEXTPREP_NFC; | |
404 break; | |
405 case ZFS_NORMALIZE_KC: | |
406 zfsvfs->z_norm |= U8_TEXTPREP_NFKC; | |
407 break; | |
408 case ZFS_NORMALIZE_D: | |
409 zfsvfs->z_norm |= U8_TEXTPREP_NFD; | |
410 break; | |
411 case ZFS_NORMALIZE_KD: | |
412 zfsvfs->z_norm |= U8_TEXTPREP_NFKD; | |
413 break; | |
414 default: | |
415 ASSERT(pval <= ZFS_NORMALIZE_KD); | |
416 break; | |
417 } | |
418 | |
419 error = dsl_prop_get_integer(osname, "utf8only", &pval, NULL); | |
420 if (error) | |
421 goto normquit; | |
422 if (pval) | |
423 zfsvfs->z_case |= ZFS_UTF8_ONLY; | |
424 else | |
425 zfsvfs->z_case &= ~ZFS_UTF8_ONLY; | |
426 | |
427 error = dsl_prop_get_integer(osname, "casesensitivity", &pval, NULL); | |
428 if (error) | |
429 goto normquit; | |
430 vfs_set_feature(zfsvfs->z_vfs, VFSFT_DIRENTFLAGS); | |
431 switch ((int)pval) { | |
432 case ZFS_CASE_SENSITIVE: | |
433 break; | |
434 case ZFS_CASE_INSENSITIVE: | |
435 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER; | |
436 zfsvfs->z_case |= ZFS_CI_ONLY; | |
437 vfs_set_feature(zfsvfs->z_vfs, VFSFT_CASEINSENSITIVE); | |
438 vfs_set_feature(zfsvfs->z_vfs, VFSFT_NOCASESENSITIVE); | |
439 break; | |
440 case ZFS_CASE_MIXED: | |
441 zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER; | |
442 zfsvfs->z_case |= ZFS_CI_MIXD; | |
443 vfs_set_feature(zfsvfs->z_vfs, VFSFT_CASEINSENSITIVE); | |
444 break; | |
445 default: | |
446 ASSERT(pval <= ZFS_CASE_MIXED); | |
447 break; | |
448 } | |
449 | |
450 normquit: | |
451 return (error); | |
452 } | |
453 | |
454 static int | |
1544 | 455 zfs_register_callbacks(vfs_t *vfsp) |
456 { | |
457 struct dsl_dataset *ds = NULL; | |
458 objset_t *os = NULL; | |
459 zfsvfs_t *zfsvfs = NULL; | |
5331 | 460 uint64_t nbmand; |
461 int readonly, do_readonly = B_FALSE; | |
462 int setuid, do_setuid = B_FALSE; | |
463 int exec, do_exec = B_FALSE; | |
464 int devices, do_devices = B_FALSE; | |
465 int xattr, do_xattr = B_FALSE; | |
466 int atime, do_atime = B_FALSE; | |
1544 | 467 int error = 0; |
468 | |
469 ASSERT(vfsp); | |
470 zfsvfs = vfsp->vfs_data; | |
471 ASSERT(zfsvfs); | |
472 os = zfsvfs->z_os; | |
473 | |
474 /* | |
475 * The act of registering our callbacks will destroy any mount | |
476 * options we may have. In order to enable temporary overrides | |
3234 | 477 * of mount options, we stash away the current values and |
1544 | 478 * restore them after we register the callbacks. |
479 */ | |
480 if (vfs_optionisset(vfsp, MNTOPT_RO, NULL)) { | |
481 readonly = B_TRUE; | |
482 do_readonly = B_TRUE; | |
483 } else if (vfs_optionisset(vfsp, MNTOPT_RW, NULL)) { | |
484 readonly = B_FALSE; | |
485 do_readonly = B_TRUE; | |
486 } | |
487 if (vfs_optionisset(vfsp, MNTOPT_NOSUID, NULL)) { | |
488 devices = B_FALSE; | |
489 setuid = B_FALSE; | |
490 do_devices = B_TRUE; | |
491 do_setuid = B_TRUE; | |
492 } else { | |
493 if (vfs_optionisset(vfsp, MNTOPT_NODEVICES, NULL)) { | |
494 devices = B_FALSE; | |
495 do_devices = B_TRUE; | |
3912 | 496 } else if (vfs_optionisset(vfsp, MNTOPT_DEVICES, NULL)) { |
1544 | 497 devices = B_TRUE; |
498 do_devices = B_TRUE; | |
499 } | |
500 | |
501 if (vfs_optionisset(vfsp, MNTOPT_NOSETUID, NULL)) { | |
502 setuid = B_FALSE; | |
503 do_setuid = B_TRUE; | |
504 } else if (vfs_optionisset(vfsp, MNTOPT_SETUID, NULL)) { | |
505 setuid = B_TRUE; | |
506 do_setuid = B_TRUE; | |
507 } | |
508 } | |
509 if (vfs_optionisset(vfsp, MNTOPT_NOEXEC, NULL)) { | |
510 exec = B_FALSE; | |
511 do_exec = B_TRUE; | |
512 } else if (vfs_optionisset(vfsp, MNTOPT_EXEC, NULL)) { | |
513 exec = B_TRUE; | |
514 do_exec = B_TRUE; | |
515 } | |
3234 | 516 if (vfs_optionisset(vfsp, MNTOPT_NOXATTR, NULL)) { |
517 xattr = B_FALSE; | |
518 do_xattr = B_TRUE; | |
519 } else if (vfs_optionisset(vfsp, MNTOPT_XATTR, NULL)) { | |
520 xattr = B_TRUE; | |
521 do_xattr = B_TRUE; | |
522 } | |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
523 if (vfs_optionisset(vfsp, MNTOPT_NOATIME, NULL)) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
524 atime = B_FALSE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
525 do_atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
526 } else if (vfs_optionisset(vfsp, MNTOPT_ATIME, NULL)) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
527 atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
528 do_atime = B_TRUE; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
529 } |
1544 | 530 |
531 /* | |
5331 | 532 * nbmand is a special property. It can only be changed at |
533 * mount time. | |
534 * | |
535 * This is weird, but it is documented to only be changeable | |
536 * at mount time. | |
537 */ | |
538 if (vfs_optionisset(vfsp, MNTOPT_NONBMAND, NULL)) { | |
539 nbmand = B_FALSE; | |
540 } else if (vfs_optionisset(vfsp, MNTOPT_NBMAND, NULL)) { | |
541 nbmand = B_TRUE; | |
542 } else { | |
543 char osname[MAXNAMELEN]; | |
544 | |
545 dmu_objset_name(os, osname); | |
546 if (error = dsl_prop_get_integer(osname, "nbmand", &nbmand, | |
547 NULL)) | |
548 return (error); | |
549 } | |
550 | |
551 /* | |
1544 | 552 * Register property callbacks. |
553 * | |
554 * It would probably be fine to just check for i/o error from | |
555 * the first prop_register(), but I guess I like to go | |
556 * overboard... | |
557 */ | |
558 ds = dmu_objset_ds(os); | |
559 error = dsl_prop_register(ds, "atime", atime_changed_cb, zfsvfs); | |
560 error = error ? error : dsl_prop_register(ds, | |
3234 | 561 "xattr", xattr_changed_cb, zfsvfs); |
562 error = error ? error : dsl_prop_register(ds, | |
1544 | 563 "recordsize", blksz_changed_cb, zfsvfs); |
564 error = error ? error : dsl_prop_register(ds, | |
565 "readonly", readonly_changed_cb, zfsvfs); | |
566 error = error ? error : dsl_prop_register(ds, | |
567 "devices", devices_changed_cb, zfsvfs); | |
568 error = error ? error : dsl_prop_register(ds, | |
569 "setuid", setuid_changed_cb, zfsvfs); | |
570 error = error ? error : dsl_prop_register(ds, | |
571 "exec", exec_changed_cb, zfsvfs); | |
572 error = error ? error : dsl_prop_register(ds, | |
573 "snapdir", snapdir_changed_cb, zfsvfs); | |
574 error = error ? error : dsl_prop_register(ds, | |
575 "aclmode", acl_mode_changed_cb, zfsvfs); | |
576 error = error ? error : dsl_prop_register(ds, | |
577 "aclinherit", acl_inherit_changed_cb, zfsvfs); | |
5331 | 578 error = error ? error : dsl_prop_register(ds, |
579 "vscan", vscan_changed_cb, zfsvfs); | |
1544 | 580 if (error) |
581 goto unregister; | |
582 | |
583 /* | |
584 * Invoke our callbacks to restore temporary mount options. | |
585 */ | |
586 if (do_readonly) | |
587 readonly_changed_cb(zfsvfs, readonly); | |
588 if (do_setuid) | |
589 setuid_changed_cb(zfsvfs, setuid); | |
590 if (do_exec) | |
591 exec_changed_cb(zfsvfs, exec); | |
592 if (do_devices) | |
593 devices_changed_cb(zfsvfs, devices); | |
3234 | 594 if (do_xattr) |
595 xattr_changed_cb(zfsvfs, xattr); | |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
596 if (do_atime) |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
597 atime_changed_cb(zfsvfs, atime); |
1544 | 598 |
5331 | 599 nbmand_changed_cb(zfsvfs, nbmand); |
600 | |
1544 | 601 return (0); |
602 | |
603 unregister: | |
604 /* | |
605 * We may attempt to unregister some callbacks that are not | |
606 * registered, but this is OK; it will simply return ENOMSG, | |
607 * which we will ignore. | |
608 */ | |
609 (void) dsl_prop_unregister(ds, "atime", atime_changed_cb, zfsvfs); | |
3234 | 610 (void) dsl_prop_unregister(ds, "xattr", xattr_changed_cb, zfsvfs); |
1544 | 611 (void) dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, zfsvfs); |
612 (void) dsl_prop_unregister(ds, "readonly", readonly_changed_cb, zfsvfs); | |
613 (void) dsl_prop_unregister(ds, "devices", devices_changed_cb, zfsvfs); | |
614 (void) dsl_prop_unregister(ds, "setuid", setuid_changed_cb, zfsvfs); | |
615 (void) dsl_prop_unregister(ds, "exec", exec_changed_cb, zfsvfs); | |
616 (void) dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, zfsvfs); | |
617 (void) dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, zfsvfs); | |
618 (void) dsl_prop_unregister(ds, "aclinherit", acl_inherit_changed_cb, | |
619 zfsvfs); | |
5331 | 620 (void) dsl_prop_unregister(ds, "vscan", vscan_changed_cb, zfsvfs); |
1544 | 621 return (error); |
622 | |
623 } | |
624 | |
625 static int | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
626 zfsvfs_setup(zfsvfs_t *zfsvfs, boolean_t mounting) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
627 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
628 uint_t readonly; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
629 int error; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
630 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
631 error = zfs_register_callbacks(zfsvfs->z_vfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
632 if (error) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
633 return (error); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
634 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
635 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
636 * Set the objset user_ptr to track its zfsvfs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
637 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
638 mutex_enter(&zfsvfs->z_os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
639 dmu_objset_set_user(zfsvfs->z_os, zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
640 mutex_exit(&zfsvfs->z_os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
641 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
642 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
643 * If we are not mounting (ie: online recv), then we don't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
644 * have to worry about replaying the log as we blocked all |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
645 * operations out since we closed the ZIL. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
646 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
647 if (mounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
648 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
649 * During replay we remove the read only flag to |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
650 * allow replays to succeed. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
651 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
652 readonly = zfsvfs->z_vfs->vfs_flag & VFS_RDONLY; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
653 if (readonly != 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
654 zfsvfs->z_vfs->vfs_flag &= ~VFS_RDONLY; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
655 else |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
656 zfs_unlinked_drain(zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
657 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
658 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
659 * Parse and replay the intent log. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
660 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
661 * Because of ziltest, this must be done after |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
662 * zfs_unlinked_drain(). (Further note: ziltest doesn't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
663 * use readonly mounts, where zfs_unlinked_drain() isn't |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
664 * called.) This is because ziltest causes spa_sync() |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
665 * to think it's committed, but actually it is not, so |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
666 * the intent log contains many txg's worth of changes. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
667 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
668 * In particular, if object N is in the unlinked set in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
669 * the last txg to actually sync, then it could be |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
670 * actually freed in a later txg and then reallocated in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
671 * a yet later txg. This would write a "create object |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
672 * N" record to the intent log. Normally, this would be |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
673 * fine because the spa_sync() would have written out |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
674 * the fact that object N is free, before we could write |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
675 * the "create object N" intent log record. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
676 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
677 * But when we are in ziltest mode, we advance the "open |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
678 * txg" without actually spa_sync()-ing the changes to |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
679 * disk. So we would see that object N is still |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
680 * allocated and in the unlinked set, and there is an |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
681 * intent log record saying to allocate it. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
682 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
683 zil_replay(zfsvfs->z_os, zfsvfs, &zfsvfs->z_assign, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
684 zfs_replay_vector); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
685 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
686 zfsvfs->z_vfs->vfs_flag |= readonly; /* restore readonly bit */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
687 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
688 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
689 if (!zil_disable) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
690 zfsvfs->z_log = zil_open(zfsvfs->z_os, zfs_get_data); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
691 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
692 return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
693 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
694 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
695 static int |
1544 | 696 zfs_domount(vfs_t *vfsp, char *osname, cred_t *cr) |
697 { | |
698 dev_t mount_dev; | |
699 uint64_t recordsize, readonly; | |
700 int error = 0; | |
701 int mode; | |
702 zfsvfs_t *zfsvfs; | |
703 znode_t *zp = NULL; | |
704 | |
705 ASSERT(vfsp); | |
706 ASSERT(osname); | |
707 | |
708 /* | |
709 * Initialize the zfs-specific filesystem structure. | |
710 * Should probably make this a kmem cache, shuffle fields, | |
711 * and just bzero up to z_hold_mtx[]. | |
712 */ | |
713 zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP); | |
714 zfsvfs->z_vfs = vfsp; | |
715 zfsvfs->z_parent = zfsvfs; | |
716 zfsvfs->z_assign = TXG_NOWAIT; | |
717 zfsvfs->z_max_blksz = SPA_MAXBLOCKSIZE; | |
718 zfsvfs->z_show_ctldir = ZFS_SNAPDIR_VISIBLE; | |
719 | |
720 mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL); | |
721 list_create(&zfsvfs->z_all_znodes, sizeof (znode_t), | |
722 offsetof(znode_t, z_link_node)); | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
723 rrw_init(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
724 rw_init(&zfsvfs->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL); |
1544 | 725 |
726 /* Initialize the generic filesystem structure. */ | |
727 vfsp->vfs_bcount = 0; | |
728 vfsp->vfs_data = NULL; | |
729 | |
730 if (zfs_create_unique_device(&mount_dev) == -1) { | |
731 error = ENODEV; | |
732 goto out; | |
733 } | |
734 ASSERT(vfs_devismounted(mount_dev) == 0); | |
735 | |
736 if (error = dsl_prop_get_integer(osname, "recordsize", &recordsize, | |
737 NULL)) | |
738 goto out; | |
739 | |
740 vfsp->vfs_dev = mount_dev; | |
741 vfsp->vfs_fstype = zfsfstype; | |
742 vfsp->vfs_bsize = recordsize; | |
743 vfsp->vfs_flag |= VFS_NOTRUNC; | |
744 vfsp->vfs_data = zfsvfs; | |
745 | |
746 if (error = dsl_prop_get_integer(osname, "readonly", &readonly, NULL)) | |
747 goto out; | |
748 | |
749 if (readonly) | |
750 mode = DS_MODE_PRIMARY | DS_MODE_READONLY; | |
751 else | |
752 mode = DS_MODE_PRIMARY; | |
753 | |
754 error = dmu_objset_open(osname, DMU_OST_ZFS, mode, &zfsvfs->z_os); | |
755 if (error == EROFS) { | |
756 mode = DS_MODE_PRIMARY | DS_MODE_READONLY; | |
757 error = dmu_objset_open(osname, DMU_OST_ZFS, mode, | |
758 &zfsvfs->z_os); | |
759 } | |
760 | |
761 if (error) | |
762 goto out; | |
763 | |
764 if (error = zfs_init_fs(zfsvfs, &zp, cr)) | |
765 goto out; | |
766 | |
767 /* The call to zfs_init_fs leaves the vnode held, release it here. */ | |
768 VN_RELE(ZTOV(zp)); | |
769 | |
5331 | 770 /* |
771 * Set features for file system. | |
772 */ | |
773 zfsvfs->z_use_fuids = USE_FUIDS(zfsvfs->z_version, zfsvfs->z_os); | |
774 if (zfsvfs->z_use_fuids) { | |
775 vfs_set_feature(vfsp, VFSFT_XVATTR); | |
776 vfs_set_feature(vfsp, VFSFT_ACEMASKONACCESS); | |
777 vfs_set_feature(vfsp, VFSFT_ACLONCREATE); | |
778 } | |
779 | |
780 /* | |
781 * Set normalization regardless of whether or not the object | |
782 * set is a snapshot. Snapshots and clones need to have | |
783 * identical normalization as did the file system they | |
784 * originated from. | |
785 */ | |
786 if ((error = zfs_normalization_set(osname, zfsvfs)) != 0) | |
787 goto out; | |
788 | |
1544 | 789 if (dmu_objset_is_snapshot(zfsvfs->z_os)) { |
5331 | 790 uint64_t pval; |
3234 | 791 |
1544 | 792 ASSERT(mode & DS_MODE_READONLY); |
793 atime_changed_cb(zfsvfs, B_FALSE); | |
794 readonly_changed_cb(zfsvfs, B_TRUE); | |
5331 | 795 if (error = dsl_prop_get_integer(osname, "xattr", &pval, NULL)) |
3234 | 796 goto out; |
5331 | 797 xattr_changed_cb(zfsvfs, pval); |
1544 | 798 zfsvfs->z_issnap = B_TRUE; |
799 } else { | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
800 error = zfsvfs_setup(zfsvfs, B_TRUE); |
1544 | 801 } |
802 | |
803 if (!zfsvfs->z_issnap) | |
804 zfsctl_create(zfsvfs); | |
805 out: | |
806 if (error) { | |
807 if (zfsvfs->z_os) | |
808 dmu_objset_close(zfsvfs->z_os); | |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
809 mutex_destroy(&zfsvfs->z_znodes_lock); |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
810 list_destroy(&zfsvfs->z_all_znodes); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
811 rrw_destroy(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
812 rw_destroy(&zfsvfs->z_teardown_inactive_lock); |
1544 | 813 kmem_free(zfsvfs, sizeof (zfsvfs_t)); |
814 } else { | |
815 atomic_add_32(&zfs_active_fs_count, 1); | |
816 } | |
817 | |
818 return (error); | |
819 } | |
820 | |
821 void | |
822 zfs_unregister_callbacks(zfsvfs_t *zfsvfs) | |
823 { | |
824 objset_t *os = zfsvfs->z_os; | |
825 struct dsl_dataset *ds; | |
826 | |
827 /* | |
828 * Unregister properties. | |
829 */ | |
830 if (!dmu_objset_is_snapshot(os)) { | |
831 ds = dmu_objset_ds(os); | |
832 VERIFY(dsl_prop_unregister(ds, "atime", atime_changed_cb, | |
833 zfsvfs) == 0); | |
834 | |
3234 | 835 VERIFY(dsl_prop_unregister(ds, "xattr", xattr_changed_cb, |
836 zfsvfs) == 0); | |
837 | |
1544 | 838 VERIFY(dsl_prop_unregister(ds, "recordsize", blksz_changed_cb, |
839 zfsvfs) == 0); | |
840 | |
841 VERIFY(dsl_prop_unregister(ds, "readonly", readonly_changed_cb, | |
842 zfsvfs) == 0); | |
843 | |
844 VERIFY(dsl_prop_unregister(ds, "devices", devices_changed_cb, | |
845 zfsvfs) == 0); | |
846 | |
847 VERIFY(dsl_prop_unregister(ds, "setuid", setuid_changed_cb, | |
848 zfsvfs) == 0); | |
849 | |
850 VERIFY(dsl_prop_unregister(ds, "exec", exec_changed_cb, | |
851 zfsvfs) == 0); | |
852 | |
853 VERIFY(dsl_prop_unregister(ds, "snapdir", snapdir_changed_cb, | |
854 zfsvfs) == 0); | |
855 | |
856 VERIFY(dsl_prop_unregister(ds, "aclmode", acl_mode_changed_cb, | |
857 zfsvfs) == 0); | |
858 | |
859 VERIFY(dsl_prop_unregister(ds, "aclinherit", | |
860 acl_inherit_changed_cb, zfsvfs) == 0); | |
5331 | 861 |
862 VERIFY(dsl_prop_unregister(ds, "vscan", | |
863 vscan_changed_cb, zfsvfs) == 0); | |
1544 | 864 } |
865 } | |
866 | |
3912 | 867 /* |
868 * Convert a decimal digit string to a uint64_t integer. | |
869 */ | |
870 static int | |
871 str_to_uint64(char *str, uint64_t *objnum) | |
872 { | |
873 uint64_t num = 0; | |
874 | |
875 while (*str) { | |
876 if (*str < '0' || *str > '9') | |
877 return (EINVAL); | |
878 | |
879 num = num*10 + *str++ - '0'; | |
880 } | |
881 | |
882 *objnum = num; | |
883 return (0); | |
884 } | |
885 | |
886 /* | |
887 * The boot path passed from the boot loader is in the form of | |
888 * "rootpool-name/root-filesystem-object-number'. Convert this | |
889 * string to a dataset name: "rootpool-name/root-filesystem-name". | |
890 */ | |
891 static int | |
892 parse_bootpath(char *bpath, char *outpath) | |
893 { | |
894 char *slashp; | |
895 uint64_t objnum; | |
896 int error; | |
897 | |
898 if (*bpath == 0 || *bpath == '/') | |
899 return (EINVAL); | |
900 | |
901 slashp = strchr(bpath, '/'); | |
902 | |
903 /* if no '/', just return the pool name */ | |
904 if (slashp == NULL) { | |
905 (void) strcpy(outpath, bpath); | |
906 return (0); | |
907 } | |
908 | |
909 if (error = str_to_uint64(slashp+1, &objnum)) | |
910 return (error); | |
911 | |
912 *slashp = '\0'; | |
913 error = dsl_dsobj_to_dsname(bpath, objnum, outpath); | |
914 *slashp = '/'; | |
915 | |
916 return (error); | |
917 } | |
918 | |
1544 | 919 static int |
920 zfs_mountroot(vfs_t *vfsp, enum whymountroot why) | |
921 { | |
922 int error = 0; | |
923 int ret = 0; | |
924 static int zfsrootdone = 0; | |
925 zfsvfs_t *zfsvfs = NULL; | |
926 znode_t *zp = NULL; | |
927 vnode_t *vp = NULL; | |
3912 | 928 char *zfs_bootpath; |
1544 | 929 |
930 ASSERT(vfsp); | |
931 | |
932 /* | |
3912 | 933 * The filesystem that we mount as root is defined in the |
934 * "zfs-bootfs" property. | |
1544 | 935 */ |
936 if (why == ROOT_INIT) { | |
937 if (zfsrootdone++) | |
938 return (EBUSY); | |
939 | |
3912 | 940 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), |
941 DDI_PROP_DONTPASS, "zfs-bootfs", &zfs_bootpath) != | |
942 DDI_SUCCESS) | |
943 return (EIO); | |
944 | |
945 error = parse_bootpath(zfs_bootpath, rootfs.bo_name); | |
946 ddi_prop_free(zfs_bootpath); | |
947 | |
948 if (error) | |
949 return (error); | |
1544 | 950 |
951 if (error = vfs_lock(vfsp)) | |
952 return (error); | |
953 | |
3912 | 954 if (error = zfs_domount(vfsp, rootfs.bo_name, CRED())) |
1544 | 955 goto out; |
956 | |
957 zfsvfs = (zfsvfs_t *)vfsp->vfs_data; | |
958 ASSERT(zfsvfs); | |
959 if (error = zfs_zget(zfsvfs, zfsvfs->z_root, &zp)) | |
960 goto out; | |
961 | |
962 vp = ZTOV(zp); | |
963 mutex_enter(&vp->v_lock); | |
964 vp->v_flag |= VROOT; | |
965 mutex_exit(&vp->v_lock); | |
966 rootvp = vp; | |
967 | |
968 /* | |
969 * The zfs_zget call above returns with a hold on vp, we release | |
970 * it here. | |
971 */ | |
972 VN_RELE(vp); | |
973 | |
974 /* | |
975 * Mount root as readonly initially, it will be remouted | |
976 * read/write by /lib/svc/method/fs-usr. | |
977 */ | |
978 readonly_changed_cb(vfsp->vfs_data, B_TRUE); | |
979 vfs_add((struct vnode *)0, vfsp, | |
980 (vfsp->vfs_flag & VFS_RDONLY) ? MS_RDONLY : 0); | |
981 out: | |
982 vfs_unlock(vfsp); | |
983 ret = (error) ? error : 0; | |
984 return (ret); | |
985 } else if (why == ROOT_REMOUNT) { | |
986 readonly_changed_cb(vfsp->vfs_data, B_FALSE); | |
987 vfsp->vfs_flag |= VFS_REMOUNT; | |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
988 |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
989 /* refresh mount options */ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
990 zfs_unregister_callbacks(vfsp->vfs_data); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
991 return (zfs_register_callbacks(vfsp)); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
992 |
1544 | 993 } else if (why == ROOT_UNMOUNT) { |
994 zfs_unregister_callbacks((zfsvfs_t *)vfsp->vfs_data); | |
995 (void) zfs_sync(vfsp, 0, 0); | |
996 return (0); | |
997 } | |
998 | |
999 /* | |
1000 * if "why" is equal to anything else other than ROOT_INIT, | |
1001 * ROOT_REMOUNT, or ROOT_UNMOUNT, we do not support it. | |
1002 */ | |
1003 return (ENOTSUP); | |
1004 } | |
1005 | |
789 | 1006 /*ARGSUSED*/ |
1007 static int | |
1008 zfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr) | |
1009 { | |
1010 char *osname; | |
1011 pathname_t spn; | |
1012 int error = 0; | |
1013 uio_seg_t fromspace = (uap->flags & MS_SYSSPACE) ? | |
3912 | 1014 UIO_SYSSPACE : UIO_USERSPACE; |
789 | 1015 int canwrite; |
1016 | |
1017 if (mvp->v_type != VDIR) | |
1018 return (ENOTDIR); | |
1019 | |
1020 mutex_enter(&mvp->v_lock); | |
1021 if ((uap->flags & MS_REMOUNT) == 0 && | |
1022 (uap->flags & MS_OVERLAY) == 0 && | |
1023 (mvp->v_count != 1 || (mvp->v_flag & VROOT))) { | |
1024 mutex_exit(&mvp->v_lock); | |
1025 return (EBUSY); | |
1026 } | |
1027 mutex_exit(&mvp->v_lock); | |
1028 | |
1029 /* | |
1030 * ZFS does not support passing unparsed data in via MS_DATA. | |
1031 * Users should use the MS_OPTIONSTR interface; this means | |
1032 * that all option parsing is already done and the options struct | |
1033 * can be interrogated. | |
1034 */ | |
1035 if ((uap->flags & MS_DATA) && uap->datalen > 0) | |
1036 return (EINVAL); | |
1037 | |
1038 /* | |
1039 * Get the objset name (the "special" mount argument). | |
1040 */ | |
1041 if (error = pn_get(uap->spec, fromspace, &spn)) | |
1042 return (error); | |
1043 | |
1044 osname = spn.pn_path; | |
1045 | |
4543 | 1046 /* |
1047 * Check for mount privilege? | |
1048 * | |
1049 * If we don't have privilege then see if | |
1050 * we have local permission to allow it | |
1051 */ | |
1052 error = secpolicy_fs_mount(cr, mvp, vfsp); | |
1053 if (error) { | |
1054 error = dsl_deleg_access(osname, ZFS_DELEG_PERM_MOUNT, cr); | |
1055 if (error == 0) { | |
1056 vattr_t vattr; | |
1057 | |
1058 /* | |
1059 * Make sure user is the owner of the mount point | |
1060 * or has sufficient privileges. | |
1061 */ | |
1062 | |
1063 vattr.va_mask = AT_UID; | |
1064 | |
5331 | 1065 if (error = VOP_GETATTR(mvp, &vattr, 0, cr, NULL)) { |
4543 | 1066 goto out; |
1067 } | |
1068 | |
1069 if (error = secpolicy_vnode_owner(cr, vattr.va_uid)) { | |
1070 goto out; | |
1071 } | |
1072 | |
5331 | 1073 if (error = VOP_ACCESS(mvp, VWRITE, 0, cr, NULL)) { |
4543 | 1074 goto out; |
1075 } | |
1076 | |
1077 secpolicy_fs_mount_clearopts(cr, vfsp); | |
1078 } else { | |
1079 goto out; | |
1080 } | |
1081 } | |
789 | 1082 |
1083 /* | |
1084 * Refuse to mount a filesystem if we are in a local zone and the | |
1085 * dataset is not visible. | |
1086 */ | |
1087 if (!INGLOBALZONE(curproc) && | |
1088 (!zone_dataset_visible(osname, &canwrite) || !canwrite)) { | |
1089 error = EPERM; | |
1090 goto out; | |
1091 } | |
1092 | |
4596
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1093 /* |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1094 * When doing a remount, we simply refresh our temporary properties |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1095 * according to those options set in the current VFS options. |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1096 */ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1097 if (uap->flags & MS_REMOUNT) { |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1098 /* refresh mount options */ |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1099 zfs_unregister_callbacks(vfsp->vfs_data); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1100 error = zfs_register_callbacks(vfsp); |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1101 goto out; |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1102 } |
3aa6e3b5dfca
6561658 xattrs aren't enabled on zfs root filesystem, weirdness with mount output
lling
parents:
4577
diff
changeset
|
1103 |
1544 | 1104 error = zfs_domount(vfsp, osname, cr); |
789 | 1105 |
1106 out: | |
1107 pn_free(&spn); | |
1108 return (error); | |
1109 } | |
1110 | |
1111 static int | |
1112 zfs_statvfs(vfs_t *vfsp, struct statvfs64 *statp) | |
1113 { | |
1114 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
1115 dev32_t d32; | |
2885 | 1116 uint64_t refdbytes, availbytes, usedobjs, availobjs; |
789 | 1117 |
1118 ZFS_ENTER(zfsvfs); | |
1119 | |
2885 | 1120 dmu_objset_space(zfsvfs->z_os, |
1121 &refdbytes, &availbytes, &usedobjs, &availobjs); | |
789 | 1122 |
1123 /* | |
1124 * The underlying storage pool actually uses multiple block sizes. | |
1125 * We report the fragsize as the smallest block size we support, | |
1126 * and we report our blocksize as the filesystem's maximum blocksize. | |
1127 */ | |
1128 statp->f_frsize = 1UL << SPA_MINBLOCKSHIFT; | |
1129 statp->f_bsize = zfsvfs->z_max_blksz; | |
1130 | |
1131 /* | |
1132 * The following report "total" blocks of various kinds in the | |
1133 * file system, but reported in terms of f_frsize - the | |
1134 * "fragment" size. | |
1135 */ | |
1136 | |
2885 | 1137 statp->f_blocks = (refdbytes + availbytes) >> SPA_MINBLOCKSHIFT; |
1138 statp->f_bfree = availbytes >> SPA_MINBLOCKSHIFT; | |
789 | 1139 statp->f_bavail = statp->f_bfree; /* no root reservation */ |
1140 | |
1141 /* | |
1142 * statvfs() should really be called statufs(), because it assumes | |
1143 * static metadata. ZFS doesn't preallocate files, so the best | |
1144 * we can do is report the max that could possibly fit in f_files, | |
1145 * and that minus the number actually used in f_ffree. | |
1146 * For f_ffree, report the smaller of the number of object available | |
1147 * and the number of blocks (each object will take at least a block). | |
1148 */ | |
2885 | 1149 statp->f_ffree = MIN(availobjs, statp->f_bfree); |
789 | 1150 statp->f_favail = statp->f_ffree; /* no "root reservation" */ |
2885 | 1151 statp->f_files = statp->f_ffree + usedobjs; |
789 | 1152 |
1153 (void) cmpldev(&d32, vfsp->vfs_dev); | |
1154 statp->f_fsid = d32; | |
1155 | |
1156 /* | |
1157 * We're a zfs filesystem. | |
1158 */ | |
1159 (void) strcpy(statp->f_basetype, vfssw[vfsp->vfs_fstype].vsw_name); | |
1160 | |
1123
02a0390fbc7d
6363529 UNIX03/UNIX98 *vsx* CAPI.os/files/fstatvfs/T.fstatvfs 11 FAILS
marks
parents:
849
diff
changeset
|
1161 statp->f_flag = vf_to_stf(vfsp->vfs_flag); |
789 | 1162 |
1163 statp->f_namemax = ZFS_MAXNAMELEN; | |
1164 | |
1165 /* | |
1166 * We have all of 32 characters to stuff a string here. | |
1167 * Is there anything useful we could/should provide? | |
1168 */ | |
1169 bzero(statp->f_fstr, sizeof (statp->f_fstr)); | |
1170 | |
1171 ZFS_EXIT(zfsvfs); | |
1172 return (0); | |
1173 } | |
1174 | |
1175 static int | |
1176 zfs_root(vfs_t *vfsp, vnode_t **vpp) | |
1177 { | |
1178 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
1179 znode_t *rootzp; | |
1180 int error; | |
1181 | |
1182 ZFS_ENTER(zfsvfs); | |
1183 | |
1184 error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp); | |
1185 if (error == 0) | |
1186 *vpp = ZTOV(rootzp); | |
1187 | |
1188 ZFS_EXIT(zfsvfs); | |
1189 return (error); | |
1190 } | |
1191 | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1192 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1193 * Teardown the zfsvfs::z_os. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1194 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1195 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock' |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1196 * and 'z_teardown_inactive_lock' held. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1197 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1198 static int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1199 zfsvfs_teardown(zfsvfs_t *zfsvfs, boolean_t unmounting) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1200 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1201 objset_t *os = zfsvfs->z_os; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1202 znode_t *zp, *nextzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1203 znode_t markerzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1204 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1205 rrw_enter(&zfsvfs->z_teardown_lock, RW_WRITER, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1206 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1207 if (!unmounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1208 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1209 * We purge the parent filesystem's vfsp as the parent |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1210 * filesystem and all of its snapshots have their vnode's |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1211 * v_vfsp set to the parent's filesystem's vfsp. Note, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1212 * 'z_parent' is self referential for non-snapshots. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1213 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1214 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1215 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1216 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1217 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1218 * Close the zil. NB: Can't close the zil while zfs_inactive |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1219 * threads are blocked as zil_close can call zfs_inactive. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1220 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1221 if (zfsvfs->z_log) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1222 zil_close(zfsvfs->z_log); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1223 zfsvfs->z_log = NULL; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1224 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1225 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1226 rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_WRITER); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1227 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1228 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1229 * If we are not unmounting (ie: online recv) and someone already |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1230 * unmounted this file system while we were doing the switcheroo, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1231 * or a reopen of z_os failed then just bail out now. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1232 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1233 if (!unmounting && (zfsvfs->z_unmounted || zfsvfs->z_os == NULL)) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1234 rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1235 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1236 return (EIO); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1237 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1238 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1239 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1240 * At this point there are no vops active, and any new vops will |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1241 * fail with EIO since we have z_teardown_lock for writer (only |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1242 * relavent for forced unmount). |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1243 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1244 * Release all holds on dbufs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1245 * Note, the dmu can still callback via znode_pageout_func() |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1246 * which can zfs_znode_free() the znode. So we lock |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1247 * z_all_znodes; search the list for a held dbuf; drop the lock |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1248 * (we know zp can't disappear if we hold a dbuf lock) then |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1249 * regrab the lock and restart. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1250 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1251 * Since we have to restart the search after finding each held dbuf, |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1252 * we do two things to speed up searching: we insert a dummy znode |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1253 * ('markerzp') to detect the original tail of the list, and move |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1254 * non-held znodes to the end of the list. Once we hit 'markerzp', |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1255 * we know we've looked at each znode and can break out. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1256 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1257 mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1258 list_insert_tail(&zfsvfs->z_all_znodes, &markerzp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1259 for (zp = list_head(&zfsvfs->z_all_znodes); zp != &markerzp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1260 zp = nextzp) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1261 nextzp = list_next(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1262 if (zp->z_dbuf_held) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1263 /* dbufs should only be held when force unmounting */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1264 zp->z_dbuf_held = 0; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1265 mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1266 dmu_buf_rele(zp->z_dbuf, NULL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1267 /* Start again */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1268 mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1269 nextzp = list_head(&zfsvfs->z_all_znodes); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1270 } else { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1271 list_remove(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1272 list_insert_tail(&zfsvfs->z_all_znodes, zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1273 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1274 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1275 list_remove(&zfsvfs->z_all_znodes, &markerzp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1276 mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1277 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1278 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1279 * If we are unmounting, set the unmounted flag and let new vops |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1280 * unblock. zfs_inactive will have the unmounted behavior, and all |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1281 * other vops will fail with EIO. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1282 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1283 if (unmounting) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1284 zfsvfs->z_unmounted = B_TRUE; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1285 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1286 rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1287 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1288 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1289 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1290 * z_os will be NULL if there was an error in attempting to reopen |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1291 * zfsvfs, so just return as the properties had already been |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1292 * unregistered and cached data had been evicted before. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1293 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1294 if (zfsvfs->z_os == NULL) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1295 return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1296 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1297 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1298 * Unregister properties. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1299 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1300 zfs_unregister_callbacks(zfsvfs); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1301 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1302 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1303 * Evict cached data |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1304 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1305 (void) dmu_objset_evict_dbufs(os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1306 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1307 return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1308 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1309 |
789 | 1310 /*ARGSUSED*/ |
1311 static int | |
1312 zfs_umount(vfs_t *vfsp, int fflag, cred_t *cr) | |
1313 { | |
1314 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1315 objset_t *os; |
789 | 1316 int ret; |
1317 | |
4543 | 1318 ret = secpolicy_fs_unmount(cr, vfsp); |
1319 if (ret) { | |
1320 ret = dsl_deleg_access((char *)refstr_value(vfsp->vfs_resource), | |
1321 ZFS_DELEG_PERM_MOUNT, cr); | |
1322 if (ret) | |
1323 return (ret); | |
1324 } | |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
1325 |
4736
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1326 /* |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1327 * We purge the parent filesystem's vfsp as the parent filesystem |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1328 * and all of its snapshots have their vnode's v_vfsp set to the |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1329 * parent's filesystem's vfsp. Note, 'z_parent' is self |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1330 * referential for non-snapshots. |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1331 */ |
f8714efb3e12
6509628 unmount of a snapshot (from 'zfs destroy') is slow
ek110237
parents:
4614
diff
changeset
|
1332 (void) dnlc_purge_vfsp(zfsvfs->z_parent->z_vfs, 0); |
1484
d330e98f8ed7
6350001 ZFS lookup performance still much slower than UFS : help tar : help spec SFS
ek110237
parents:
1298
diff
changeset
|
1333 |
789 | 1334 /* |
1335 * Unmount any snapshots mounted under .zfs before unmounting the | |
1336 * dataset itself. | |
1337 */ | |
1338 if (zfsvfs->z_ctldir != NULL && | |
4543 | 1339 (ret = zfsctl_umount_snapshots(vfsp, fflag, cr)) != 0) { |
789 | 1340 return (ret); |
4543 | 1341 } |
789 | 1342 |
4787 | 1343 if (!(fflag & MS_FORCE)) { |
4480
0976678e58c5
6544140 assertion failed: err == 0 (0x11 == 0x0), file: ../../common/fs/zfs/zfs_znode.c, line: 555
gw25295
parents:
3912
diff
changeset
|
1344 /* |
4787 | 1345 * Check the number of active vnodes in the file system. |
1346 * Our count is maintained in the vfs structure, but the | |
1347 * number is off by 1 to indicate a hold on the vfs | |
1348 * structure itself. | |
1349 * | |
1350 * The '.zfs' directory maintains a reference of its | |
1351 * own, and any active references underneath are | |
1352 * reflected in the vnode count. | |
789 | 1353 */ |
4787 | 1354 if (zfsvfs->z_ctldir == NULL) { |
1355 if (vfsp->vfs_count > 1) | |
1356 return (EBUSY); | |
1357 } else { | |
1358 if (vfsp->vfs_count > 2 || | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1359 zfsvfs->z_ctldir->v_count > 1) |
4787 | 1360 return (EBUSY); |
789 | 1361 } |
1362 } | |
1363 | |
1364 vfsp->vfs_flag |= VFS_UNMOUNTED; | |
4787 | 1365 |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1366 VERIFY(zfsvfs_teardown(zfsvfs, B_TRUE) == 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1367 os = zfsvfs->z_os; |
4787 | 1368 |
1369 /* | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1370 * z_os will be NULL if there was an error in |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1371 * attempting to reopen zfsvfs. |
4787 | 1372 */ |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1373 if (os != NULL) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1374 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1375 * Unset the objset user_ptr. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1376 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1377 mutex_enter(&os->os->os_user_ptr_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1378 dmu_objset_set_user(os, NULL); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1379 mutex_exit(&os->os->os_user_ptr_lock); |
4787 | 1380 |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1381 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1382 * Finally close the objset |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1383 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1384 dmu_objset_close(os); |
4787 | 1385 } |
1386 | |
1387 /* | |
1388 * We can now safely destroy the '.zfs' directory node. | |
1389 */ | |
1390 if (zfsvfs->z_ctldir != NULL) | |
1391 zfsctl_destroy(zfsvfs); | |
789 | 1392 |
1393 return (0); | |
1394 } | |
1395 | |
1396 static int | |
1397 zfs_vget(vfs_t *vfsp, vnode_t **vpp, fid_t *fidp) | |
1398 { | |
1399 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
1400 znode_t *zp; | |
1401 uint64_t object = 0; | |
1402 uint64_t fid_gen = 0; | |
1403 uint64_t gen_mask; | |
1404 uint64_t zp_gen; | |
1405 int i, err; | |
1406 | |
1407 *vpp = NULL; | |
1408 | |
1409 ZFS_ENTER(zfsvfs); | |
1410 | |
1411 if (fidp->fid_len == LONG_FID_LEN) { | |
1412 zfid_long_t *zlfid = (zfid_long_t *)fidp; | |
1413 uint64_t objsetid = 0; | |
1414 uint64_t setgen = 0; | |
1415 | |
1416 for (i = 0; i < sizeof (zlfid->zf_setid); i++) | |
1417 objsetid |= ((uint64_t)zlfid->zf_setid[i]) << (8 * i); | |
1418 | |
1419 for (i = 0; i < sizeof (zlfid->zf_setgen); i++) | |
1420 setgen |= ((uint64_t)zlfid->zf_setgen[i]) << (8 * i); | |
1421 | |
1422 ZFS_EXIT(zfsvfs); | |
1423 | |
1424 err = zfsctl_lookup_objset(vfsp, objsetid, &zfsvfs); | |
1425 if (err) | |
1426 return (EINVAL); | |
1427 ZFS_ENTER(zfsvfs); | |
1428 } | |
1429 | |
1430 if (fidp->fid_len == SHORT_FID_LEN || fidp->fid_len == LONG_FID_LEN) { | |
1431 zfid_short_t *zfid = (zfid_short_t *)fidp; | |
1432 | |
1433 for (i = 0; i < sizeof (zfid->zf_object); i++) | |
1434 object |= ((uint64_t)zfid->zf_object[i]) << (8 * i); | |
1435 | |
1436 for (i = 0; i < sizeof (zfid->zf_gen); i++) | |
1437 fid_gen |= ((uint64_t)zfid->zf_gen[i]) << (8 * i); | |
1438 } else { | |
1439 ZFS_EXIT(zfsvfs); | |
1440 return (EINVAL); | |
1441 } | |
1442 | |
1443 /* A zero fid_gen means we are in the .zfs control directories */ | |
1444 if (fid_gen == 0 && | |
1445 (object == ZFSCTL_INO_ROOT || object == ZFSCTL_INO_SNAPDIR)) { | |
1446 *vpp = zfsvfs->z_ctldir; | |
1447 ASSERT(*vpp != NULL); | |
1448 if (object == ZFSCTL_INO_SNAPDIR) { | |
1449 VERIFY(zfsctl_root_lookup(*vpp, "snapshot", vpp, NULL, | |
5331 | 1450 0, NULL, NULL, NULL, NULL, NULL) == 0); |
789 | 1451 } else { |
1452 VN_HOLD(*vpp); | |
1453 } | |
1454 ZFS_EXIT(zfsvfs); | |
1455 return (0); | |
1456 } | |
1457 | |
1458 gen_mask = -1ULL >> (64 - 8 * i); | |
1459 | |
1460 dprintf("getting %llu [%u mask %llx]\n", object, fid_gen, gen_mask); | |
1461 if (err = zfs_zget(zfsvfs, object, &zp)) { | |
1462 ZFS_EXIT(zfsvfs); | |
1463 return (err); | |
1464 } | |
1465 zp_gen = zp->z_phys->zp_gen & gen_mask; | |
1466 if (zp_gen == 0) | |
1467 zp_gen = 1; | |
3461 | 1468 if (zp->z_unlinked || zp_gen != fid_gen) { |
789 | 1469 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen, fid_gen); |
1470 VN_RELE(ZTOV(zp)); | |
1471 ZFS_EXIT(zfsvfs); | |
1472 return (EINVAL); | |
1473 } | |
1474 | |
1475 *vpp = ZTOV(zp); | |
1476 ZFS_EXIT(zfsvfs); | |
1477 return (0); | |
1478 } | |
1479 | |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1480 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1481 * Block out VOPs and close zfsvfs_t::z_os |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1482 * |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1483 * Note, if successful, then we return with the 'z_teardown_lock' and |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1484 * 'z_teardown_inactive_lock' write held. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1485 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1486 int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1487 zfs_suspend_fs(zfsvfs_t *zfsvfs, char *name, int *mode) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1488 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1489 int error; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1490 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1491 if ((error = zfsvfs_teardown(zfsvfs, B_FALSE)) != 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1492 return (error); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1493 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1494 *mode = zfsvfs->z_os->os_mode; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1495 dmu_objset_name(zfsvfs->z_os, name); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1496 dmu_objset_close(zfsvfs->z_os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1497 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1498 return (0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1499 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1500 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1501 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1502 * Reopen zfsvfs_t::z_os and release VOPs. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1503 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1504 int |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1505 zfs_resume_fs(zfsvfs_t *zfsvfs, const char *osname, int mode) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1506 { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1507 int err; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1508 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1509 ASSERT(RRW_WRITE_HELD(&zfsvfs->z_teardown_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1510 ASSERT(RW_WRITE_HELD(&zfsvfs->z_teardown_inactive_lock)); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1511 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1512 err = dmu_objset_open(osname, DMU_OST_ZFS, mode, &zfsvfs->z_os); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1513 if (err) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1514 zfsvfs->z_os = NULL; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1515 } else { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1516 znode_t *zp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1517 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1518 VERIFY(zfsvfs_setup(zfsvfs, B_FALSE) == 0); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1519 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1520 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1521 * Attempt to re-establish all the active znodes with |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1522 * their dbufs. If a zfs_rezget() fails, then we'll let |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1523 * any potential callers discover that via ZFS_ENTER_VERIFY_VP |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1524 * when they try to use their znode. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1525 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1526 mutex_enter(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1527 for (zp = list_head(&zfsvfs->z_all_znodes); zp; |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1528 zp = list_next(&zfsvfs->z_all_znodes, zp)) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1529 ASSERT(!zp->z_dbuf_held); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1530 (void) zfs_rezget(zp); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1531 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1532 mutex_exit(&zfsvfs->z_znodes_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1533 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1534 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1535 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1536 /* release the VOPs */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1537 rw_exit(&zfsvfs->z_teardown_inactive_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1538 rrw_exit(&zfsvfs->z_teardown_lock, FTAG); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1539 |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1540 if (err) { |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1541 /* |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1542 * Since we couldn't reopen zfsvfs::z_os, force |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1543 * unmount this file system. |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1544 */ |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1545 if (vn_vfswlock(zfsvfs->z_vfs->vfs_vnodecovered) == 0) |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1546 (void) dounmount(zfsvfs->z_vfs, MS_FORCE, CRED()); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1547 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1548 return (err); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1549 } |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1550 |
789 | 1551 static void |
1552 zfs_freevfs(vfs_t *vfsp) | |
1553 { | |
1554 zfsvfs_t *zfsvfs = vfsp->vfs_data; | |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1555 int i; |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1556 |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1557 for (i = 0; i != ZFS_OBJ_MTX_SZ; i++) |
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1558 mutex_destroy(&zfsvfs->z_hold_mtx[i]); |
789 | 1559 |
4787 | 1560 mutex_destroy(&zfsvfs->z_znodes_lock); |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4787
diff
changeset
|
1561 list_destroy(&zfsvfs->z_all_znodes); |
5326
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1562 rrw_destroy(&zfsvfs->z_teardown_lock); |
6752aa2bd5bc
6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents:
5147
diff
changeset
|
1563 rw_destroy(&zfsvfs->z_teardown_inactive_lock); |
5331 | 1564 zfs_fuid_destroy(zfsvfs); |
789 | 1565 kmem_free(zfsvfs, sizeof (zfsvfs_t)); |
1566 | |
1567 atomic_add_32(&zfs_active_fs_count, -1); | |
1568 } | |
1569 | |
1570 /* | |
1571 * VFS_INIT() initialization. Note that there is no VFS_FINI(), | |
1572 * so we can't safely do any non-idempotent initialization here. | |
1573 * Leave that to zfs_init() and zfs_fini(), which are called | |
1574 * from the module's _init() and _fini() entry points. | |
1575 */ | |
1576 /*ARGSUSED*/ | |
1577 static int | |
1578 zfs_vfsinit(int fstype, char *name) | |
1579 { | |
1580 int error; | |
1581 | |
1582 zfsfstype = fstype; | |
1583 | |
1584 /* | |
1585 * Setup vfsops and vnodeops tables. | |
1586 */ | |
1587 error = vfs_setfsops(fstype, zfs_vfsops_template, &zfs_vfsops); | |
1588 if (error != 0) { | |
1589 cmn_err(CE_WARN, "zfs: bad vfs ops template"); | |
1590 } | |
1591 | |
1592 error = zfs_create_op_tables(); | |
1593 if (error) { | |
1594 zfs_remove_op_tables(); | |
1595 cmn_err(CE_WARN, "zfs: bad vnode ops template"); | |
1596 (void) vfs_freevfsops_by_type(zfsfstype); | |
1597 return (error); | |
1598 } | |
1599 | |
1600 mutex_init(&zfs_dev_mtx, NULL, MUTEX_DEFAULT, NULL); | |
1601 | |
1602 /* | |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1603 * Unique major number for all zfs mounts. |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1604 * If we run out of 32-bit minors, we'll getudev() another major. |
789 | 1605 */ |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1606 zfs_major = ddi_name_to_major(ZFS_DRIVER); |
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
1607 zfs_minor = ZFS_MIN_MINOR; |
789 | 1608 |
1609 return (0); | |
1610 } | |
1611 | |
1612 void | |
1613 zfs_init(void) | |
1614 { | |
1615 /* | |
1616 * Initialize .zfs directory structures | |
1617 */ | |
1618 zfsctl_init(); | |
1619 | |
1620 /* | |
1621 * Initialize znode cache, vnode ops, etc... | |
1622 */ | |
1623 zfs_znode_init(); | |
1624 } | |
1625 | |
1626 void | |
1627 zfs_fini(void) | |
1628 { | |
1629 zfsctl_fini(); | |
1630 zfs_znode_fini(); | |
1631 } | |
1632 | |
1633 int | |
1634 zfs_busy(void) | |
1635 { | |
1636 return (zfs_active_fs_count != 0); | |
1637 } | |
1638 | |
4577 | 1639 int |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
4944
diff
changeset
|
1640 zfs_get_version(objset_t *os, uint64_t *version) |
4577 | 1641 { |
1642 int error; | |
1643 | |
5147
5e950ccc9585
6596190 "zfs list" is slow due to version property
rm160521
parents:
4944
diff
changeset
|
1644 error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 8, 1, version); |
4577 | 1645 return (error); |
1646 } | |
1647 | |
1648 int | |
1649 zfs_set_version(const char *name, uint64_t newvers) | |
1650 { | |
1651 int error; | |
1652 objset_t *os; | |
1653 dmu_tx_t *tx; | |
1654 uint64_t curvers; | |
1655 | |
1656 /* | |
1657 * XXX for now, require that the filesystem be unmounted. Would | |
1658 * be nice to find the zfsvfs_t and just update that if | |
1659 * possible. | |
1660 */ | |
1661 | |
1662 if (newvers < ZPL_VERSION_INITIAL || newvers > ZPL_VERSION) | |
1663 return (EINVAL); | |
1664 | |
1665 error = dmu_objset_open(name, DMU_OST_ZFS, DS_MODE_PRIMARY, &os); | |
1666 if (error) | |
1667 return (error); | |
1668 | |
1669 error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, | |
1670 8, 1, &curvers); | |
1671 if (error) | |
1672 goto out; | |
1673 if (newvers < curvers) { | |
1674 error = EINVAL; | |
1675 goto out; | |
1676 } | |
1677 | |
1678 tx = dmu_tx_create(os); | |
1679 dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, 0, ZPL_VERSION_STR); | |
1680 error = dmu_tx_assign(tx, TXG_WAIT); | |
1681 if (error) { | |
1682 dmu_tx_abort(tx); | |
1683 goto out; | |
1684 } | |
1685 error = zap_update(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 8, 1, | |
1686 &newvers, tx); | |
1687 | |
1688 spa_history_internal_log(LOG_DS_UPGRADE, | |
1689 dmu_objset_spa(os), tx, CRED(), | |
1690 "oldver=%llu newver=%llu dataset = %llu", curvers, newvers, | |
1691 dmu_objset_id(os)); | |
1692 dmu_tx_commit(tx); | |
1693 | |
1694 out: | |
1695 dmu_objset_close(os); | |
1696 return (error); | |
1697 } | |
1698 | |
789 | 1699 static vfsdef_t vfw = { |
1700 VFSDEF_VERSION, | |
1701 MNTTYPE_ZFS, | |
1702 zfs_vfsinit, | |
5331 | 1703 VSW_HASPROTO|VSW_CANRWRO|VSW_CANREMOUNT|VSW_VOLATILEDEV|VSW_STATS| |
1704 VSW_XID, | |
789 | 1705 &zfs_mntopts |
1706 }; | |
1707 | |
1708 struct modlfs zfs_modlfs = { | |
4577 | 1709 &mod_fsops, "ZFS filesystem version " SPA_VERSION_STRING, &vfw |
789 | 1710 }; |