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) 2013 by Delphix. All rights reserved.
26 /* Portions Copyright 2010 Robert Milkowski */
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/sysmacros.h>
33 #include <sys/pathname.h>
34 #include <sys/vnode.h>
36 #include <sys/vfs_opreg.h>
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>
42 #include <sys/zfs_vnops.h>
43 #include <sys/zfs_dir.h>
45 #include <sys/fs/zfs.h>
47 #include <sys/dsl_prop.h>
48 #include <sys/dsl_dataset.h>
49 #include <sys/dsl_deleg.h>
53 #include <sys/sa_impl.h>
54 #include <sys/varargs.h>
55 #include <sys/policy.h>
56 #include <sys/atomic.h>
57 #include <sys/mkdev.h>
58 #include <sys/modctl.h>
59 #include <sys/refstr.h>
60 #include <sys/zfs_ioctl.h>
61 #include <sys/zfs_ctldir.h>
62 #include <sys/zfs_fuid.h>
63 #include <sys/bootconf.h>
64 #include <sys/sunddi.h>
66 #include <sys/dmu_objset.h>
67 #include <sys/spa_boot.h>
69 #include "zfs_comutil.h"
74 zfs_sync(struct super_block
*sb
, int wait
, cred_t
*cr
)
76 zfs_sb_t
*zsb
= sb
->s_fs_info
;
79 * Data integrity is job one. We don't want a compromised kernel
80 * writing to the storage pool, so we never sync during panic.
82 if (unlikely(oops_in_progress
))
86 * Semantically, the only requirement is that the sync be initiated.
87 * The DMU syncs out txgs frequently, so there's nothing to do.
94 * Sync a specific filesystem.
99 dp
= dmu_objset_pool(zsb
->z_os
);
102 * If the system is shutting down, then skip any
103 * filesystems which may exist on a suspended pool.
105 if (spa_suspended(dp
->dp_spa
)) {
110 if (zsb
->z_log
!= NULL
)
111 zil_commit(zsb
->z_log
, 0);
116 * Sync all ZFS filesystems. This is what happens when you
117 * run sync(1M). Unlike other filesystems, ZFS honors the
118 * request by waiting for all pools to commit all dirty data.
125 EXPORT_SYMBOL(zfs_sync
);
128 zfs_is_readonly(zfs_sb_t
*zsb
)
130 return (!!(zsb
->z_sb
->s_flags
& MS_RDONLY
));
132 EXPORT_SYMBOL(zfs_is_readonly
);
135 atime_changed_cb(void *arg
, uint64_t newval
)
137 ((zfs_sb_t
*)arg
)->z_atime
= newval
;
141 relatime_changed_cb(void *arg
, uint64_t newval
)
143 ((zfs_sb_t
*)arg
)->z_relatime
= newval
;
147 xattr_changed_cb(void *arg
, uint64_t newval
)
151 if (newval
== ZFS_XATTR_OFF
) {
152 zsb
->z_flags
&= ~ZSB_XATTR
;
154 zsb
->z_flags
|= ZSB_XATTR
;
156 if (newval
== ZFS_XATTR_SA
)
157 zsb
->z_xattr_sa
= B_TRUE
;
159 zsb
->z_xattr_sa
= B_FALSE
;
164 acltype_changed_cb(void *arg
, uint64_t newval
)
169 case ZFS_ACLTYPE_OFF
:
170 zsb
->z_acl_type
= ZFS_ACLTYPE_OFF
;
171 zsb
->z_sb
->s_flags
&= ~MS_POSIXACL
;
173 case ZFS_ACLTYPE_POSIXACL
:
174 #ifdef CONFIG_FS_POSIX_ACL
175 zsb
->z_acl_type
= ZFS_ACLTYPE_POSIXACL
;
176 zsb
->z_sb
->s_flags
|= MS_POSIXACL
;
178 zsb
->z_acl_type
= ZFS_ACLTYPE_OFF
;
179 zsb
->z_sb
->s_flags
&= ~MS_POSIXACL
;
180 #endif /* CONFIG_FS_POSIX_ACL */
188 blksz_changed_cb(void *arg
, uint64_t newval
)
192 if (newval
< SPA_MINBLOCKSIZE
||
193 newval
> SPA_MAXBLOCKSIZE
|| !ISP2(newval
))
194 newval
= SPA_MAXBLOCKSIZE
;
196 zsb
->z_max_blksz
= newval
;
200 readonly_changed_cb(void *arg
, uint64_t newval
)
203 struct super_block
*sb
= zsb
->z_sb
;
209 sb
->s_flags
|= MS_RDONLY
;
211 sb
->s_flags
&= ~MS_RDONLY
;
215 devices_changed_cb(void *arg
, uint64_t newval
)
220 setuid_changed_cb(void *arg
, uint64_t newval
)
225 exec_changed_cb(void *arg
, uint64_t newval
)
230 nbmand_changed_cb(void *arg
, uint64_t newval
)
233 struct super_block
*sb
= zsb
->z_sb
;
239 sb
->s_flags
|= MS_MANDLOCK
;
241 sb
->s_flags
&= ~MS_MANDLOCK
;
245 snapdir_changed_cb(void *arg
, uint64_t newval
)
247 ((zfs_sb_t
*)arg
)->z_show_ctldir
= newval
;
251 vscan_changed_cb(void *arg
, uint64_t newval
)
253 ((zfs_sb_t
*)arg
)->z_vscan
= newval
;
257 acl_inherit_changed_cb(void *arg
, uint64_t newval
)
259 ((zfs_sb_t
*)arg
)->z_acl_inherit
= newval
;
263 zfs_register_callbacks(zfs_sb_t
*zsb
)
265 struct dsl_dataset
*ds
= NULL
;
266 objset_t
*os
= zsb
->z_os
;
267 boolean_t do_readonly
= B_FALSE
;
270 if (zfs_is_readonly(zsb
) || !spa_writeable(dmu_objset_spa(os
)))
271 do_readonly
= B_TRUE
;
274 * Register property callbacks.
276 * It would probably be fine to just check for i/o error from
277 * the first prop_register(), but I guess I like to go
280 ds
= dmu_objset_ds(os
);
281 dsl_pool_config_enter(dmu_objset_pool(os
), FTAG
);
282 error
= dsl_prop_register(ds
,
283 zfs_prop_to_name(ZFS_PROP_ATIME
), atime_changed_cb
, zsb
);
284 error
= dsl_prop_register(ds
,
285 zfs_prop_to_name(ZFS_PROP_RELATIME
), relatime_changed_cb
, zsb
);
286 error
= error
? error
: dsl_prop_register(ds
,
287 zfs_prop_to_name(ZFS_PROP_XATTR
), xattr_changed_cb
, zsb
);
288 error
= error
? error
: dsl_prop_register(ds
,
289 zfs_prop_to_name(ZFS_PROP_RECORDSIZE
), blksz_changed_cb
, zsb
);
290 error
= error
? error
: dsl_prop_register(ds
,
291 zfs_prop_to_name(ZFS_PROP_READONLY
), readonly_changed_cb
, zsb
);
292 error
= error
? error
: dsl_prop_register(ds
,
293 zfs_prop_to_name(ZFS_PROP_DEVICES
), devices_changed_cb
, zsb
);
294 error
= error
? error
: dsl_prop_register(ds
,
295 zfs_prop_to_name(ZFS_PROP_SETUID
), setuid_changed_cb
, zsb
);
296 error
= error
? error
: dsl_prop_register(ds
,
297 zfs_prop_to_name(ZFS_PROP_EXEC
), exec_changed_cb
, zsb
);
298 error
= error
? error
: dsl_prop_register(ds
,
299 zfs_prop_to_name(ZFS_PROP_SNAPDIR
), snapdir_changed_cb
, zsb
);
300 error
= error
? error
: dsl_prop_register(ds
,
301 zfs_prop_to_name(ZFS_PROP_ACLTYPE
), acltype_changed_cb
, zsb
);
302 error
= error
? error
: dsl_prop_register(ds
,
303 zfs_prop_to_name(ZFS_PROP_ACLINHERIT
), acl_inherit_changed_cb
, zsb
);
304 error
= error
? error
: dsl_prop_register(ds
,
305 zfs_prop_to_name(ZFS_PROP_VSCAN
), vscan_changed_cb
, zsb
);
306 error
= error
? error
: dsl_prop_register(ds
,
307 zfs_prop_to_name(ZFS_PROP_NBMAND
), nbmand_changed_cb
, zsb
);
308 dsl_pool_config_exit(dmu_objset_pool(os
), FTAG
);
313 readonly_changed_cb(zsb
, B_TRUE
);
319 * We may attempt to unregister some callbacks that are not
320 * registered, but this is OK; it will simply return ENOMSG,
321 * which we will ignore.
323 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_ATIME
),
324 atime_changed_cb
, zsb
);
325 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_RELATIME
),
326 relatime_changed_cb
, zsb
);
327 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_XATTR
),
328 xattr_changed_cb
, zsb
);
329 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_RECORDSIZE
),
330 blksz_changed_cb
, zsb
);
331 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_READONLY
),
332 readonly_changed_cb
, zsb
);
333 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_DEVICES
),
334 devices_changed_cb
, zsb
);
335 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_SETUID
),
336 setuid_changed_cb
, zsb
);
337 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_EXEC
),
338 exec_changed_cb
, zsb
);
339 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_SNAPDIR
),
340 snapdir_changed_cb
, zsb
);
341 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_ACLTYPE
),
342 acltype_changed_cb
, zsb
);
343 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_ACLINHERIT
),
344 acl_inherit_changed_cb
, zsb
);
345 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_VSCAN
),
346 vscan_changed_cb
, zsb
);
347 (void) dsl_prop_unregister(ds
, zfs_prop_to_name(ZFS_PROP_NBMAND
),
348 nbmand_changed_cb
, zsb
);
352 EXPORT_SYMBOL(zfs_register_callbacks
);
355 zfs_space_delta_cb(dmu_object_type_t bonustype
, void *data
,
356 uint64_t *userp
, uint64_t *groupp
)
359 * Is it a valid type of object to track?
361 if (bonustype
!= DMU_OT_ZNODE
&& bonustype
!= DMU_OT_SA
)
362 return (SET_ERROR(ENOENT
));
365 * If we have a NULL data pointer
366 * then assume the id's aren't changing and
367 * return EEXIST to the dmu to let it know to
371 return (SET_ERROR(EEXIST
));
373 if (bonustype
== DMU_OT_ZNODE
) {
374 znode_phys_t
*znp
= data
;
375 *userp
= znp
->zp_uid
;
376 *groupp
= znp
->zp_gid
;
379 sa_hdr_phys_t
*sap
= data
;
380 sa_hdr_phys_t sa
= *sap
;
381 boolean_t swap
= B_FALSE
;
383 ASSERT(bonustype
== DMU_OT_SA
);
385 if (sa
.sa_magic
== 0) {
387 * This should only happen for newly created
388 * files that haven't had the znode data filled
395 if (sa
.sa_magic
== BSWAP_32(SA_MAGIC
)) {
396 sa
.sa_magic
= SA_MAGIC
;
397 sa
.sa_layout_info
= BSWAP_16(sa
.sa_layout_info
);
400 VERIFY3U(sa
.sa_magic
, ==, SA_MAGIC
);
403 hdrsize
= sa_hdrsize(&sa
);
404 VERIFY3U(hdrsize
, >=, sizeof (sa_hdr_phys_t
));
405 *userp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+
407 *groupp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+
410 *userp
= BSWAP_64(*userp
);
411 *groupp
= BSWAP_64(*groupp
);
418 fuidstr_to_sid(zfs_sb_t
*zsb
, const char *fuidstr
,
419 char *domainbuf
, int buflen
, uid_t
*ridp
)
424 fuid
= strtonum(fuidstr
, NULL
);
426 domain
= zfs_fuid_find_by_idx(zsb
, FUID_INDEX(fuid
));
428 (void) strlcpy(domainbuf
, domain
, buflen
);
431 *ridp
= FUID_RID(fuid
);
435 zfs_userquota_prop_to_obj(zfs_sb_t
*zsb
, zfs_userquota_prop_t type
)
438 case ZFS_PROP_USERUSED
:
439 return (DMU_USERUSED_OBJECT
);
440 case ZFS_PROP_GROUPUSED
:
441 return (DMU_GROUPUSED_OBJECT
);
442 case ZFS_PROP_USERQUOTA
:
443 return (zsb
->z_userquota_obj
);
444 case ZFS_PROP_GROUPQUOTA
:
445 return (zsb
->z_groupquota_obj
);
447 return (SET_ERROR(ENOTSUP
));
453 zfs_userspace_many(zfs_sb_t
*zsb
, zfs_userquota_prop_t type
,
454 uint64_t *cookiep
, void *vbuf
, uint64_t *bufsizep
)
459 zfs_useracct_t
*buf
= vbuf
;
462 if (!dmu_objset_userspace_present(zsb
->z_os
))
463 return (SET_ERROR(ENOTSUP
));
465 obj
= zfs_userquota_prop_to_obj(zsb
, type
);
471 for (zap_cursor_init_serialized(&zc
, zsb
->z_os
, obj
, *cookiep
);
472 (error
= zap_cursor_retrieve(&zc
, &za
)) == 0;
473 zap_cursor_advance(&zc
)) {
474 if ((uintptr_t)buf
- (uintptr_t)vbuf
+ sizeof (zfs_useracct_t
) >
478 fuidstr_to_sid(zsb
, za
.za_name
,
479 buf
->zu_domain
, sizeof (buf
->zu_domain
), &buf
->zu_rid
);
481 buf
->zu_space
= za
.za_first_integer
;
487 ASSERT3U((uintptr_t)buf
- (uintptr_t)vbuf
, <=, *bufsizep
);
488 *bufsizep
= (uintptr_t)buf
- (uintptr_t)vbuf
;
489 *cookiep
= zap_cursor_serialize(&zc
);
490 zap_cursor_fini(&zc
);
493 EXPORT_SYMBOL(zfs_userspace_many
);
496 * buf must be big enough (eg, 32 bytes)
499 id_to_fuidstr(zfs_sb_t
*zsb
, const char *domain
, uid_t rid
,
500 char *buf
, boolean_t addok
)
505 if (domain
&& domain
[0]) {
506 domainid
= zfs_fuid_find_by_domain(zsb
, domain
, NULL
, addok
);
508 return (SET_ERROR(ENOENT
));
510 fuid
= FUID_ENCODE(domainid
, rid
);
511 (void) sprintf(buf
, "%llx", (longlong_t
)fuid
);
516 zfs_userspace_one(zfs_sb_t
*zsb
, zfs_userquota_prop_t type
,
517 const char *domain
, uint64_t rid
, uint64_t *valp
)
525 if (!dmu_objset_userspace_present(zsb
->z_os
))
526 return (SET_ERROR(ENOTSUP
));
528 obj
= zfs_userquota_prop_to_obj(zsb
, type
);
532 err
= id_to_fuidstr(zsb
, domain
, rid
, buf
, B_FALSE
);
536 err
= zap_lookup(zsb
->z_os
, obj
, buf
, 8, 1, valp
);
541 EXPORT_SYMBOL(zfs_userspace_one
);
544 zfs_set_userquota(zfs_sb_t
*zsb
, zfs_userquota_prop_t type
,
545 const char *domain
, uint64_t rid
, uint64_t quota
)
551 boolean_t fuid_dirtied
;
553 if (type
!= ZFS_PROP_USERQUOTA
&& type
!= ZFS_PROP_GROUPQUOTA
)
554 return (SET_ERROR(EINVAL
));
556 if (zsb
->z_version
< ZPL_VERSION_USERSPACE
)
557 return (SET_ERROR(ENOTSUP
));
559 objp
= (type
== ZFS_PROP_USERQUOTA
) ? &zsb
->z_userquota_obj
:
560 &zsb
->z_groupquota_obj
;
562 err
= id_to_fuidstr(zsb
, domain
, rid
, buf
, B_TRUE
);
565 fuid_dirtied
= zsb
->z_fuid_dirty
;
567 tx
= dmu_tx_create(zsb
->z_os
);
568 dmu_tx_hold_zap(tx
, *objp
? *objp
: DMU_NEW_OBJECT
, B_TRUE
, NULL
);
570 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
571 zfs_userquota_prop_prefixes
[type
]);
574 zfs_fuid_txhold(zsb
, tx
);
575 err
= dmu_tx_assign(tx
, TXG_WAIT
);
581 mutex_enter(&zsb
->z_lock
);
583 *objp
= zap_create(zsb
->z_os
, DMU_OT_USERGROUP_QUOTA
,
585 VERIFY(0 == zap_add(zsb
->z_os
, MASTER_NODE_OBJ
,
586 zfs_userquota_prop_prefixes
[type
], 8, 1, objp
, tx
));
588 mutex_exit(&zsb
->z_lock
);
591 err
= zap_remove(zsb
->z_os
, *objp
, buf
, tx
);
595 err
= zap_update(zsb
->z_os
, *objp
, buf
, 8, 1, "a
, tx
);
599 zfs_fuid_sync(zsb
, tx
);
603 EXPORT_SYMBOL(zfs_set_userquota
);
606 zfs_fuid_overquota(zfs_sb_t
*zsb
, boolean_t isgroup
, uint64_t fuid
)
609 uint64_t used
, quota
, usedobj
, quotaobj
;
612 usedobj
= isgroup
? DMU_GROUPUSED_OBJECT
: DMU_USERUSED_OBJECT
;
613 quotaobj
= isgroup
? zsb
->z_groupquota_obj
: zsb
->z_userquota_obj
;
615 if (quotaobj
== 0 || zsb
->z_replay
)
618 (void) sprintf(buf
, "%llx", (longlong_t
)fuid
);
619 err
= zap_lookup(zsb
->z_os
, quotaobj
, buf
, 8, 1, "a
);
623 err
= zap_lookup(zsb
->z_os
, usedobj
, buf
, 8, 1, &used
);
626 return (used
>= quota
);
628 EXPORT_SYMBOL(zfs_fuid_overquota
);
631 zfs_owner_overquota(zfs_sb_t
*zsb
, znode_t
*zp
, boolean_t isgroup
)
636 quotaobj
= isgroup
? zsb
->z_groupquota_obj
: zsb
->z_userquota_obj
;
638 fuid
= isgroup
? zp
->z_gid
: zp
->z_uid
;
640 if (quotaobj
== 0 || zsb
->z_replay
)
643 return (zfs_fuid_overquota(zsb
, isgroup
, fuid
));
645 EXPORT_SYMBOL(zfs_owner_overquota
);
648 zfs_sb_create(const char *osname
, zfs_sb_t
**zsbp
)
656 zsb
= kmem_zalloc(sizeof (zfs_sb_t
), KM_SLEEP
| KM_NODEBUG
);
659 * We claim to always be readonly so we can open snapshots;
660 * other ZPL code will prevent us from writing to snapshots.
662 error
= dmu_objset_own(osname
, DMU_OST_ZFS
, B_TRUE
, zsb
, &os
);
664 kmem_free(zsb
, sizeof (zfs_sb_t
));
669 * Initialize the zfs-specific filesystem structure.
670 * Should probably make this a kmem cache, shuffle fields,
671 * and just bzero up to z_hold_mtx[].
675 zsb
->z_max_blksz
= SPA_MAXBLOCKSIZE
;
676 zsb
->z_show_ctldir
= ZFS_SNAPDIR_VISIBLE
;
679 error
= zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zsb
->z_version
);
682 } else if (zsb
->z_version
>
683 zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)))) {
684 (void) printk("Can't mount a version %lld file system "
685 "on a version %lld pool\n. Pool must be upgraded to mount "
686 "this file system.", (u_longlong_t
)zsb
->z_version
,
687 (u_longlong_t
)spa_version(dmu_objset_spa(os
)));
688 error
= SET_ERROR(ENOTSUP
);
691 if ((error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &zval
)) != 0)
693 zsb
->z_norm
= (int)zval
;
695 if ((error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &zval
)) != 0)
697 zsb
->z_utf8
= (zval
!= 0);
699 if ((error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &zval
)) != 0)
701 zsb
->z_case
= (uint_t
)zval
;
703 if ((error
= zfs_get_zplprop(os
, ZFS_PROP_ACLTYPE
, &zval
)) != 0)
705 zsb
->z_acl_type
= (uint_t
)zval
;
708 * Fold case on file systems that are always or sometimes case
711 if (zsb
->z_case
== ZFS_CASE_INSENSITIVE
||
712 zsb
->z_case
== ZFS_CASE_MIXED
)
713 zsb
->z_norm
|= U8_TEXTPREP_TOUPPER
;
715 zsb
->z_use_fuids
= USE_FUIDS(zsb
->z_version
, zsb
->z_os
);
716 zsb
->z_use_sa
= USE_SA(zsb
->z_version
, zsb
->z_os
);
719 /* should either have both of these objects or none */
720 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1,
725 error
= zfs_get_zplprop(os
, ZFS_PROP_XATTR
, &zval
);
726 if ((error
== 0) && (zval
== ZFS_XATTR_SA
))
727 zsb
->z_xattr_sa
= B_TRUE
;
730 * Pre SA versions file systems should never touch
731 * either the attribute registration or layout objects.
736 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
741 if (zsb
->z_version
>= ZPL_VERSION_SA
)
742 sa_register_update_callback(os
, zfs_sa_upgrade
);
744 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_ROOT_OBJ
, 8, 1,
748 ASSERT(zsb
->z_root
!= 0);
750 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_UNLINKED_SET
, 8, 1,
751 &zsb
->z_unlinkedobj
);
755 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
756 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
],
757 8, 1, &zsb
->z_userquota_obj
);
758 if (error
&& error
!= ENOENT
)
761 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
762 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
],
763 8, 1, &zsb
->z_groupquota_obj
);
764 if (error
&& error
!= ENOENT
)
767 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_FUID_TABLES
, 8, 1,
769 if (error
&& error
!= ENOENT
)
772 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SHARES_DIR
, 8, 1,
774 if (error
&& error
!= ENOENT
)
777 mutex_init(&zsb
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
778 mutex_init(&zsb
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
779 list_create(&zsb
->z_all_znodes
, sizeof (znode_t
),
780 offsetof(znode_t
, z_link_node
));
781 rrw_init(&zsb
->z_teardown_lock
, B_FALSE
);
782 rw_init(&zsb
->z_teardown_inactive_lock
, NULL
, RW_DEFAULT
, NULL
);
783 rw_init(&zsb
->z_fuid_lock
, NULL
, RW_DEFAULT
, NULL
);
784 for (i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
785 mutex_init(&zsb
->z_hold_mtx
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
787 avl_create(&zsb
->z_ctldir_snaps
, snapentry_compare
,
788 sizeof (zfs_snapentry_t
), offsetof(zfs_snapentry_t
, se_node
));
789 mutex_init(&zsb
->z_ctldir_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
795 dmu_objset_disown(os
, zsb
);
797 kmem_free(zsb
, sizeof (zfs_sb_t
));
800 EXPORT_SYMBOL(zfs_sb_create
);
803 zfs_sb_setup(zfs_sb_t
*zsb
, boolean_t mounting
)
807 error
= zfs_register_callbacks(zsb
);
812 * Set the objset user_ptr to track its zsb.
814 mutex_enter(&zsb
->z_os
->os_user_ptr_lock
);
815 dmu_objset_set_user(zsb
->z_os
, zsb
);
816 mutex_exit(&zsb
->z_os
->os_user_ptr_lock
);
818 zsb
->z_log
= zil_open(zsb
->z_os
, zfs_get_data
);
821 * If we are not mounting (ie: online recv), then we don't
822 * have to worry about replaying the log as we blocked all
823 * operations out since we closed the ZIL.
829 * During replay we remove the read only flag to
830 * allow replays to succeed.
832 readonly
= zfs_is_readonly(zsb
);
834 readonly_changed_cb(zsb
, B_FALSE
);
836 zfs_unlinked_drain(zsb
);
839 * Parse and replay the intent log.
841 * Because of ziltest, this must be done after
842 * zfs_unlinked_drain(). (Further note: ziltest
843 * doesn't use readonly mounts, where
844 * zfs_unlinked_drain() isn't called.) This is because
845 * ziltest causes spa_sync() to think it's committed,
846 * but actually it is not, so the intent log contains
847 * many txg's worth of changes.
849 * In particular, if object N is in the unlinked set in
850 * the last txg to actually sync, then it could be
851 * actually freed in a later txg and then reallocated
852 * in a yet later txg. This would write a "create
853 * object N" record to the intent log. Normally, this
854 * would be fine because the spa_sync() would have
855 * written out the fact that object N is free, before
856 * we could write the "create object N" intent log
859 * But when we are in ziltest mode, we advance the "open
860 * txg" without actually spa_sync()-ing the changes to
861 * disk. So we would see that object N is still
862 * allocated and in the unlinked set, and there is an
863 * intent log record saying to allocate it.
865 if (spa_writeable(dmu_objset_spa(zsb
->z_os
))) {
866 if (zil_replay_disable
) {
867 zil_destroy(zsb
->z_log
, B_FALSE
);
869 zsb
->z_replay
= B_TRUE
;
870 zil_replay(zsb
->z_os
, zsb
,
872 zsb
->z_replay
= B_FALSE
;
876 /* restore readonly bit */
878 readonly_changed_cb(zsb
, B_TRUE
);
883 EXPORT_SYMBOL(zfs_sb_setup
);
886 zfs_sb_free(zfs_sb_t
*zsb
)
890 zfs_fuid_destroy(zsb
);
892 mutex_destroy(&zsb
->z_znodes_lock
);
893 mutex_destroy(&zsb
->z_lock
);
894 list_destroy(&zsb
->z_all_znodes
);
895 rrw_destroy(&zsb
->z_teardown_lock
);
896 rw_destroy(&zsb
->z_teardown_inactive_lock
);
897 rw_destroy(&zsb
->z_fuid_lock
);
898 for (i
= 0; i
!= ZFS_OBJ_MTX_SZ
; i
++)
899 mutex_destroy(&zsb
->z_hold_mtx
[i
]);
900 mutex_destroy(&zsb
->z_ctldir_lock
);
901 avl_destroy(&zsb
->z_ctldir_snaps
);
902 kmem_free(zsb
, sizeof (zfs_sb_t
));
904 EXPORT_SYMBOL(zfs_sb_free
);
907 zfs_set_fuid_feature(zfs_sb_t
*zsb
)
909 zsb
->z_use_fuids
= USE_FUIDS(zsb
->z_version
, zsb
->z_os
);
910 zsb
->z_use_sa
= USE_SA(zsb
->z_version
, zsb
->z_os
);
914 zfs_unregister_callbacks(zfs_sb_t
*zsb
)
916 objset_t
*os
= zsb
->z_os
;
917 struct dsl_dataset
*ds
;
920 * Unregister properties.
922 if (!dmu_objset_is_snapshot(os
)) {
923 ds
= dmu_objset_ds(os
);
924 VERIFY(dsl_prop_unregister(ds
, "atime", atime_changed_cb
,
927 VERIFY(dsl_prop_unregister(ds
, "relatime", relatime_changed_cb
,
930 VERIFY(dsl_prop_unregister(ds
, "xattr", xattr_changed_cb
,
933 VERIFY(dsl_prop_unregister(ds
, "recordsize", blksz_changed_cb
,
936 VERIFY(dsl_prop_unregister(ds
, "readonly", readonly_changed_cb
,
939 VERIFY(dsl_prop_unregister(ds
, "devices", devices_changed_cb
,
942 VERIFY(dsl_prop_unregister(ds
, "setuid", setuid_changed_cb
,
945 VERIFY(dsl_prop_unregister(ds
, "exec", exec_changed_cb
,
948 VERIFY(dsl_prop_unregister(ds
, "snapdir", snapdir_changed_cb
,
951 VERIFY(dsl_prop_unregister(ds
, "acltype", acltype_changed_cb
,
954 VERIFY(dsl_prop_unregister(ds
, "aclinherit",
955 acl_inherit_changed_cb
, zsb
) == 0);
957 VERIFY(dsl_prop_unregister(ds
, "vscan",
958 vscan_changed_cb
, zsb
) == 0);
960 VERIFY(dsl_prop_unregister(ds
, "nbmand",
961 nbmand_changed_cb
, zsb
) == 0);
964 EXPORT_SYMBOL(zfs_unregister_callbacks
);
968 * Check that the hex label string is appropriate for the dataset being
969 * mounted into the global_zone proper.
971 * Return an error if the hex label string is not default or
972 * admin_low/admin_high. For admin_low labels, the corresponding
973 * dataset must be readonly.
976 zfs_check_global_label(const char *dsname
, const char *hexsl
)
978 if (strcasecmp(hexsl
, ZFS_MLSLABEL_DEFAULT
) == 0)
980 if (strcasecmp(hexsl
, ADMIN_HIGH
) == 0)
982 if (strcasecmp(hexsl
, ADMIN_LOW
) == 0) {
983 /* must be readonly */
986 if (dsl_prop_get_integer(dsname
,
987 zfs_prop_to_name(ZFS_PROP_READONLY
), &rdonly
, NULL
))
988 return (SET_ERROR(EACCES
));
989 return (rdonly
? 0 : EACCES
);
991 return (SET_ERROR(EACCES
));
993 EXPORT_SYMBOL(zfs_check_global_label
);
994 #endif /* HAVE_MLSLABEL */
997 zfs_statvfs(struct dentry
*dentry
, struct kstatfs
*statp
)
999 zfs_sb_t
*zsb
= dentry
->d_sb
->s_fs_info
;
1000 uint64_t refdbytes
, availbytes
, usedobjs
, availobjs
;
1006 dmu_objset_space(zsb
->z_os
,
1007 &refdbytes
, &availbytes
, &usedobjs
, &availobjs
);
1009 fsid
= dmu_objset_fsid_guid(zsb
->z_os
);
1011 * The underlying storage pool actually uses multiple block
1012 * size. Under Solaris frsize (fragment size) is reported as
1013 * the smallest block size we support, and bsize (block size)
1014 * as the filesystem's maximum block size. Unfortunately,
1015 * under Linux the fragment size and block size are often used
1016 * interchangeably. Thus we are forced to report both of them
1017 * as the filesystem's maximum block size.
1019 statp
->f_frsize
= zsb
->z_max_blksz
;
1020 statp
->f_bsize
= zsb
->z_max_blksz
;
1021 bshift
= fls(statp
->f_bsize
) - 1;
1024 * The following report "total" blocks of various kinds in
1025 * the file system, but reported in terms of f_bsize - the
1029 statp
->f_blocks
= (refdbytes
+ availbytes
) >> bshift
;
1030 statp
->f_bfree
= availbytes
>> bshift
;
1031 statp
->f_bavail
= statp
->f_bfree
; /* no root reservation */
1034 * statvfs() should really be called statufs(), because it assumes
1035 * static metadata. ZFS doesn't preallocate files, so the best
1036 * we can do is report the max that could possibly fit in f_files,
1037 * and that minus the number actually used in f_ffree.
1038 * For f_ffree, report the smaller of the number of object available
1039 * and the number of blocks (each object will take at least a block).
1041 statp
->f_ffree
= MIN(availobjs
, availbytes
>> DNODE_SHIFT
);
1042 statp
->f_files
= statp
->f_ffree
+ usedobjs
;
1043 statp
->f_fsid
.val
[0] = (uint32_t)fsid
;
1044 statp
->f_fsid
.val
[1] = (uint32_t)(fsid
>> 32);
1045 statp
->f_type
= ZFS_SUPER_MAGIC
;
1046 statp
->f_namelen
= ZFS_MAXNAMELEN
;
1049 * We have all of 40 characters to stuff a string here.
1050 * Is there anything useful we could/should provide?
1052 bzero(statp
->f_spare
, sizeof (statp
->f_spare
));
1057 EXPORT_SYMBOL(zfs_statvfs
);
1060 zfs_root(zfs_sb_t
*zsb
, struct inode
**ipp
)
1067 error
= zfs_zget(zsb
, zsb
->z_root
, &rootzp
);
1069 *ipp
= ZTOI(rootzp
);
1074 EXPORT_SYMBOL(zfs_root
);
1078 zfs_sb_prune(struct super_block
*sb
, unsigned long nr_to_scan
, int *objects
)
1080 zfs_sb_t
*zsb
= sb
->s_fs_info
;
1081 struct shrinker
*shrinker
= &sb
->s_shrink
;
1082 struct shrink_control sc
= {
1083 .nr_to_scan
= nr_to_scan
,
1084 .gfp_mask
= GFP_KERNEL
,
1088 *objects
= (*shrinker
->shrink
)(shrinker
, &sc
);
1093 EXPORT_SYMBOL(zfs_sb_prune
);
1094 #endif /* HAVE_SHRINK */
1097 * Teardown the zfs_sb_t.
1099 * Note, if 'unmounting' if FALSE, we return with the 'z_teardown_lock'
1100 * and 'z_teardown_inactive_lock' held.
1103 zfs_sb_teardown(zfs_sb_t
*zsb
, boolean_t unmounting
)
1108 * If someone has not already unmounted this file system,
1109 * drain the iput_taskq to ensure all active references to the
1110 * zfs_sb_t have been handled only then can it be safely destroyed.
1113 taskq_wait(dsl_pool_iput_taskq(dmu_objset_pool(zsb
->z_os
)));
1115 rrw_enter(&zsb
->z_teardown_lock
, RW_WRITER
, FTAG
);
1119 * We purge the parent filesystem's super block as the
1120 * parent filesystem and all of its snapshots have their
1121 * inode's super block set to the parent's filesystem's
1122 * super block. Note, 'z_parent' is self referential
1123 * for non-snapshots.
1125 shrink_dcache_sb(zsb
->z_parent
->z_sb
);
1129 * Close the zil. NB: Can't close the zil while zfs_inactive
1130 * threads are blocked as zil_close can call zfs_inactive.
1133 zil_close(zsb
->z_log
);
1137 rw_enter(&zsb
->z_teardown_inactive_lock
, RW_WRITER
);
1140 * If we are not unmounting (ie: online recv) and someone already
1141 * unmounted this file system while we were doing the switcheroo,
1142 * or a reopen of z_os failed then just bail out now.
1144 if (!unmounting
&& (zsb
->z_unmounted
|| zsb
->z_os
== NULL
)) {
1145 rw_exit(&zsb
->z_teardown_inactive_lock
);
1146 rrw_exit(&zsb
->z_teardown_lock
, FTAG
);
1147 return (SET_ERROR(EIO
));
1151 * At this point there are no VFS ops active, and any new VFS ops
1152 * will fail with EIO since we have z_teardown_lock for writer (only
1153 * relevant for forced unmount).
1155 * Release all holds on dbufs.
1157 mutex_enter(&zsb
->z_znodes_lock
);
1158 for (zp
= list_head(&zsb
->z_all_znodes
); zp
!= NULL
;
1159 zp
= list_next(&zsb
->z_all_znodes
, zp
)) {
1161 zfs_znode_dmu_fini(zp
);
1163 mutex_exit(&zsb
->z_znodes_lock
);
1166 * If we are unmounting, set the unmounted flag and let new VFS ops
1167 * unblock. zfs_inactive will have the unmounted behavior, and all
1168 * other VFS ops will fail with EIO.
1171 zsb
->z_unmounted
= B_TRUE
;
1172 rrw_exit(&zsb
->z_teardown_lock
, FTAG
);
1173 rw_exit(&zsb
->z_teardown_inactive_lock
);
1177 * z_os will be NULL if there was an error in attempting to reopen
1178 * zsb, so just return as the properties had already been
1180 * unregistered and cached data had been evicted before.
1182 if (zsb
->z_os
== NULL
)
1186 * Unregister properties.
1188 zfs_unregister_callbacks(zsb
);
1193 if (dsl_dataset_is_dirty(dmu_objset_ds(zsb
->z_os
)) &&
1194 !zfs_is_readonly(zsb
))
1195 txg_wait_synced(dmu_objset_pool(zsb
->z_os
), 0);
1196 dmu_objset_evict_dbufs(zsb
->z_os
);
1200 EXPORT_SYMBOL(zfs_sb_teardown
);
1202 #if defined(HAVE_BDI) && !defined(HAVE_BDI_SETUP_AND_REGISTER)
1203 atomic_long_t zfs_bdi_seq
= ATOMIC_LONG_INIT(0);
1204 #endif /* HAVE_BDI && !HAVE_BDI_SETUP_AND_REGISTER */
1207 zfs_domount(struct super_block
*sb
, void *data
, int silent
)
1209 zpl_mount_data_t
*zmd
= data
;
1210 const char *osname
= zmd
->z_osname
;
1212 struct inode
*root_inode
;
1213 uint64_t recordsize
;
1216 error
= zfs_sb_create(osname
, &zsb
);
1220 if ((error
= dsl_prop_get_integer(osname
, "recordsize",
1221 &recordsize
, NULL
)))
1225 sb
->s_fs_info
= zsb
;
1226 sb
->s_magic
= ZFS_SUPER_MAGIC
;
1227 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1228 sb
->s_time_gran
= 1;
1229 sb
->s_blocksize
= recordsize
;
1230 sb
->s_blocksize_bits
= ilog2(recordsize
);
1234 * 2.6.32 API change,
1235 * Added backing_device_info (BDI) per super block interfaces. A BDI
1236 * must be configured when using a non-device backed filesystem for
1237 * proper writeback. This is not required for older pdflush kernels.
1239 * NOTE: Linux read-ahead is disabled in favor of zfs read-ahead.
1241 zsb
->z_bdi
.ra_pages
= 0;
1242 sb
->s_bdi
= &zsb
->z_bdi
;
1244 error
= -bdi_setup_and_register(&zsb
->z_bdi
, "zfs", BDI_CAP_MAP_COPY
);
1247 #endif /* HAVE_BDI */
1249 /* Set callback operations for the file system. */
1250 sb
->s_op
= &zpl_super_operations
;
1251 sb
->s_xattr
= zpl_xattr_handlers
;
1252 sb
->s_export_op
= &zpl_export_operations
;
1254 sb
->s_d_op
= &zpl_dentry_operations
;
1255 #endif /* HAVE_S_D_OP */
1257 /* Set features for file system. */
1258 zfs_set_fuid_feature(zsb
);
1260 if (dmu_objset_is_snapshot(zsb
->z_os
)) {
1263 atime_changed_cb(zsb
, B_FALSE
);
1264 readonly_changed_cb(zsb
, B_TRUE
);
1265 if ((error
= dsl_prop_get_integer(osname
,
1266 "xattr", &pval
, NULL
)))
1268 xattr_changed_cb(zsb
, pval
);
1269 if ((error
= dsl_prop_get_integer(osname
,
1270 "acltype", &pval
, NULL
)))
1272 acltype_changed_cb(zsb
, pval
);
1273 zsb
->z_issnap
= B_TRUE
;
1274 zsb
->z_os
->os_sync
= ZFS_SYNC_DISABLED
;
1276 mutex_enter(&zsb
->z_os
->os_user_ptr_lock
);
1277 dmu_objset_set_user(zsb
->z_os
, zsb
);
1278 mutex_exit(&zsb
->z_os
->os_user_ptr_lock
);
1280 error
= zfs_sb_setup(zsb
, B_TRUE
);
1283 /* Allocate a root inode for the filesystem. */
1284 error
= zfs_root(zsb
, &root_inode
);
1286 (void) zfs_umount(sb
);
1290 /* Allocate a root dentry for the filesystem */
1291 sb
->s_root
= d_make_root(root_inode
);
1292 if (sb
->s_root
== NULL
) {
1293 (void) zfs_umount(sb
);
1294 error
= SET_ERROR(ENOMEM
);
1302 dmu_objset_disown(zsb
->z_os
, zsb
);
1308 EXPORT_SYMBOL(zfs_domount
);
1311 * Called when an unmount is requested and certain sanity checks have
1312 * already passed. At this point no dentries or inodes have been reclaimed
1313 * from their respective caches. We drop the extra reference on the .zfs
1314 * control directory to allow everything to be reclaimed. All snapshots
1315 * must already have been unmounted to reach this point.
1318 zfs_preumount(struct super_block
*sb
)
1320 zfs_sb_t
*zsb
= sb
->s_fs_info
;
1322 if (zsb
!= NULL
&& zsb
->z_ctldir
!= NULL
)
1323 zfsctl_destroy(zsb
);
1325 EXPORT_SYMBOL(zfs_preumount
);
1328 * Called once all other unmount released tear down has occurred.
1329 * It is our responsibility to release any remaining infrastructure.
1333 zfs_umount(struct super_block
*sb
)
1335 zfs_sb_t
*zsb
= sb
->s_fs_info
;
1338 VERIFY(zfs_sb_teardown(zsb
, B_TRUE
) == 0);
1342 bdi_destroy(sb
->s_bdi
);
1343 #endif /* HAVE_BDI */
1346 * z_os will be NULL if there was an error in
1347 * attempting to reopen zsb.
1351 * Unset the objset user_ptr.
1353 mutex_enter(&os
->os_user_ptr_lock
);
1354 dmu_objset_set_user(os
, NULL
);
1355 mutex_exit(&os
->os_user_ptr_lock
);
1358 * Finally release the objset
1360 dmu_objset_disown(os
, zsb
);
1366 EXPORT_SYMBOL(zfs_umount
);
1369 zfs_remount(struct super_block
*sb
, int *flags
, char *data
)
1372 * All namespace flags (MNT_*) and super block flags (MS_*) will
1373 * be handled by the Linux VFS. Only handle custom options here.
1377 EXPORT_SYMBOL(zfs_remount
);
1380 zfs_vget(struct super_block
*sb
, struct inode
**ipp
, fid_t
*fidp
)
1382 zfs_sb_t
*zsb
= sb
->s_fs_info
;
1384 uint64_t object
= 0;
1385 uint64_t fid_gen
= 0;
1394 if (fidp
->fid_len
== LONG_FID_LEN
) {
1395 zfid_long_t
*zlfid
= (zfid_long_t
*)fidp
;
1396 uint64_t objsetid
= 0;
1397 uint64_t setgen
= 0;
1399 for (i
= 0; i
< sizeof (zlfid
->zf_setid
); i
++)
1400 objsetid
|= ((uint64_t)zlfid
->zf_setid
[i
]) << (8 * i
);
1402 for (i
= 0; i
< sizeof (zlfid
->zf_setgen
); i
++)
1403 setgen
|= ((uint64_t)zlfid
->zf_setgen
[i
]) << (8 * i
);
1407 err
= zfsctl_lookup_objset(sb
, objsetid
, &zsb
);
1409 return (SET_ERROR(EINVAL
));
1414 if (fidp
->fid_len
== SHORT_FID_LEN
|| fidp
->fid_len
== LONG_FID_LEN
) {
1415 zfid_short_t
*zfid
= (zfid_short_t
*)fidp
;
1417 for (i
= 0; i
< sizeof (zfid
->zf_object
); i
++)
1418 object
|= ((uint64_t)zfid
->zf_object
[i
]) << (8 * i
);
1420 for (i
= 0; i
< sizeof (zfid
->zf_gen
); i
++)
1421 fid_gen
|= ((uint64_t)zfid
->zf_gen
[i
]) << (8 * i
);
1424 return (SET_ERROR(EINVAL
));
1427 /* A zero fid_gen means we are in the .zfs control directories */
1429 (object
== ZFSCTL_INO_ROOT
|| object
== ZFSCTL_INO_SNAPDIR
)) {
1430 *ipp
= zsb
->z_ctldir
;
1431 ASSERT(*ipp
!= NULL
);
1432 if (object
== ZFSCTL_INO_SNAPDIR
) {
1433 VERIFY(zfsctl_root_lookup(*ipp
, "snapshot", ipp
,
1434 0, kcred
, NULL
, NULL
) == 0);
1442 gen_mask
= -1ULL >> (64 - 8 * i
);
1444 dprintf("getting %llu [%u mask %llx]\n", object
, fid_gen
, gen_mask
);
1445 if ((err
= zfs_zget(zsb
, object
, &zp
))) {
1449 (void) sa_lookup(zp
->z_sa_hdl
, SA_ZPL_GEN(zsb
), &zp_gen
,
1451 zp_gen
= zp_gen
& gen_mask
;
1454 if (zp
->z_unlinked
|| zp_gen
!= fid_gen
) {
1455 dprintf("znode gen (%u) != fid gen (%u)\n", zp_gen
, fid_gen
);
1458 return (SET_ERROR(EINVAL
));
1463 zfs_inode_update(ITOZ(*ipp
));
1468 EXPORT_SYMBOL(zfs_vget
);
1471 * Block out VFS ops and close zfs_sb_t
1473 * Note, if successful, then we return with the 'z_teardown_lock' and
1474 * 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
1475 * dataset and objset intact so that they can be atomically handed off during
1476 * a subsequent rollback or recv operation and the resume thereafter.
1479 zfs_suspend_fs(zfs_sb_t
*zsb
)
1483 if ((error
= zfs_sb_teardown(zsb
, B_FALSE
)) != 0)
1488 EXPORT_SYMBOL(zfs_suspend_fs
);
1491 * Reopen zfs_sb_t and release VFS ops.
1494 zfs_resume_fs(zfs_sb_t
*zsb
, const char *osname
)
1498 uint64_t sa_obj
= 0;
1500 ASSERT(RRW_WRITE_HELD(&zsb
->z_teardown_lock
));
1501 ASSERT(RW_WRITE_HELD(&zsb
->z_teardown_inactive_lock
));
1504 * We already own this, so just hold and rele it to update the
1505 * objset_t, as the one we had before may have been evicted.
1507 VERIFY0(dmu_objset_hold(osname
, zsb
, &zsb
->z_os
));
1508 VERIFY3P(zsb
->z_os
->os_dsl_dataset
->ds_owner
, ==, zsb
);
1509 VERIFY(dsl_dataset_long_held(zsb
->z_os
->os_dsl_dataset
));
1510 dmu_objset_rele(zsb
->z_os
, zsb
);
1513 * Make sure version hasn't changed
1516 err
= zfs_get_zplprop(zsb
->z_os
, ZFS_PROP_VERSION
,
1522 err
= zap_lookup(zsb
->z_os
, MASTER_NODE_OBJ
,
1523 ZFS_SA_ATTRS
, 8, 1, &sa_obj
);
1525 if (err
&& zsb
->z_version
>= ZPL_VERSION_SA
)
1528 if ((err
= sa_setup(zsb
->z_os
, sa_obj
,
1529 zfs_attr_table
, ZPL_END
, &zsb
->z_attr_table
)) != 0)
1532 if (zsb
->z_version
>= ZPL_VERSION_SA
)
1533 sa_register_update_callback(zsb
->z_os
,
1536 VERIFY(zfs_sb_setup(zsb
, B_FALSE
) == 0);
1538 zfs_set_fuid_feature(zsb
);
1539 zsb
->z_rollback_time
= jiffies
;
1542 * Attempt to re-establish all the active inodes with their
1543 * dbufs. If a zfs_rezget() fails, then we unhash the inode
1544 * and mark it stale. This prevents a collision if a new
1545 * inode/object is created which must use the same inode
1546 * number. The stale inode will be be released when the
1547 * VFS prunes the dentry holding the remaining references
1548 * on the stale inode.
1550 mutex_enter(&zsb
->z_znodes_lock
);
1551 for (zp
= list_head(&zsb
->z_all_znodes
); zp
;
1552 zp
= list_next(&zsb
->z_all_znodes
, zp
)) {
1553 err2
= zfs_rezget(zp
);
1555 remove_inode_hash(ZTOI(zp
));
1556 zp
->z_is_stale
= B_TRUE
;
1559 mutex_exit(&zsb
->z_znodes_lock
);
1562 /* release the VFS ops */
1563 rw_exit(&zsb
->z_teardown_inactive_lock
);
1564 rrw_exit(&zsb
->z_teardown_lock
, FTAG
);
1568 * Since we couldn't setup the sa framework, try to force
1569 * unmount this file system.
1572 (void) zfs_umount(zsb
->z_sb
);
1576 EXPORT_SYMBOL(zfs_resume_fs
);
1579 zfs_set_version(zfs_sb_t
*zsb
, uint64_t newvers
)
1582 objset_t
*os
= zsb
->z_os
;
1585 if (newvers
< ZPL_VERSION_INITIAL
|| newvers
> ZPL_VERSION
)
1586 return (SET_ERROR(EINVAL
));
1588 if (newvers
< zsb
->z_version
)
1589 return (SET_ERROR(EINVAL
));
1591 if (zfs_spa_version_map(newvers
) >
1592 spa_version(dmu_objset_spa(zsb
->z_os
)))
1593 return (SET_ERROR(ENOTSUP
));
1595 tx
= dmu_tx_create(os
);
1596 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_FALSE
, ZPL_VERSION_STR
);
1597 if (newvers
>= ZPL_VERSION_SA
&& !zsb
->z_use_sa
) {
1598 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
1600 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
1602 error
= dmu_tx_assign(tx
, TXG_WAIT
);
1608 error
= zap_update(os
, MASTER_NODE_OBJ
, ZPL_VERSION_STR
,
1609 8, 1, &newvers
, tx
);
1616 if (newvers
>= ZPL_VERSION_SA
&& !zsb
->z_use_sa
) {
1619 ASSERT3U(spa_version(dmu_objset_spa(zsb
->z_os
)), >=,
1621 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
1622 DMU_OT_NONE
, 0, tx
);
1624 error
= zap_add(os
, MASTER_NODE_OBJ
,
1625 ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
1628 VERIFY(0 == sa_set_sa_object(os
, sa_obj
));
1629 sa_register_update_callback(os
, zfs_sa_upgrade
);
1632 spa_history_log_internal_ds(dmu_objset_ds(os
), "upgrade", tx
,
1633 "from %llu to %llu", zsb
->z_version
, newvers
);
1637 zsb
->z_version
= newvers
;
1639 zfs_set_fuid_feature(zsb
);
1643 EXPORT_SYMBOL(zfs_set_version
);
1646 * Read a property stored within the master node.
1649 zfs_get_zplprop(objset_t
*os
, zfs_prop_t prop
, uint64_t *value
)
1652 int error
= SET_ERROR(ENOENT
);
1655 * Look up the file system's value for the property. For the
1656 * version property, we look up a slightly different string.
1658 if (prop
== ZFS_PROP_VERSION
)
1659 pname
= ZPL_VERSION_STR
;
1661 pname
= zfs_prop_to_name(prop
);
1664 error
= zap_lookup(os
, MASTER_NODE_OBJ
, pname
, 8, 1, value
);
1666 if (error
== ENOENT
) {
1667 /* No value set, use the default value */
1669 case ZFS_PROP_VERSION
:
1670 *value
= ZPL_VERSION
;
1672 case ZFS_PROP_NORMALIZE
:
1673 case ZFS_PROP_UTF8ONLY
:
1677 *value
= ZFS_CASE_SENSITIVE
;
1679 case ZFS_PROP_ACLTYPE
:
1680 *value
= ZFS_ACLTYPE_OFF
;
1689 EXPORT_SYMBOL(zfs_get_zplprop
);
1696 dmu_objset_register_type(DMU_OST_ZFS
, zfs_space_delta_cb
);
1697 register_filesystem(&zpl_fs_type
);
1698 (void) arc_add_prune_callback(zpl_prune_sbs
, NULL
);
1704 taskq_wait(system_taskq
);
1705 unregister_filesystem(&zpl_fs_type
);