zfs: merge OpenZFS master-9305ff2ed
[freebsd.git] / sys / contrib / openzfs / 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 http://www.opensolaris.org/os/licensing.
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         uint64_t        z_nr_znodes;    /* number of znodes in the fs */
97         kmutex_t        z_znodes_lock;  /* lock for z_all_znodes */
98         struct zfsctl_root      *z_ctldir;      /* .zfs directory pointer */
99         boolean_t       z_show_ctldir;  /* expose .zfs in the root dir */
100         boolean_t       z_issnap;       /* true if this is a snapshot */
101         boolean_t       z_vscan;        /* virus scan on/off */
102         boolean_t       z_use_fuids;    /* version allows fuids */
103         boolean_t       z_replay;       /* set during ZIL replay */
104         boolean_t       z_use_sa;       /* version allow system attributes */
105         boolean_t       z_xattr_sa;     /* allow xattrs to be stores as SA */
106         boolean_t       z_use_namecache; /* make use of FreeBSD name cache */
107         uint8_t         z_xattr;        /* xattr type in use */
108         uint64_t        z_version;      /* ZPL version */
109         uint64_t        z_shares_dir;   /* hidden shares dir */
110         dataset_kstats_t        z_kstat;        /* fs kstats */
111         kmutex_t        z_lock;
112         uint64_t        z_userquota_obj;
113         uint64_t        z_groupquota_obj;
114         uint64_t        z_userobjquota_obj;
115         uint64_t        z_groupobjquota_obj;
116         uint64_t        z_projectquota_obj;
117         uint64_t        z_projectobjquota_obj;
118         uint64_t        z_replay_eof;   /* New end of file - replay only */
119         sa_attr_type_t  *z_attr_table;  /* SA attr mapping->id */
120 #define ZFS_OBJ_MTX_SZ  64
121         kmutex_t        z_hold_mtx[ZFS_OBJ_MTX_SZ];     /* znode hold locks */
122         struct task     z_unlinked_drain_task;
123 };
124
125 #ifdef TEARDOWN_RMS
126 #define ZFS_TEARDOWN_INIT(zfsvfs)               \
127         rms_init(&(zfsvfs)->z_teardown_lock, "zfs teardown")
128
129 #define ZFS_TEARDOWN_DESTROY(zfsvfs)            \
130         rms_destroy(&(zfsvfs)->z_teardown_lock)
131
132 #define ZFS_TEARDOWN_TRY_ENTER_READ(zfsvfs)     \
133         rms_try_rlock(&(zfsvfs)->z_teardown_lock)
134
135 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag)    \
136         rms_rlock(&(zfsvfs)->z_teardown_lock);
137
138 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag)     \
139         rms_runlock(&(zfsvfs)->z_teardown_lock)
140
141 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag)   \
142         rms_wlock(&(zfsvfs)->z_teardown_lock)
143
144 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs)         \
145         rms_wunlock(&(zfsvfs)->z_teardown_lock)
146
147 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag)          \
148         rms_unlock(&(zfsvfs)->z_teardown_lock)
149
150 #define ZFS_TEARDOWN_READ_HELD(zfsvfs)          \
151         rms_rowned(&(zfsvfs)->z_teardown_lock)
152
153 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs)         \
154         rms_wowned(&(zfsvfs)->z_teardown_lock)
155
156 #define ZFS_TEARDOWN_HELD(zfsvfs)               \
157         rms_owned_any(&(zfsvfs)->z_teardown_lock)
158 #else
159 #define ZFS_TEARDOWN_INIT(zfsvfs)               \
160         rrm_init(&(zfsvfs)->z_teardown_lock, B_FALSE)
161
162 #define ZFS_TEARDOWN_DESTROY(zfsvfs)            \
163         rrm_destroy(&(zfsvfs)->z_teardown_lock)
164
165 #define ZFS_TEARDOWN_TRY_ENTER_READ(zfsvfs)     \
166         rw_tryenter(&(zfsvfs)->z_teardown_lock, RW_READER)
167
168 #define ZFS_TEARDOWN_ENTER_READ(zfsvfs, tag)    \
169         rrm_enter_read(&(zfsvfs)->z_teardown_lock, tag);
170
171 #define ZFS_TEARDOWN_EXIT_READ(zfsvfs, tag)     \
172         rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
173
174 #define ZFS_TEARDOWN_ENTER_WRITE(zfsvfs, tag)   \
175         rrm_enter(&(zfsvfs)->z_teardown_lock, RW_WRITER, tag)
176
177 #define ZFS_TEARDOWN_EXIT_WRITE(zfsvfs)         \
178         rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
179
180 #define ZFS_TEARDOWN_EXIT(zfsvfs, tag)          \
181         rrm_exit(&(zfsvfs)->z_teardown_lock, tag)
182
183 #define ZFS_TEARDOWN_READ_HELD(zfsvfs)          \
184         RRM_READ_HELD(&(zfsvfs)->z_teardown_lock)
185
186 #define ZFS_TEARDOWN_WRITE_HELD(zfsvfs)         \
187         RRM_WRITE_HELD(&(zfsvfs)->z_teardown_lock)
188
189 #define ZFS_TEARDOWN_HELD(zfsvfs)               \
190         RRM_LOCK_HELD(&(zfsvfs)->z_teardown_lock)
191 #endif
192
193 #ifdef TEARDOWN_INACTIVE_RMS
194 #define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs)              \
195         rms_init(&(zfsvfs)->z_teardown_inactive_lock, "zfs teardown inactive")
196
197 #define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs)           \
198         rms_destroy(&(zfsvfs)->z_teardown_inactive_lock)
199
200 #define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs)    \
201         rms_try_rlock(&(zfsvfs)->z_teardown_inactive_lock)
202
203 #define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs)        \
204         rms_rlock(&(zfsvfs)->z_teardown_inactive_lock)
205
206 #define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs)         \
207         rms_runlock(&(zfsvfs)->z_teardown_inactive_lock)
208
209 #define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs)       \
210         rms_wlock(&(zfsvfs)->z_teardown_inactive_lock)
211
212 #define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs)        \
213         rms_wunlock(&(zfsvfs)->z_teardown_inactive_lock)
214
215 #define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs)        \
216         rms_wowned(&(zfsvfs)->z_teardown_inactive_lock)
217 #else
218 #define ZFS_TEARDOWN_INACTIVE_INIT(zfsvfs)              \
219         rw_init(&(zfsvfs)->z_teardown_inactive_lock, NULL, RW_DEFAULT, NULL)
220
221 #define ZFS_TEARDOWN_INACTIVE_DESTROY(zfsvfs)           \
222         rw_destroy(&(zfsvfs)->z_teardown_inactive_lock)
223
224 #define ZFS_TEARDOWN_INACTIVE_TRY_ENTER_READ(zfsvfs)    \
225         rw_tryenter(&(zfsvfs)->z_teardown_inactive_lock, RW_READER)
226
227 #define ZFS_TEARDOWN_INACTIVE_ENTER_READ(zfsvfs)        \
228         rw_enter(&(zfsvfs)->z_teardown_inactive_lock, RW_READER)
229
230 #define ZFS_TEARDOWN_INACTIVE_EXIT_READ(zfsvfs)         \
231         rw_exit(&(zfsvfs)->z_teardown_inactive_lock)
232
233 #define ZFS_TEARDOWN_INACTIVE_ENTER_WRITE(zfsvfs)       \
234         rw_enter(&(zfsvfs)->z_teardown_inactive_lock, RW_WRITER)
235
236 #define ZFS_TEARDOWN_INACTIVE_EXIT_WRITE(zfsvfs)        \
237         rw_exit(&(zfsvfs)->z_teardown_inactive_lock)
238
239 #define ZFS_TEARDOWN_INACTIVE_WRITE_HELD(zfsvfs)        \
240         RW_WRITE_HELD(&(zfsvfs)->z_teardown_inactive_lock)
241 #endif
242
243 #define ZSB_XATTR       0x0001          /* Enable user xattrs */
244 /*
245  * Normal filesystems (those not under .zfs/snapshot) have a total
246  * file ID size limited to 12 bytes (including the length field) due to
247  * NFSv2 protocol's limitation of 32 bytes for a filehandle.  For historical
248  * reasons, this same limit is being imposed by the Solaris NFSv3 implementation
249  * (although the NFSv3 protocol actually permits a maximum of 64 bytes).  It
250  * is not possible to expand beyond 12 bytes without abandoning support
251  * of NFSv2.
252  *
253  * For normal filesystems, we partition up the available space as follows:
254  *      2 bytes         fid length (required)
255  *      6 bytes         object number (48 bits)
256  *      4 bytes         generation number (32 bits)
257  *
258  * We reserve only 48 bits for the object number, as this is the limit
259  * currently defined and imposed by the DMU.
260  */
261 typedef struct zfid_short {
262         uint16_t        zf_len;
263         uint8_t         zf_object[6];           /* obj[i] = obj >> (8 * i) */
264         uint8_t         zf_gen[4];              /* gen[i] = gen >> (8 * i) */
265 } zfid_short_t;
266
267 /*
268  * Filesystems under .zfs/snapshot have a total file ID size of 22[*] bytes
269  * (including the length field).  This makes files under .zfs/snapshot
270  * accessible by NFSv3 and NFSv4, but not NFSv2.
271  *
272  * For files under .zfs/snapshot, we partition up the available space
273  * as follows:
274  *      2 bytes         fid length (required)
275  *      6 bytes         object number (48 bits)
276  *      4 bytes         generation number (32 bits)
277  *      6 bytes         objset id (48 bits)
278  *      4 bytes[**]     currently just zero (32 bits)
279  *
280  * We reserve only 48 bits for the object number and objset id, as these are
281  * the limits currently defined and imposed by the DMU.
282  *
283  * [*] 20 bytes on FreeBSD to fit into the size of struct fid.
284  * [**] 2 bytes on FreeBSD for the above reason.
285  */
286 typedef struct zfid_long {
287         zfid_short_t    z_fid;
288         uint8_t         zf_setid[6];            /* obj[i] = obj >> (8 * i) */
289         uint8_t         zf_setgen[2];           /* gen[i] = gen >> (8 * i) */
290 } zfid_long_t;
291
292 #define SHORT_FID_LEN   (sizeof (zfid_short_t) - sizeof (uint16_t))
293 #define LONG_FID_LEN    (sizeof (zfid_long_t) - sizeof (uint16_t))
294
295 extern uint_t zfs_fsyncer_key;
296 extern int zfs_super_owner;
297
298 extern void zfs_init(void);
299 extern void zfs_fini(void);
300
301 extern int zfs_suspend_fs(zfsvfs_t *zfsvfs);
302 extern int zfs_resume_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
303 extern int zfs_end_fs(zfsvfs_t *zfsvfs, struct dsl_dataset *ds);
304 extern int zfs_set_version(zfsvfs_t *zfsvfs, uint64_t newvers);
305 extern int zfsvfs_create(const char *name, boolean_t readonly, zfsvfs_t **zfvp);
306 extern int zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, objset_t *os);
307 extern void zfsvfs_free(zfsvfs_t *zfsvfs);
308 extern int zfs_check_global_label(const char *dsname, const char *hexsl);
309 extern boolean_t zfs_is_readonly(zfsvfs_t *zfsvfs);
310 extern int zfs_get_temporary_prop(struct dsl_dataset *ds, zfs_prop_t zfs_prop,
311     uint64_t *val, char *setpoint);
312 extern int zfs_busy(void);
313
314 #ifdef  __cplusplus
315 }
316 #endif
317
318 #endif  /* _SYS_FS_ZFS_VFSOPS_H */