1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * CDDL HEADER START 4 * 5 * The contents of this file are subject to the terms of the 6 * Common Development and Distribution License (the "License"). 7 * You may not use this file except in compliance with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or https://opensource.org/licenses/CDDL-1.0. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>. 25 * All rights reserved. 26 */ 27 28 #ifndef _SYS_FS_ZFS_VFSOPS_H 29 #define _SYS_FS_ZFS_VFSOPS_H 30 31 #include <sys/dataset_kstats.h> 32 #include <sys/list.h> 33 #include <sys/vfs.h> 34 #include <sys/zil.h> 35 #include <sys/sa.h> 36 #include <sys/rrwlock.h> 37 #include <sys/rmlock.h> 38 #include <sys/zfs_ioctl.h> 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 typedef struct rmslock zfs_teardown_lock_t; 45 typedef struct rmslock zfs_teardown_inactive_lock_t; 46 47 typedef struct zfsvfs zfsvfs_t; 48 struct znode; 49 50 struct zfsvfs { 51 vfs_t *z_vfs; /* generic fs struct */ 52 zfsvfs_t *z_parent; /* parent fs */ 53 objset_t *z_os; /* objset reference */ 54 uint64_t z_flags; /* super_block flags */ 55 uint64_t z_root; /* id of root znode */ 56 uint64_t z_unlinkedobj; /* id of unlinked zapobj */ 57 uint64_t z_max_blksz; /* maximum block size for files */ 58 uint64_t z_fuid_obj; /* fuid table object number */ 59 uint64_t z_fuid_size; /* fuid table size */ 60 avl_tree_t z_fuid_idx; /* fuid tree keyed by index */ 61 avl_tree_t z_fuid_domain; /* fuid tree keyed by domain */ 62 krwlock_t z_fuid_lock; /* fuid lock */ 63 boolean_t z_fuid_loaded; /* fuid tables are loaded */ 64 boolean_t z_fuid_dirty; /* need to sync fuid table ? */ 65 struct zfs_fuid_info *z_fuid_replay; /* fuid info for replay */ 66 zilog_t *z_log; /* intent log pointer */ 67 uint_t z_acl_type; /* type of acl usable on this fs */ 68 uint_t z_acl_mode; /* acl chmod/mode behavior */ 69 uint_t z_acl_inherit; /* acl inheritance behavior */ 70 zfs_case_t z_case; /* case-sense */ 71 boolean_t z_utf8; /* utf8-only */ 72 int z_norm; /* normalization flags */ 73 boolean_t z_atime; /* enable atimes mount option */ 74 boolean_t z_unmounted; /* unmounted */ 75 zfs_teardown_lock_t z_teardown_lock; 76 zfs_teardown_inactive_lock_t z_teardown_inactive_lock; 77 list_t z_all_znodes; /* all vnodes in the fs */ 78 kmutex_t z_znodes_lock; /* lock for z_all_znodes */ 79 struct zfsctl_root *z_ctldir; /* .zfs directory pointer */ 80 uint_t z_show_ctldir; /* how to expose .zfs in the root dir */ 81 boolean_t z_issnap; /* true if this is a snapshot */ 82 boolean_t z_use_fuids; /* version allows fuids */ 83 boolean_t z_replay; /* set during ZIL replay */ 84 boolean_t z_use_sa; /* version allow system attributes */ 85 boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */ 86 boolean_t z_use_namecache; /* make use of FreeBSD name cache */ 87 boolean_t z_longname; /* Dataset supports long names */ 88 uint8_t z_xattr; /* xattr type in use */ 89 uint64_t z_version; /* ZPL version */ 90 uint64_t z_shares_dir; /* hidden shares dir */ 91 dataset_kstats_t z_kstat; /* fs kstats */ 92 kmutex_t z_lock; 93 uint64_t z_userquota_obj; 94 uint64_t z_groupquota_obj; 95 uint64_t z_userobjquota_obj; 96 uint64_t z_groupobjquota_obj; 97 uint64_t z_projectquota_obj; 98 uint64_t z_projectobjquota_obj; 99 uint64_t z_replay_eof; /* New end of file - replay only */ 100 sa_attr_type_t *z_attr_table; /* SA attr mapping->id */ 101 #define ZFS_OBJ_MTX_SZ 64 102 kmutex_t z_hold_mtx[ZFS_OBJ_MTX_SZ]; /* znode hold locks */ 103 struct task z_unlinked_drain_task; 104 }; 105 106 #define ZFS_TEARDOWN_INIT(zfsvfs) \ 107 rms_init(&(zfsvfs)->z_teardown_lock, "zfs teardown") 108 109 #define ZFS_TEARDOWN_DESTROY(zfsvfs) \ 110 rms_destroy(&(zfsvfs)->z_teardown_lock) 111 112 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag) \ 113 rms_rlock(&(zfsvfs)->z_teardown_lock); 114 115 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag) \ 116 rms_runlock(&(zfsvfs)->z_teardown_lock) 117 118 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag) \ 119 rms_wlock(&(zfsvfs)->z_teardown_lock) 120 121 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs) \ 122 rms_wunlock(&(zfsvfs)->z_teardown_lock) 123 124 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag) \ 125 rms_unlock(&(zfsvfs)->z_teardown_lock) 126 127 #define ZFS_TEARDOWN_READ_HELD(zfsvfs) \ 128 rms_rowned(&(zfsvfs)->z_teardown_lock) 129 130 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs) \ 131 rms_wowned(&(zfsvfs)->z_teardown_lock) 132 133 #define ZFS_TEARDOWN_HELD(zfsvfs) \ 134 rms_owned_any(&(zfsvfs)->z_teardown_lock) 135 136 #define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs) \ 137 rms_init(&(zfsvfs)->z_teardown_inactive_lock, "zfs teardown inactive") 138 139 #define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs) \ 140 rms_destroy(&(zfsvfs)->z_teardown_inactive_lock) 141 142 #define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs) \ 143 rms_try_rlock(&(zfsvfs)->z_teardown_inactive_lock) 144 145 #define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs) \ 146 rms_rlock(&(zfsvfs)->z_teardown_inactive_lock) 147 148 #define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs) \ 149 rms_runlock(&(zfsvfs)->z_teardown_inactive_lock) 150 151 #define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs) \ 152 rms_wlock(&(zfsvfs)->z_teardown_inactive_lock) 153 154 #define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs) \ 155 rms_wunlock(&(zfsvfs)->z_teardown_inactive_lock) 156 157 #define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs) \ 158 rms_wowned(&(zfsvfs)->z_teardown_inactive_lock) 159 160 #define ZSB_XATTR 0x0001 /* Enable user xattrs */ 161 /* 162 * Normal filesystems (those not under .zfs/snapshot) have a total 163 * file ID size limited to 12 bytes (including the length field) due to 164 * NFSv2 protocol's limitation of 32 bytes for a filehandle. For historical 165 * reasons, this same limit is being imposed by the Solaris NFSv3 implementation 166 * (although the NFSv3 protocol actually permits a maximum of 64 bytes). It 167 * is not possible to expand beyond 12 bytes without abandoning support 168 * of NFSv2. 169 * 170 * For normal filesystems, we partition up the available space as follows: 171 * 2 bytes fid length (required) 172 * 6 bytes object number (48 bits) 173 * 4 bytes generation number (32 bits) 174 * 175 * We reserve only 48 bits for the object number, as this is the limit 176 * currently defined and imposed by the DMU. 177 */ 178 typedef struct zfid_short { 179 uint16_t zf_len; 180 uint8_t zf_object[6]; /* obj[i] = obj >> (8 * i) */ 181 uint8_t zf_gen[4]; /* gen[i] = gen >> (8 * i) */ 182 } zfid_short_t; 183 184 /* 185 * Filesystems under .zfs/snapshot have a total file ID size of 22[*] bytes 186 * (including the length field). This makes files under .zfs/snapshot 187 * accessible by NFSv3 and NFSv4, but not NFSv2. 188 * 189 * For files under .zfs/snapshot, we partition up the available space 190 * as follows: 191 * 2 bytes fid length (required) 192 * 6 bytes object number (48 bits) 193 * 4 bytes generation number (32 bits) 194 * 6 bytes objset id (48 bits) 195 * 4 bytes[**] currently just zero (32 bits) 196 * 197 * We reserve only 48 bits for the object number and objset id, as these are 198 * the limits currently defined and imposed by the DMU. 199 * 200 * [*] 20 bytes on FreeBSD to fit into the size of struct fid. 201 * [**] 2 bytes on FreeBSD for the above reason. 202 */ 203 typedef struct zfid_long { 204 zfid_short_t z_fid; 205 uint8_t zf_setid[6]; /* obj[i] = obj >> (8 * i) */ 206 uint8_t zf_setgen[2]; /* gen[i] = gen >> (8 * i) */ 207 } zfid_long_t; 208 209 #define SHORT_FID_LEN (sizeof (zfid_short_t) - sizeof (uint16_t)) 210 #define LONG_FID_LEN (sizeof (zfid_long_t) - sizeof (uint16_t)) 211 212 extern int zfs_super_owner; 213 214 extern void zfs_init(void); 215 extern void zfs_fini(void); 216 217 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs); 218 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds); 219 extern int zfs_end_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds); 220 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers); 221 extern int zfsvfs_create(const char *name, boolean_t readonly, zfsvfs_t **zfvp); 222 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os); 223 extern void zfsvfs_free(zfsvfs_t *zfsvfs); 224 extern int zfs_check_global_label(const char *dsname, const char *hexsl); 225 extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs); 226 extern int zfs_get_temporary_prop(struct dsl_dataset *ds, zfs_prop_t zfs_prop, 227 uint64_t *val, char *setpoint); 228 extern int zfs_busy(void); 229 230 #ifdef __cplusplus 231 } 232 #endif 233 234 #endif /* _SYS_FS_ZFS_VFSOPS_H */ 235