4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24 * Copyright (c) 2014 Integros [integros.com]
25 * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
28 /* Portions Copyright 2010 Robert Milkowski */
30 #include <sys/types.h>
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/sysmacros.h>
35 #include <sys/pathname.h>
36 #include <sys/vnode.h>
38 #include <sys/vfs_opreg.h>
39 #include <sys/mntent.h>
40 #include <sys/mount.h>
41 #include <sys/cmn_err.h>
42 #include "fs/fs_subr.h"
43 #include <sys/zfs_znode.h>
44 #include <sys/zfs_dir.h>
46 #include <sys/fs/zfs.h>
48 #include <sys/dsl_prop.h>
49 #include <sys/dsl_dataset.h>
50 #include <sys/dsl_deleg.h>
54 #include <sys/sa_impl.h>
55 #include <sys/varargs.h>
56 #include <sys/policy.h>
57 #include <sys/atomic.h>
58 #include <sys/mkdev.h>
59 #include <sys/modctl.h>
60 #include <sys/refstr.h>
61 #include <sys/zfs_ioctl.h>
62 #include <sys/zfs_ctldir.h>
63 #include <sys/zfs_fuid.h>
64 #include <sys/bootconf.h>
65 #include <sys/sunddi.h>
67 #include <sys/dmu_objset.h>
68 #include <sys/spa_boot.h>
69 #include "zfs_comutil.h"
72 vfsops_t
*zfs_vfsops
= NULL
;
73 static major_t zfs_major
;
74 static minor_t zfs_minor
;
75 static kmutex_t zfs_dev_mtx
;
77 extern int sys_shutdown
;
79 static int zfs_mount(vfs_t
*vfsp
, vnode_t
*mvp
, struct mounta
*uap
, cred_t
*cr
);
80 static int zfs_umount(vfs_t
*vfsp
, int fflag
, cred_t
*cr
);
81 static int zfs_mountroot(vfs_t
*vfsp
, enum whymountroot
);
82 static int zfs_root(vfs_t
*vfsp
, vnode_t
**vpp
);
83 static int zfs_statvfs(vfs_t
*vfsp
, struct statvfs64
*statp
);
84 static int zfs_vget(vfs_t
*vfsp
, vnode_t
**vpp
, fid_t
*fidp
);
85 static void zfs_freevfs(vfs_t
*vfsp
);
87 static const fs_operation_def_t zfs_vfsops_template
[] = {
88 VFSNAME_MOUNT
, { .vfs_mount
= zfs_mount
},
89 VFSNAME_MOUNTROOT
, { .vfs_mountroot
= zfs_mountroot
},
90 VFSNAME_UNMOUNT
, { .vfs_unmount
= zfs_umount
},
91 VFSNAME_ROOT
, { .vfs_root
= zfs_root
},
92 VFSNAME_STATVFS
, { .vfs_statvfs
= zfs_statvfs
},
93 VFSNAME_SYNC
, { .vfs_sync
= zfs_sync
},
94 VFSNAME_VGET
, { .vfs_vget
= zfs_vget
},
95 VFSNAME_FREEVFS
, { .vfs_freevfs
= zfs_freevfs
},
100 * We need to keep a count of active fs's.
101 * This is necessary to prevent our module
102 * from being unloaded after a umount -f
104 static uint32_t zfs_active_fs_count
= 0;
106 static char *noatime_cancel
[] = { MNTOPT_ATIME
, NULL
};
107 static char *atime_cancel
[] = { MNTOPT_NOATIME
, NULL
};
108 static char *noxattr_cancel
[] = { MNTOPT_XATTR
, NULL
};
109 static char *xattr_cancel
[] = { MNTOPT_NOXATTR
, NULL
};
112 * MO_DEFAULT is not used since the default value is determined
113 * by the equivalent property.
115 static mntopt_t mntopts
[] = {
116 { MNTOPT_NOXATTR
, noxattr_cancel
, NULL
, 0, NULL
},
117 { MNTOPT_XATTR
, xattr_cancel
, NULL
, 0, NULL
},
118 { MNTOPT_NOATIME
, noatime_cancel
, NULL
, 0, NULL
},
119 { MNTOPT_ATIME
, atime_cancel
, NULL
, 0, NULL
}
122 static mntopts_t zfs_mntopts
= {
123 sizeof (mntopts
) / sizeof (mntopt_t
),
129 zfs_sync(vfs_t
*vfsp
, short flag
, cred_t
*cr
)
132 * Data integrity is job one. We don't want a compromised kernel
133 * writing to the storage pool, so we never sync during panic.
139 * SYNC_ATTR is used by fsflush() to force old filesystems like UFS
140 * to sync metadata, which they would otherwise cache indefinitely.
141 * Semantically, the only requirement is that the sync be initiated.
142 * The DMU syncs out txgs frequently, so there's nothing to do.
144 if (flag
& SYNC_ATTR
)
149 * Sync a specific filesystem.
151 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
155 dp
= dmu_objset_pool(zfsvfs
->z_os
);
158 * If the system is shutting down, then skip any
159 * filesystems which may exist on a suspended pool.
161 if (sys_shutdown
&& spa_suspended(dp
->dp_spa
)) {
166 if (zfsvfs
->z_log
!= NULL
)
167 zil_commit(zfsvfs
->z_log
, 0);
172 * Sync all ZFS filesystems. This is what happens when you
173 * run sync(1M). Unlike other filesystems, ZFS honors the
174 * request by waiting for all pools to commit all dirty data.
183 zfs_create_unique_device(dev_t
*dev
)
188 ASSERT3U(zfs_minor
, <=, MAXMIN32
);
189 minor_t start
= zfs_minor
;
191 mutex_enter(&zfs_dev_mtx
);
192 if (zfs_minor
>= MAXMIN32
) {
194 * If we're still using the real major
195 * keep out of /dev/zfs and /dev/zvol minor
196 * number space. If we're using a getudev()'ed
197 * major number, we can use all of its minors.
199 if (zfs_major
== ddi_name_to_major(ZFS_DRIVER
))
200 zfs_minor
= ZFS_MIN_MINOR
;
206 *dev
= makedevice(zfs_major
, zfs_minor
);
207 mutex_exit(&zfs_dev_mtx
);
208 } while (vfs_devismounted(*dev
) && zfs_minor
!= start
);
209 if (zfs_minor
== start
) {
211 * We are using all ~262,000 minor numbers for the
212 * current major number. Create a new major number.
214 if ((new_major
= getudev()) == (major_t
)-1) {
216 "zfs_mount: Can't get unique major "
220 mutex_enter(&zfs_dev_mtx
);
221 zfs_major
= new_major
;
224 mutex_exit(&zfs_dev_mtx
);
228 /* CONSTANTCONDITION */
235 atime_changed_cb(void *arg
, uint64_t newval
)
237 zfsvfs_t
*zfsvfs
= arg
;
239 if (newval
== TRUE
) {
240 zfsvfs
->z_atime
= TRUE
;
241 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NOATIME
);
242 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_ATIME
, NULL
, 0);
244 zfsvfs
->z_atime
= FALSE
;
245 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_ATIME
);
246 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NOATIME
, NULL
, 0);
251 xattr_changed_cb(void *arg
, uint64_t newval
)
253 zfsvfs_t
*zfsvfs
= arg
;
255 if (newval
== TRUE
) {
256 /* XXX locking on vfs_flag? */
257 zfsvfs
->z_vfs
->vfs_flag
|= VFS_XATTR
;
258 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NOXATTR
);
259 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_XATTR
, NULL
, 0);
261 /* XXX locking on vfs_flag? */
262 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_XATTR
;
263 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_XATTR
);
264 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NOXATTR
, NULL
, 0);
269 blksz_changed_cb(void *arg
, uint64_t newval
)
271 zfsvfs_t
*zfsvfs
= arg
;
272 ASSERT3U(newval
, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs
->z_os
)));
273 ASSERT3U(newval
, >=, SPA_MINBLOCKSIZE
);
274 ASSERT(ISP2(newval
));
276 zfsvfs
->z_max_blksz
= newval
;
277 zfsvfs
->z_vfs
->vfs_bsize
= newval
;
281 readonly_changed_cb(void *arg
, uint64_t newval
)
283 zfsvfs_t
*zfsvfs
= arg
;
286 /* XXX locking on vfs_flag? */
287 zfsvfs
->z_vfs
->vfs_flag
|= VFS_RDONLY
;
288 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_RW
);
289 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_RO
, NULL
, 0);
291 /* XXX locking on vfs_flag? */
292 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_RDONLY
;
293 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_RO
);
294 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_RW
, NULL
, 0);
299 devices_changed_cb(void *arg
, uint64_t newval
)
301 zfsvfs_t
*zfsvfs
= arg
;
303 if (newval
== FALSE
) {
304 zfsvfs
->z_vfs
->vfs_flag
|= VFS_NODEVICES
;
305 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_DEVICES
);
306 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NODEVICES
, NULL
, 0);
308 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_NODEVICES
;
309 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NODEVICES
);
310 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_DEVICES
, NULL
, 0);
315 setuid_changed_cb(void *arg
, uint64_t newval
)
317 zfsvfs_t
*zfsvfs
= arg
;
319 if (newval
== FALSE
) {
320 zfsvfs
->z_vfs
->vfs_flag
|= VFS_NOSETUID
;
321 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_SETUID
);
322 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NOSETUID
, NULL
, 0);
324 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_NOSETUID
;
325 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NOSETUID
);
326 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_SETUID
, NULL
, 0);
331 exec_changed_cb(void *arg
, uint64_t newval
)
333 zfsvfs_t
*zfsvfs
= arg
;
335 if (newval
== FALSE
) {
336 zfsvfs
->z_vfs
->vfs_flag
|= VFS_NOEXEC
;
337 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_EXEC
);
338 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NOEXEC
, NULL
, 0);
340 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_NOEXEC
;
341 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NOEXEC
);
342 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_EXEC
, NULL
, 0);
347 * The nbmand mount option can be changed at mount time.
348 * We can't allow it to be toggled on live file systems or incorrect
349 * behavior may be seen from cifs clients
351 * This property isn't registered via dsl_prop_register(), but this callback
352 * will be called when a file system is first mounted
355 nbmand_changed_cb(void *arg
, uint64_t newval
)
357 zfsvfs_t
*zfsvfs
= arg
;
358 if (newval
== FALSE
) {
359 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NBMAND
);
360 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NONBMAND
, NULL
, 0);
362 vfs_clearmntopt(zfsvfs
->z_vfs
, MNTOPT_NONBMAND
);
363 vfs_setmntopt(zfsvfs
->z_vfs
, MNTOPT_NBMAND
, NULL
, 0);
368 snapdir_changed_cb(void *arg
, uint64_t newval
)
370 zfsvfs_t
*zfsvfs
= arg
;
372 zfsvfs
->z_show_ctldir
= newval
;
376 vscan_changed_cb(void *arg
, uint64_t newval
)
378 zfsvfs_t
*zfsvfs
= arg
;
380 zfsvfs
->z_vscan
= newval
;
384 acl_mode_changed_cb(void *arg
, uint64_t newval
)
386 zfsvfs_t
*zfsvfs
= arg
;
388 zfsvfs
->z_acl_mode
= newval
;
392 acl_inherit_changed_cb(void *arg
, uint64_t newval
)
394 zfsvfs_t
*zfsvfs
= arg
;
396 zfsvfs
->z_acl_inherit
= newval
;
400 zfs_register_callbacks(vfs_t
*vfsp
)
402 struct dsl_dataset
*ds
= NULL
;
404 zfsvfs_t
*zfsvfs
= NULL
;
406 boolean_t readonly
= B_FALSE
;
407 boolean_t do_readonly
= B_FALSE
;
408 boolean_t setuid
= B_FALSE
;
409 boolean_t do_setuid
= B_FALSE
;
410 boolean_t exec
= B_FALSE
;
411 boolean_t do_exec
= B_FALSE
;
412 boolean_t devices
= B_FALSE
;
413 boolean_t do_devices
= B_FALSE
;
414 boolean_t xattr
= B_FALSE
;
415 boolean_t do_xattr
= B_FALSE
;
416 boolean_t atime
= B_FALSE
;
417 boolean_t do_atime
= B_FALSE
;
421 zfsvfs
= vfsp
->vfs_data
;
426 * The act of registering our callbacks will destroy any mount
427 * options we may have. In order to enable temporary overrides
428 * of mount options, we stash away the current values and
429 * restore them after we register the callbacks.
431 if (vfs_optionisset(vfsp
, MNTOPT_RO
, NULL
) ||
432 !spa_writeable(dmu_objset_spa(os
))) {
434 do_readonly
= B_TRUE
;
435 } else if (vfs_optionisset(vfsp
, MNTOPT_RW
, NULL
)) {
437 do_readonly
= B_TRUE
;
439 if (vfs_optionisset(vfsp
, MNTOPT_NOSUID
, NULL
)) {
445 if (vfs_optionisset(vfsp
, MNTOPT_NODEVICES
, NULL
)) {
448 } else if (vfs_optionisset(vfsp
, MNTOPT_DEVICES
, NULL
)) {
453 if (vfs_optionisset(vfsp
, MNTOPT_NOSETUID
, NULL
)) {
456 } else if (vfs_optionisset(vfsp
, MNTOPT_SETUID
, NULL
)) {
461 if (vfs_optionisset(vfsp
, MNTOPT_NOEXEC
, NULL
)) {
464 } else if (vfs_optionisset(vfsp
, MNTOPT_EXEC
, NULL
)) {
468 if (vfs_optionisset(vfsp
, MNTOPT_NOXATTR
, NULL
)) {
471 } else if (vfs_optionisset(vfsp
, MNTOPT_XATTR
, NULL
)) {
475 if (vfs_optionisset(vfsp
, MNTOPT_NOATIME
, NULL
)) {
478 } else if (vfs_optionisset(vfsp
, MNTOPT_ATIME
, NULL
)) {
484 * nbmand is a special property. It can only be changed at
487 * This is weird, but it is documented to only be changeable
490 if (vfs_optionisset(vfsp
, MNTOPT_NONBMAND
, NULL
)) {
492 } else if (vfs_optionisset(vfsp
, MNTOPT_NBMAND
, NULL
)) {
495 char osname
[ZFS_MAX_DATASET_NAME_LEN
];
497 dmu_objset_name(os
, osname
);
498 if (error
= dsl_prop_get_integer(osname
, "nbmand", &nbmand
,
505 * Register property callbacks.
507 * It would probably be fine to just check for i/o error from
508 * the first prop_register(), but I guess I like to go
511 ds
= dmu_objset_ds(os
);
512 dsl_pool_config_enter(dmu_objset_pool(os
), FTAG
);
513 error
= dsl_prop_register(ds
,
514 zfs_prop_to_name(ZFS_PROP_ATIME
), atime_changed_cb
, zfsvfs
);
515 error
= error
? error
: dsl_prop_register(ds
,
516 zfs_prop_to_name(ZFS_PROP_XATTR
), xattr_changed_cb
, zfsvfs
);
517 error
= error
? error
: dsl_prop_register(ds
,
518 zfs_prop_to_name(ZFS_PROP_RECORDSIZE
), blksz_changed_cb
, zfsvfs
);
519 error
= error
? error
: dsl_prop_register(ds
,
520 zfs_prop_to_name(ZFS_PROP_READONLY
), readonly_changed_cb
, zfsvfs
);
521 error
= error
? error
: dsl_prop_register(ds
,
522 zfs_prop_to_name(ZFS_PROP_DEVICES
), devices_changed_cb
, zfsvfs
);
523 error
= error
? error
: dsl_prop_register(ds
,
524 zfs_prop_to_name(ZFS_PROP_SETUID
), setuid_changed_cb
, zfsvfs
);
525 error
= error
? error
: dsl_prop_register(ds
,
526 zfs_prop_to_name(ZFS_PROP_EXEC
), exec_changed_cb
, zfsvfs
);
527 error
= error
? error
: dsl_prop_register(ds
,
528 zfs_prop_to_name(ZFS_PROP_SNAPDIR
), snapdir_changed_cb
, zfsvfs
);
529 error
= error
? error
: dsl_prop_register(ds
,
530 zfs_prop_to_name(ZFS_PROP_ACLMODE
), acl_mode_changed_cb
, zfsvfs
);
531 error
= error
? error
: dsl_prop_register(ds
,
532 zfs_prop_to_name(ZFS_PROP_ACLINHERIT
), acl_inherit_changed_cb
,
534 error
= error
? error
: dsl_prop_register(ds
,
535 zfs_prop_to_name(ZFS_PROP_VSCAN
), vscan_changed_cb
, zfsvfs
);
536 dsl_pool_config_exit(dmu_objset_pool(os
), FTAG
);
541 * Invoke our callbacks to restore temporary mount options.
544 readonly_changed_cb(zfsvfs
, readonly
);
546 setuid_changed_cb(zfsvfs
, setuid
);
548 exec_changed_cb(zfsvfs
, exec
);
550 devices_changed_cb(zfsvfs
, devices
);
552 xattr_changed_cb(zfsvfs
, xattr
);
554 atime_changed_cb(zfsvfs
, atime
);
556 nbmand_changed_cb(zfsvfs
, nbmand
);
561 dsl_prop_unregister_all(ds
, zfsvfs
);
566 zfs_space_delta_cb(dmu_object_type_t bonustype
, void *data
,
567 uint64_t *userp
, uint64_t *groupp
)
570 * Is it a valid type of object to track?
572 if (bonustype
!= DMU_OT_ZNODE
&& bonustype
!= DMU_OT_SA
)
573 return (SET_ERROR(ENOENT
));
576 * If we have a NULL data pointer
577 * then assume the id's aren't changing and
578 * return EEXIST to the dmu to let it know to
582 return (SET_ERROR(EEXIST
));
584 if (bonustype
== DMU_OT_ZNODE
) {
585 znode_phys_t
*znp
= data
;
586 *userp
= znp
->zp_uid
;
587 *groupp
= znp
->zp_gid
;
590 sa_hdr_phys_t
*sap
= data
;
591 sa_hdr_phys_t sa
= *sap
;
592 boolean_t swap
= B_FALSE
;
594 ASSERT(bonustype
== DMU_OT_SA
);
596 if (sa
.sa_magic
== 0) {
598 * This should only happen for newly created
599 * files that haven't had the znode data filled
606 if (sa
.sa_magic
== BSWAP_32(SA_MAGIC
)) {
607 sa
.sa_magic
= SA_MAGIC
;
608 sa
.sa_layout_info
= BSWAP_16(sa
.sa_layout_info
);
611 VERIFY3U(sa
.sa_magic
, ==, SA_MAGIC
);
614 hdrsize
= sa_hdrsize(&sa
);
615 VERIFY3U(hdrsize
, >=, sizeof (sa_hdr_phys_t
));
616 *userp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+
618 *groupp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+
621 *userp
= BSWAP_64(*userp
);
622 *groupp
= BSWAP_64(*groupp
);
629 fuidstr_to_sid(zfsvfs_t
*zfsvfs
, const char *fuidstr
,
630 char *domainbuf
, int buflen
, uid_t
*ridp
)
635 fuid
= zfs_strtonum(fuidstr
, NULL
);
637 domain
= zfs_fuid_find_by_idx(zfsvfs
, FUID_INDEX(fuid
));
639 (void) strlcpy(domainbuf
, domain
, buflen
);
642 *ridp
= FUID_RID(fuid
);
646 zfs_userquota_prop_to_obj(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
)
649 case ZFS_PROP_USERUSED
:
650 return (DMU_USERUSED_OBJECT
);
651 case ZFS_PROP_GROUPUSED
:
652 return (DMU_GROUPUSED_OBJECT
);
653 case ZFS_PROP_USERQUOTA
:
654 return (zfsvfs
->z_userquota_obj
);
655 case ZFS_PROP_GROUPQUOTA
:
656 return (zfsvfs
->z_groupquota_obj
);
662 zfs_userspace_many(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
663 uint64_t *cookiep
, void *vbuf
, uint64_t *bufsizep
)
668 zfs_useracct_t
*buf
= vbuf
;
671 if (!dmu_objset_userspace_present(zfsvfs
->z_os
))
672 return (SET_ERROR(ENOTSUP
));
674 obj
= zfs_userquota_prop_to_obj(zfsvfs
, type
);
680 for (zap_cursor_init_serialized(&zc
, zfsvfs
->z_os
, obj
, *cookiep
);
681 (error
= zap_cursor_retrieve(&zc
, &za
)) == 0;
682 zap_cursor_advance(&zc
)) {
683 if ((uintptr_t)buf
- (uintptr_t)vbuf
+ sizeof (zfs_useracct_t
) >
687 fuidstr_to_sid(zfsvfs
, za
.za_name
,
688 buf
->zu_domain
, sizeof (buf
->zu_domain
), &buf
->zu_rid
);
690 buf
->zu_space
= za
.za_first_integer
;
696 ASSERT3U((uintptr_t)buf
- (uintptr_t)vbuf
, <=, *bufsizep
);
697 *bufsizep
= (uintptr_t)buf
- (uintptr_t)vbuf
;
698 *cookiep
= zap_cursor_serialize(&zc
);
699 zap_cursor_fini(&zc
);
704 * buf must be big enough (eg, 32 bytes)
707 id_to_fuidstr(zfsvfs_t
*zfsvfs
, const char *domain
, uid_t rid
,
708 char *buf
, boolean_t addok
)
713 if (domain
&& domain
[0]) {
714 domainid
= zfs_fuid_find_by_domain(zfsvfs
, domain
, NULL
, addok
);
716 return (SET_ERROR(ENOENT
));
718 fuid
= FUID_ENCODE(domainid
, rid
);
719 (void) sprintf(buf
, "%llx", (longlong_t
)fuid
);
724 zfs_userspace_one(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
725 const char *domain
, uint64_t rid
, uint64_t *valp
)
733 if (!dmu_objset_userspace_present(zfsvfs
->z_os
))
734 return (SET_ERROR(ENOTSUP
));
736 obj
= zfs_userquota_prop_to_obj(zfsvfs
, type
);
740 err
= id_to_fuidstr(zfsvfs
, domain
, rid
, buf
, B_FALSE
);
744 err
= zap_lookup(zfsvfs
->z_os
, obj
, buf
, 8, 1, valp
);
751 zfs_set_userquota(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
752 const char *domain
, uint64_t rid
, uint64_t quota
)
758 boolean_t fuid_dirtied
;
760 if (type
!= ZFS_PROP_USERQUOTA
&& type
!= ZFS_PROP_GROUPQUOTA
)
761 return (SET_ERROR(EINVAL
));
763 if (zfsvfs
->z_version
< ZPL_VERSION_USERSPACE
)
764 return (SET_ERROR(ENOTSUP
));
766 objp
= (type
== ZFS_PROP_USERQUOTA
) ? &zfsvfs
->z_userquota_obj
:
767 &zfsvfs
->z_groupquota_obj
;
769 err
= id_to_fuidstr(zfsvfs
, domain
, rid
, buf
, B_TRUE
);
772 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
774 tx
= dmu_tx_create(zfsvfs
->z_os
);
775 dmu_tx_hold_zap(tx
, *objp
? *objp
: DMU_NEW_OBJECT
, B_TRUE
, NULL
);
777 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
778 zfs_userquota_prop_prefixes
[type
]);
781 zfs_fuid_txhold(zfsvfs
, tx
);
782 err
= dmu_tx_assign(tx
, TXG_WAIT
);
788 mutex_enter(&zfsvfs
->z_lock
);
790 *objp
= zap_create(zfsvfs
->z_os
, DMU_OT_USERGROUP_QUOTA
,
792 VERIFY(0 == zap_add(zfsvfs
->z_os
, MASTER_NODE_OBJ
,
793 zfs_userquota_prop_prefixes
[type
], 8, 1, objp
, tx
));
795 mutex_exit(&zfsvfs
->z_lock
);
798 err
= zap_remove(zfsvfs
->z_os
, *objp
, buf
, tx
);
802 err
= zap_update(zfsvfs
->z_os
, *objp
, buf
, 8, 1, "a
, tx
);
806 zfs_fuid_sync(zfsvfs
, tx
);
812 zfs_fuid_overquota(zfsvfs_t
*zfsvfs
, boolean_t isgroup
, uint64_t fuid
)
815 uint64_t used
, quota
, usedobj
, quotaobj
;
818 usedobj
= isgroup
? DMU_GROUPUSED_OBJECT
: DMU_USERUSED_OBJECT
;
819 quotaobj
= isgroup
? zfsvfs
->z_groupquota_obj
: zfsvfs
->z_userquota_obj
;
821 if (quotaobj
== 0 || zfsvfs
->z_replay
)
824 (void) sprintf(buf
, "%llx", (longlong_t
)fuid
);
825 err
= zap_lookup(zfsvfs
->z_os
, quotaobj
, buf
, 8, 1, "a
);
829 err
= zap_lookup(zfsvfs
->z_os
, usedobj
, buf
, 8, 1, &used
);
832 return (used
>= quota
);
836 zfs_owner_overquota(zfsvfs_t
*zfsvfs
, znode_t
*zp
, boolean_t isgroup
)
841 quotaobj
= isgroup
? zfsvfs
->z_groupquota_obj
: zfsvfs
->z_userquota_obj
;
843 fuid
= isgroup
? zp
->z_gid
: zp
->z_uid
;
845 if (quotaobj
== 0 || zfsvfs
->z_replay
)
848 return (zfs_fuid_overquota(zfsvfs
, isgroup
, fuid
));
852 * Associate this zfsvfs with the given objset, which must be owned.
853 * This will cache a bunch of on-disk state from the objset in the
857 zfsvfs_init(zfsvfs_t
*zfsvfs
, objset_t
*os
)
862 zfsvfs
->z_max_blksz
= SPA_OLD_MAXBLOCKSIZE
;
863 zfsvfs
->z_show_ctldir
= ZFS_SNAPDIR_VISIBLE
;
866 error
= zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zfsvfs
->z_version
);
869 if (zfsvfs
->z_version
>
870 zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)))) {
871 (void) printf("Can't mount a version %lld file system "
872 "on a version %lld pool\n. Pool must be upgraded to mount "
873 "this file system.", (u_longlong_t
)zfsvfs
->z_version
,
874 (u_longlong_t
)spa_version(dmu_objset_spa(os
)));
875 return (SET_ERROR(ENOTSUP
));
877 error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &val
);
880 zfsvfs
->z_norm
= (int)val
;
882 error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &val
);
885 zfsvfs
->z_utf8
= (val
!= 0);
887 error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &val
);
890 zfsvfs
->z_case
= (uint_t
)val
;
893 * Fold case on file systems that are always or sometimes case
896 if (zfsvfs
->z_case
== ZFS_CASE_INSENSITIVE
||
897 zfsvfs
->z_case
== ZFS_CASE_MIXED
)
898 zfsvfs
->z_norm
|= U8_TEXTPREP_TOUPPER
;
900 zfsvfs
->z_use_fuids
= USE_FUIDS(zfsvfs
->z_version
, zfsvfs
->z_os
);
901 zfsvfs
->z_use_sa
= USE_SA(zfsvfs
->z_version
, zfsvfs
->z_os
);
904 if (zfsvfs
->z_use_sa
) {
905 /* should either have both of these objects or none */
906 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1,
912 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
913 &zfsvfs
->z_attr_table
);
917 if (zfsvfs
->z_version
>= ZPL_VERSION_SA
)
918 sa_register_update_callback(os
, zfs_sa_upgrade
);
920 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_ROOT_OBJ
, 8, 1,
924 ASSERT(zfsvfs
->z_root
!= 0);
926 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_UNLINKED_SET
, 8, 1,
927 &zfsvfs
->z_unlinkedobj
);
931 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
932 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
],
933 8, 1, &zfsvfs
->z_userquota_obj
);
935 zfsvfs
->z_userquota_obj
= 0;
939 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
940 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
],
941 8, 1, &zfsvfs
->z_groupquota_obj
);
943 zfsvfs
->z_groupquota_obj
= 0;
947 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_FUID_TABLES
, 8, 1,
948 &zfsvfs
->z_fuid_obj
);
950 zfsvfs
->z_fuid_obj
= 0;
954 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SHARES_DIR
, 8, 1,
955 &zfsvfs
->z_shares_dir
);
957 zfsvfs
->z_shares_dir
= 0;
965 zfsvfs_create(const char *osname
, zfsvfs_t
**zfvp
)
971 zfsvfs
= kmem_zalloc(sizeof (zfsvfs_t
), KM_SLEEP
);
974 * We claim to always be readonly so we can open snapshots;
975 * other ZPL code will prevent us from writing to snapshots.
978 error
= dmu_objset_own(osname
, DMU_OST_ZFS
, B_TRUE
, zfsvfs
, &os
);
980 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
984 error
= zfsvfs_create_impl(zfvp
, zfsvfs
, os
);
986 dmu_objset_disown(os
, zfsvfs
);
993 zfsvfs_create_impl(zfsvfs_t
**zfvp
, zfsvfs_t
*zfsvfs
, objset_t
*os
)
997 zfsvfs
->z_vfs
= NULL
;
998 zfsvfs
->z_parent
= zfsvfs
;
1000 mutex_init(&zfsvfs
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1001 mutex_init(&zfsvfs
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1002 list_create(&zfsvfs
->z_all_znodes
, sizeof (znode_t
),
1003 offsetof(znode_t
, z_link_node
));
1004 rrm_init(&zfsvfs
->z_teardown_lock
, B_FALSE
);
1005 rw_init(&zfsvfs
->z_teardown_inactive_lock
, NULL
, RW_DEFAULT
, NULL
);
1006 rw_init(&zfsvfs
->z_fuid_lock
, NULL
, RW_DEFAULT
, NULL
);
1007 for (int i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
1008 mutex_init(&zfsvfs
->z_hold_mtx
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1010 error
= zfsvfs_init(zfsvfs
, os
);
1013 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
1022 zfsvfs_setup(zfsvfs_t
*zfsvfs
, boolean_t mounting
)
1026 error
= zfs_register_callbacks(zfsvfs
->z_vfs
);
1030 zfsvfs
->z_log
= zil_open(zfsvfs
->z_os
, zfs_get_data
);
1033 * If we are not mounting (ie: online recv), then we don't
1034 * have to worry about replaying the log as we blocked all
1035 * operations out since we closed the ZIL.
1041 * During replay we remove the read only flag to
1042 * allow replays to succeed.
1044 readonly
= zfsvfs
->z_vfs
->vfs_flag
& VFS_RDONLY
;
1046 zfsvfs
->z_vfs
->vfs_flag
&= ~VFS_RDONLY
;
1048 zfs_unlinked_drain(zfsvfs
);
1051 * Parse and replay the intent log.
1053 * Because of ziltest, this must be done after
1054 * zfs_unlinked_drain(). (Further note: ziltest
1055 * doesn't use readonly mounts, where
1056 * zfs_unlinked_drain() isn't called.) This is because
1057 * ziltest causes spa_sync() to think it's committed,
1058 * but actually it is not, so the intent log contains
1059 * many txg's worth of changes.
1061 * In particular, if object N is in the unlinked set in
1062 * the last txg to actually sync, then it could be
1063 * actually freed in a later txg and then reallocated
1064 * in a yet later txg. This would write a "create
1065 * object N" record to the intent log. Normally, this
1066 * would be fine because the spa_sync() would have
1067 * written out the fact that object N is free, before
1068 * we could write the "create object N" intent log
1071 * But when we are in ziltest mode, we advance the "open
1072 * txg" without actually spa_sync()-ing the changes to
1073 * disk. So we would see that object N is still
1074 * allocated and in the unlinked set, and there is an
1075 * intent log record saying to allocate it.
1077 if (spa_writeable(dmu_objset_spa(zfsvfs
->z_os
))) {
1078 if (zil_replay_disable
) {
1079 zil_destroy(zfsvfs
->z_log
, B_FALSE
);
1081 zfsvfs
->z_replay
= B_TRUE
;
1082 zil_replay(zfsvfs
->z_os
, zfsvfs
,
1084 zfsvfs
->z_replay
= B_FALSE
;
1087 zfsvfs
->z_vfs
->vfs_flag
|= readonly
; /* restore readonly bit */
1091 * Set the objset user_ptr to track its zfsvfs.
1093 mutex_enter(&zfsvfs
->z_os
->os_user_ptr_lock
);
1094 dmu_objset_set_user(zfsvfs
->z_os
, zfsvfs
);
1095 mutex_exit(&zfsvfs
->z_os
->os_user_ptr_lock
);
1101 zfsvfs_free(zfsvfs_t
*zfsvfs
)
1104 extern krwlock_t zfsvfs_lock
; /* in zfs_znode.c */
1107 * This is a barrier to prevent the filesystem from going away in
1108 * zfs_znode_move() until we can safely ensure that the filesystem is
1109 * not unmounted. We consider the filesystem valid before the barrier
1110 * and invalid after the barrier.
1112 rw_enter(&zfsvfs_lock
, RW_READER
);
1113 rw_exit(&zfsvfs_lock
);
1115 zfs_fuid_destroy(zfsvfs
);
1117 mutex_destroy(&zfsvfs
->z_znodes_lock
);
1118 mutex_destroy(&zfsvfs
->z_lock
);
1119 list_destroy(&zfsvfs
->z_all_znodes
);
1120 rrm_destroy(&zfsvfs
->z_teardown_lock
);
1121 rw_destroy(&zfsvfs
->z_teardown_inactive_lock
);
1122 rw_destroy(&zfsvfs
->z_fuid_lock
);
1123 for (i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
1124 mutex_destroy(&zfsvfs
->z_hold_mtx
[i
]);
1125 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
1129 zfs_set_fuid_feature(zfsvfs_t
*zfsvfs
)
1131 zfsvfs
->z_use_fuids
= USE_FUIDS(zfsvfs
->z_version
, zfsvfs
->z_os
);
1132 if (zfsvfs
->z_vfs
) {
1133 if (zfsvfs
->z_use_fuids
) {
1134 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_XVATTR
);
1135 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_SYSATTR_VIEWS
);
1136 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_ACEMASKONACCESS
);
1137 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_ACLONCREATE
);
1138 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_ACCESS_FILTER
);
1139 vfs_set_feature(zfsvfs
->z_vfs
, VFSFT_REPARSE
);
1141 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_XVATTR
);
1142 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_SYSATTR_VIEWS
);
1143 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_ACEMASKONACCESS
);
1144 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_ACLONCREATE
);
1145 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_ACCESS_FILTER
);
1146 vfs_clear_feature(zfsvfs
->z_vfs
, VFSFT_REPARSE
);
1149 zfsvfs
->z_use_sa
= USE_SA(zfsvfs
->z_version
, zfsvfs
->z_os
);
1153 zfs_domount(vfs_t
*vfsp
, char *osname
)
1156 uint64_t recordsize
, fsid_guid
;
1163 error
= zfsvfs_create(osname
, &zfsvfs
);
1166 zfsvfs
->z_vfs
= vfsp
;
1168 /* Initialize the generic filesystem structure. */
1169 vfsp
->vfs_bcount
= 0;
1170 vfsp
->vfs_data
= NULL
;
1172 if (zfs_create_unique_device(&mount_dev
) == -1) {
1173 error
= SET_ERROR(ENODEV
);
1176 ASSERT(vfs_devismounted(mount_dev
) == 0);
1178 if (error
= dsl_prop_get_integer(osname
, "recordsize", &recordsize
,
1182 vfsp
->vfs_dev
= mount_dev
;
1183 vfsp
->vfs_fstype
= zfsfstype
;
1184 vfsp
->vfs_bsize
= recordsize
;
1185 vfsp
->vfs_flag
|= VFS_NOTRUNC
;
1186 vfsp
->vfs_data
= zfsvfs
;
1189 * The fsid is 64 bits, composed of an 8-bit fs type, which
1190 * separates our fsid from any other filesystem types, and a
1191 * 56-bit objset unique ID. The objset unique ID is unique to
1192 * all objsets open on this system, provided by unique_create().
1193 * The 8-bit fs type must be put in the low bits of fsid[1]
1194 * because that's where other Solaris filesystems put it.
1196 fsid_guid
= dmu_objset_fsid_guid(zfsvfs
->z_os
);
1197 ASSERT((fsid_guid
& ~((1ULL<<56)-1)) == 0);
1198 vfsp
->vfs_fsid
.val
[0] = fsid_guid
;
1199 vfsp
->vfs_fsid
.val
[1] = ((fsid_guid
>>32) << 8) |
1203 * Set features for file system.
1205 zfs_set_fuid_feature(zfsvfs
);
1206 if (zfsvfs
->z_case
== ZFS_CASE_INSENSITIVE
) {
1207 vfs_set_feature(vfsp
, VFSFT_DIRENTFLAGS
);
1208 vfs_set_feature(vfsp
, VFSFT_CASEINSENSITIVE
);
1209 vfs_set_feature(vfsp
, VFSFT_NOCASESENSITIVE
);
1210 } else if (zfsvfs
->z_case
== ZFS_CASE_MIXED
) {
1211 vfs_set_feature(vfsp
, VFSFT_DIRENTFLAGS
);
1212 vfs_set_feature(vfsp
, VFSFT_CASEINSENSITIVE
);
1214 vfs_set_feature(vfsp
, VFSFT_ZEROCOPY_SUPPORTED
);
1216 if (dmu_objset_is_snapshot(zfsvfs
->z_os
)) {
1219 atime_changed_cb(zfsvfs
, B_FALSE
);
1220 readonly_changed_cb(zfsvfs
, B_TRUE
);
1221 if (error
= dsl_prop_get_integer(osname
, "xattr", &pval
, NULL
))
1223 xattr_changed_cb(zfsvfs
, pval
);
1224 zfsvfs
->z_issnap
= B_TRUE
;
1225 zfsvfs
->z_os
->os_sync
= ZFS_SYNC_DISABLED
;
1227 mutex_enter(&zfsvfs
->z_os
->os_user_ptr_lock
);
1228 dmu_objset_set_user(zfsvfs
->z_os
, zfsvfs
);
1229 mutex_exit(&zfsvfs
->z_os
->os_user_ptr_lock
);
1231 error
= zfsvfs_setup(zfsvfs
, B_TRUE
);
1234 if (!zfsvfs
->z_issnap
)
1235 zfsctl_create(zfsvfs
);
1238 dmu_objset_disown(zfsvfs
->z_os
, zfsvfs
);
1239 zfsvfs_free(zfsvfs
);
1241 atomic_inc_32(&zfs_active_fs_count
);
1248 zfs_unregister_callbacks(zfsvfs_t
*zfsvfs
)
1250 objset_t
*os
= zfsvfs
->z_os
;
1252 if (!dmu_objset_is_snapshot(os
))
1253 dsl_prop_unregister_all(dmu_objset_ds(os
), zfsvfs
);
1257 * Convert a decimal digit string to a uint64_t integer.
1260 str_to_uint64(char *str
, uint64_t *objnum
)
1265 if (*str
< '0' || *str
> '9')
1266 return (SET_ERROR(EINVAL
));
1268 num
= num
*10 + *str
++ - '0';
1276 * The boot path passed from the boot loader is in the form of
1277 * "rootpool-name/root-filesystem-object-number'. Convert this
1278 * string to a dataset name: "rootpool-name/root-filesystem-name".
1281 zfs_parse_bootfs(char *bpath
, char *outpath
)
1287 if (*bpath
== 0 || *bpath
== '/')
1288 return (SET_ERROR(EINVAL
));
1290 (void) strcpy(outpath
, bpath
);
1292 slashp
= strchr(bpath
, '/');
1294 /* if no '/', just return the pool name */
1295 if (slashp
== NULL
) {
1299 /* if not a number, just return the root dataset name */
1300 if (str_to_uint64(slashp
+1, &objnum
)) {
1305 error
= dsl_dsobj_to_dsname(bpath
, objnum
, outpath
);
1312 * Check that the hex label string is appropriate for the dataset being
1313 * mounted into the global_zone proper.
1315 * Return an error if the hex label string is not default or
1316 * admin_low/admin_high. For admin_low labels, the corresponding
1317 * dataset must be readonly.
1320 zfs_check_global_label(const char *dsname
, const char *hexsl
)
1322 if (strcasecmp(hexsl
, ZFS_MLSLABEL_DEFAULT
) == 0)
1324 if (strcasecmp(hexsl
, ADMIN_HIGH
) == 0)
1326 if (strcasecmp(hexsl
, ADMIN_LOW
) == 0) {
1327 /* must be readonly */
1330 if (dsl_prop_get_integer(dsname
,
1331 zfs_prop_to_name(ZFS_PROP_READONLY
), &rdonly
, NULL
))
1332 return (SET_ERROR(EACCES
));
1333 return (rdonly
? 0 : EACCES
);
1335 return (SET_ERROR(EACCES
));
1339 * Determine whether the mount is allowed according to MAC check.
1340 * by comparing (where appropriate) label of the dataset against
1341 * the label of the zone being mounted into. If the dataset has
1342 * no label, create one.
1344 * Returns 0 if access allowed, error otherwise (e.g. EACCES)
1347 zfs_mount_label_policy(vfs_t
*vfsp
, char *osname
)
1350 zone_t
*mntzone
= NULL
;
1351 ts_label_t
*mnt_tsl
;
1354 char ds_hexsl
[MAXNAMELEN
];
1356 retv
= EACCES
; /* assume the worst */
1359 * Start by getting the dataset label if it exists.
1361 error
= dsl_prop_get(osname
, zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
1362 1, sizeof (ds_hexsl
), &ds_hexsl
, NULL
);
1364 return (SET_ERROR(EACCES
));
1367 * If labeling is NOT enabled, then disallow the mount of datasets
1368 * which have a non-default label already. No other label checks
1371 if (!is_system_labeled()) {
1372 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) == 0)
1374 return (SET_ERROR(EACCES
));
1378 * Get the label of the mountpoint. If mounting into the global
1379 * zone (i.e. mountpoint is not within an active zone and the
1380 * zoned property is off), the label must be default or
1381 * admin_low/admin_high only; no other checks are needed.
1383 mntzone
= zone_find_by_any_path(refstr_value(vfsp
->vfs_mntpt
), B_FALSE
);
1384 if (mntzone
->zone_id
== GLOBAL_ZONEID
) {
1389 if (dsl_prop_get_integer(osname
,
1390 zfs_prop_to_name(ZFS_PROP_ZONED
), &zoned
, NULL
))
1391 return (SET_ERROR(EACCES
));
1393 return (zfs_check_global_label(osname
, ds_hexsl
));
1396 * This is the case of a zone dataset being mounted
1397 * initially, before the zone has been fully created;
1398 * allow this mount into global zone.
1403 mnt_tsl
= mntzone
->zone_slabel
;
1404 ASSERT(mnt_tsl
!= NULL
);
1405 label_hold(mnt_tsl
);
1406 mnt_sl
= label2bslabel(mnt_tsl
);
1408 if (strcasecmp(ds_hexsl
, ZFS_MLSLABEL_DEFAULT
) == 0) {
1410 * The dataset doesn't have a real label, so fabricate one.
1414 if (l_to_str_internal(mnt_sl
, &str
) == 0 &&
1415 dsl_prop_set_string(osname
,
1416 zfs_prop_to_name(ZFS_PROP_MLSLABEL
),
1417 ZPROP_SRC_LOCAL
, str
) == 0)
1420 kmem_free(str
, strlen(str
) + 1);
1421 } else if (hexstr_to_label(ds_hexsl
, &ds_sl
) == 0) {
1423 * Now compare labels to complete the MAC check. If the
1424 * labels are equal then allow access. If the mountpoint
1425 * label dominates the dataset label, allow readonly access.
1426 * Otherwise, access is denied.
1428 if (blequal(mnt_sl
, &ds_sl
))
1430 else if (bldominates(mnt_sl
, &ds_sl
)) {
1431 vfs_setmntopt(vfsp
, MNTOPT_RO
, NULL
, 0);
1436 label_rele(mnt_tsl
);
1442 zfs_mountroot(vfs_t
*vfsp
, enum whymountroot why
)
1445 static int zfsrootdone
= 0;
1446 zfsvfs_t
*zfsvfs
= NULL
;
1455 * The filesystem that we mount as root is defined in the
1456 * boot property "zfs-bootfs" with a format of
1457 * "poolname/root-dataset-objnum".
1459 if (why
== ROOT_INIT
) {
1461 return (SET_ERROR(EBUSY
));
1463 * the process of doing a spa_load will require the
1464 * clock to be set before we could (for example) do
1465 * something better by looking at the timestamp on
1466 * an uberblock, so just set it to -1.
1470 if ((zfs_bootfs
= spa_get_bootprop("zfs-bootfs")) == NULL
) {
1471 cmn_err(CE_NOTE
, "spa_get_bootfs: can not get "
1473 return (SET_ERROR(EINVAL
));
1475 zfs_devid
= spa_get_bootprop("diskdevid");
1476 error
= spa_import_rootpool(rootfs
.bo_name
, zfs_devid
);
1478 spa_free_bootprop(zfs_devid
);
1480 spa_free_bootprop(zfs_bootfs
);
1481 cmn_err(CE_NOTE
, "spa_import_rootpool: error %d",
1485 if (error
= zfs_parse_bootfs(zfs_bootfs
, rootfs
.bo_name
)) {
1486 spa_free_bootprop(zfs_bootfs
);
1487 cmn_err(CE_NOTE
, "zfs_parse_bootfs: error %d",
1492 spa_free_bootprop(zfs_bootfs
);
1494 if (error
= vfs_lock(vfsp
))
1497 if (error
= zfs_domount(vfsp
, rootfs
.bo_name
)) {
1498 cmn_err(CE_NOTE
, "zfs_domount: error %d", error
);
1502 zfsvfs
= (zfsvfs_t
*)vfsp
->vfs_data
;
1504 if (error
= zfs_zget(zfsvfs
, zfsvfs
->z_root
, &zp
)) {
1505 cmn_err(CE_NOTE
, "zfs_zget: error %d", error
);
1510 mutex_enter(&vp
->v_lock
);
1511 vp
->v_flag
|= VROOT
;
1512 mutex_exit(&vp
->v_lock
);
1516 * Leave rootvp held. The root file system is never unmounted.
1519 vfs_add((struct vnode
*)0, vfsp
,
1520 (vfsp
->vfs_flag
& VFS_RDONLY
) ? MS_RDONLY
: 0);
1524 } else if (why
== ROOT_REMOUNT
) {
1525 readonly_changed_cb(vfsp
->vfs_data
, B_FALSE
);
1526 vfsp
->vfs_flag
|= VFS_REMOUNT
;
1528 /* refresh mount options */
1529 zfs_unregister_callbacks(vfsp
->vfs_data
);
1530 return (zfs_register_callbacks(vfsp
));
1532 } else if (why
== ROOT_UNMOUNT
) {
1533 zfs_unregister_callbacks((zfsvfs_t
*)vfsp
->vfs_data
);
1534 (void) zfs_sync(vfsp
, 0, 0);
1539 * if "why" is equal to anything else other than ROOT_INIT,
1540 * ROOT_REMOUNT, or ROOT_UNMOUNT, we do not support it.
1542 return (SET_ERROR(ENOTSUP
));
1547 zfs_mount(vfs_t
*vfsp
, vnode_t
*mvp
, struct mounta
*uap
, cred_t
*cr
)
1552 uio_seg_t fromspace
= (uap
->flags
& MS_SYSSPACE
) ?
1553 UIO_SYSSPACE
: UIO_USERSPACE
;
1556 if (mvp
->v_type
!= VDIR
)
1557 return (SET_ERROR(ENOTDIR
));
1559 mutex_enter(&mvp
->v_lock
);
1560 if ((uap
->flags
& MS_REMOUNT
) == 0 &&
1561 (uap
->flags
& MS_OVERLAY
) == 0 &&
1562 (mvp
->v_count
!= 1 || (mvp
->v_flag
& VROOT
))) {
1563 mutex_exit(&mvp
->v_lock
);
1564 return (SET_ERROR(EBUSY
));
1566 mutex_exit(&mvp
->v_lock
);
1569 * ZFS does not support passing unparsed data in via MS_DATA.
1570 * Users should use the MS_OPTIONSTR interface; this means
1571 * that all option parsing is already done and the options struct
1572 * can be interrogated.
1574 if ((uap
->flags
& MS_DATA
) && uap
->datalen
> 0)
1575 return (SET_ERROR(EINVAL
));
1578 * Get the objset name (the "special" mount argument).
1580 if (error
= pn_get(uap
->spec
, fromspace
, &spn
))
1583 osname
= spn
.pn_path
;
1586 * Check for mount privilege?
1588 * If we don't have privilege then see if
1589 * we have local permission to allow it
1591 error
= secpolicy_fs_mount(cr
, mvp
, vfsp
);
1593 if (dsl_deleg_access(osname
, ZFS_DELEG_PERM_MOUNT
, cr
) == 0) {
1597 * Make sure user is the owner of the mount point
1598 * or has sufficient privileges.
1601 vattr
.va_mask
= AT_UID
;
1603 if (VOP_GETATTR(mvp
, &vattr
, 0, cr
, NULL
)) {
1607 if (secpolicy_vnode_owner(cr
, vattr
.va_uid
) != 0 &&
1608 VOP_ACCESS(mvp
, VWRITE
, 0, cr
, NULL
) != 0) {
1611 secpolicy_fs_mount_clearopts(cr
, vfsp
);
1618 * Refuse to mount a filesystem if we are in a local zone and the
1619 * dataset is not visible.
1621 if (!INGLOBALZONE(curproc
) &&
1622 (!zone_dataset_visible(osname
, &canwrite
) || !canwrite
)) {
1623 error
= SET_ERROR(EPERM
);
1627 error
= zfs_mount_label_policy(vfsp
, osname
);
1632 * When doing a remount, we simply refresh our temporary properties
1633 * according to those options set in the current VFS options.
1635 if (uap
->flags
& MS_REMOUNT
) {
1636 /* refresh mount options */
1637 zfs_unregister_callbacks(vfsp
->vfs_data
);
1638 error
= zfs_register_callbacks(vfsp
);
1642 error
= zfs_domount(vfsp
, osname
);
1645 * Add an extra VFS_HOLD on our parent vfs so that it can't
1646 * disappear due to a forced unmount.
1648 if (error
== 0 && ((zfsvfs_t
*)vfsp
->vfs_data
)->z_issnap
)
1649 VFS_HOLD(mvp
->v_vfsp
);
1657 zfs_statvfs(vfs_t
*vfsp
, struct statvfs64
*statp
)
1659 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
1661 uint64_t refdbytes
, availbytes
, usedobjs
, availobjs
;
1665 dmu_objset_space(zfsvfs
->z_os
,
1666 &refdbytes
, &availbytes
, &usedobjs
, &availobjs
);
1669 * The underlying storage pool actually uses multiple block sizes.
1670 * We report the fragsize as the smallest block size we support,
1671 * and we report our blocksize as the filesystem's maximum blocksize.
1673 statp
->f_frsize
= 1UL << SPA_MINBLOCKSHIFT
;
1674 statp
->f_bsize
= zfsvfs
->z_max_blksz
;
1677 * The following report "total" blocks of various kinds in the
1678 * file system, but reported in terms of f_frsize - the
1682 statp
->f_blocks
= (refdbytes
+ availbytes
) >> SPA_MINBLOCKSHIFT
;
1683 statp
->f_bfree
= availbytes
>> SPA_MINBLOCKSHIFT
;
1684 statp
->f_bavail
= statp
->f_bfree
; /* no root reservation */
1687 * statvfs() should really be called statufs(), because it assumes
1688 * static metadata. ZFS doesn't preallocate files, so the best
1689 * we can do is report the max that could possibly fit in f_files,
1690 * and that minus the number actually used in f_ffree.
1691 * For f_ffree, report the smaller of the number of object available
1692 * and the number of blocks (each object will take at least a block).
1694 statp
->f_ffree
= MIN(availobjs
, statp
->f_bfree
);
1695 statp
->f_favail
= statp
->f_ffree
; /* no "root reservation" */
1696 statp
->f_files
= statp
->f_ffree
+ usedobjs
;
1698 (void) cmpldev(&d32
, vfsp
->vfs_dev
);
1699 statp
->f_fsid
= d32
;
1702 * We're a zfs filesystem.
1704 (void) strcpy(statp
->f_basetype
, vfssw
[vfsp
->vfs_fstype
].vsw_name
);
1706 statp
->f_flag
= vf_to_stf(vfsp
->vfs_flag
);
1708 statp
->f_namemax
= MAXNAMELEN
- 1;
1711 * We have all of 32 characters to stuff a string here.
1712 * Is there anything useful we could/should provide?
1714 bzero(statp
->f_fstr
, sizeof (statp
->f_fstr
));
1721 zfs_root(vfs_t
*vfsp
, vnode_t
**vpp
)
1723 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
1729 error
= zfs_zget(zfsvfs
, zfsvfs
->z_root
, &rootzp
);
1731 *vpp
= ZTOV(rootzp
);
1738 * Teardown the zfsvfs::z_os.
1740 * Note, if 'unmounting' is FALSE, we return with the 'z_teardown_lock'
1741 * and 'z_teardown_inactive_lock' held.
1744 zfsvfs_teardown(zfsvfs_t
*zfsvfs
, boolean_t unmounting
)
1748 rrm_enter(&zfsvfs
->z_teardown_lock
, RW_WRITER
, FTAG
);
1752 * We purge the parent filesystem's vfsp as the parent
1753 * filesystem and all of its snapshots have their vnode's
1754 * v_vfsp set to the parent's filesystem's vfsp. Note,
1755 * 'z_parent' is self referential for non-snapshots.
1757 (void) dnlc_purge_vfsp(zfsvfs
->z_parent
->z_vfs
, 0);
1761 * Close the zil. NB: Can't close the zil while zfs_inactive
1762 * threads are blocked as zil_close can call zfs_inactive.
1764 if (zfsvfs
->z_log
) {
1765 zil_close(zfsvfs
->z_log
);
1766 zfsvfs
->z_log
= NULL
;
1769 rw_enter(&zfsvfs
->z_teardown_inactive_lock
, RW_WRITER
);
1772 * If we are not unmounting (ie: online recv) and someone already
1773 * unmounted this file system while we were doing the switcheroo,
1774 * or a reopen of z_os failed then just bail out now.
1776 if (!unmounting
&& (zfsvfs
->z_unmounted
|| zfsvfs
->z_os
== NULL
)) {
1777 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
1778 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
1779 return (SET_ERROR(EIO
));
1783 * At this point there are no vops active, and any new vops will
1784 * fail with EIO since we have z_teardown_lock for writer (only
1785 * relavent for forced unmount).
1787 * Release all holds on dbufs.
1789 mutex_enter(&zfsvfs
->z_znodes_lock
);
1790 for (zp
= list_head(&zfsvfs
->z_all_znodes
); zp
!= NULL
;
1791 zp
= list_next(&zfsvfs
->z_all_znodes
, zp
))
1793 ASSERT(ZTOV(zp
)->v_count
> 0);
1794 zfs_znode_dmu_fini(zp
);
1796 mutex_exit(&zfsvfs
->z_znodes_lock
);
1799 * If we are unmounting, set the unmounted flag and let new vops
1800 * unblock. zfs_inactive will have the unmounted behavior, and all
1801 * other vops will fail with EIO.
1804 zfsvfs
->z_unmounted
= B_TRUE
;
1805 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
1806 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
1810 * z_os will be NULL if there was an error in attempting to reopen
1811 * zfsvfs, so just return as the properties had already been
1812 * unregistered and cached data had been evicted before.
1814 if (zfsvfs
->z_os
== NULL
)
1818 * Unregister properties.
1820 zfs_unregister_callbacks(zfsvfs
);
1825 if (dsl_dataset_is_dirty(dmu_objset_ds(zfsvfs
->z_os
)) &&
1826 !(zfsvfs
->z_vfs
->vfs_flag
& VFS_RDONLY
))
1827 txg_wait_synced(dmu_objset_pool(zfsvfs
->z_os
), 0);
1828 dmu_objset_evict_dbufs(zfsvfs
->z_os
);
1835 zfs_umount(vfs_t
*vfsp
, int fflag
, cred_t
*cr
)
1837 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
1841 ret
= secpolicy_fs_unmount(cr
, vfsp
);
1843 if (dsl_deleg_access((char *)refstr_value(vfsp
->vfs_resource
),
1844 ZFS_DELEG_PERM_MOUNT
, cr
))
1849 * We purge the parent filesystem's vfsp as the parent filesystem
1850 * and all of its snapshots have their vnode's v_vfsp set to the
1851 * parent's filesystem's vfsp. Note, 'z_parent' is self
1852 * referential for non-snapshots.
1854 (void) dnlc_purge_vfsp(zfsvfs
->z_parent
->z_vfs
, 0);
1857 * Unmount any snapshots mounted under .zfs before unmounting the
1860 if (zfsvfs
->z_ctldir
!= NULL
&&
1861 (ret
= zfsctl_umount_snapshots(vfsp
, fflag
, cr
)) != 0) {
1865 if (!(fflag
& MS_FORCE
)) {
1867 * Check the number of active vnodes in the file system.
1868 * Our count is maintained in the vfs structure, but the
1869 * number is off by 1 to indicate a hold on the vfs
1872 * The '.zfs' directory maintains a reference of its
1873 * own, and any active references underneath are
1874 * reflected in the vnode count.
1876 if (zfsvfs
->z_ctldir
== NULL
) {
1877 if (vfsp
->vfs_count
> 1)
1878 return (SET_ERROR(EBUSY
));
1880 if (vfsp
->vfs_count
> 2 ||
1881 zfsvfs
->z_ctldir
->v_count
> 1)
1882 return (SET_ERROR(EBUSY
));
1886 vfsp
->vfs_flag
|= VFS_UNMOUNTED
;
1888 VERIFY(zfsvfs_teardown(zfsvfs
, B_TRUE
) == 0);
1892 * z_os will be NULL if there was an error in
1893 * attempting to reopen zfsvfs.
1897 * Unset the objset user_ptr.
1899 mutex_enter(&os
->os_user_ptr_lock
);
1900 dmu_objset_set_user(os
, NULL
);
1901 mutex_exit(&os
->os_user_ptr_lock
);
1904 * Finally release the objset
1906 dmu_objset_disown(os
, zfsvfs
);
1910 * We can now safely destroy the '.zfs' directory node.
1912 if (zfsvfs
->z_ctldir
!= NULL
)
1913 zfsctl_destroy(zfsvfs
);
1919 zfs_vget(vfs_t
*vfsp
, vnode_t
**vpp
, fid_t
*fidp
)
1921 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
1923 uint64_t object
= 0;
1924 uint64_t fid_gen
= 0;
1933 if (fidp
->fid_len
== LONG_FID_LEN
) {
1934 zfid_long_t
*zlfid
= (zfid_long_t
*)fidp
;
1935 uint64_t objsetid
= 0;
1936 uint64_t setgen
= 0;
1938 for (i
= 0; i
< sizeof (zlfid
->zf_setid
); i
++)
1939 objsetid
|= ((uint64_t)zlfid
->zf_setid
[i
]) << (8 * i
);
1941 for (i
= 0; i
< sizeof (zlfid
->zf_setgen
); i
++)
1942 setgen
|= ((uint64_t)zlfid
->zf_setgen
[i
]) << (8 * i
);
1946 err
= zfsctl_lookup_objset(vfsp
, objsetid
, &zfsvfs
);
1948 return (SET_ERROR(EINVAL
));
1952 if (fidp
->fid_len
== SHORT_FID_LEN
|| fidp
->fid_len
== LONG_FID_LEN
) {
1953 zfid_short_t
*zfid
= (zfid_short_t
*)fidp
;
1955 for (i
= 0; i
< sizeof (zfid
->zf_object
); i
++)
1956 object
|= ((uint64_t)zfid
->zf_object
[i
]) << (8 * i
);
1958 for (i
= 0; i
< sizeof (zfid
->zf_gen
); i
++)
1959 fid_gen
|= ((uint64_t)zfid
->zf_gen
[i
]) << (8 * i
);
1962 return (SET_ERROR(EINVAL
));
1965 /* A zero fid_gen means we are in the .zfs control directories */
1967 (object
== ZFSCTL_INO_ROOT
|| object
== ZFSCTL_INO_SNAPDIR
)) {
1968 *vpp
= zfsvfs
->z_ctldir
;
1969 ASSERT(*vpp
!= NULL
);
1970 if (object
== ZFSCTL_INO_SNAPDIR
) {
1971 VERIFY(zfsctl_root_lookup(*vpp
, "snapshot", vpp
, NULL
,
1972 0, NULL
, NULL
, NULL
, NULL
, NULL
) == 0);
1980 gen_mask
= -1ULL >> (64 - 8 * i
);
1982 dprintf("getting %llu [%u mask %llx]\n", object
, fid_gen
, gen_mask
);
1983 if (err
= zfs_zget(zfsvfs
, object
, &zp
)) {
1987 (void) sa_lookup(zp
->z_sa_hdl
, SA_ZPL_GEN(zfsvfs
), &zp_gen
,
1989 zp_gen
= zp_gen
& gen_mask
;
1992 if (zp
->z_unlinked
|| zp_gen
!= fid_gen
) {
1993 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen
, fid_gen
);
1996 return (SET_ERROR(EINVAL
));
2005 * Block out VOPs and close zfsvfs_t::z_os
2007 * Note, if successful, then we return with the 'z_teardown_lock' and
2008 * 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
2009 * dataset and objset intact so that they can be atomically handed off during
2010 * a subsequent rollback or recv operation and the resume thereafter.
2013 zfs_suspend_fs(zfsvfs_t
*zfsvfs
)
2017 if ((error
= zfsvfs_teardown(zfsvfs
, B_FALSE
)) != 0)
2024 * Rebuild SA and release VOPs. Note that ownership of the underlying dataset
2025 * is an invariant across any of the operations that can be performed while the
2026 * filesystem was suspended. Whether it succeeded or failed, the preconditions
2027 * are the same: the relevant objset and associated dataset are owned by
2028 * zfsvfs, held, and long held on entry.
2031 zfs_resume_fs(zfsvfs_t
*zfsvfs
, dsl_dataset_t
*ds
)
2036 ASSERT(RRM_WRITE_HELD(&zfsvfs
->z_teardown_lock
));
2037 ASSERT(RW_WRITE_HELD(&zfsvfs
->z_teardown_inactive_lock
));
2040 * We already own this, so just update the objset_t, as the one we
2041 * had before may have been evicted.
2044 VERIFY3P(ds
->ds_owner
, ==, zfsvfs
);
2045 VERIFY(dsl_dataset_long_held(ds
));
2046 VERIFY0(dmu_objset_from_ds(ds
, &os
));
2048 err
= zfsvfs_init(zfsvfs
, os
);
2052 VERIFY(zfsvfs_setup(zfsvfs
, B_FALSE
) == 0);
2054 zfs_set_fuid_feature(zfsvfs
);
2057 * Attempt to re-establish all the active znodes with
2058 * their dbufs. If a zfs_rezget() fails, then we'll let
2059 * any potential callers discover that via ZFS_ENTER_VERIFY_VP
2060 * when they try to use their znode.
2062 mutex_enter(&zfsvfs
->z_znodes_lock
);
2063 for (zp
= list_head(&zfsvfs
->z_all_znodes
); zp
;
2064 zp
= list_next(&zfsvfs
->z_all_znodes
, zp
)) {
2065 (void) zfs_rezget(zp
);
2067 mutex_exit(&zfsvfs
->z_znodes_lock
);
2070 /* release the VOPs */
2071 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
2072 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
2076 * Since we couldn't setup the sa framework, try to force
2077 * unmount this file system.
2079 if (vn_vfswlock(zfsvfs
->z_vfs
->vfs_vnodecovered
) == 0)
2080 (void) dounmount(zfsvfs
->z_vfs
, MS_FORCE
, CRED());
2086 zfs_freevfs(vfs_t
*vfsp
)
2088 zfsvfs_t
*zfsvfs
= vfsp
->vfs_data
;
2091 * If this is a snapshot, we have an extra VFS_HOLD on our parent
2092 * from zfs_mount(). Release it here. If we came through
2093 * zfs_mountroot() instead, we didn't grab an extra hold, so
2094 * skip the VFS_RELE for rootvfs.
2096 if (zfsvfs
->z_issnap
&& (vfsp
!= rootvfs
))
2097 VFS_RELE(zfsvfs
->z_parent
->z_vfs
);
2099 zfsvfs_free(zfsvfs
);
2101 atomic_dec_32(&zfs_active_fs_count
);
2105 * VFS_INIT() initialization. Note that there is no VFS_FINI(),
2106 * so we can't safely do any non-idempotent initialization here.
2107 * Leave that to zfs_init() and zfs_fini(), which are called
2108 * from the module's _init() and _fini() entry points.
2112 zfs_vfsinit(int fstype
, char *name
)
2119 * Setup vfsops and vnodeops tables.
2121 error
= vfs_setfsops(fstype
, zfs_vfsops_template
, &zfs_vfsops
);
2123 cmn_err(CE_WARN
, "zfs: bad vfs ops template");
2126 error
= zfs_create_op_tables();
2128 zfs_remove_op_tables();
2129 cmn_err(CE_WARN
, "zfs: bad vnode ops template");
2130 (void) vfs_freevfsops_by_type(zfsfstype
);
2134 mutex_init(&zfs_dev_mtx
, NULL
, MUTEX_DEFAULT
, NULL
);
2137 * Unique major number for all zfs mounts.
2138 * If we run out of 32-bit minors, we'll getudev() another major.
2140 zfs_major
= ddi_name_to_major(ZFS_DRIVER
);
2141 zfs_minor
= ZFS_MIN_MINOR
;
2150 * Initialize .zfs directory structures
2155 * Initialize znode cache, vnode ops, etc...
2159 dmu_objset_register_type(DMU_OST_ZFS
, zfs_space_delta_cb
);
2172 return (zfs_active_fs_count
!= 0);
2176 zfs_set_version(zfsvfs_t
*zfsvfs
, uint64_t newvers
)
2179 objset_t
*os
= zfsvfs
->z_os
;
2182 if (newvers
< ZPL_VERSION_INITIAL
|| newvers
> ZPL_VERSION
)
2183 return (SET_ERROR(EINVAL
));
2185 if (newvers
< zfsvfs
->z_version
)
2186 return (SET_ERROR(EINVAL
));
2188 if (zfs_spa_version_map(newvers
) >
2189 spa_version(dmu_objset_spa(zfsvfs
->z_os
)))
2190 return (SET_ERROR(ENOTSUP
));
2192 tx
= dmu_tx_create(os
);
2193 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_FALSE
, ZPL_VERSION_STR
);
2194 if (newvers
>= ZPL_VERSION_SA
&& !zfsvfs
->z_use_sa
) {
2195 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
2197 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
2199 error
= dmu_tx_assign(tx
, TXG_WAIT
);
2205 error
= zap_update(os
, MASTER_NODE_OBJ
, ZPL_VERSION_STR
,
2206 8, 1, &newvers
, tx
);
2213 if (newvers
>= ZPL_VERSION_SA
&& !zfsvfs
->z_use_sa
) {
2216 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs
->z_os
)), >=,
2218 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
2219 DMU_OT_NONE
, 0, tx
);
2221 error
= zap_add(os
, MASTER_NODE_OBJ
,
2222 ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
2225 VERIFY(0 == sa_set_sa_object(os
, sa_obj
));
2226 sa_register_update_callback(os
, zfs_sa_upgrade
);
2229 spa_history_log_internal_ds(dmu_objset_ds(os
), "upgrade", tx
,
2230 "from %llu to %llu", zfsvfs
->z_version
, newvers
);
2234 zfsvfs
->z_version
= newvers
;
2235 os
->os_version
= newvers
;
2237 zfs_set_fuid_feature(zfsvfs
);
2243 * Read a property stored within the master node.
2246 zfs_get_zplprop(objset_t
*os
, zfs_prop_t prop
, uint64_t *value
)
2248 uint64_t *cached_copy
= NULL
;
2251 * Figure out where in the objset_t the cached copy would live, if it
2252 * is available for the requested property.
2256 case ZFS_PROP_VERSION
:
2257 cached_copy
= &os
->os_version
;
2259 case ZFS_PROP_NORMALIZE
:
2260 cached_copy
= &os
->os_normalization
;
2262 case ZFS_PROP_UTF8ONLY
:
2263 cached_copy
= &os
->os_utf8only
;
2266 cached_copy
= &os
->os_casesensitivity
;
2272 if (cached_copy
!= NULL
&& *cached_copy
!= OBJSET_PROP_UNINITIALIZED
) {
2273 *value
= *cached_copy
;
2278 * If the property wasn't cached, look up the file system's value for
2279 * the property. For the version property, we look up a slightly
2284 if (prop
== ZFS_PROP_VERSION
) {
2285 pname
= ZPL_VERSION_STR
;
2287 pname
= zfs_prop_to_name(prop
);
2291 ASSERT3U(os
->os_phys
->os_type
, ==, DMU_OST_ZFS
);
2292 error
= zap_lookup(os
, MASTER_NODE_OBJ
, pname
, 8, 1, value
);
2295 if (error
== ENOENT
) {
2296 /* No value set, use the default value */
2298 case ZFS_PROP_VERSION
:
2299 *value
= ZPL_VERSION
;
2301 case ZFS_PROP_NORMALIZE
:
2302 case ZFS_PROP_UTF8ONLY
:
2306 *value
= ZFS_CASE_SENSITIVE
;
2315 * If one of the methods for getting the property value above worked,
2316 * copy it into the objset_t's cache.
2318 if (error
== 0 && cached_copy
!= NULL
) {
2319 *cached_copy
= *value
;
2326 * Return true if the coresponding vfs's unmounted flag is set.
2327 * Otherwise return false.
2328 * If this function returns true we know VFS unmount has been initiated.
2331 zfs_get_vfs_flag_unmounted(objset_t
*os
)
2334 boolean_t unmounted
= B_FALSE
;
2336 ASSERT(dmu_objset_type(os
) == DMU_OST_ZFS
);
2338 mutex_enter(&os
->os_user_ptr_lock
);
2339 zfvp
= dmu_objset_get_user(os
);
2340 if (zfvp
!= NULL
&& zfvp
->z_vfs
!= NULL
&&
2341 (zfvp
->z_vfs
->vfs_flag
& VFS_UNMOUNTED
))
2343 mutex_exit(&os
->os_user_ptr_lock
);
2348 static vfsdef_t vfw
= {
2352 VSW_HASPROTO
|VSW_CANRWRO
|VSW_CANREMOUNT
|VSW_VOLATILEDEV
|VSW_STATS
|
2357 struct modlfs zfs_modlfs
= {
2358 &mod_fsops
, "ZFS filesystem version " SPA_VERSION_STRING
, &vfw