xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zfs_ioctl.h (revision 9e69d7d0feb2a0394435ca1d9746c4c3d7bf9b22)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
222c2961f8Sjose borrego  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef	_SYS_ZFS_IOCTL_H
27fa9e4066Sahrens #define	_SYS_ZFS_IOCTL_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/cred.h>
30fa9e4066Sahrens #include <sys/dmu.h>
31ea8dc4b6Seschrock #include <sys/zio.h>
32ecd6cf80Smarks #include <sys/dsl_deleg.h>
33*9e69d7d0SLori Alt #include <sys/spa.h>
34fa9e4066Sahrens 
35da6c28aaSamw #ifdef _KERNEL
36da6c28aaSamw #include <sys/nvpair.h>
37da6c28aaSamw #endif	/* _KERNEL */
38da6c28aaSamw 
39fa9e4066Sahrens #ifdef	__cplusplus
40fa9e4066Sahrens extern "C" {
41fa9e4066Sahrens #endif
42fa9e4066Sahrens 
43fa9e4066Sahrens /*
44fa9e4066Sahrens  * Property values for snapdir
45fa9e4066Sahrens  */
46a0965f35Sbonwick #define	ZFS_SNAPDIR_HIDDEN		0
47a0965f35Sbonwick #define	ZFS_SNAPDIR_VISIBLE		1
48fa9e4066Sahrens 
49*9e69d7d0SLori Alt /*
50*9e69d7d0SLori Alt  * Field manipulation macros for the drr_versioninfo field of the
51*9e69d7d0SLori Alt  * send stream header.
52*9e69d7d0SLori Alt  */
53*9e69d7d0SLori Alt 
54*9e69d7d0SLori Alt /*
55*9e69d7d0SLori Alt  * Header types for zfs send streams.
56*9e69d7d0SLori Alt  */
57*9e69d7d0SLori Alt typedef enum drr_headertype {
58*9e69d7d0SLori Alt 	DMU_SUBSTREAM = 0x1,
59*9e69d7d0SLori Alt 	DMU_COMPOUNDSTREAM = 0x2
60*9e69d7d0SLori Alt } drr_headertype_t;
61*9e69d7d0SLori Alt 
62*9e69d7d0SLori Alt #define	DMU_GET_STREAM_HDRTYPE(vi)	BF64_GET((vi), 0, 2)
63*9e69d7d0SLori Alt #define	DMU_SET_STREAM_HDRTYPE(vi, x)	BF64_SET((vi), 0, 2, x)
64*9e69d7d0SLori Alt 
65*9e69d7d0SLori Alt #define	DMU_GET_FEATUREFLAGS(vi)	BF64_GET((vi), 2, 30)
66*9e69d7d0SLori Alt #define	DMU_SET_FEATUREFLAGS(vi, x)	BF64_SET((vi), 2, 30, x)
67*9e69d7d0SLori Alt 
68*9e69d7d0SLori Alt /*
69*9e69d7d0SLori Alt  * Feature flags for zfs send streams (flags in drr_versioninfo)
70*9e69d7d0SLori Alt  */
71*9e69d7d0SLori Alt 
72*9e69d7d0SLori Alt #define	DMU_BACKUP_FEATURE_DEDUP	(0x1)
73*9e69d7d0SLori Alt 
74*9e69d7d0SLori Alt /*
75*9e69d7d0SLori Alt  * Mask of all supported backup features
76*9e69d7d0SLori Alt  */
77*9e69d7d0SLori Alt #define	DMU_BACKUP_FEATURE_MASK	(DMU_BACKUP_FEATURE_DEDUP)
78*9e69d7d0SLori Alt 
79*9e69d7d0SLori Alt /* Are all features in the given flag word currently supported? */
80*9e69d7d0SLori Alt #define	DMU_STREAM_SUPPORTED(x)	(!((x) & ~DMU_BACKUP_FEATURE_MASK))
81*9e69d7d0SLori Alt 
82*9e69d7d0SLori Alt /*
83*9e69d7d0SLori Alt  * The drr_versioninfo field of the dmu_replay_record has the
84*9e69d7d0SLori Alt  * following layout:
85*9e69d7d0SLori Alt  *
86*9e69d7d0SLori Alt  *	64	56	48	40	32	24	16	8	0
87*9e69d7d0SLori Alt  *	+-------+-------+-------+-------+-------+-------+-------+-------+
88*9e69d7d0SLori Alt  *  	|		reserved	|        feature-flags	    |C|S|
89*9e69d7d0SLori Alt  *	+-------+-------+-------+-------+-------+-------+-------+-------+
90*9e69d7d0SLori Alt  *
91*9e69d7d0SLori Alt  * The low order two bits indicate the header type: SUBSTREAM (0x1)
92*9e69d7d0SLori Alt  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
93*9e69d7d0SLori Alt  * this field used to be a version number, where the two version types
94*9e69d7d0SLori Alt  * were 1 and 2.  Using two bits for this allows earlier versions of
95*9e69d7d0SLori Alt  * the code to be able to recognize send streams that don't use any
96*9e69d7d0SLori Alt  * of the features indicated by feature flags.
97*9e69d7d0SLori Alt  */
98*9e69d7d0SLori Alt 
99fa9e4066Sahrens #define	DMU_BACKUP_MAGIC 0x2F5bacbacULL
100fa9e4066Sahrens 
101ab04eb8eStimh #define	DRR_FLAG_CLONE		(1<<0)
102ab04eb8eStimh #define	DRR_FLAG_CI_DATA	(1<<1)
1033cb34c60Sahrens 
104fa9e4066Sahrens /*
105fa9e4066Sahrens  * zfs ioctl command structure
106fa9e4066Sahrens  */
107fa9e4066Sahrens typedef struct dmu_replay_record {
108fa9e4066Sahrens 	enum {
109fa9e4066Sahrens 		DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
110*9e69d7d0SLori Alt 		DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
111*9e69d7d0SLori Alt 		DRR_NUMTYPES
112fa9e4066Sahrens 	} drr_type;
1133cb34c60Sahrens 	uint32_t drr_payloadlen;
114fa9e4066Sahrens 	union {
115fa9e4066Sahrens 		struct drr_begin {
116fa9e4066Sahrens 			uint64_t drr_magic;
117*9e69d7d0SLori Alt 			uint64_t drr_versioninfo; /* was drr_version */
118fa9e4066Sahrens 			uint64_t drr_creation_time;
119fa9e4066Sahrens 			dmu_objset_type_t drr_type;
1203cb34c60Sahrens 			uint32_t drr_flags;
121fa9e4066Sahrens 			uint64_t drr_toguid;
122fa9e4066Sahrens 			uint64_t drr_fromguid;
123fa9e4066Sahrens 			char drr_toname[MAXNAMELEN];
124fa9e4066Sahrens 		} drr_begin;
125fa9e4066Sahrens 		struct drr_end {
126ea8dc4b6Seschrock 			zio_cksum_t drr_checksum;
127*9e69d7d0SLori Alt 			uint64_t drr_toguid;
128fa9e4066Sahrens 		} drr_end;
129fa9e4066Sahrens 		struct drr_object {
130fa9e4066Sahrens 			uint64_t drr_object;
131fa9e4066Sahrens 			dmu_object_type_t drr_type;
132fa9e4066Sahrens 			dmu_object_type_t drr_bonustype;
133fa9e4066Sahrens 			uint32_t drr_blksz;
134fa9e4066Sahrens 			uint32_t drr_bonuslen;
135*9e69d7d0SLori Alt 			uint8_t drr_checksumtype;
136fa9e4066Sahrens 			uint8_t drr_compress;
137fa9e4066Sahrens 			uint8_t drr_pad[6];
138*9e69d7d0SLori Alt 			uint64_t drr_toguid;
139a2eea2e1Sahrens 			/* bonus content follows */
140fa9e4066Sahrens 		} drr_object;
141fa9e4066Sahrens 		struct drr_freeobjects {
142fa9e4066Sahrens 			uint64_t drr_firstobj;
143fa9e4066Sahrens 			uint64_t drr_numobjs;
144*9e69d7d0SLori Alt 			uint64_t drr_toguid;
145fa9e4066Sahrens 		} drr_freeobjects;
146fa9e4066Sahrens 		struct drr_write {
147fa9e4066Sahrens 			uint64_t drr_object;
148fa9e4066Sahrens 			dmu_object_type_t drr_type;
149fa9e4066Sahrens 			uint32_t drr_pad;
150fa9e4066Sahrens 			uint64_t drr_offset;
151fa9e4066Sahrens 			uint64_t drr_length;
152*9e69d7d0SLori Alt 			uint64_t drr_toguid;
153*9e69d7d0SLori Alt 			uint8_t drr_checksumtype;
154*9e69d7d0SLori Alt 			uint8_t drr_pad2[7];
155*9e69d7d0SLori Alt 			zio_cksum_t drr_blkcksum;
156a2eea2e1Sahrens 			/* content follows */
157fa9e4066Sahrens 		} drr_write;
158fa9e4066Sahrens 		struct drr_free {
159fa9e4066Sahrens 			uint64_t drr_object;
160fa9e4066Sahrens 			uint64_t drr_offset;
161fa9e4066Sahrens 			uint64_t drr_length;
162*9e69d7d0SLori Alt 			uint64_t drr_toguid;
163fa9e4066Sahrens 		} drr_free;
164*9e69d7d0SLori Alt 		struct drr_write_byref {
165*9e69d7d0SLori Alt 			/* where to put the data */
166*9e69d7d0SLori Alt 			uint64_t drr_object;
167*9e69d7d0SLori Alt 			uint64_t drr_offset;
168*9e69d7d0SLori Alt 			uint64_t drr_length;
169*9e69d7d0SLori Alt 			uint64_t drr_toguid;
170*9e69d7d0SLori Alt 			/* where to find the prior copy of the data */
171*9e69d7d0SLori Alt 			uint64_t drr_refguid;
172*9e69d7d0SLori Alt 			uint64_t drr_refobject;
173*9e69d7d0SLori Alt 			uint64_t drr_refoffset;
174*9e69d7d0SLori Alt 			uint8_t drr_checksumtype;
175*9e69d7d0SLori Alt 			uint8_t drr_pad[7];
176*9e69d7d0SLori Alt 			zio_cksum_t drr_blkcksum;
177*9e69d7d0SLori Alt 		} drr_write_byref;
178fa9e4066Sahrens 	} drr_u;
179fa9e4066Sahrens } dmu_replay_record_t;
180fa9e4066Sahrens 
181ea8dc4b6Seschrock typedef struct zinject_record {
182ea8dc4b6Seschrock 	uint64_t	zi_objset;
183ea8dc4b6Seschrock 	uint64_t	zi_object;
184ea8dc4b6Seschrock 	uint64_t	zi_start;
185ea8dc4b6Seschrock 	uint64_t	zi_end;
186ea8dc4b6Seschrock 	uint64_t	zi_guid;
187ea8dc4b6Seschrock 	uint32_t	zi_level;
188ea8dc4b6Seschrock 	uint32_t	zi_error;
189ea8dc4b6Seschrock 	uint64_t	zi_type;
190ea8dc4b6Seschrock 	uint32_t	zi_freq;
1918956713aSEric Schrock 	uint32_t	zi_failfast;
19288ecc943SGeorge Wilson 	char		zi_func[MAXNAMELEN];
1938f18d1faSGeorge Wilson 	uint32_t	zi_iotype;
194468c413aSTim Haley 	int32_t		zi_duration;
195468c413aSTim Haley 	uint64_t	zi_timer;
196ea8dc4b6Seschrock } zinject_record_t;
197ea8dc4b6Seschrock 
198ea8dc4b6Seschrock #define	ZINJECT_NULL		0x1
199ea8dc4b6Seschrock #define	ZINJECT_FLUSH_ARC	0x2
200ea8dc4b6Seschrock #define	ZINJECT_UNLOAD_SPA	0x4
201ea8dc4b6Seschrock 
202ecd6cf80Smarks typedef struct zfs_share {
203ecd6cf80Smarks 	uint64_t	z_exportdata;
204ecd6cf80Smarks 	uint64_t	z_sharedata;
205ecd6cf80Smarks 	uint64_t	z_sharetype;	/* 0 = share, 1 = unshare */
206ecd6cf80Smarks 	uint64_t	z_sharemax;  /* max length of share string */
207ecd6cf80Smarks } zfs_share_t;
208ecd6cf80Smarks 
209de8267e0Stimh /*
210de8267e0Stimh  * ZFS file systems may behave the usual, POSIX-compliant way, where
211de8267e0Stimh  * name lookups are case-sensitive.  They may also be set up so that
212de8267e0Stimh  * all the name lookups are case-insensitive, or so that only some
213de8267e0Stimh  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
214de8267e0Stimh  */
215de8267e0Stimh typedef enum zfs_case {
216de8267e0Stimh 	ZFS_CASE_SENSITIVE,
217de8267e0Stimh 	ZFS_CASE_INSENSITIVE,
218de8267e0Stimh 	ZFS_CASE_MIXED
219de8267e0Stimh } zfs_case_t;
220de8267e0Stimh 
221fa9e4066Sahrens typedef struct zfs_cmd {
22215f66a7fSek 	char		zc_name[MAXPATHLEN];
22355434c77Sek 	char		zc_value[MAXPATHLEN * 2];
2243cb34c60Sahrens 	char		zc_string[MAXNAMELEN];
225*9e69d7d0SLori Alt 	char		zc_top_ds[MAXPATHLEN];
226ea8dc4b6Seschrock 	uint64_t	zc_guid;
227990b4856Slling 	uint64_t	zc_nvlist_conf;		/* really (char *) */
228990b4856Slling 	uint64_t	zc_nvlist_conf_size;
229990b4856Slling 	uint64_t	zc_nvlist_src;		/* really (char *) */
230e9dbad6fSeschrock 	uint64_t	zc_nvlist_src_size;
231990b4856Slling 	uint64_t	zc_nvlist_dst;		/* really (char *) */
232e9dbad6fSeschrock 	uint64_t	zc_nvlist_dst_size;
233fa9e4066Sahrens 	uint64_t	zc_cookie;
234fa9e4066Sahrens 	uint64_t	zc_objset_type;
235ecd6cf80Smarks 	uint64_t	zc_perm_action;
236990b4856Slling 	uint64_t 	zc_history;		/* really (char *) */
237ecd6cf80Smarks 	uint64_t 	zc_history_len;
23806eeb2adSek 	uint64_t	zc_history_offset;
23955434c77Sek 	uint64_t	zc_obj;
240478ed9adSEric Taylor 	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
241ecd6cf80Smarks 	zfs_share_t	zc_share;
242fa9e4066Sahrens 	dmu_objset_stats_t zc_objset_stats;
243fa9e4066Sahrens 	struct drr_begin zc_begin_record;
244ea8dc4b6Seschrock 	zinject_record_t zc_inject_record;
245842727c2SChris Kirby 	boolean_t	zc_defer_destroy;
246ca45db41SChris Kirby 	boolean_t	zc_temphold;
247fa9e4066Sahrens } zfs_cmd_t;
248fa9e4066Sahrens 
24914843421SMatthew Ahrens typedef struct zfs_useracct {
25014843421SMatthew Ahrens 	char zu_domain[256];
25114843421SMatthew Ahrens 	uid_t zu_rid;
25214843421SMatthew Ahrens 	uint32_t zu_pad;
25314843421SMatthew Ahrens 	uint64_t zu_space;
25414843421SMatthew Ahrens } zfs_useracct_t;
25514843421SMatthew Ahrens 
256a0965f35Sbonwick #define	ZVOL_MAX_MINOR	(1 << 16)
257a0965f35Sbonwick #define	ZFS_MIN_MINOR	(ZVOL_MAX_MINOR + 1)
258a0965f35Sbonwick 
259fa9e4066Sahrens #ifdef _KERNEL
260fa9e4066Sahrens 
261da6c28aaSamw typedef struct zfs_creat {
262de8267e0Stimh 	nvlist_t	*zct_zplprops;
263da6c28aaSamw 	nvlist_t	*zct_props;
264da6c28aaSamw } zfs_creat_t;
265da6c28aaSamw 
266fa9e4066Sahrens extern dev_info_t *zfs_dip;
267fa9e4066Sahrens 
268ecd6cf80Smarks extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
269ecd6cf80Smarks extern int zfs_secpolicy_rename_perms(const char *from,
270ecd6cf80Smarks     const char *to, cred_t *cr);
271ecd6cf80Smarks extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
272fa9e4066Sahrens extern int zfs_busy(void);
273cdf5b4caSmmusante extern int zfs_unmount_snap(char *, void *);
274fa9e4066Sahrens 
275fa9e4066Sahrens #endif	/* _KERNEL */
276fa9e4066Sahrens 
277fa9e4066Sahrens #ifdef	__cplusplus
278fa9e4066Sahrens }
279fa9e4066Sahrens #endif
280fa9e4066Sahrens 
281fa9e4066Sahrens #endif	/* _SYS_ZFS_IOCTL_H */
282