]> granicus.if.org Git - zfs/blob - include/sys/zfs_ioctl.h
OpenZFS 8491 - uberblock on-disk padding to reserve space for smoothly merging zpool...
[zfs] / include / sys / zfs_ioctl.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) 2012, 2015 by Delphix. All rights reserved.
24  * Copyright 2016 RackTop Systems.
25  * Copyright (c) 2017, Intel Corporation.
26  */
27
28 #ifndef _SYS_ZFS_IOCTL_H
29 #define _SYS_ZFS_IOCTL_H
30
31 #include <sys/cred.h>
32 #include <sys/dmu.h>
33 #include <sys/zio.h>
34 #include <sys/dsl_deleg.h>
35 #include <sys/spa.h>
36 #include <sys/zfs_stat.h>
37
38 #ifdef _KERNEL
39 #include <sys/nvpair.h>
40 #endif  /* _KERNEL */
41
42 #ifdef  __cplusplus
43 extern "C" {
44 #endif
45
46 /*
47  * The structures in this file are passed between userland and the
48  * kernel.  Userland may be running a 32-bit process, while the kernel
49  * is 64-bit.  Therefore, these structures need to compile the same in
50  * 32-bit and 64-bit.  This means not using type "long", and adding
51  * explicit padding so that the 32-bit structure will not be packed more
52  * tightly than the 64-bit structure (which requires 64-bit alignment).
53  */
54
55 /*
56  * Property values for snapdir
57  */
58 #define ZFS_SNAPDIR_HIDDEN              0
59 #define ZFS_SNAPDIR_VISIBLE             1
60
61 /*
62  * Property values for snapdev
63  */
64 #define ZFS_SNAPDEV_HIDDEN              0
65 #define ZFS_SNAPDEV_VISIBLE             1
66 /*
67  * Property values for acltype
68  */
69 #define ZFS_ACLTYPE_OFF                 0
70 #define ZFS_ACLTYPE_POSIXACL            1
71
72 /*
73  * Field manipulation macros for the drr_versioninfo field of the
74  * send stream header.
75  */
76
77 /*
78  * Header types for zfs send streams.
79  */
80 typedef enum drr_headertype {
81         DMU_SUBSTREAM = 0x1,
82         DMU_COMPOUNDSTREAM = 0x2
83 } drr_headertype_t;
84
85 #define DMU_GET_STREAM_HDRTYPE(vi)      BF64_GET((vi), 0, 2)
86 #define DMU_SET_STREAM_HDRTYPE(vi, x)   BF64_SET((vi), 0, 2, x)
87
88 #define DMU_GET_FEATUREFLAGS(vi)        BF64_GET((vi), 2, 30)
89 #define DMU_SET_FEATUREFLAGS(vi, x)     BF64_SET((vi), 2, 30, x)
90
91 /*
92  * Feature flags for zfs send streams (flags in drr_versioninfo)
93  */
94
95 #define DMU_BACKUP_FEATURE_DEDUP                (1 << 0)
96 #define DMU_BACKUP_FEATURE_DEDUPPROPS           (1 << 1)
97 #define DMU_BACKUP_FEATURE_SA_SPILL             (1 << 2)
98 /* flags #3 - #15 are reserved for incompatible closed-source implementations */
99 #define DMU_BACKUP_FEATURE_EMBED_DATA           (1 << 16)
100 #define DMU_BACKUP_FEATURE_LZ4                  (1 << 17)
101 /* flag #18 is reserved for a Delphix feature */
102 #define DMU_BACKUP_FEATURE_LARGE_BLOCKS         (1 << 19)
103 #define DMU_BACKUP_FEATURE_RESUMING             (1 << 20)
104 /* flag #21 is reserved for a Delphix feature */
105 #define DMU_BACKUP_FEATURE_COMPRESSED           (1 << 22)
106 #define DMU_BACKUP_FEATURE_LARGE_DNODE          (1 << 23)
107
108 /*
109  * Mask of all supported backup features
110  */
111 #define DMU_BACKUP_FEATURE_MASK (DMU_BACKUP_FEATURE_DEDUP | \
112     DMU_BACKUP_FEATURE_DEDUPPROPS | DMU_BACKUP_FEATURE_SA_SPILL | \
113     DMU_BACKUP_FEATURE_EMBED_DATA | DMU_BACKUP_FEATURE_LZ4 | \
114     DMU_BACKUP_FEATURE_RESUMING | DMU_BACKUP_FEATURE_LARGE_BLOCKS | \
115     DMU_BACKUP_FEATURE_COMPRESSED | DMU_BACKUP_FEATURE_LARGE_DNODE)
116
117 /* Are all features in the given flag word currently supported? */
118 #define DMU_STREAM_SUPPORTED(x) (!((x) & ~DMU_BACKUP_FEATURE_MASK))
119
120 typedef enum dmu_send_resume_token_version {
121         ZFS_SEND_RESUME_TOKEN_VERSION = 1
122 } dmu_send_resume_token_version_t;
123
124 /*
125  * The drr_versioninfo field of the dmu_replay_record has the
126  * following layout:
127  *
128  *      64      56      48      40      32      24      16      8       0
129  *      +-------+-------+-------+-------+-------+-------+-------+-------+
130  *      |               reserved        |        feature-flags      |C|S|
131  *      +-------+-------+-------+-------+-------+-------+-------+-------+
132  *
133  * The low order two bits indicate the header type: SUBSTREAM (0x1)
134  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
135  * this field used to be a version number, where the two version types
136  * were 1 and 2.  Using two bits for this allows earlier versions of
137  * the code to be able to recognize send streams that don't use any
138  * of the features indicated by feature flags.
139  */
140
141 #define DMU_BACKUP_MAGIC 0x2F5bacbacULL
142
143 /*
144  * Send stream flags.  Bits 24-31 are reserved for vendor-specific
145  * implementations and should not be used.
146  */
147 #define DRR_FLAG_CLONE          (1<<0)
148 #define DRR_FLAG_CI_DATA        (1<<1)
149 /*
150  * This send stream, if it is a full send, includes the FREE and FREEOBJECT
151  * records that are created by the sending process.  This means that the send
152  * stream can be received as a clone, even though it is not an incremental.
153  * This is not implemented as a feature flag, because the receiving side does
154  * not need to have implemented it to receive this stream; it is fully backwards
155  * compatible.  We need a flag, though, because full send streams without it
156  * cannot necessarily be received as a clone correctly.
157  */
158 #define DRR_FLAG_FREERECORDS    (1<<2)
159
160 /*
161  * flags in the drr_checksumflags field in the DRR_WRITE and
162  * DRR_WRITE_BYREF blocks
163  */
164 #define DRR_CHECKSUM_DEDUP      (1<<0)
165
166 #define DRR_IS_DEDUP_CAPABLE(flags)     ((flags) & DRR_CHECKSUM_DEDUP)
167
168 /* deal with compressed drr_write replay records */
169 #define DRR_WRITE_COMPRESSED(drrw)      ((drrw)->drr_compressiontype != 0)
170 #define DRR_WRITE_PAYLOAD_SIZE(drrw) \
171         (DRR_WRITE_COMPRESSED(drrw) ? (drrw)->drr_compressed_size : \
172         (drrw)->drr_logical_size)
173
174 /*
175  * zfs ioctl command structure
176  */
177 typedef struct dmu_replay_record {
178         enum {
179                 DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
180                 DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
181                 DRR_SPILL, DRR_WRITE_EMBEDDED, DRR_NUMTYPES
182         } drr_type;
183         uint32_t drr_payloadlen;
184         union {
185                 struct drr_begin {
186                         uint64_t drr_magic;
187                         uint64_t drr_versioninfo; /* was drr_version */
188                         uint64_t drr_creation_time;
189                         dmu_objset_type_t drr_type;
190                         uint32_t drr_flags;
191                         uint64_t drr_toguid;
192                         uint64_t drr_fromguid;
193                         char drr_toname[MAXNAMELEN];
194                 } drr_begin;
195                 struct drr_end {
196                         zio_cksum_t drr_checksum;
197                         uint64_t drr_toguid;
198                 } drr_end;
199                 struct drr_object {
200                         uint64_t drr_object;
201                         dmu_object_type_t drr_type;
202                         dmu_object_type_t drr_bonustype;
203                         uint32_t drr_blksz;
204                         uint32_t drr_bonuslen;
205                         uint8_t drr_checksumtype;
206                         uint8_t drr_compress;
207                         uint8_t drr_dn_slots;
208                         uint8_t drr_pad[5];
209                         uint64_t drr_toguid;
210                         /* bonus content follows */
211                 } drr_object;
212                 struct drr_freeobjects {
213                         uint64_t drr_firstobj;
214                         uint64_t drr_numobjs;
215                         uint64_t drr_toguid;
216                 } drr_freeobjects;
217                 struct drr_write {
218                         uint64_t drr_object;
219                         dmu_object_type_t drr_type;
220                         uint32_t drr_pad;
221                         uint64_t drr_offset;
222                         uint64_t drr_logical_size;
223                         uint64_t drr_toguid;
224                         uint8_t drr_checksumtype;
225                         uint8_t drr_checksumflags;
226                         uint8_t drr_compressiontype;
227                         uint8_t drr_pad2[5];
228                         /* deduplication key */
229                         ddt_key_t drr_key;
230                         /* only nonzero if drr_compressiontype is not 0 */
231                         uint64_t drr_compressed_size;
232                         /* content follows */
233                 } drr_write;
234                 struct drr_free {
235                         uint64_t drr_object;
236                         uint64_t drr_offset;
237                         uint64_t drr_length;
238                         uint64_t drr_toguid;
239                 } drr_free;
240                 struct drr_write_byref {
241                         /* where to put the data */
242                         uint64_t drr_object;
243                         uint64_t drr_offset;
244                         uint64_t drr_length;
245                         uint64_t drr_toguid;
246                         /* where to find the prior copy of the data */
247                         uint64_t drr_refguid;
248                         uint64_t drr_refobject;
249                         uint64_t drr_refoffset;
250                         /* properties of the data */
251                         uint8_t drr_checksumtype;
252                         uint8_t drr_checksumflags;
253                         uint8_t drr_pad2[6];
254                         ddt_key_t drr_key; /* deduplication key */
255                 } drr_write_byref;
256                 struct drr_spill {
257                         uint64_t drr_object;
258                         uint64_t drr_length;
259                         uint64_t drr_toguid;
260                         uint64_t drr_pad[4]; /* needed for crypto */
261                         /* spill data follows */
262                 } drr_spill;
263                 struct drr_write_embedded {
264                         uint64_t drr_object;
265                         uint64_t drr_offset;
266                         /* logical length, should equal blocksize */
267                         uint64_t drr_length;
268                         uint64_t drr_toguid;
269                         uint8_t drr_compression;
270                         uint8_t drr_etype;
271                         uint8_t drr_pad[6];
272                         uint32_t drr_lsize; /* uncompressed size of payload */
273                         uint32_t drr_psize; /* compr. (real) size of payload */
274                         /* (possibly compressed) content follows */
275                 } drr_write_embedded;
276
277                 /*
278                  * Nore: drr_checksum is overlaid with all record types
279                  * except DRR_BEGIN.  Therefore its (non-pad) members
280                  * must not overlap with members from the other structs.
281                  * We accomplish this by putting its members at the very
282                  * end of the struct.
283                  */
284                 struct drr_checksum {
285                         uint64_t drr_pad[34];
286                         /*
287                          * fletcher-4 checksum of everything preceding the
288                          * checksum.
289                          */
290                         zio_cksum_t drr_checksum;
291                 } drr_checksum;
292         } drr_u;
293 } dmu_replay_record_t;
294
295 /* diff record range types */
296 typedef enum diff_type {
297         DDR_NONE = 0x1,
298         DDR_INUSE = 0x2,
299         DDR_FREE = 0x4
300 } diff_type_t;
301
302 /*
303  * The diff reports back ranges of free or in-use objects.
304  */
305 typedef struct dmu_diff_record {
306         uint64_t ddr_type;
307         uint64_t ddr_first;
308         uint64_t ddr_last;
309 } dmu_diff_record_t;
310
311 typedef struct zinject_record {
312         uint64_t        zi_objset;
313         uint64_t        zi_object;
314         uint64_t        zi_start;
315         uint64_t        zi_end;
316         uint64_t        zi_guid;
317         uint32_t        zi_level;
318         uint32_t        zi_error;
319         uint64_t        zi_type;
320         uint32_t        zi_freq;
321         uint32_t        zi_failfast;
322         char            zi_func[MAXNAMELEN];
323         uint32_t        zi_iotype;
324         int32_t         zi_duration;
325         uint64_t        zi_timer;
326         uint64_t        zi_nlanes;
327         uint32_t        zi_cmd;
328         uint32_t        zi_pad;
329 } zinject_record_t;
330
331 #define ZINJECT_NULL            0x1
332 #define ZINJECT_FLUSH_ARC       0x2
333 #define ZINJECT_UNLOAD_SPA      0x4
334
335 #define ZEVENT_NONE             0x0
336 #define ZEVENT_NONBLOCK         0x1
337 #define ZEVENT_SIZE             1024
338
339 #define ZEVENT_SEEK_START       0
340 #define ZEVENT_SEEK_END         UINT64_MAX
341
342 /* scaled frequency ranges */
343 #define ZI_PERCENTAGE_MIN       4294UL
344 #define ZI_PERCENTAGE_MAX       UINT32_MAX
345
346 typedef enum zinject_type {
347         ZINJECT_UNINITIALIZED,
348         ZINJECT_DATA_FAULT,
349         ZINJECT_DEVICE_FAULT,
350         ZINJECT_LABEL_FAULT,
351         ZINJECT_IGNORED_WRITES,
352         ZINJECT_PANIC,
353         ZINJECT_DELAY_IO,
354 } zinject_type_t;
355
356 typedef struct zfs_share {
357         uint64_t        z_exportdata;
358         uint64_t        z_sharedata;
359         uint64_t        z_sharetype;    /* 0 = share, 1 = unshare */
360         uint64_t        z_sharemax;  /* max length of share string */
361 } zfs_share_t;
362
363 /*
364  * ZFS file systems may behave the usual, POSIX-compliant way, where
365  * name lookups are case-sensitive.  They may also be set up so that
366  * all the name lookups are case-insensitive, or so that only some
367  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
368  */
369 typedef enum zfs_case {
370         ZFS_CASE_SENSITIVE,
371         ZFS_CASE_INSENSITIVE,
372         ZFS_CASE_MIXED
373 } zfs_case_t;
374
375 /*
376  * Note: this struct must have the same layout in 32-bit and 64-bit, so
377  * that 32-bit processes (like /sbin/zfs) can pass it to the 64-bit
378  * kernel.  Therefore, we add padding to it so that no "hidden" padding
379  * is automatically added on 64-bit (but not on 32-bit).
380  */
381 typedef struct zfs_cmd {
382         char            zc_name[MAXPATHLEN];    /* name of pool or dataset */
383         uint64_t        zc_nvlist_src;          /* really (char *) */
384         uint64_t        zc_nvlist_src_size;
385         uint64_t        zc_nvlist_dst;          /* really (char *) */
386         uint64_t        zc_nvlist_dst_size;
387         boolean_t       zc_nvlist_dst_filled;   /* put an nvlist in dst? */
388         int             zc_pad2;
389
390         /*
391          * The following members are for legacy ioctls which haven't been
392          * converted to the new method.
393          */
394         uint64_t        zc_history;             /* really (char *) */
395         char            zc_value[MAXPATHLEN * 2];
396         char            zc_string[MAXNAMELEN];
397         uint64_t        zc_guid;
398         uint64_t        zc_nvlist_conf;         /* really (char *) */
399         uint64_t        zc_nvlist_conf_size;
400         uint64_t        zc_cookie;
401         uint64_t        zc_objset_type;
402         uint64_t        zc_perm_action;
403         uint64_t        zc_history_len;
404         uint64_t        zc_history_offset;
405         uint64_t        zc_obj;
406         uint64_t        zc_iflags;              /* internal to zfs(7fs) */
407         zfs_share_t     zc_share;
408         dmu_objset_stats_t zc_objset_stats;
409         struct drr_begin zc_begin_record;
410         zinject_record_t zc_inject_record;
411         uint32_t        zc_defer_destroy;
412         uint32_t        zc_flags;
413         uint64_t        zc_action_handle;
414         int             zc_cleanup_fd;
415         uint8_t         zc_simple;
416         uint8_t         zc_pad[3];              /* alignment */
417         uint64_t        zc_sendobj;
418         uint64_t        zc_fromobj;
419         uint64_t        zc_createtxg;
420         zfs_stat_t      zc_stat;
421 } zfs_cmd_t;
422
423 typedef struct zfs_useracct {
424         char zu_domain[256];
425         uid_t zu_rid;
426         uint32_t zu_pad;
427         uint64_t zu_space;
428 } zfs_useracct_t;
429
430 #define ZFSDEV_MAX_MINOR        (1 << 16)
431 #define ZFS_MIN_MINOR   (ZFSDEV_MAX_MINOR + 1)
432
433 #define ZPOOL_EXPORT_AFTER_SPLIT 0x1
434
435 #ifdef _KERNEL
436
437 typedef struct zfs_creat {
438         nvlist_t        *zct_zplprops;
439         nvlist_t        *zct_props;
440 } zfs_creat_t;
441
442 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
443 extern int zfs_secpolicy_rename_perms(const char *from,
444     const char *to, cred_t *cr);
445 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
446 extern int zfs_unmount_snap(const char *);
447 extern void zfs_destroy_unmount_origin(const char *);
448
449 extern boolean_t dataset_name_hidden(const char *name);
450
451 enum zfsdev_state_type {
452         ZST_ONEXIT,
453         ZST_ZEVENT,
454         ZST_ALL,
455 };
456
457 /*
458  * The zfsdev_state_t structure is managed as a singly-linked list
459  * from which items are never deleted.  This allows for lock-free
460  * reading of the list so long as assignments to the zs_next and
461  * reads from zs_minor are performed atomically.  Empty items are
462  * indicated by storing -1 into zs_minor.
463  */
464 typedef struct zfsdev_state {
465         struct zfsdev_state     *zs_next;       /* next zfsdev_state_t link */
466         struct file             *zs_file;       /* associated file struct */
467         minor_t                 zs_minor;       /* made up minor number */
468         void                    *zs_onexit;     /* onexit data */
469         void                    *zs_zevent;     /* zevent data */
470 } zfsdev_state_t;
471
472 extern void *zfsdev_get_state(minor_t minor, enum zfsdev_state_type which);
473 extern int zfsdev_getminor(struct file *filp, minor_t *minorp);
474 extern minor_t zfsdev_minor_alloc(void);
475
476 #endif  /* _KERNEL */
477
478 #ifdef  __cplusplus
479 }
480 #endif
481
482 #endif  /* _SYS_ZFS_IOCTL_H */