xref: /freebsd/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_vfsops_os.h (revision 071ab5a1f3cbfd29c8fbec27f7e619418adaf074)
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_defaultuserquota;
100 	uint64_t	z_defaultgroupquota;
101 	uint64_t	z_defaultprojectquota;
102 	uint64_t	z_defaultuserobjquota;
103 	uint64_t	z_defaultgroupobjquota;
104 	uint64_t	z_defaultprojectobjquota;
105 	uint64_t	z_replay_eof;	/* New end of file - replay only */
106 	sa_attr_type_t	*z_attr_table;	/* SA attr mapping->id */
107 #define	ZFS_OBJ_MTX_SZ	64
108 	kmutex_t	z_hold_mtx[ZFS_OBJ_MTX_SZ];	/* znode hold locks */
109 	struct task	z_unlinked_drain_task;
110 };
111 
112 #define	ZFS_TEARDOWN_INIT(zfsvfs)		\
113 	rms_init(&(zfsvfs)->z_teardown_lock, "zfs teardown")
114 
115 #define	ZFS_TEARDOWN_DESTROY(zfsvfs)		\
116 	rms_destroy(&(zfsvfs)->z_teardown_lock)
117 
118 #define	ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag)	\
119 	rms_rlock(&(zfsvfs)->z_teardown_lock);
120 
121 #define	ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag)	\
122 	rms_runlock(&(zfsvfs)->z_teardown_lock)
123 
124 #define	ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag)	\
125 	rms_wlock(&(zfsvfs)->z_teardown_lock)
126 
127 #define	ZFS_TEARDOWN_EXIT_WRITE(zfsvfs)		\
128 	rms_wunlock(&(zfsvfs)->z_teardown_lock)
129 
130 #define	ZFS_TEARDOWN_EXIT(zfsvfs, tag)		\
131 	rms_unlock(&(zfsvfs)->z_teardown_lock)
132 
133 #define	ZFS_TEARDOWN_READ_HELD(zfsvfs)		\
134 	rms_rowned(&(zfsvfs)->z_teardown_lock)
135 
136 #define	ZFS_TEARDOWN_WRITE_HELD(zfsvfs)		\
137 	rms_wowned(&(zfsvfs)->z_teardown_lock)
138 
139 #define	ZFS_TEARDOWN_HELD(zfsvfs)		\
140 	rms_owned_any(&(zfsvfs)->z_teardown_lock)
141 
142 #define	ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs)		\
143 	rms_init(&(zfsvfs)->z_teardown_inactive_lock, "zfs teardown inactive")
144 
145 #define	ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs)		\
146 	rms_destroy(&(zfsvfs)->z_teardown_inactive_lock)
147 
148 #define	ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs)	\
149 	rms_try_rlock(&(zfsvfs)->z_teardown_inactive_lock)
150 
151 #define	ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs)	\
152 	rms_rlock(&(zfsvfs)->z_teardown_inactive_lock)
153 
154 #define	ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs)		\
155 	rms_runlock(&(zfsvfs)->z_teardown_inactive_lock)
156 
157 #define	ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs)	\
158 	rms_wlock(&(zfsvfs)->z_teardown_inactive_lock)
159 
160 #define	ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs)	\
161 	rms_wunlock(&(zfsvfs)->z_teardown_inactive_lock)
162 
163 #define	ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs)	\
164 	rms_wowned(&(zfsvfs)->z_teardown_inactive_lock)
165 
166 #define	ZSB_XATTR	0x0001		/* Enable user xattrs */
167 /*
168  * Normal filesystems (those not under .zfs/snapshot) have a total
169  * file ID size limited to 12 bytes (including the length field) due to
170  * NFSv2 protocol's limitation of 32 bytes for a filehandle.  For historical
171  * reasons, this same limit is being imposed by the Solaris NFSv3 implementation
172  * (although the NFSv3 protocol actually permits a maximum of 64 bytes).  It
173  * is not possible to expand beyond 12 bytes without abandoning support
174  * of NFSv2.
175  *
176  * For normal filesystems, we partition up the available space as follows:
177  *	2 bytes		fid length (required)
178  *	6 bytes		object number (48 bits)
179  *	4 bytes		generation number (32 bits)
180  *
181  * We reserve only 48 bits for the object number, as this is the limit
182  * currently defined and imposed by the DMU.
183  */
184 typedef struct zfid_short {
185 	uint16_t	zf_len;
186 	uint8_t		zf_object[6];		/* obj[i] = obj >> (8 * i) */
187 	uint8_t		zf_gen[4];		/* gen[i] = gen >> (8 * i) */
188 } zfid_short_t;
189 
190 /*
191  * Filesystems under .zfs/snapshot have a total file ID size of 22[*] bytes
192  * (including the length field).  This makes files under .zfs/snapshot
193  * accessible by NFSv3 and NFSv4, but not NFSv2.
194  *
195  * For files under .zfs/snapshot, we partition up the available space
196  * as follows:
197  *	2 bytes		fid length (required)
198  *	6 bytes		object number (48 bits)
199  *	4 bytes		generation number (32 bits)
200  *	6 bytes		objset id (48 bits)
201  *	4 bytes[**]	currently just zero (32 bits)
202  *
203  * We reserve only 48 bits for the object number and objset id, as these are
204  * the limits currently defined and imposed by the DMU.
205  *
206  * [*] 20 bytes on FreeBSD to fit into the size of struct fid.
207  * [**] 2 bytes on FreeBSD for the above reason.
208  */
209 typedef struct zfid_long {
210 	zfid_short_t	z_fid;
211 	uint8_t		zf_setid[6];		/* obj[i] = obj >> (8 * i) */
212 	uint8_t		zf_setgen[2];		/* gen[i] = gen >> (8 * i) */
213 } zfid_long_t;
214 
215 #define	SHORT_FID_LEN	(sizeof (zfid_short_t) - sizeof (uint16_t))
216 #define	LONG_FID_LEN	(sizeof (zfid_long_t) - sizeof (uint16_t))
217 
218 extern int zfs_super_owner;
219 
220 extern void zfs_init(void);
221 extern void zfs_fini(void);
222 
223 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs);
224 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
225 extern int zfs_end_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
226 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers);
227 extern int zfsvfs_create(const char *name, boolean_t readonly, zfsvfs_t **zfvp);
228 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os);
229 extern void zfsvfs_free(zfsvfs_t *zfsvfs);
230 extern int zfs_check_global_label(const char *dsname, const char *hexsl);
231 extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs);
232 extern int zfs_get_temporary_prop(struct dsl_dataset *ds, zfs_prop_t zfs_prop,
233     uint64_t *val, char *setpoint);
234 extern int zfs_busy(void);
235 extern int zfs_set_default_quota(zfsvfs_t *zfsvfs, zfs_prop_t zfs_prop,
236     uint64_t quota);
237 
238 #ifdef	__cplusplus
239 }
240 #endif
241 
242 #endif	/* _SYS_FS_ZFS_VFSOPS_H */
243