]> git.proxmox.com Git - mirror_zfs.git/blob - include/os/freebsd/zfs/sys/zfs_vfsops_os.h
BRT: Fix FICLONE/FICLONERANGE shortened copy
[mirror_zfs.git] / include / os / freebsd / zfs / sys / zfs_vfsops_os.h
1 /*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>.
24 * All rights reserved.
25 */
26
27 #ifndef _SYS_FS_ZFS_VFSOPS_H
28 #define _SYS_FS_ZFS_VFSOPS_H
29
30 #if __FreeBSD_version >= 1300125
31 #define TEARDOWN_RMS
32 #endif
33
34 #if __FreeBSD_version >= 1300109
35 #define TEARDOWN_INACTIVE_RMS
36 #endif
37
38 #include <sys/dataset_kstats.h>
39 #include <sys/list.h>
40 #include <sys/vfs.h>
41 #include <sys/zil.h>
42 #include <sys/sa.h>
43 #include <sys/rrwlock.h>
44 #ifdef TEARDOWN_INACTIVE_RMS
45 #include <sys/rmlock.h>
46 #endif
47 #include <sys/zfs_ioctl.h>
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 #ifdef TEARDOWN_RMS
54 typedef struct rmslock zfs_teardown_lock_t;
55 #else
56 #define zfs_teardown_lock_t rrmlock_t
57 #endif
58
59 #ifdef TEARDOWN_INACTIVE_RMS
60 typedef struct rmslock zfs_teardown_inactive_lock_t;
61 #else
62 #define zfs_teardown_inactive_lock_t krwlock_t
63 #endif
64
65 typedef struct zfsvfs zfsvfs_t;
66 struct znode;
67
68 struct zfsvfs {
69 vfs_t *z_vfs; /* generic fs struct */
70 zfsvfs_t *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_type; /* type of acl usable on this fs */
86 uint_t z_acl_mode; /* acl chmod/mode behavior */
87 uint_t z_acl_inherit; /* acl inheritance behavior */
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_atime; /* enable atimes mount option */
92 boolean_t z_unmounted; /* unmounted */
93 zfs_teardown_lock_t z_teardown_lock;
94 zfs_teardown_inactive_lock_t z_teardown_inactive_lock;
95 list_t z_all_znodes; /* all vnodes in the fs */
96 kmutex_t z_znodes_lock; /* lock for z_all_znodes */
97 struct zfsctl_root *z_ctldir; /* .zfs directory pointer */
98 boolean_t z_show_ctldir; /* expose .zfs in the root dir */
99 boolean_t z_issnap; /* true if this is a snapshot */
100 boolean_t z_use_fuids; /* version allows fuids */
101 boolean_t z_replay; /* set during ZIL replay */
102 boolean_t z_use_sa; /* version allow system attributes */
103 boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */
104 boolean_t z_use_namecache; /* make use of FreeBSD name cache */
105 uint8_t z_xattr; /* xattr type in use */
106 uint64_t z_version; /* ZPL version */
107 uint64_t z_shares_dir; /* hidden shares dir */
108 dataset_kstats_t z_kstat; /* fs kstats */
109 kmutex_t z_lock;
110 uint64_t z_userquota_obj;
111 uint64_t z_groupquota_obj;
112 uint64_t z_userobjquota_obj;
113 uint64_t z_groupobjquota_obj;
114 uint64_t z_projectquota_obj;
115 uint64_t z_projectobjquota_obj;
116 uint64_t z_replay_eof; /* New end of file - replay only */
117 sa_attr_type_t *z_attr_table; /* SA attr mapping->id */
118 #define ZFS_OBJ_MTX_SZ 64
119 kmutex_t z_hold_mtx[ZFS_OBJ_MTX_SZ]; /* znode hold locks */
120 struct task z_unlinked_drain_task;
121 };
122
123 #ifdef TEARDOWN_RMS
124 #define ZFS_TEARDOWN_INIT(zfsvfs) \
125 rms_init(&(zfsvfs)->z_teardown_lock, "zfs teardown")
126
127 #define ZFS_TEARDOWN_DESTROY(zfsvfs) \
128 rms_destroy(&(zfsvfs)->z_teardown_lock)
129
130 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag) \
131 rms_rlock(&(zfsvfs)->z_teardown_lock);
132
133 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag) \
134 rms_runlock(&(zfsvfs)->z_teardown_lock)
135
136 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag) \
137 rms_wlock(&(zfsvfs)->z_teardown_lock)
138
139 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs) \
140 rms_wunlock(&(zfsvfs)->z_teardown_lock)
141
142 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag) \
143 rms_unlock(&(zfsvfs)->z_teardown_lock)
144
145 #define ZFS_TEARDOWN_READ_HELD(zfsvfs) \
146 rms_rowned(&(zfsvfs)->z_teardown_lock)
147
148 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs) \
149 rms_wowned(&(zfsvfs)->z_teardown_lock)
150
151 #define ZFS_TEARDOWN_HELD(zfsvfs) \
152 rms_owned_any(&(zfsvfs)->z_teardown_lock)
153 #else
154 #define ZFS_TEARDOWN_INIT(zfsvfs) \
155 rrm_init(&(zfsvfs)->z_teardown_lock, B_FALSE)
156
157 #define ZFS_TEARDOWN_DESTROY(zfsvfs) \
158 rrm_destroy(&(zfsvfs)->z_teardown_lock)
159
160 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag) \
161 rrm_enter_read(&(zfsvfs)->z_teardown_lock, tag);
162
163 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag) \
164 rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
165
166 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag) \
167 rrm_enter(&(zfsvfs)->z_teardown_lock, RW_WRITER, tag)
168
169 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs) \
170 rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
171
172 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag) \
173 rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
174
175 #define ZFS_TEARDOWN_READ_HELD(zfsvfs) \
176 RRM_READ_HELD(&(zfsvfs)->z_teardown_lock)
177
178 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs) \
179 RRM_WRITE_HELD(&(zfsvfs)->z_teardown_lock)
180
181 #define ZFS_TEARDOWN_HELD(zfsvfs) \
182 RRM_LOCK_HELD(&(zfsvfs)->z_teardown_lock)
183 #endif
184
185 #ifdef TEARDOWN_INACTIVE_RMS
186 #define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs) \
187 rms_init(&(zfsvfs)->z_teardown_inactive_lock, "zfs teardown inactive")
188
189 #define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs) \
190 rms_destroy(&(zfsvfs)->z_teardown_inactive_lock)
191
192 #define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs) \
193 rms_try_rlock(&(zfsvfs)->z_teardown_inactive_lock)
194
195 #define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs) \
196 rms_rlock(&(zfsvfs)->z_teardown_inactive_lock)
197
198 #define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs) \
199 rms_runlock(&(zfsvfs)->z_teardown_inactive_lock)
200
201 #define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs) \
202 rms_wlock(&(zfsvfs)->z_teardown_inactive_lock)
203
204 #define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs) \
205 rms_wunlock(&(zfsvfs)->z_teardown_inactive_lock)
206
207 #define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs) \
208 rms_wowned(&(zfsvfs)->z_teardown_inactive_lock)
209 #else
210 #define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs) \
211 rw_init(&(zfsvfs)->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL)
212
213 #define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs) \
214 rw_destroy(&(zfsvfs)->z_teardown_inactive_lock)
215
216 #define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs) \
217 rw_tryenter(&(zfsvfs)->z_teardown_inactive_lock, RW_READER)
218
219 #define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs) \
220 rw_enter(&(zfsvfs)->z_teardown_inactive_lock, RW_READER)
221
222 #define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs) \
223 rw_exit(&(zfsvfs)->z_teardown_inactive_lock)
224
225 #define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs) \
226 rw_enter(&(zfsvfs)->z_teardown_inactive_lock, RW_WRITER)
227
228 #define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs) \
229 rw_exit(&(zfsvfs)->z_teardown_inactive_lock)
230
231 #define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs) \
232 RW_WRITE_HELD(&(zfsvfs)->z_teardown_inactive_lock)
233 #endif
234
235 #define ZSB_XATTR 0x0001 /* Enable user xattrs */
236 /*
237 * Normal filesystems (those not under .zfs/snapshot) have a total
238 * file ID size limited to 12 bytes (including the length field) due to
239 * NFSv2 protocol's limitation of 32 bytes for a filehandle. For historical
240 * reasons, this same limit is being imposed by the Solaris NFSv3 implementation
241 * (although the NFSv3 protocol actually permits a maximum of 64 bytes). It
242 * is not possible to expand beyond 12 bytes without abandoning support
243 * of NFSv2.
244 *
245 * For normal filesystems, we partition up the available space as follows:
246 * 2 bytes fid length (required)
247 * 6 bytes object number (48 bits)
248 * 4 bytes generation number (32 bits)
249 *
250 * We reserve only 48 bits for the object number, as this is the limit
251 * currently defined and imposed by the DMU.
252 */
253 typedef struct zfid_short {
254 uint16_t zf_len;
255 uint8_t zf_object[6]; /* obj[i] = obj >> (8 * i) */
256 uint8_t zf_gen[4]; /* gen[i] = gen >> (8 * i) */
257 } zfid_short_t;
258
259 /*
260 * Filesystems under .zfs/snapshot have a total file ID size of 22[*] bytes
261 * (including the length field). This makes files under .zfs/snapshot
262 * accessible by NFSv3 and NFSv4, but not NFSv2.
263 *
264 * For files under .zfs/snapshot, we partition up the available space
265 * as follows:
266 * 2 bytes fid length (required)
267 * 6 bytes object number (48 bits)
268 * 4 bytes generation number (32 bits)
269 * 6 bytes objset id (48 bits)
270 * 4 bytes[**] currently just zero (32 bits)
271 *
272 * We reserve only 48 bits for the object number and objset id, as these are
273 * the limits currently defined and imposed by the DMU.
274 *
275 * [*] 20 bytes on FreeBSD to fit into the size of struct fid.
276 * [**] 2 bytes on FreeBSD for the above reason.
277 */
278 typedef struct zfid_long {
279 zfid_short_t z_fid;
280 uint8_t zf_setid[6]; /* obj[i] = obj >> (8 * i) */
281 uint8_t zf_setgen[2]; /* gen[i] = gen >> (8 * i) */
282 } zfid_long_t;
283
284 #define SHORT_FID_LEN (sizeof (zfid_short_t) - sizeof (uint16_t))
285 #define LONG_FID_LEN (sizeof (zfid_long_t) - sizeof (uint16_t))
286
287 extern int zfs_super_owner;
288
289 extern void zfs_init(void);
290 extern void zfs_fini(void);
291
292 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs);
293 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
294 extern int zfs_end_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
295 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers);
296 extern int zfsvfs_create(const char *name, boolean_t readonly, zfsvfs_t **zfvp);
297 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os);
298 extern void zfsvfs_free(zfsvfs_t *zfsvfs);
299 extern int zfs_check_global_label(const char *dsname, const char *hexsl);
300 extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs);
301 extern int zfs_get_temporary_prop(struct dsl_dataset *ds, zfs_prop_t zfs_prop,
302 uint64_t *val, char *setpoint);
303 extern int zfs_busy(void);
304
305 #ifdef __cplusplus
306 }
307 #endif
308
309 #endif /* _SYS_FS_ZFS_VFSOPS_H */