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