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