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, 2018 by Delphix. All rights reserved.
26 /* Portions Copyright 2010 Robert Milkowski */
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/sysmacros.h>
32 #include <sys/pathname.h>
33 #include <sys/vnode.h>
35 #include <sys/mntent.h>
36 #include <sys/cmn_err.h>
37 #include <sys/zfs_znode.h>
38 #include <sys/zfs_vnops.h>
39 #include <sys/zfs_dir.h>
41 #include <sys/fs/zfs.h>
43 #include <sys/dsl_prop.h>
44 #include <sys/dsl_dataset.h>
45 #include <sys/dsl_deleg.h>
49 #include <sys/sa_impl.h>
50 #include <sys/policy.h>
51 #include <sys/atomic.h>
52 #include <sys/zfs_ioctl.h>
53 #include <sys/zfs_ctldir.h>
54 #include <sys/zfs_fuid.h>
55 #include <sys/sunddi.h>
56 #include <sys/dmu_objset.h>
57 #include <sys/spa_boot.h>
59 #include <linux/vfs_compat.h>
60 #include "zfs_comutil.h"
85 static const match_table_t zpl_tokens
= {
86 { TOKEN_RO
, MNTOPT_RO
},
87 { TOKEN_RW
, MNTOPT_RW
},
88 { TOKEN_SETUID
, MNTOPT_SETUID
},
89 { TOKEN_NOSETUID
, MNTOPT_NOSETUID
},
90 { TOKEN_EXEC
, MNTOPT_EXEC
},
91 { TOKEN_NOEXEC
, MNTOPT_NOEXEC
},
92 { TOKEN_DEVICES
, MNTOPT_DEVICES
},
93 { TOKEN_NODEVICES
, MNTOPT_NODEVICES
},
94 { TOKEN_DIRXATTR
, MNTOPT_DIRXATTR
},
95 { TOKEN_SAXATTR
, MNTOPT_SAXATTR
},
96 { TOKEN_XATTR
, MNTOPT_XATTR
},
97 { TOKEN_NOXATTR
, MNTOPT_NOXATTR
},
98 { TOKEN_ATIME
, MNTOPT_ATIME
},
99 { TOKEN_NOATIME
, MNTOPT_NOATIME
},
100 { TOKEN_RELATIME
, MNTOPT_RELATIME
},
101 { TOKEN_NORELATIME
, MNTOPT_NORELATIME
},
102 { TOKEN_NBMAND
, MNTOPT_NBMAND
},
103 { TOKEN_NONBMAND
, MNTOPT_NONBMAND
},
104 { TOKEN_MNTPOINT
, MNTOPT_MNTPOINT
"=%s" },
105 { TOKEN_LAST
, NULL
},
109 zfsvfs_vfs_free(vfs_t
*vfsp
)
112 if (vfsp
->vfs_mntpoint
!= NULL
)
113 strfree(vfsp
->vfs_mntpoint
);
115 kmem_free(vfsp
, sizeof (vfs_t
));
120 zfsvfs_parse_option(char *option
, int token
, substring_t
*args
, vfs_t
*vfsp
)
124 vfsp
->vfs_readonly
= B_TRUE
;
125 vfsp
->vfs_do_readonly
= B_TRUE
;
128 vfsp
->vfs_readonly
= B_FALSE
;
129 vfsp
->vfs_do_readonly
= B_TRUE
;
132 vfsp
->vfs_setuid
= B_TRUE
;
133 vfsp
->vfs_do_setuid
= B_TRUE
;
136 vfsp
->vfs_setuid
= B_FALSE
;
137 vfsp
->vfs_do_setuid
= B_TRUE
;
140 vfsp
->vfs_exec
= B_TRUE
;
141 vfsp
->vfs_do_exec
= B_TRUE
;
144 vfsp
->vfs_exec
= B_FALSE
;
145 vfsp
->vfs_do_exec
= B_TRUE
;
148 vfsp
->vfs_devices
= B_TRUE
;
149 vfsp
->vfs_do_devices
= B_TRUE
;
151 case TOKEN_NODEVICES
:
152 vfsp
->vfs_devices
= B_FALSE
;
153 vfsp
->vfs_do_devices
= B_TRUE
;
156 vfsp
->vfs_xattr
= ZFS_XATTR_DIR
;
157 vfsp
->vfs_do_xattr
= B_TRUE
;
160 vfsp
->vfs_xattr
= ZFS_XATTR_SA
;
161 vfsp
->vfs_do_xattr
= B_TRUE
;
164 vfsp
->vfs_xattr
= ZFS_XATTR_DIR
;
165 vfsp
->vfs_do_xattr
= B_TRUE
;
168 vfsp
->vfs_xattr
= ZFS_XATTR_OFF
;
169 vfsp
->vfs_do_xattr
= B_TRUE
;
172 vfsp
->vfs_atime
= B_TRUE
;
173 vfsp
->vfs_do_atime
= B_TRUE
;
176 vfsp
->vfs_atime
= B_FALSE
;
177 vfsp
->vfs_do_atime
= B_TRUE
;
180 vfsp
->vfs_relatime
= B_TRUE
;
181 vfsp
->vfs_do_relatime
= B_TRUE
;
183 case TOKEN_NORELATIME
:
184 vfsp
->vfs_relatime
= B_FALSE
;
185 vfsp
->vfs_do_relatime
= B_TRUE
;
188 vfsp
->vfs_nbmand
= B_TRUE
;
189 vfsp
->vfs_do_nbmand
= B_TRUE
;
192 vfsp
->vfs_nbmand
= B_FALSE
;
193 vfsp
->vfs_do_nbmand
= B_TRUE
;
196 vfsp
->vfs_mntpoint
= match_strdup(&args
[0]);
197 if (vfsp
->vfs_mntpoint
== NULL
)
198 return (SET_ERROR(ENOMEM
));
209 * Parse the raw mntopts and return a vfs_t describing the options.
212 zfsvfs_parse_options(char *mntopts
, vfs_t
**vfsp
)
217 tmp_vfsp
= kmem_zalloc(sizeof (vfs_t
), KM_SLEEP
);
219 if (mntopts
!= NULL
) {
220 substring_t args
[MAX_OPT_ARGS
];
221 char *tmp_mntopts
, *p
, *t
;
224 tmp_mntopts
= t
= strdup(mntopts
);
225 if (tmp_mntopts
== NULL
)
226 return (SET_ERROR(ENOMEM
));
228 while ((p
= strsep(&t
, ",")) != NULL
) {
232 args
[0].to
= args
[0].from
= NULL
;
233 token
= match_token(p
, zpl_tokens
, args
);
234 error
= zfsvfs_parse_option(p
, token
, args
, tmp_vfsp
);
236 strfree(tmp_mntopts
);
237 zfsvfs_vfs_free(tmp_vfsp
);
242 strfree(tmp_mntopts
);
251 zfs_is_readonly(zfsvfs_t
*zfsvfs
)
253 return (!!(zfsvfs
->z_sb
->s_flags
& SB_RDONLY
));
258 zfs_sync(struct super_block
*sb
, int wait
, cred_t
*cr
)
260 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
263 * Semantically, the only requirement is that the sync be initiated.
264 * The DMU syncs out txgs frequently, so there's nothing to do.
269 if (zfsvfs
!= NULL
) {
271 * Sync a specific filesystem.
276 dp
= dmu_objset_pool(zfsvfs
->z_os
);
279 * If the system is shutting down, then skip any
280 * filesystems which may exist on a suspended pool.
282 if (spa_suspended(dp
->dp_spa
)) {
287 if (zfsvfs
->z_log
!= NULL
)
288 zil_commit(zfsvfs
->z_log
, 0);
293 * Sync all ZFS filesystems. This is what happens when you
294 * run sync(1M). Unlike other filesystems, ZFS honors the
295 * request by waiting for all pools to commit all dirty data.
304 atime_changed_cb(void *arg
, uint64_t newval
)
306 ((zfsvfs_t
*)arg
)->z_atime
= newval
;
310 relatime_changed_cb(void *arg
, uint64_t newval
)
312 ((zfsvfs_t
*)arg
)->z_relatime
= newval
;
316 xattr_changed_cb(void *arg
, uint64_t newval
)
318 zfsvfs_t
*zfsvfs
= arg
;
320 if (newval
== ZFS_XATTR_OFF
) {
321 zfsvfs
->z_flags
&= ~ZSB_XATTR
;
323 zfsvfs
->z_flags
|= ZSB_XATTR
;
325 if (newval
== ZFS_XATTR_SA
)
326 zfsvfs
->z_xattr_sa
= B_TRUE
;
328 zfsvfs
->z_xattr_sa
= B_FALSE
;
333 acltype_changed_cb(void *arg
, uint64_t newval
)
335 zfsvfs_t
*zfsvfs
= arg
;
338 case ZFS_ACLTYPE_OFF
:
339 zfsvfs
->z_acl_type
= ZFS_ACLTYPE_OFF
;
340 zfsvfs
->z_sb
->s_flags
&= ~SB_POSIXACL
;
342 case ZFS_ACLTYPE_POSIXACL
:
343 #ifdef CONFIG_FS_POSIX_ACL
344 zfsvfs
->z_acl_type
= ZFS_ACLTYPE_POSIXACL
;
345 zfsvfs
->z_sb
->s_flags
|= SB_POSIXACL
;
347 zfsvfs
->z_acl_type
= ZFS_ACLTYPE_OFF
;
348 zfsvfs
->z_sb
->s_flags
&= ~SB_POSIXACL
;
349 #endif /* CONFIG_FS_POSIX_ACL */
357 blksz_changed_cb(void *arg
, uint64_t newval
)
359 zfsvfs_t
*zfsvfs
= arg
;
360 ASSERT3U(newval
, <=, spa_maxblocksize(dmu_objset_spa(zfsvfs
->z_os
)));
361 ASSERT3U(newval
, >=, SPA_MINBLOCKSIZE
);
362 ASSERT(ISP2(newval
));
364 zfsvfs
->z_max_blksz
= newval
;
368 readonly_changed_cb(void *arg
, uint64_t newval
)
370 zfsvfs_t
*zfsvfs
= arg
;
371 struct super_block
*sb
= zfsvfs
->z_sb
;
377 sb
->s_flags
|= SB_RDONLY
;
379 sb
->s_flags
&= ~SB_RDONLY
;
383 devices_changed_cb(void *arg
, uint64_t newval
)
388 setuid_changed_cb(void *arg
, uint64_t newval
)
393 exec_changed_cb(void *arg
, uint64_t newval
)
398 nbmand_changed_cb(void *arg
, uint64_t newval
)
400 zfsvfs_t
*zfsvfs
= arg
;
401 struct super_block
*sb
= zfsvfs
->z_sb
;
407 sb
->s_flags
|= SB_MANDLOCK
;
409 sb
->s_flags
&= ~SB_MANDLOCK
;
413 snapdir_changed_cb(void *arg
, uint64_t newval
)
415 ((zfsvfs_t
*)arg
)->z_show_ctldir
= newval
;
419 vscan_changed_cb(void *arg
, uint64_t newval
)
421 ((zfsvfs_t
*)arg
)->z_vscan
= newval
;
425 acl_inherit_changed_cb(void *arg
, uint64_t newval
)
427 ((zfsvfs_t
*)arg
)->z_acl_inherit
= newval
;
431 zfs_register_callbacks(vfs_t
*vfsp
)
433 struct dsl_dataset
*ds
= NULL
;
435 zfsvfs_t
*zfsvfs
= NULL
;
439 zfsvfs
= vfsp
->vfs_data
;
444 * The act of registering our callbacks will destroy any mount
445 * options we may have. In order to enable temporary overrides
446 * of mount options, we stash away the current values and
447 * restore them after we register the callbacks.
449 if (zfs_is_readonly(zfsvfs
) || !spa_writeable(dmu_objset_spa(os
))) {
450 vfsp
->vfs_do_readonly
= B_TRUE
;
451 vfsp
->vfs_readonly
= B_TRUE
;
455 * Register property callbacks.
457 * It would probably be fine to just check for i/o error from
458 * the first prop_register(), but I guess I like to go
461 ds
= dmu_objset_ds(os
);
462 dsl_pool_config_enter(dmu_objset_pool(os
), FTAG
);
463 error
= dsl_prop_register(ds
,
464 zfs_prop_to_name(ZFS_PROP_ATIME
), atime_changed_cb
, zfsvfs
);
465 error
= error
? error
: dsl_prop_register(ds
,
466 zfs_prop_to_name(ZFS_PROP_RELATIME
), relatime_changed_cb
, zfsvfs
);
467 error
= error
? error
: dsl_prop_register(ds
,
468 zfs_prop_to_name(ZFS_PROP_XATTR
), xattr_changed_cb
, zfsvfs
);
469 error
= error
? error
: dsl_prop_register(ds
,
470 zfs_prop_to_name(ZFS_PROP_RECORDSIZE
), blksz_changed_cb
, zfsvfs
);
471 error
= error
? error
: dsl_prop_register(ds
,
472 zfs_prop_to_name(ZFS_PROP_READONLY
), readonly_changed_cb
, zfsvfs
);
473 error
= error
? error
: dsl_prop_register(ds
,
474 zfs_prop_to_name(ZFS_PROP_DEVICES
), devices_changed_cb
, zfsvfs
);
475 error
= error
? error
: dsl_prop_register(ds
,
476 zfs_prop_to_name(ZFS_PROP_SETUID
), setuid_changed_cb
, zfsvfs
);
477 error
= error
? error
: dsl_prop_register(ds
,
478 zfs_prop_to_name(ZFS_PROP_EXEC
), exec_changed_cb
, zfsvfs
);
479 error
= error
? error
: dsl_prop_register(ds
,
480 zfs_prop_to_name(ZFS_PROP_SNAPDIR
), snapdir_changed_cb
, zfsvfs
);
481 error
= error
? error
: dsl_prop_register(ds
,
482 zfs_prop_to_name(ZFS_PROP_ACLTYPE
), acltype_changed_cb
, zfsvfs
);
483 error
= error
? error
: dsl_prop_register(ds
,
484 zfs_prop_to_name(ZFS_PROP_ACLINHERIT
), acl_inherit_changed_cb
,
486 error
= error
? error
: dsl_prop_register(ds
,
487 zfs_prop_to_name(ZFS_PROP_VSCAN
), vscan_changed_cb
, zfsvfs
);
488 error
= error
? error
: dsl_prop_register(ds
,
489 zfs_prop_to_name(ZFS_PROP_NBMAND
), nbmand_changed_cb
, zfsvfs
);
490 dsl_pool_config_exit(dmu_objset_pool(os
), FTAG
);
495 * Invoke our callbacks to restore temporary mount options.
497 if (vfsp
->vfs_do_readonly
)
498 readonly_changed_cb(zfsvfs
, vfsp
->vfs_readonly
);
499 if (vfsp
->vfs_do_setuid
)
500 setuid_changed_cb(zfsvfs
, vfsp
->vfs_setuid
);
501 if (vfsp
->vfs_do_exec
)
502 exec_changed_cb(zfsvfs
, vfsp
->vfs_exec
);
503 if (vfsp
->vfs_do_devices
)
504 devices_changed_cb(zfsvfs
, vfsp
->vfs_devices
);
505 if (vfsp
->vfs_do_xattr
)
506 xattr_changed_cb(zfsvfs
, vfsp
->vfs_xattr
);
507 if (vfsp
->vfs_do_atime
)
508 atime_changed_cb(zfsvfs
, vfsp
->vfs_atime
);
509 if (vfsp
->vfs_do_relatime
)
510 relatime_changed_cb(zfsvfs
, vfsp
->vfs_relatime
);
511 if (vfsp
->vfs_do_nbmand
)
512 nbmand_changed_cb(zfsvfs
, vfsp
->vfs_nbmand
);
517 dsl_prop_unregister_all(ds
, zfsvfs
);
522 zfs_space_delta_cb(dmu_object_type_t bonustype
, void *data
,
523 uint64_t *userp
, uint64_t *groupp
, uint64_t *projectp
)
526 sa_hdr_phys_t
*sap
= data
;
529 boolean_t swap
= B_FALSE
;
532 * Is it a valid type of object to track?
534 if (bonustype
!= DMU_OT_ZNODE
&& bonustype
!= DMU_OT_SA
)
535 return (SET_ERROR(ENOENT
));
538 * If we have a NULL data pointer
539 * then assume the id's aren't changing and
540 * return EEXIST to the dmu to let it know to
544 return (SET_ERROR(EEXIST
));
546 if (bonustype
== DMU_OT_ZNODE
) {
547 znode_phys_t
*znp
= data
;
548 *userp
= znp
->zp_uid
;
549 *groupp
= znp
->zp_gid
;
550 *projectp
= ZFS_DEFAULT_PROJID
;
554 if (sap
->sa_magic
== 0) {
556 * This should only happen for newly created files
557 * that haven't had the znode data filled in yet.
561 *projectp
= ZFS_DEFAULT_PROJID
;
566 if (sa
.sa_magic
== BSWAP_32(SA_MAGIC
)) {
567 sa
.sa_magic
= SA_MAGIC
;
568 sa
.sa_layout_info
= BSWAP_16(sa
.sa_layout_info
);
571 VERIFY3U(sa
.sa_magic
, ==, SA_MAGIC
);
574 hdrsize
= sa_hdrsize(&sa
);
575 VERIFY3U(hdrsize
, >=, sizeof (sa_hdr_phys_t
));
577 *userp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+ SA_UID_OFFSET
));
578 *groupp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+ SA_GID_OFFSET
));
579 flags
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+ SA_FLAGS_OFFSET
));
581 flags
= BSWAP_64(flags
);
583 if (flags
& ZFS_PROJID
)
584 *projectp
= *((uint64_t *)((uintptr_t)data
+ hdrsize
+
587 *projectp
= ZFS_DEFAULT_PROJID
;
590 *userp
= BSWAP_64(*userp
);
591 *groupp
= BSWAP_64(*groupp
);
592 *projectp
= BSWAP_64(*projectp
);
598 fuidstr_to_sid(zfsvfs_t
*zfsvfs
, const char *fuidstr
,
599 char *domainbuf
, int buflen
, uid_t
*ridp
)
604 fuid
= zfs_strtonum(fuidstr
, NULL
);
606 domain
= zfs_fuid_find_by_idx(zfsvfs
, FUID_INDEX(fuid
));
608 (void) strlcpy(domainbuf
, domain
, buflen
);
611 *ridp
= FUID_RID(fuid
);
615 zfs_userquota_prop_to_obj(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
)
618 case ZFS_PROP_USERUSED
:
619 case ZFS_PROP_USEROBJUSED
:
620 return (DMU_USERUSED_OBJECT
);
621 case ZFS_PROP_GROUPUSED
:
622 case ZFS_PROP_GROUPOBJUSED
:
623 return (DMU_GROUPUSED_OBJECT
);
624 case ZFS_PROP_PROJECTUSED
:
625 case ZFS_PROP_PROJECTOBJUSED
:
626 return (DMU_PROJECTUSED_OBJECT
);
627 case ZFS_PROP_USERQUOTA
:
628 return (zfsvfs
->z_userquota_obj
);
629 case ZFS_PROP_GROUPQUOTA
:
630 return (zfsvfs
->z_groupquota_obj
);
631 case ZFS_PROP_USEROBJQUOTA
:
632 return (zfsvfs
->z_userobjquota_obj
);
633 case ZFS_PROP_GROUPOBJQUOTA
:
634 return (zfsvfs
->z_groupobjquota_obj
);
635 case ZFS_PROP_PROJECTQUOTA
:
636 return (zfsvfs
->z_projectquota_obj
);
637 case ZFS_PROP_PROJECTOBJQUOTA
:
638 return (zfsvfs
->z_projectobjquota_obj
);
640 return (ZFS_NO_OBJECT
);
645 zfs_userspace_many(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
646 uint64_t *cookiep
, void *vbuf
, uint64_t *bufsizep
)
651 zfs_useracct_t
*buf
= vbuf
;
655 if (!dmu_objset_userspace_present(zfsvfs
->z_os
))
656 return (SET_ERROR(ENOTSUP
));
658 if ((type
== ZFS_PROP_PROJECTQUOTA
|| type
== ZFS_PROP_PROJECTUSED
||
659 type
== ZFS_PROP_PROJECTOBJQUOTA
||
660 type
== ZFS_PROP_PROJECTOBJUSED
) &&
661 !dmu_objset_projectquota_present(zfsvfs
->z_os
))
662 return (SET_ERROR(ENOTSUP
));
664 if ((type
== ZFS_PROP_USEROBJUSED
|| type
== ZFS_PROP_GROUPOBJUSED
||
665 type
== ZFS_PROP_USEROBJQUOTA
|| type
== ZFS_PROP_GROUPOBJQUOTA
||
666 type
== ZFS_PROP_PROJECTOBJUSED
||
667 type
== ZFS_PROP_PROJECTOBJQUOTA
) &&
668 !dmu_objset_userobjspace_present(zfsvfs
->z_os
))
669 return (SET_ERROR(ENOTSUP
));
671 obj
= zfs_userquota_prop_to_obj(zfsvfs
, type
);
672 if (obj
== ZFS_NO_OBJECT
) {
677 if (type
== ZFS_PROP_USEROBJUSED
|| type
== ZFS_PROP_GROUPOBJUSED
||
678 type
== ZFS_PROP_PROJECTOBJUSED
)
679 offset
= DMU_OBJACCT_PREFIX_LEN
;
681 for (zap_cursor_init_serialized(&zc
, zfsvfs
->z_os
, obj
, *cookiep
);
682 (error
= zap_cursor_retrieve(&zc
, &za
)) == 0;
683 zap_cursor_advance(&zc
)) {
684 if ((uintptr_t)buf
- (uintptr_t)vbuf
+ sizeof (zfs_useracct_t
) >
689 * skip object quota (with zap name prefix DMU_OBJACCT_PREFIX)
690 * when dealing with block quota and vice versa.
692 if ((offset
> 0) != (strncmp(za
.za_name
, DMU_OBJACCT_PREFIX
,
693 DMU_OBJACCT_PREFIX_LEN
) == 0))
696 fuidstr_to_sid(zfsvfs
, za
.za_name
+ offset
,
697 buf
->zu_domain
, sizeof (buf
->zu_domain
), &buf
->zu_rid
);
699 buf
->zu_space
= za
.za_first_integer
;
705 ASSERT3U((uintptr_t)buf
- (uintptr_t)vbuf
, <=, *bufsizep
);
706 *bufsizep
= (uintptr_t)buf
- (uintptr_t)vbuf
;
707 *cookiep
= zap_cursor_serialize(&zc
);
708 zap_cursor_fini(&zc
);
713 * buf must be big enough (eg, 32 bytes)
716 id_to_fuidstr(zfsvfs_t
*zfsvfs
, const char *domain
, uid_t rid
,
717 char *buf
, boolean_t addok
)
722 if (domain
&& domain
[0]) {
723 domainid
= zfs_fuid_find_by_domain(zfsvfs
, domain
, NULL
, addok
);
725 return (SET_ERROR(ENOENT
));
727 fuid
= FUID_ENCODE(domainid
, rid
);
728 (void) sprintf(buf
, "%llx", (longlong_t
)fuid
);
733 zfs_userspace_one(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
734 const char *domain
, uint64_t rid
, uint64_t *valp
)
736 char buf
[20 + DMU_OBJACCT_PREFIX_LEN
];
743 if (!dmu_objset_userspace_present(zfsvfs
->z_os
))
744 return (SET_ERROR(ENOTSUP
));
746 if ((type
== ZFS_PROP_USEROBJUSED
|| type
== ZFS_PROP_GROUPOBJUSED
||
747 type
== ZFS_PROP_USEROBJQUOTA
|| type
== ZFS_PROP_GROUPOBJQUOTA
||
748 type
== ZFS_PROP_PROJECTOBJUSED
||
749 type
== ZFS_PROP_PROJECTOBJQUOTA
) &&
750 !dmu_objset_userobjspace_present(zfsvfs
->z_os
))
751 return (SET_ERROR(ENOTSUP
));
753 if (type
== ZFS_PROP_PROJECTQUOTA
|| type
== ZFS_PROP_PROJECTUSED
||
754 type
== ZFS_PROP_PROJECTOBJQUOTA
||
755 type
== ZFS_PROP_PROJECTOBJUSED
) {
756 if (!dmu_objset_projectquota_present(zfsvfs
->z_os
))
757 return (SET_ERROR(ENOTSUP
));
758 if (!zpl_is_valid_projid(rid
))
759 return (SET_ERROR(EINVAL
));
762 obj
= zfs_userquota_prop_to_obj(zfsvfs
, type
);
763 if (obj
== ZFS_NO_OBJECT
)
766 if (type
== ZFS_PROP_USEROBJUSED
|| type
== ZFS_PROP_GROUPOBJUSED
||
767 type
== ZFS_PROP_PROJECTOBJUSED
) {
768 strlcpy(buf
, DMU_OBJACCT_PREFIX
, DMU_OBJACCT_PREFIX_LEN
+ 1);
769 offset
= DMU_OBJACCT_PREFIX_LEN
;
772 err
= id_to_fuidstr(zfsvfs
, domain
, rid
, buf
+ offset
, B_FALSE
);
776 err
= zap_lookup(zfsvfs
->z_os
, obj
, buf
, 8, 1, valp
);
783 zfs_set_userquota(zfsvfs_t
*zfsvfs
, zfs_userquota_prop_t type
,
784 const char *domain
, uint64_t rid
, uint64_t quota
)
790 boolean_t fuid_dirtied
;
792 if (zfsvfs
->z_version
< ZPL_VERSION_USERSPACE
)
793 return (SET_ERROR(ENOTSUP
));
796 case ZFS_PROP_USERQUOTA
:
797 objp
= &zfsvfs
->z_userquota_obj
;
799 case ZFS_PROP_GROUPQUOTA
:
800 objp
= &zfsvfs
->z_groupquota_obj
;
802 case ZFS_PROP_USEROBJQUOTA
:
803 objp
= &zfsvfs
->z_userobjquota_obj
;
805 case ZFS_PROP_GROUPOBJQUOTA
:
806 objp
= &zfsvfs
->z_groupobjquota_obj
;
808 case ZFS_PROP_PROJECTQUOTA
:
809 if (!dmu_objset_projectquota_enabled(zfsvfs
->z_os
))
810 return (SET_ERROR(ENOTSUP
));
811 if (!zpl_is_valid_projid(rid
))
812 return (SET_ERROR(EINVAL
));
814 objp
= &zfsvfs
->z_projectquota_obj
;
816 case ZFS_PROP_PROJECTOBJQUOTA
:
817 if (!dmu_objset_projectquota_enabled(zfsvfs
->z_os
))
818 return (SET_ERROR(ENOTSUP
));
819 if (!zpl_is_valid_projid(rid
))
820 return (SET_ERROR(EINVAL
));
822 objp
= &zfsvfs
->z_projectobjquota_obj
;
825 return (SET_ERROR(EINVAL
));
828 err
= id_to_fuidstr(zfsvfs
, domain
, rid
, buf
, B_TRUE
);
831 fuid_dirtied
= zfsvfs
->z_fuid_dirty
;
833 tx
= dmu_tx_create(zfsvfs
->z_os
);
834 dmu_tx_hold_zap(tx
, *objp
? *objp
: DMU_NEW_OBJECT
, B_TRUE
, NULL
);
836 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
837 zfs_userquota_prop_prefixes
[type
]);
840 zfs_fuid_txhold(zfsvfs
, tx
);
841 err
= dmu_tx_assign(tx
, TXG_WAIT
);
847 mutex_enter(&zfsvfs
->z_lock
);
849 *objp
= zap_create(zfsvfs
->z_os
, DMU_OT_USERGROUP_QUOTA
,
851 VERIFY(0 == zap_add(zfsvfs
->z_os
, MASTER_NODE_OBJ
,
852 zfs_userquota_prop_prefixes
[type
], 8, 1, objp
, tx
));
854 mutex_exit(&zfsvfs
->z_lock
);
857 err
= zap_remove(zfsvfs
->z_os
, *objp
, buf
, tx
);
861 err
= zap_update(zfsvfs
->z_os
, *objp
, buf
, 8, 1, "a
, tx
);
865 zfs_fuid_sync(zfsvfs
, tx
);
871 zfs_id_overobjquota(zfsvfs_t
*zfsvfs
, uint64_t usedobj
, uint64_t id
)
873 char buf
[20 + DMU_OBJACCT_PREFIX_LEN
];
874 uint64_t used
, quota
, quotaobj
;
877 if (!dmu_objset_userobjspace_present(zfsvfs
->z_os
)) {
878 if (dmu_objset_userobjspace_upgradable(zfsvfs
->z_os
)) {
879 dsl_pool_config_enter(
880 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
881 dmu_objset_id_quota_upgrade(zfsvfs
->z_os
);
882 dsl_pool_config_exit(
883 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
888 if (usedobj
== DMU_PROJECTUSED_OBJECT
) {
889 if (!dmu_objset_projectquota_present(zfsvfs
->z_os
)) {
890 if (dmu_objset_projectquota_upgradable(zfsvfs
->z_os
)) {
891 dsl_pool_config_enter(
892 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
893 dmu_objset_id_quota_upgrade(zfsvfs
->z_os
);
894 dsl_pool_config_exit(
895 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
899 quotaobj
= zfsvfs
->z_projectobjquota_obj
;
900 } else if (usedobj
== DMU_USERUSED_OBJECT
) {
901 quotaobj
= zfsvfs
->z_userobjquota_obj
;
902 } else if (usedobj
== DMU_GROUPUSED_OBJECT
) {
903 quotaobj
= zfsvfs
->z_groupobjquota_obj
;
907 if (quotaobj
== 0 || zfsvfs
->z_replay
)
910 (void) sprintf(buf
, "%llx", (longlong_t
)id
);
911 err
= zap_lookup(zfsvfs
->z_os
, quotaobj
, buf
, 8, 1, "a
);
915 (void) sprintf(buf
, DMU_OBJACCT_PREFIX
"%llx", (longlong_t
)id
);
916 err
= zap_lookup(zfsvfs
->z_os
, usedobj
, buf
, 8, 1, &used
);
919 return (used
>= quota
);
923 zfs_id_overblockquota(zfsvfs_t
*zfsvfs
, uint64_t usedobj
, uint64_t id
)
926 uint64_t used
, quota
, quotaobj
;
929 if (usedobj
== DMU_PROJECTUSED_OBJECT
) {
930 if (!dmu_objset_projectquota_present(zfsvfs
->z_os
)) {
931 if (dmu_objset_projectquota_upgradable(zfsvfs
->z_os
)) {
932 dsl_pool_config_enter(
933 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
934 dmu_objset_id_quota_upgrade(zfsvfs
->z_os
);
935 dsl_pool_config_exit(
936 dmu_objset_pool(zfsvfs
->z_os
), FTAG
);
940 quotaobj
= zfsvfs
->z_projectquota_obj
;
941 } else if (usedobj
== DMU_USERUSED_OBJECT
) {
942 quotaobj
= zfsvfs
->z_userquota_obj
;
943 } else if (usedobj
== DMU_GROUPUSED_OBJECT
) {
944 quotaobj
= zfsvfs
->z_groupquota_obj
;
948 if (quotaobj
== 0 || zfsvfs
->z_replay
)
951 (void) sprintf(buf
, "%llx", (longlong_t
)id
);
952 err
= zap_lookup(zfsvfs
->z_os
, quotaobj
, buf
, 8, 1, "a
);
956 err
= zap_lookup(zfsvfs
->z_os
, usedobj
, buf
, 8, 1, &used
);
959 return (used
>= quota
);
963 zfs_id_overquota(zfsvfs_t
*zfsvfs
, uint64_t usedobj
, uint64_t id
)
965 return (zfs_id_overblockquota(zfsvfs
, usedobj
, id
) ||
966 zfs_id_overobjquota(zfsvfs
, usedobj
, id
));
970 * Associate this zfsvfs with the given objset, which must be owned.
971 * This will cache a bunch of on-disk state from the objset in the
975 zfsvfs_init(zfsvfs_t
*zfsvfs
, objset_t
*os
)
980 zfsvfs
->z_max_blksz
= SPA_OLD_MAXBLOCKSIZE
;
981 zfsvfs
->z_show_ctldir
= ZFS_SNAPDIR_VISIBLE
;
984 error
= zfs_get_zplprop(os
, ZFS_PROP_VERSION
, &zfsvfs
->z_version
);
987 if (zfsvfs
->z_version
>
988 zfs_zpl_version_map(spa_version(dmu_objset_spa(os
)))) {
989 (void) printk("Can't mount a version %lld file system "
990 "on a version %lld pool\n. Pool must be upgraded to mount "
991 "this file system.", (u_longlong_t
)zfsvfs
->z_version
,
992 (u_longlong_t
)spa_version(dmu_objset_spa(os
)));
993 return (SET_ERROR(ENOTSUP
));
995 error
= zfs_get_zplprop(os
, ZFS_PROP_NORMALIZE
, &val
);
998 zfsvfs
->z_norm
= (int)val
;
1000 error
= zfs_get_zplprop(os
, ZFS_PROP_UTF8ONLY
, &val
);
1003 zfsvfs
->z_utf8
= (val
!= 0);
1005 error
= zfs_get_zplprop(os
, ZFS_PROP_CASE
, &val
);
1008 zfsvfs
->z_case
= (uint_t
)val
;
1010 if ((error
= zfs_get_zplprop(os
, ZFS_PROP_ACLTYPE
, &val
)) != 0)
1012 zfsvfs
->z_acl_type
= (uint_t
)val
;
1015 * Fold case on file systems that are always or sometimes case
1018 if (zfsvfs
->z_case
== ZFS_CASE_INSENSITIVE
||
1019 zfsvfs
->z_case
== ZFS_CASE_MIXED
)
1020 zfsvfs
->z_norm
|= U8_TEXTPREP_TOUPPER
;
1022 zfsvfs
->z_use_fuids
= USE_FUIDS(zfsvfs
->z_version
, zfsvfs
->z_os
);
1023 zfsvfs
->z_use_sa
= USE_SA(zfsvfs
->z_version
, zfsvfs
->z_os
);
1025 uint64_t sa_obj
= 0;
1026 if (zfsvfs
->z_use_sa
) {
1027 /* should either have both of these objects or none */
1028 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
, 8, 1,
1033 error
= zfs_get_zplprop(os
, ZFS_PROP_XATTR
, &val
);
1034 if ((error
== 0) && (val
== ZFS_XATTR_SA
))
1035 zfsvfs
->z_xattr_sa
= B_TRUE
;
1038 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_ROOT_OBJ
, 8, 1,
1042 ASSERT(zfsvfs
->z_root
!= 0);
1044 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_UNLINKED_SET
, 8, 1,
1045 &zfsvfs
->z_unlinkedobj
);
1049 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1050 zfs_userquota_prop_prefixes
[ZFS_PROP_USERQUOTA
],
1051 8, 1, &zfsvfs
->z_userquota_obj
);
1052 if (error
== ENOENT
)
1053 zfsvfs
->z_userquota_obj
= 0;
1054 else if (error
!= 0)
1057 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1058 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPQUOTA
],
1059 8, 1, &zfsvfs
->z_groupquota_obj
);
1060 if (error
== ENOENT
)
1061 zfsvfs
->z_groupquota_obj
= 0;
1062 else if (error
!= 0)
1065 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1066 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTQUOTA
],
1067 8, 1, &zfsvfs
->z_projectquota_obj
);
1068 if (error
== ENOENT
)
1069 zfsvfs
->z_projectquota_obj
= 0;
1070 else if (error
!= 0)
1073 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1074 zfs_userquota_prop_prefixes
[ZFS_PROP_USEROBJQUOTA
],
1075 8, 1, &zfsvfs
->z_userobjquota_obj
);
1076 if (error
== ENOENT
)
1077 zfsvfs
->z_userobjquota_obj
= 0;
1078 else if (error
!= 0)
1081 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1082 zfs_userquota_prop_prefixes
[ZFS_PROP_GROUPOBJQUOTA
],
1083 8, 1, &zfsvfs
->z_groupobjquota_obj
);
1084 if (error
== ENOENT
)
1085 zfsvfs
->z_groupobjquota_obj
= 0;
1086 else if (error
!= 0)
1089 error
= zap_lookup(os
, MASTER_NODE_OBJ
,
1090 zfs_userquota_prop_prefixes
[ZFS_PROP_PROJECTOBJQUOTA
],
1091 8, 1, &zfsvfs
->z_projectobjquota_obj
);
1092 if (error
== ENOENT
)
1093 zfsvfs
->z_projectobjquota_obj
= 0;
1094 else if (error
!= 0)
1097 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_FUID_TABLES
, 8, 1,
1098 &zfsvfs
->z_fuid_obj
);
1099 if (error
== ENOENT
)
1100 zfsvfs
->z_fuid_obj
= 0;
1101 else if (error
!= 0)
1104 error
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_SHARES_DIR
, 8, 1,
1105 &zfsvfs
->z_shares_dir
);
1106 if (error
== ENOENT
)
1107 zfsvfs
->z_shares_dir
= 0;
1108 else if (error
!= 0)
1111 error
= sa_setup(os
, sa_obj
, zfs_attr_table
, ZPL_END
,
1112 &zfsvfs
->z_attr_table
);
1116 if (zfsvfs
->z_version
>= ZPL_VERSION_SA
)
1117 sa_register_update_callback(os
, zfs_sa_upgrade
);
1123 zfsvfs_create(const char *osname
, boolean_t readonly
, zfsvfs_t
**zfvp
)
1128 boolean_t ro
= (readonly
|| (strchr(osname
, '@') != NULL
));
1130 zfsvfs
= kmem_zalloc(sizeof (zfsvfs_t
), KM_SLEEP
);
1132 error
= dmu_objset_own(osname
, DMU_OST_ZFS
, ro
, B_TRUE
, zfsvfs
, &os
);
1134 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
1138 error
= zfsvfs_create_impl(zfvp
, zfsvfs
, os
);
1140 dmu_objset_disown(os
, B_TRUE
, zfsvfs
);
1147 * Note: zfsvfs is assumed to be malloc'd, and will be freed by this function
1148 * on a failure. Do not pass in a statically allocated zfsvfs.
1151 zfsvfs_create_impl(zfsvfs_t
**zfvp
, zfsvfs_t
*zfsvfs
, objset_t
*os
)
1155 zfsvfs
->z_vfs
= NULL
;
1156 zfsvfs
->z_sb
= NULL
;
1157 zfsvfs
->z_parent
= zfsvfs
;
1159 mutex_init(&zfsvfs
->z_znodes_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1160 mutex_init(&zfsvfs
->z_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
1161 list_create(&zfsvfs
->z_all_znodes
, sizeof (znode_t
),
1162 offsetof(znode_t
, z_link_node
));
1163 rrm_init(&zfsvfs
->z_teardown_lock
, B_FALSE
);
1164 rw_init(&zfsvfs
->z_teardown_inactive_lock
, NULL
, RW_DEFAULT
, NULL
);
1165 rw_init(&zfsvfs
->z_fuid_lock
, NULL
, RW_DEFAULT
, NULL
);
1167 int size
= MIN(1 << (highbit64(zfs_object_mutex_size
) - 1),
1169 zfsvfs
->z_hold_size
= size
;
1170 zfsvfs
->z_hold_trees
= vmem_zalloc(sizeof (avl_tree_t
) * size
,
1172 zfsvfs
->z_hold_locks
= vmem_zalloc(sizeof (kmutex_t
) * size
, KM_SLEEP
);
1173 for (int i
= 0; i
!= size
; i
++) {
1174 avl_create(&zfsvfs
->z_hold_trees
[i
], zfs_znode_hold_compare
,
1175 sizeof (znode_hold_t
), offsetof(znode_hold_t
, zh_node
));
1176 mutex_init(&zfsvfs
->z_hold_locks
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
1179 error
= zfsvfs_init(zfsvfs
, os
);
1182 zfsvfs_free(zfsvfs
);
1186 zfsvfs
->z_drain_task
= TASKQID_INVALID
;
1187 zfsvfs
->z_draining
= B_FALSE
;
1188 zfsvfs
->z_drain_cancel
= B_TRUE
;
1195 zfsvfs_setup(zfsvfs_t
*zfsvfs
, boolean_t mounting
)
1198 boolean_t readonly
= zfs_is_readonly(zfsvfs
);
1200 error
= zfs_register_callbacks(zfsvfs
->z_vfs
);
1204 zfsvfs
->z_log
= zil_open(zfsvfs
->z_os
, zfs_get_data
);
1207 * If we are not mounting (ie: online recv), then we don't
1208 * have to worry about replaying the log as we blocked all
1209 * operations out since we closed the ZIL.
1212 ASSERT3P(zfsvfs
->z_kstat
.dk_kstats
, ==, NULL
);
1213 dataset_kstats_create(&zfsvfs
->z_kstat
, zfsvfs
->z_os
);
1216 * During replay we remove the read only flag to
1217 * allow replays to succeed.
1219 if (readonly
!= 0) {
1220 readonly_changed_cb(zfsvfs
, B_FALSE
);
1223 if (zap_get_stats(zfsvfs
->z_os
, zfsvfs
->z_unlinkedobj
,
1225 dataset_kstats_update_nunlinks_kstat(
1226 &zfsvfs
->z_kstat
, zs
.zs_num_entries
);
1228 dprintf_ds(zfsvfs
->z_os
->os_dsl_dataset
,
1229 "num_entries in unlinked set: %llu",
1231 zfs_unlinked_drain(zfsvfs
);
1235 * Parse and replay the intent log.
1237 * Because of ziltest, this must be done after
1238 * zfs_unlinked_drain(). (Further note: ziltest
1239 * doesn't use readonly mounts, where
1240 * zfs_unlinked_drain() isn't called.) This is because
1241 * ziltest causes spa_sync() to think it's committed,
1242 * but actually it is not, so the intent log contains
1243 * many txg's worth of changes.
1245 * In particular, if object N is in the unlinked set in
1246 * the last txg to actually sync, then it could be
1247 * actually freed in a later txg and then reallocated
1248 * in a yet later txg. This would write a "create
1249 * object N" record to the intent log. Normally, this
1250 * would be fine because the spa_sync() would have
1251 * written out the fact that object N is free, before
1252 * we could write the "create object N" intent log
1255 * But when we are in ziltest mode, we advance the "open
1256 * txg" without actually spa_sync()-ing the changes to
1257 * disk. So we would see that object N is still
1258 * allocated and in the unlinked set, and there is an
1259 * intent log record saying to allocate it.
1261 if (spa_writeable(dmu_objset_spa(zfsvfs
->z_os
))) {
1262 if (zil_replay_disable
) {
1263 zil_destroy(zfsvfs
->z_log
, B_FALSE
);
1265 zfsvfs
->z_replay
= B_TRUE
;
1266 zil_replay(zfsvfs
->z_os
, zfsvfs
,
1268 zfsvfs
->z_replay
= B_FALSE
;
1272 /* restore readonly bit */
1274 readonly_changed_cb(zfsvfs
, B_TRUE
);
1278 * Set the objset user_ptr to track its zfsvfs.
1280 mutex_enter(&zfsvfs
->z_os
->os_user_ptr_lock
);
1281 dmu_objset_set_user(zfsvfs
->z_os
, zfsvfs
);
1282 mutex_exit(&zfsvfs
->z_os
->os_user_ptr_lock
);
1288 zfsvfs_free(zfsvfs_t
*zfsvfs
)
1290 int i
, size
= zfsvfs
->z_hold_size
;
1292 zfs_fuid_destroy(zfsvfs
);
1294 mutex_destroy(&zfsvfs
->z_znodes_lock
);
1295 mutex_destroy(&zfsvfs
->z_lock
);
1296 list_destroy(&zfsvfs
->z_all_znodes
);
1297 rrm_destroy(&zfsvfs
->z_teardown_lock
);
1298 rw_destroy(&zfsvfs
->z_teardown_inactive_lock
);
1299 rw_destroy(&zfsvfs
->z_fuid_lock
);
1300 for (i
= 0; i
!= size
; i
++) {
1301 avl_destroy(&zfsvfs
->z_hold_trees
[i
]);
1302 mutex_destroy(&zfsvfs
->z_hold_locks
[i
]);
1304 vmem_free(zfsvfs
->z_hold_trees
, sizeof (avl_tree_t
) * size
);
1305 vmem_free(zfsvfs
->z_hold_locks
, sizeof (kmutex_t
) * size
);
1306 zfsvfs_vfs_free(zfsvfs
->z_vfs
);
1307 dataset_kstats_destroy(&zfsvfs
->z_kstat
);
1308 kmem_free(zfsvfs
, sizeof (zfsvfs_t
));
1312 zfs_set_fuid_feature(zfsvfs_t
*zfsvfs
)
1314 zfsvfs
->z_use_fuids
= USE_FUIDS(zfsvfs
->z_version
, zfsvfs
->z_os
);
1315 zfsvfs
->z_use_sa
= USE_SA(zfsvfs
->z_version
, zfsvfs
->z_os
);
1319 zfs_unregister_callbacks(zfsvfs_t
*zfsvfs
)
1321 objset_t
*os
= zfsvfs
->z_os
;
1323 if (!dmu_objset_is_snapshot(os
))
1324 dsl_prop_unregister_all(dmu_objset_ds(os
), zfsvfs
);
1327 #ifdef HAVE_MLSLABEL
1329 * Check that the hex label string is appropriate for the dataset being
1330 * mounted into the global_zone proper.
1332 * Return an error if the hex label string is not default or
1333 * admin_low/admin_high. For admin_low labels, the corresponding
1334 * dataset must be readonly.
1337 zfs_check_global_label(const char *dsname
, const char *hexsl
)
1339 if (strcasecmp(hexsl
, ZFS_MLSLABEL_DEFAULT
) == 0)
1341 if (strcasecmp(hexsl
, ADMIN_HIGH
) == 0)
1343 if (strcasecmp(hexsl
, ADMIN_LOW
) == 0) {
1344 /* must be readonly */
1347 if (dsl_prop_get_integer(dsname
,
1348 zfs_prop_to_name(ZFS_PROP_READONLY
), &rdonly
, NULL
))
1349 return (SET_ERROR(EACCES
));
1350 return (rdonly
? 0 : EACCES
);
1352 return (SET_ERROR(EACCES
));
1354 #endif /* HAVE_MLSLABEL */
1357 zfs_statfs_project(zfsvfs_t
*zfsvfs
, znode_t
*zp
, struct kstatfs
*statp
,
1360 char buf
[20 + DMU_OBJACCT_PREFIX_LEN
];
1361 uint64_t offset
= DMU_OBJACCT_PREFIX_LEN
;
1366 strlcpy(buf
, DMU_OBJACCT_PREFIX
, DMU_OBJACCT_PREFIX_LEN
+ 1);
1367 err
= id_to_fuidstr(zfsvfs
, NULL
, zp
->z_projid
, buf
+ offset
, B_FALSE
);
1371 if (zfsvfs
->z_projectquota_obj
== 0)
1374 err
= zap_lookup(zfsvfs
->z_os
, zfsvfs
->z_projectquota_obj
,
1375 buf
+ offset
, 8, 1, "a
);
1381 err
= zap_lookup(zfsvfs
->z_os
, DMU_PROJECTUSED_OBJECT
,
1382 buf
+ offset
, 8, 1, &used
);
1383 if (unlikely(err
== ENOENT
)) {
1385 u_longlong_t nblocks
;
1388 * Quota accounting is async, so it is possible race case.
1389 * There is at least one object with the given project ID.
1391 sa_object_size(zp
->z_sa_hdl
, &blksize
, &nblocks
);
1392 if (unlikely(zp
->z_blksz
== 0))
1393 blksize
= zfsvfs
->z_max_blksz
;
1395 used
= blksize
* nblocks
;
1400 statp
->f_blocks
= quota
>> bshift
;
1401 statp
->f_bfree
= (quota
> used
) ? ((quota
- used
) >> bshift
) : 0;
1402 statp
->f_bavail
= statp
->f_bfree
;
1405 if (zfsvfs
->z_projectobjquota_obj
== 0)
1408 err
= zap_lookup(zfsvfs
->z_os
, zfsvfs
->z_projectobjquota_obj
,
1409 buf
+ offset
, 8, 1, "a
);
1415 err
= zap_lookup(zfsvfs
->z_os
, DMU_PROJECTUSED_OBJECT
,
1417 if (unlikely(err
== ENOENT
)) {
1419 * Quota accounting is async, so it is possible race case.
1420 * There is at least one object with the given project ID.
1427 statp
->f_files
= quota
;
1428 statp
->f_ffree
= (quota
> used
) ? (quota
- used
) : 0;
1434 zfs_statvfs(struct dentry
*dentry
, struct kstatfs
*statp
)
1436 zfsvfs_t
*zfsvfs
= dentry
->d_sb
->s_fs_info
;
1437 uint64_t refdbytes
, availbytes
, usedobjs
, availobjs
;
1442 dmu_objset_space(zfsvfs
->z_os
,
1443 &refdbytes
, &availbytes
, &usedobjs
, &availobjs
);
1445 uint64_t fsid
= dmu_objset_fsid_guid(zfsvfs
->z_os
);
1447 * The underlying storage pool actually uses multiple block
1448 * size. Under Solaris frsize (fragment size) is reported as
1449 * the smallest block size we support, and bsize (block size)
1450 * as the filesystem's maximum block size. Unfortunately,
1451 * under Linux the fragment size and block size are often used
1452 * interchangeably. Thus we are forced to report both of them
1453 * as the filesystem's maximum block size.
1455 statp
->f_frsize
= zfsvfs
->z_max_blksz
;
1456 statp
->f_bsize
= zfsvfs
->z_max_blksz
;
1457 uint32_t bshift
= fls(statp
->f_bsize
) - 1;
1460 * The following report "total" blocks of various kinds in
1461 * the file system, but reported in terms of f_bsize - the
1465 /* Round up so we never have a filesytem using 0 blocks. */
1466 refdbytes
= P2ROUNDUP(refdbytes
, statp
->f_bsize
);
1467 statp
->f_blocks
= (refdbytes
+ availbytes
) >> bshift
;
1468 statp
->f_bfree
= availbytes
>> bshift
;
1469 statp
->f_bavail
= statp
->f_bfree
; /* no root reservation */
1472 * statvfs() should really be called statufs(), because it assumes
1473 * static metadata. ZFS doesn't preallocate files, so the best
1474 * we can do is report the max that could possibly fit in f_files,
1475 * and that minus the number actually used in f_ffree.
1476 * For f_ffree, report the smaller of the number of objects available
1477 * and the number of blocks (each object will take at least a block).
1479 statp
->f_ffree
= MIN(availobjs
, availbytes
>> DNODE_SHIFT
);
1480 statp
->f_files
= statp
->f_ffree
+ usedobjs
;
1481 statp
->f_fsid
.val
[0] = (uint32_t)fsid
;
1482 statp
->f_fsid
.val
[1] = (uint32_t)(fsid
>> 32);
1483 statp
->f_type
= ZFS_SUPER_MAGIC
;
1484 statp
->f_namelen
= MAXNAMELEN
- 1;
1487 * We have all of 40 characters to stuff a string here.
1488 * Is there anything useful we could/should provide?
1490 bzero(statp
->f_spare
, sizeof (statp
->f_spare
));
1492 if (dmu_objset_projectquota_enabled(zfsvfs
->z_os
) &&
1493 dmu_objset_projectquota_present(zfsvfs
->z_os
)) {
1494 znode_t
*zp
= ITOZ(dentry
->d_inode
);
1496 if (zp
->z_pflags
& ZFS_PROJINHERIT
&& zp
->z_projid
&&
1497 zpl_is_valid_projid(zp
->z_projid
))
1498 err
= zfs_statfs_project(zfsvfs
, zp
, statp
, bshift
);
1506 zfs_root(zfsvfs_t
*zfsvfs
, struct inode
**ipp
)
1513 error
= zfs_zget(zfsvfs
, zfsvfs
->z_root
, &rootzp
);
1515 *ipp
= ZTOI(rootzp
);
1521 #ifdef HAVE_D_PRUNE_ALIASES
1523 * Linux kernels older than 3.1 do not support a per-filesystem shrinker.
1524 * To accommodate this we must improvise and manually walk the list of znodes
1525 * attempting to prune dentries in order to be able to drop the inodes.
1527 * To avoid scanning the same znodes multiple times they are always rotated
1528 * to the end of the z_all_znodes list. New znodes are inserted at the
1529 * end of the list so we're always scanning the oldest znodes first.
1532 zfs_prune_aliases(zfsvfs_t
*zfsvfs
, unsigned long nr_to_scan
)
1534 znode_t
**zp_array
, *zp
;
1535 int max_array
= MIN(nr_to_scan
, PAGE_SIZE
* 8 / sizeof (znode_t
*));
1539 zp_array
= kmem_zalloc(max_array
* sizeof (znode_t
*), KM_SLEEP
);
1541 mutex_enter(&zfsvfs
->z_znodes_lock
);
1542 while ((zp
= list_head(&zfsvfs
->z_all_znodes
)) != NULL
) {
1544 if ((i
++ > nr_to_scan
) || (j
>= max_array
))
1547 ASSERT(list_link_active(&zp
->z_link_node
));
1548 list_remove(&zfsvfs
->z_all_znodes
, zp
);
1549 list_insert_tail(&zfsvfs
->z_all_znodes
, zp
);
1551 /* Skip active znodes and .zfs entries */
1552 if (MUTEX_HELD(&zp
->z_lock
) || zp
->z_is_ctldir
)
1555 if (igrab(ZTOI(zp
)) == NULL
)
1561 mutex_exit(&zfsvfs
->z_znodes_lock
);
1563 for (i
= 0; i
< j
; i
++) {
1566 ASSERT3P(zp
, !=, NULL
);
1567 d_prune_aliases(ZTOI(zp
));
1569 if (atomic_read(&ZTOI(zp
)->i_count
) == 1)
1575 kmem_free(zp_array
, max_array
* sizeof (znode_t
*));
1579 #endif /* HAVE_D_PRUNE_ALIASES */
1582 * The ARC has requested that the filesystem drop entries from the dentry
1583 * and inode caches. This can occur when the ARC needs to free meta data
1584 * blocks but can't because they are all pinned by entries in these caches.
1587 zfs_prune(struct super_block
*sb
, unsigned long nr_to_scan
, int *objects
)
1589 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
1591 #if defined(HAVE_SHRINK) || defined(HAVE_SPLIT_SHRINKER_CALLBACK)
1592 struct shrinker
*shrinker
= &sb
->s_shrink
;
1593 struct shrink_control sc
= {
1594 .nr_to_scan
= nr_to_scan
,
1595 .gfp_mask
= GFP_KERNEL
,
1601 #if defined(HAVE_SPLIT_SHRINKER_CALLBACK) && \
1602 defined(SHRINK_CONTROL_HAS_NID) && \
1603 defined(SHRINKER_NUMA_AWARE)
1604 if (sb
->s_shrink
.flags
& SHRINKER_NUMA_AWARE
) {
1606 for_each_online_node(sc
.nid
) {
1607 *objects
+= (*shrinker
->scan_objects
)(shrinker
, &sc
);
1610 *objects
= (*shrinker
->scan_objects
)(shrinker
, &sc
);
1613 #elif defined(HAVE_SPLIT_SHRINKER_CALLBACK)
1614 *objects
= (*shrinker
->scan_objects
)(shrinker
, &sc
);
1615 #elif defined(HAVE_SHRINK)
1616 *objects
= (*shrinker
->shrink
)(shrinker
, &sc
);
1617 #elif defined(HAVE_D_PRUNE_ALIASES)
1618 #define D_PRUNE_ALIASES_IS_DEFAULT
1619 *objects
= zfs_prune_aliases(zfsvfs
, nr_to_scan
);
1621 #error "No available dentry and inode cache pruning mechanism."
1624 #if defined(HAVE_D_PRUNE_ALIASES) && !defined(D_PRUNE_ALIASES_IS_DEFAULT)
1625 #undef D_PRUNE_ALIASES_IS_DEFAULT
1627 * Fall back to zfs_prune_aliases if the kernel's per-superblock
1628 * shrinker couldn't free anything, possibly due to the inodes being
1629 * allocated in a different memcg.
1632 *objects
= zfs_prune_aliases(zfsvfs
, nr_to_scan
);
1637 dprintf_ds(zfsvfs
->z_os
->os_dsl_dataset
,
1638 "pruning, nr_to_scan=%lu objects=%d error=%d\n",
1639 nr_to_scan
, *objects
, error
);
1645 * Teardown the zfsvfs_t.
1647 * Note, if 'unmounting' is FALSE, we return with the 'z_teardown_lock'
1648 * and 'z_teardown_inactive_lock' held.
1651 zfsvfs_teardown(zfsvfs_t
*zfsvfs
, boolean_t unmounting
)
1655 zfs_unlinked_drain_stop_wait(zfsvfs
);
1658 * If someone has not already unmounted this file system,
1659 * drain the iput_taskq to ensure all active references to the
1660 * zfsvfs_t have been handled only then can it be safely destroyed.
1664 * If we're unmounting we have to wait for the list to
1667 * If we're not unmounting there's no guarantee the list
1668 * will drain completely, but iputs run from the taskq
1669 * may add the parents of dir-based xattrs to the taskq
1670 * so we want to wait for these.
1672 * We can safely read z_nr_znodes without locking because the
1673 * VFS has already blocked operations which add to the
1674 * z_all_znodes list and thus increment z_nr_znodes.
1677 while (zfsvfs
->z_nr_znodes
> 0) {
1678 taskq_wait_outstanding(dsl_pool_iput_taskq(
1679 dmu_objset_pool(zfsvfs
->z_os
)), 0);
1680 if (++round
> 1 && !unmounting
)
1685 rrm_enter(&zfsvfs
->z_teardown_lock
, RW_WRITER
, FTAG
);
1689 * We purge the parent filesystem's super block as the
1690 * parent filesystem and all of its snapshots have their
1691 * inode's super block set to the parent's filesystem's
1692 * super block. Note, 'z_parent' is self referential
1693 * for non-snapshots.
1695 shrink_dcache_sb(zfsvfs
->z_parent
->z_sb
);
1699 * Close the zil. NB: Can't close the zil while zfs_inactive
1700 * threads are blocked as zil_close can call zfs_inactive.
1702 if (zfsvfs
->z_log
) {
1703 zil_close(zfsvfs
->z_log
);
1704 zfsvfs
->z_log
= NULL
;
1707 rw_enter(&zfsvfs
->z_teardown_inactive_lock
, RW_WRITER
);
1710 * If we are not unmounting (ie: online recv) and someone already
1711 * unmounted this file system while we were doing the switcheroo,
1712 * or a reopen of z_os failed then just bail out now.
1714 if (!unmounting
&& (zfsvfs
->z_unmounted
|| zfsvfs
->z_os
== NULL
)) {
1715 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
1716 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
1717 return (SET_ERROR(EIO
));
1721 * At this point there are no VFS ops active, and any new VFS ops
1722 * will fail with EIO since we have z_teardown_lock for writer (only
1723 * relevant for forced unmount).
1725 * Release all holds on dbufs.
1728 mutex_enter(&zfsvfs
->z_znodes_lock
);
1729 for (zp
= list_head(&zfsvfs
->z_all_znodes
); zp
!= NULL
;
1730 zp
= list_next(&zfsvfs
->z_all_znodes
, zp
)) {
1732 zfs_znode_dmu_fini(zp
);
1734 mutex_exit(&zfsvfs
->z_znodes_lock
);
1738 * If we are unmounting, set the unmounted flag and let new VFS ops
1739 * unblock. zfs_inactive will have the unmounted behavior, and all
1740 * other VFS ops will fail with EIO.
1743 zfsvfs
->z_unmounted
= B_TRUE
;
1744 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
1745 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
1749 * z_os will be NULL if there was an error in attempting to reopen
1750 * zfsvfs, so just return as the properties had already been
1752 * unregistered and cached data had been evicted before.
1754 if (zfsvfs
->z_os
== NULL
)
1758 * Unregister properties.
1760 zfs_unregister_callbacks(zfsvfs
);
1763 * Evict cached data. We must write out any dirty data before
1764 * disowning the dataset.
1766 if (!zfs_is_readonly(zfsvfs
))
1767 txg_wait_synced(dmu_objset_pool(zfsvfs
->z_os
), 0);
1768 dmu_objset_evict_dbufs(zfsvfs
->z_os
);
1773 #if !defined(HAVE_2ARGS_BDI_SETUP_AND_REGISTER) && \
1774 !defined(HAVE_3ARGS_BDI_SETUP_AND_REGISTER)
1775 atomic_long_t zfs_bdi_seq
= ATOMIC_LONG_INIT(0);
1779 zfs_domount(struct super_block
*sb
, zfs_mnt_t
*zm
, int silent
)
1781 const char *osname
= zm
->mnt_osname
;
1782 struct inode
*root_inode
;
1783 uint64_t recordsize
;
1785 zfsvfs_t
*zfsvfs
= NULL
;
1791 error
= zfsvfs_parse_options(zm
->mnt_data
, &vfs
);
1795 error
= zfsvfs_create(osname
, vfs
->vfs_readonly
, &zfsvfs
);
1797 zfsvfs_vfs_free(vfs
);
1801 if ((error
= dsl_prop_get_integer(osname
, "recordsize",
1802 &recordsize
, NULL
))) {
1803 zfsvfs_vfs_free(vfs
);
1807 vfs
->vfs_data
= zfsvfs
;
1808 zfsvfs
->z_vfs
= vfs
;
1810 sb
->s_fs_info
= zfsvfs
;
1811 sb
->s_magic
= ZFS_SUPER_MAGIC
;
1812 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
1813 sb
->s_time_gran
= 1;
1814 sb
->s_blocksize
= recordsize
;
1815 sb
->s_blocksize_bits
= ilog2(recordsize
);
1817 error
= -zpl_bdi_setup(sb
, "zfs");
1821 sb
->s_bdi
->ra_pages
= 0;
1823 /* Set callback operations for the file system. */
1824 sb
->s_op
= &zpl_super_operations
;
1825 sb
->s_xattr
= zpl_xattr_handlers
;
1826 sb
->s_export_op
= &zpl_export_operations
;
1828 sb
->s_d_op
= &zpl_dentry_operations
;
1829 #endif /* HAVE_S_D_OP */
1831 /* Set features for file system. */
1832 zfs_set_fuid_feature(zfsvfs
);
1834 if (dmu_objset_is_snapshot(zfsvfs
->z_os
)) {
1837 atime_changed_cb(zfsvfs
, B_FALSE
);
1838 readonly_changed_cb(zfsvfs
, B_TRUE
);
1839 if ((error
= dsl_prop_get_integer(osname
,
1840 "xattr", &pval
, NULL
)))
1842 xattr_changed_cb(zfsvfs
, pval
);
1843 if ((error
= dsl_prop_get_integer(osname
,
1844 "acltype", &pval
, NULL
)))
1846 acltype_changed_cb(zfsvfs
, pval
);
1847 zfsvfs
->z_issnap
= B_TRUE
;
1848 zfsvfs
->z_os
->os_sync
= ZFS_SYNC_DISABLED
;
1849 zfsvfs
->z_snap_defer_time
= jiffies
;
1851 mutex_enter(&zfsvfs
->z_os
->os_user_ptr_lock
);
1852 dmu_objset_set_user(zfsvfs
->z_os
, zfsvfs
);
1853 mutex_exit(&zfsvfs
->z_os
->os_user_ptr_lock
);
1855 if ((error
= zfsvfs_setup(zfsvfs
, B_TRUE
)))
1859 /* Allocate a root inode for the filesystem. */
1860 error
= zfs_root(zfsvfs
, &root_inode
);
1862 (void) zfs_umount(sb
);
1866 /* Allocate a root dentry for the filesystem */
1867 sb
->s_root
= d_make_root(root_inode
);
1868 if (sb
->s_root
== NULL
) {
1869 (void) zfs_umount(sb
);
1870 error
= SET_ERROR(ENOMEM
);
1874 if (!zfsvfs
->z_issnap
)
1875 zfsctl_create(zfsvfs
);
1877 zfsvfs
->z_arc_prune
= arc_add_prune_callback(zpl_prune_sb
, sb
);
1880 if (zfsvfs
!= NULL
) {
1881 dmu_objset_disown(zfsvfs
->z_os
, B_TRUE
, zfsvfs
);
1882 zfsvfs_free(zfsvfs
);
1885 * make sure we don't have dangling sb->s_fs_info which
1886 * zfs_preumount will use.
1888 sb
->s_fs_info
= NULL
;
1895 * Called when an unmount is requested and certain sanity checks have
1896 * already passed. At this point no dentries or inodes have been reclaimed
1897 * from their respective caches. We drop the extra reference on the .zfs
1898 * control directory to allow everything to be reclaimed. All snapshots
1899 * must already have been unmounted to reach this point.
1902 zfs_preumount(struct super_block
*sb
)
1904 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
1906 /* zfsvfs is NULL when zfs_domount fails during mount */
1908 zfs_unlinked_drain_stop_wait(zfsvfs
);
1909 zfsctl_destroy(sb
->s_fs_info
);
1911 * Wait for iput_async before entering evict_inodes in
1912 * generic_shutdown_super. The reason we must finish before
1913 * evict_inodes is when lazytime is on, or when zfs_purgedir
1914 * calls zfs_zget, iput would bump i_count from 0 to 1. This
1915 * would race with the i_count check in evict_inodes. This means
1916 * it could destroy the inode while we are still using it.
1918 * We wait for two passes. xattr directories in the first pass
1919 * may add xattr entries in zfs_purgedir, so in the second pass
1920 * we wait for them. We don't use taskq_wait here because it is
1921 * a pool wide taskq. Other mounted filesystems can constantly
1922 * do iput_async and there's no guarantee when taskq will be
1925 taskq_wait_outstanding(dsl_pool_iput_taskq(
1926 dmu_objset_pool(zfsvfs
->z_os
)), 0);
1927 taskq_wait_outstanding(dsl_pool_iput_taskq(
1928 dmu_objset_pool(zfsvfs
->z_os
)), 0);
1933 * Called once all other unmount released tear down has occurred.
1934 * It is our responsibility to release any remaining infrastructure.
1938 zfs_umount(struct super_block
*sb
)
1940 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
1943 if (zfsvfs
->z_arc_prune
!= NULL
)
1944 arc_remove_prune_callback(zfsvfs
->z_arc_prune
);
1945 VERIFY(zfsvfs_teardown(zfsvfs
, B_TRUE
) == 0);
1947 zpl_bdi_destroy(sb
);
1950 * z_os will be NULL if there was an error in
1951 * attempting to reopen zfsvfs.
1955 * Unset the objset user_ptr.
1957 mutex_enter(&os
->os_user_ptr_lock
);
1958 dmu_objset_set_user(os
, NULL
);
1959 mutex_exit(&os
->os_user_ptr_lock
);
1962 * Finally release the objset
1964 dmu_objset_disown(os
, B_TRUE
, zfsvfs
);
1967 zfsvfs_free(zfsvfs
);
1972 zfs_remount(struct super_block
*sb
, int *flags
, zfs_mnt_t
*zm
)
1974 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
1976 boolean_t issnap
= dmu_objset_is_snapshot(zfsvfs
->z_os
);
1979 if ((issnap
|| !spa_writeable(dmu_objset_spa(zfsvfs
->z_os
))) &&
1980 !(*flags
& SB_RDONLY
)) {
1981 *flags
|= SB_RDONLY
;
1985 error
= zfsvfs_parse_options(zm
->mnt_data
, &vfsp
);
1989 if (!zfs_is_readonly(zfsvfs
) && (*flags
& SB_RDONLY
))
1990 txg_wait_synced(dmu_objset_pool(zfsvfs
->z_os
), 0);
1992 zfs_unregister_callbacks(zfsvfs
);
1993 zfsvfs_vfs_free(zfsvfs
->z_vfs
);
1995 vfsp
->vfs_data
= zfsvfs
;
1996 zfsvfs
->z_vfs
= vfsp
;
1998 (void) zfs_register_callbacks(vfsp
);
2004 zfs_vget(struct super_block
*sb
, struct inode
**ipp
, fid_t
*fidp
)
2006 zfsvfs_t
*zfsvfs
= sb
->s_fs_info
;
2008 uint64_t object
= 0;
2009 uint64_t fid_gen
= 0;
2016 if (fidp
->fid_len
== SHORT_FID_LEN
|| fidp
->fid_len
== LONG_FID_LEN
) {
2017 zfid_short_t
*zfid
= (zfid_short_t
*)fidp
;
2019 for (i
= 0; i
< sizeof (zfid
->zf_object
); i
++)
2020 object
|= ((uint64_t)zfid
->zf_object
[i
]) << (8 * i
);
2022 for (i
= 0; i
< sizeof (zfid
->zf_gen
); i
++)
2023 fid_gen
|= ((uint64_t)zfid
->zf_gen
[i
]) << (8 * i
);
2025 return (SET_ERROR(EINVAL
));
2028 /* LONG_FID_LEN means snapdirs */
2029 if (fidp
->fid_len
== LONG_FID_LEN
) {
2030 zfid_long_t
*zlfid
= (zfid_long_t
*)fidp
;
2031 uint64_t objsetid
= 0;
2032 uint64_t setgen
= 0;
2034 for (i
= 0; i
< sizeof (zlfid
->zf_setid
); i
++)
2035 objsetid
|= ((uint64_t)zlfid
->zf_setid
[i
]) << (8 * i
);
2037 for (i
= 0; i
< sizeof (zlfid
->zf_setgen
); i
++)
2038 setgen
|= ((uint64_t)zlfid
->zf_setgen
[i
]) << (8 * i
);
2040 if (objsetid
!= ZFSCTL_INO_SNAPDIRS
- object
) {
2041 dprintf("snapdir fid: objsetid (%llu) != "
2042 "ZFSCTL_INO_SNAPDIRS (%llu) - object (%llu)\n",
2043 objsetid
, ZFSCTL_INO_SNAPDIRS
, object
);
2045 return (SET_ERROR(EINVAL
));
2048 if (fid_gen
> 1 || setgen
!= 0) {
2049 dprintf("snapdir fid: fid_gen (%llu) and setgen "
2050 "(%llu)\n", fid_gen
, setgen
);
2051 return (SET_ERROR(EINVAL
));
2054 return (zfsctl_snapdir_vget(sb
, objsetid
, fid_gen
, ipp
));
2058 /* A zero fid_gen means we are in the .zfs control directories */
2060 (object
== ZFSCTL_INO_ROOT
|| object
== ZFSCTL_INO_SNAPDIR
)) {
2061 *ipp
= zfsvfs
->z_ctldir
;
2062 ASSERT(*ipp
!= NULL
);
2063 if (object
== ZFSCTL_INO_SNAPDIR
) {
2064 VERIFY(zfsctl_root_lookup(*ipp
, "snapshot", ipp
,
2065 0, kcred
, NULL
, NULL
) == 0);
2073 gen_mask
= -1ULL >> (64 - 8 * i
);
2075 dprintf("getting %llu [%llu mask %llx]\n", object
, fid_gen
, gen_mask
);
2076 if ((err
= zfs_zget(zfsvfs
, object
, &zp
))) {
2081 /* Don't export xattr stuff */
2082 if (zp
->z_pflags
& ZFS_XATTR
) {
2085 return (SET_ERROR(ENOENT
));
2088 (void) sa_lookup(zp
->z_sa_hdl
, SA_ZPL_GEN(zfsvfs
), &zp_gen
,
2090 zp_gen
= zp_gen
& gen_mask
;
2093 if ((fid_gen
== 0) && (zfsvfs
->z_root
== object
))
2095 if (zp
->z_unlinked
|| zp_gen
!= fid_gen
) {
2096 dprintf("znode gen (%llu) != fid gen (%llu)\n", zp_gen
,
2100 return (SET_ERROR(ENOENT
));
2105 zfs_inode_update(ITOZ(*ipp
));
2112 * Block out VFS ops and close zfsvfs_t
2114 * Note, if successful, then we return with the 'z_teardown_lock' and
2115 * 'z_teardown_inactive_lock' write held. We leave ownership of the underlying
2116 * dataset and objset intact so that they can be atomically handed off during
2117 * a subsequent rollback or recv operation and the resume thereafter.
2120 zfs_suspend_fs(zfsvfs_t
*zfsvfs
)
2124 if ((error
= zfsvfs_teardown(zfsvfs
, B_FALSE
)) != 0)
2131 * Rebuild SA and release VOPs. Note that ownership of the underlying dataset
2132 * is an invariant across any of the operations that can be performed while the
2133 * filesystem was suspended. Whether it succeeded or failed, the preconditions
2134 * are the same: the relevant objset and associated dataset are owned by
2135 * zfsvfs, held, and long held on entry.
2138 zfs_resume_fs(zfsvfs_t
*zfsvfs
, dsl_dataset_t
*ds
)
2143 ASSERT(RRM_WRITE_HELD(&zfsvfs
->z_teardown_lock
));
2144 ASSERT(RW_WRITE_HELD(&zfsvfs
->z_teardown_inactive_lock
));
2147 * We already own this, so just update the objset_t, as the one we
2148 * had before may have been evicted.
2151 VERIFY3P(ds
->ds_owner
, ==, zfsvfs
);
2152 VERIFY(dsl_dataset_long_held(ds
));
2153 VERIFY0(dmu_objset_from_ds(ds
, &os
));
2155 err
= zfsvfs_init(zfsvfs
, os
);
2159 VERIFY(zfsvfs_setup(zfsvfs
, B_FALSE
) == 0);
2161 zfs_set_fuid_feature(zfsvfs
);
2162 zfsvfs
->z_rollback_time
= jiffies
;
2165 * Attempt to re-establish all the active inodes with their
2166 * dbufs. If a zfs_rezget() fails, then we unhash the inode
2167 * and mark it stale. This prevents a collision if a new
2168 * inode/object is created which must use the same inode
2169 * number. The stale inode will be be released when the
2170 * VFS prunes the dentry holding the remaining references
2171 * on the stale inode.
2173 mutex_enter(&zfsvfs
->z_znodes_lock
);
2174 for (zp
= list_head(&zfsvfs
->z_all_znodes
); zp
;
2175 zp
= list_next(&zfsvfs
->z_all_znodes
, zp
)) {
2176 err2
= zfs_rezget(zp
);
2178 remove_inode_hash(ZTOI(zp
));
2179 zp
->z_is_stale
= B_TRUE
;
2182 mutex_exit(&zfsvfs
->z_znodes_lock
);
2184 if (!zfs_is_readonly(zfsvfs
) && !zfsvfs
->z_unmounted
) {
2186 * zfs_suspend_fs() could have interrupted freeing
2187 * of dnodes. We need to restart this freeing so
2188 * that we don't "leak" the space.
2190 zfs_unlinked_drain(zfsvfs
);
2194 /* release the VFS ops */
2195 rw_exit(&zfsvfs
->z_teardown_inactive_lock
);
2196 rrm_exit(&zfsvfs
->z_teardown_lock
, FTAG
);
2200 * Since we couldn't setup the sa framework, try to force
2201 * unmount this file system.
2204 (void) zfs_umount(zfsvfs
->z_sb
);
2210 zfs_set_version(zfsvfs_t
*zfsvfs
, uint64_t newvers
)
2213 objset_t
*os
= zfsvfs
->z_os
;
2216 if (newvers
< ZPL_VERSION_INITIAL
|| newvers
> ZPL_VERSION
)
2217 return (SET_ERROR(EINVAL
));
2219 if (newvers
< zfsvfs
->z_version
)
2220 return (SET_ERROR(EINVAL
));
2222 if (zfs_spa_version_map(newvers
) >
2223 spa_version(dmu_objset_spa(zfsvfs
->z_os
)))
2224 return (SET_ERROR(ENOTSUP
));
2226 tx
= dmu_tx_create(os
);
2227 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_FALSE
, ZPL_VERSION_STR
);
2228 if (newvers
>= ZPL_VERSION_SA
&& !zfsvfs
->z_use_sa
) {
2229 dmu_tx_hold_zap(tx
, MASTER_NODE_OBJ
, B_TRUE
,
2231 dmu_tx_hold_zap(tx
, DMU_NEW_OBJECT
, FALSE
, NULL
);
2233 error
= dmu_tx_assign(tx
, TXG_WAIT
);
2239 error
= zap_update(os
, MASTER_NODE_OBJ
, ZPL_VERSION_STR
,
2240 8, 1, &newvers
, tx
);
2247 if (newvers
>= ZPL_VERSION_SA
&& !zfsvfs
->z_use_sa
) {
2250 ASSERT3U(spa_version(dmu_objset_spa(zfsvfs
->z_os
)), >=,
2252 sa_obj
= zap_create(os
, DMU_OT_SA_MASTER_NODE
,
2253 DMU_OT_NONE
, 0, tx
);
2255 error
= zap_add(os
, MASTER_NODE_OBJ
,
2256 ZFS_SA_ATTRS
, 8, 1, &sa_obj
, tx
);
2259 VERIFY(0 == sa_set_sa_object(os
, sa_obj
));
2260 sa_register_update_callback(os
, zfs_sa_upgrade
);
2263 spa_history_log_internal_ds(dmu_objset_ds(os
), "upgrade", tx
,
2264 "from %llu to %llu", zfsvfs
->z_version
, newvers
);
2268 zfsvfs
->z_version
= newvers
;
2269 os
->os_version
= newvers
;
2271 zfs_set_fuid_feature(zfsvfs
);
2277 * Read a property stored within the master node.
2280 zfs_get_zplprop(objset_t
*os
, zfs_prop_t prop
, uint64_t *value
)
2282 uint64_t *cached_copy
= NULL
;
2285 * Figure out where in the objset_t the cached copy would live, if it
2286 * is available for the requested property.
2290 case ZFS_PROP_VERSION
:
2291 cached_copy
= &os
->os_version
;
2293 case ZFS_PROP_NORMALIZE
:
2294 cached_copy
= &os
->os_normalization
;
2296 case ZFS_PROP_UTF8ONLY
:
2297 cached_copy
= &os
->os_utf8only
;
2300 cached_copy
= &os
->os_casesensitivity
;
2306 if (cached_copy
!= NULL
&& *cached_copy
!= OBJSET_PROP_UNINITIALIZED
) {
2307 *value
= *cached_copy
;
2312 * If the property wasn't cached, look up the file system's value for
2313 * the property. For the version property, we look up a slightly
2318 if (prop
== ZFS_PROP_VERSION
)
2319 pname
= ZPL_VERSION_STR
;
2321 pname
= zfs_prop_to_name(prop
);
2324 ASSERT3U(os
->os_phys
->os_type
, ==, DMU_OST_ZFS
);
2325 error
= zap_lookup(os
, MASTER_NODE_OBJ
, pname
, 8, 1, value
);
2328 if (error
== ENOENT
) {
2329 /* No value set, use the default value */
2331 case ZFS_PROP_VERSION
:
2332 *value
= ZPL_VERSION
;
2334 case ZFS_PROP_NORMALIZE
:
2335 case ZFS_PROP_UTF8ONLY
:
2339 *value
= ZFS_CASE_SENSITIVE
;
2341 case ZFS_PROP_ACLTYPE
:
2342 *value
= ZFS_ACLTYPE_OFF
;
2351 * If one of the methods for getting the property value above worked,
2352 * copy it into the objset_t's cache.
2354 if (error
== 0 && cached_copy
!= NULL
) {
2355 *cached_copy
= *value
;
2362 * Return true if the coresponding vfs's unmounted flag is set.
2363 * Otherwise return false.
2364 * If this function returns true we know VFS unmount has been initiated.
2367 zfs_get_vfs_flag_unmounted(objset_t
*os
)
2370 boolean_t unmounted
= B_FALSE
;
2372 ASSERT(dmu_objset_type(os
) == DMU_OST_ZFS
);
2374 mutex_enter(&os
->os_user_ptr_lock
);
2375 zfvp
= dmu_objset_get_user(os
);
2376 if (zfvp
!= NULL
&& zfvp
->z_unmounted
)
2378 mutex_exit(&os
->os_user_ptr_lock
);
2388 dmu_objset_register_type(DMU_OST_ZFS
, zfs_space_delta_cb
);
2389 register_filesystem(&zpl_fs_type
);
2396 * we don't use outstanding because zpl_posix_acl_free might add more.
2398 taskq_wait(system_delay_taskq
);
2399 taskq_wait(system_taskq
);
2400 unregister_filesystem(&zpl_fs_type
);
2405 #if defined(_KERNEL)
2406 EXPORT_SYMBOL(zfs_suspend_fs
);
2407 EXPORT_SYMBOL(zfs_resume_fs
);
2408 EXPORT_SYMBOL(zfs_userspace_one
);
2409 EXPORT_SYMBOL(zfs_userspace_many
);
2410 EXPORT_SYMBOL(zfs_set_userquota
);
2411 EXPORT_SYMBOL(zfs_id_overblockquota
);
2412 EXPORT_SYMBOL(zfs_id_overobjquota
);
2413 EXPORT_SYMBOL(zfs_id_overquota
);
2414 EXPORT_SYMBOL(zfs_set_version
);
2415 EXPORT_SYMBOL(zfsvfs_create
);
2416 EXPORT_SYMBOL(zfsvfs_free
);
2417 EXPORT_SYMBOL(zfs_is_readonly
);
2418 EXPORT_SYMBOL(zfs_domount
);
2419 EXPORT_SYMBOL(zfs_preumount
);
2420 EXPORT_SYMBOL(zfs_umount
);
2421 EXPORT_SYMBOL(zfs_remount
);
2422 EXPORT_SYMBOL(zfs_statvfs
);
2423 EXPORT_SYMBOL(zfs_vget
);
2424 EXPORT_SYMBOL(zfs_prune
);