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) 2013, 2018 by Delphix. All rights reserved. 25 */ 26 27 #ifndef _SYS_FS_ZFS_VFSOPS_H 28 #define _SYS_FS_ZFS_VFSOPS_H 29 30 #include <sys/dataset_kstats.h> 31 #include <sys/isa_defs.h> 32 #include <sys/types32.h> 33 #include <sys/list.h> 34 #include <sys/vfs.h> 35 #include <sys/zil.h> 36 #include <sys/sa.h> 37 #include <sys/rrwlock.h> 38 #include <sys/dsl_dataset.h> 39 #include <sys/zfs_ioctl.h> 40 #include <sys/objlist.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 typedef struct zfsvfs zfsvfs_t; 47 struct znode; 48 49 /* 50 * This structure emulates the vfs_t from other platforms. It's purpose 51 * is to facilitate the handling of mount options and minimize structural 52 * differences between the platforms. 53 */ 54 typedef struct vfs { 55 struct zfsvfs *vfs_data; 56 char *vfs_mntpoint; /* Primary mount point */ 57 uint64_t vfs_xattr; 58 boolean_t vfs_readonly; 59 boolean_t vfs_do_readonly; 60 boolean_t vfs_setuid; 61 boolean_t vfs_do_setuid; 62 boolean_t vfs_exec; 63 boolean_t vfs_do_exec; 64 boolean_t vfs_devices; 65 boolean_t vfs_do_devices; 66 boolean_t vfs_do_xattr; 67 boolean_t vfs_atime; 68 boolean_t vfs_do_atime; 69 boolean_t vfs_relatime; 70 boolean_t vfs_do_relatime; 71 boolean_t vfs_nbmand; 72 boolean_t vfs_do_nbmand; 73 kmutex_t vfs_mntpt_lock; 74 } vfs_t; 75 76 typedef struct zfs_mnt { 77 const char *mnt_osname; /* Objset name */ 78 char *mnt_data; /* Raw mount options */ 79 } zfs_mnt_t; 80 81 struct zfsvfs { 82 vfs_t *z_vfs; /* generic fs struct */ 83 struct super_block *z_sb; /* generic super_block */ 84 struct zfsvfs *z_parent; /* parent fs */ 85 objset_t *z_os; /* objset reference */ 86 uint64_t z_flags; /* super_block flags */ 87 uint64_t z_root; /* id of root znode */ 88 uint64_t z_unlinkedobj; /* id of unlinked zapobj */ 89 uint64_t z_max_blksz; /* maximum block size for files */ 90 uint64_t z_fuid_obj; /* fuid table object number */ 91 uint64_t z_fuid_size; /* fuid table size */ 92 avl_tree_t z_fuid_idx; /* fuid tree keyed by index */ 93 avl_tree_t z_fuid_domain; /* fuid tree keyed by domain */ 94 krwlock_t z_fuid_lock; /* fuid lock */ 95 boolean_t z_fuid_loaded; /* fuid tables are loaded */ 96 boolean_t z_fuid_dirty; /* need to sync fuid table ? */ 97 struct zfs_fuid_info *z_fuid_replay; /* fuid info for replay */ 98 zilog_t *z_log; /* intent log pointer */ 99 uint_t z_acl_mode; /* acl chmod/mode behavior */ 100 uint_t z_acl_inherit; /* acl inheritance behavior */ 101 uint_t z_acl_type; /* type of ACL usable on this FS */ 102 zfs_case_t z_case; /* case-sense */ 103 boolean_t z_utf8; /* utf8-only */ 104 int z_norm; /* normalization flags */ 105 boolean_t z_relatime; /* enable relatime mount option */ 106 boolean_t z_unmounted; /* unmounted */ 107 rrmlock_t z_teardown_lock; 108 krwlock_t z_teardown_inactive_lock; 109 list_t z_all_znodes; /* all znodes in the fs */ 110 unsigned long z_rollback_time; /* last online rollback time */ 111 unsigned long z_snap_defer_time; /* last snapshot unmount deferral */ 112 kmutex_t z_znodes_lock; /* lock for z_all_znodes */ 113 arc_prune_t *z_arc_prune; /* called by ARC to prune caches */ 114 struct inode *z_ctldir; /* .zfs directory inode */ 115 uint_t z_show_ctldir; /* how to expose .zfs in the root dir */ 116 boolean_t z_issnap; /* true if this is a snapshot */ 117 boolean_t z_use_fuids; /* version allows fuids */ 118 boolean_t z_replay; /* set during ZIL replay */ 119 boolean_t z_use_sa; /* version allow system attributes */ 120 boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */ 121 boolean_t z_draining; /* is true when drain is active */ 122 boolean_t z_drain_cancel; /* signal the unlinked drain to stop */ 123 boolean_t z_longname; /* Dataset supports long names */ 124 uint64_t z_version; /* ZPL version */ 125 uint64_t z_shares_dir; /* hidden shares dir */ 126 dataset_kstats_t z_kstat; /* fs kstats */ 127 kmutex_t z_lock; 128 uint64_t z_userquota_obj; 129 uint64_t z_groupquota_obj; 130 uint64_t z_userobjquota_obj; 131 uint64_t z_groupobjquota_obj; 132 uint64_t z_projectquota_obj; 133 uint64_t z_projectobjquota_obj; 134 uint64_t z_defaultuserquota; 135 uint64_t z_defaultgroupquota; 136 uint64_t z_defaultprojectquota; 137 uint64_t z_defaultuserobjquota; 138 uint64_t z_defaultgroupobjquota; 139 uint64_t z_defaultprojectobjquota; 140 uint64_t z_replay_eof; /* New end of file - replay only */ 141 sa_attr_type_t *z_attr_table; /* SA attr mapping->id */ 142 uint64_t z_hold_size; /* znode hold array size */ 143 avl_tree_t *z_hold_trees; /* znode hold trees */ 144 kmutex_t *z_hold_locks; /* znode hold locks */ 145 taskqid_t z_drain_task; /* task id for the unlink drain task */ 146 }; 147 148 #define ZFS_TEARDOWN_INIT(zfsvfs) \ 149 rrm_init(&(zfsvfs)->z_teardown_lock, B_FALSE) 150 151 #define ZFS_TEARDOWN_DESTROY(zfsvfs) \ 152 rrm_destroy(&(zfsvfs)->z_teardown_lock) 153 154 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag) \ 155 rrm_enter_read(&(zfsvfs)->z_teardown_lock, tag); 156 157 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag) \ 158 rrm_exit(&(zfsvfs)->z_teardown_lock, tag) 159 160 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag) \ 161 rrm_enter(&(zfsvfs)->z_teardown_lock, RW_WRITER, tag) 162 163 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs) \ 164 rrm_exit(&(zfsvfs)->z_teardown_lock, tag) 165 166 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag) \ 167 rrm_exit(&(zfsvfs)->z_teardown_lock, tag) 168 169 #define ZFS_TEARDOWN_READ_HELD(zfsvfs) \ 170 RRM_READ_HELD(&(zfsvfs)->z_teardown_lock) 171 172 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs) \ 173 RRM_WRITE_HELD(&(zfsvfs)->z_teardown_lock) 174 175 #define ZFS_TEARDOWN_HELD(zfsvfs) \ 176 RRM_LOCK_HELD(&(zfsvfs)->z_teardown_lock) 177 178 #define ZSB_XATTR 0x0001 /* Enable user xattrs */ 179 180 /* 181 * Allow a maximum number of links. While ZFS does not internally limit 182 * this the inode->i_nlink member is defined as an unsigned int. To be 183 * safe we use 2^31-1 as the limit. 184 */ 185 #define ZFS_LINK_MAX ((1U << 31) - 1U) 186 187 /* 188 * Normal filesystems (those not under .zfs/snapshot) have a total 189 * file ID size limited to 12 bytes (including the length field) due to 190 * NFSv2 protocol's limitation of 32 bytes for a filehandle. For historical 191 * reasons, this same limit is being imposed by the Solaris NFSv3 implementation 192 * (although the NFSv3 protocol actually permits a maximum of 64 bytes). It 193 * is not possible to expand beyond 12 bytes without abandoning support 194 * of NFSv2. 195 * 196 * For normal filesystems, we partition up the available space as follows: 197 * 2 bytes fid length (required) 198 * 6 bytes object number (48 bits) 199 * 4 bytes generation number (32 bits) 200 * 201 * We reserve only 48 bits for the object number, as this is the limit 202 * currently defined and imposed by the DMU. 203 */ 204 typedef struct zfid_short { 205 uint16_t zf_len; 206 uint8_t zf_object[6]; /* obj[i] = obj >> (8 * i) */ 207 uint8_t zf_gen[4]; /* gen[i] = gen >> (8 * i) */ 208 } zfid_short_t; 209 210 /* 211 * Filesystems under .zfs/snapshot have a total file ID size of 22 bytes 212 * (including the length field). This makes files under .zfs/snapshot 213 * accessible by NFSv3 and NFSv4, but not NFSv2. 214 * 215 * For files under .zfs/snapshot, we partition up the available space 216 * as follows: 217 * 2 bytes fid length (required) 218 * 6 bytes object number (48 bits) 219 * 4 bytes generation number (32 bits) 220 * 6 bytes objset id (48 bits) 221 * 4 bytes currently just zero (32 bits) 222 * 223 * We reserve only 48 bits for the object number and objset id, as these are 224 * the limits currently defined and imposed by the DMU. 225 */ 226 typedef struct zfid_long { 227 zfid_short_t z_fid; 228 uint8_t zf_setid[6]; /* obj[i] = obj >> (8 * i) */ 229 uint8_t zf_setgen[4]; /* gen[i] = gen >> (8 * i) */ 230 } zfid_long_t; 231 232 #define SHORT_FID_LEN (sizeof (zfid_short_t) - sizeof (uint16_t)) 233 #define LONG_FID_LEN (sizeof (zfid_long_t) - sizeof (uint16_t)) 234 235 extern void zfs_init(void); 236 extern void zfs_fini(void); 237 238 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs); 239 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds); 240 extern int zfs_end_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds); 241 extern void zfs_exit_fs(zfsvfs_t *zfsvfs); 242 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers); 243 extern int zfsvfs_create(const char *name, boolean_t readony, zfsvfs_t **zfvp); 244 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os); 245 extern void zfsvfs_free(zfsvfs_t *zfsvfs); 246 extern int zfs_check_global_label(const char *dsname, const char *hexsl); 247 248 extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs); 249 extern int zfs_domount(struct super_block *sb, zfs_mnt_t *zm, int silent); 250 extern void zfs_preumount(struct super_block *sb); 251 extern int zfs_umount(struct super_block *sb); 252 extern int zfs_remount(struct super_block *sb, int *flags, zfs_mnt_t *zm); 253 extern int zfs_statvfs(struct inode *ip, struct kstatfs *statp); 254 extern int zfs_vget(struct super_block *sb, struct inode **ipp, fid_t *fidp); 255 extern int zfs_prune(struct super_block *sb, unsigned long nr_to_scan, 256 int *objects); 257 extern int zfs_get_temporary_prop(dsl_dataset_t *ds, zfs_prop_t zfs_prop, 258 uint64_t *val, char *setpoint); 259 extern int zfs_set_default_quota(zfsvfs_t *zfsvfs, zfs_prop_t zfs_prop, 260 uint64_t quota); 261 262 #ifdef __cplusplus 263 } 264 #endif 265 266 #endif /* _SYS_FS_ZFS_VFSOPS_H */ 267