xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zfs_ioctl.h (revision 8e7144747a94247ce9dbb4fb1f67bdcb666b30d8)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_ZFS_IOCTL_H
27 #define	_SYS_ZFS_IOCTL_H
28 
29 #include <sys/cred.h>
30 #include <sys/dmu.h>
31 #include <sys/zio.h>
32 #include <sys/dsl_deleg.h>
33 #include <sys/spa.h>
34 
35 #ifdef _KERNEL
36 #include <sys/nvpair.h>
37 #endif	/* _KERNEL */
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Property values for snapdir
45  */
46 #define	ZFS_SNAPDIR_HIDDEN		0
47 #define	ZFS_SNAPDIR_VISIBLE		1
48 
49 /*
50  * Field manipulation macros for the drr_versioninfo field of the
51  * send stream header.
52  */
53 
54 /*
55  * Header types for zfs send streams.
56  */
57 typedef enum drr_headertype {
58 	DMU_SUBSTREAM = 0x1,
59 	DMU_COMPOUNDSTREAM = 0x2
60 } drr_headertype_t;
61 
62 #define	DMU_GET_STREAM_HDRTYPE(vi)	BF64_GET((vi), 0, 2)
63 #define	DMU_SET_STREAM_HDRTYPE(vi, x)	BF64_SET((vi), 0, 2, x)
64 
65 #define	DMU_GET_FEATUREFLAGS(vi)	BF64_GET((vi), 2, 30)
66 #define	DMU_SET_FEATUREFLAGS(vi, x)	BF64_SET((vi), 2, 30, x)
67 
68 /*
69  * Feature flags for zfs send streams (flags in drr_versioninfo)
70  */
71 
72 #define	DMU_BACKUP_FEATURE_DEDUP	(0x1)
73 #define	DMU_BACKUP_FEATURE_DEDUPPROPS	(0x2)
74 
75 /*
76  * Mask of all supported backup features
77  */
78 #define	DMU_BACKUP_FEATURE_MASK	(DMU_BACKUP_FEATURE_DEDUP | \
79 		DMU_BACKUP_FEATURE_DEDUPPROPS)
80 
81 /* Are all features in the given flag word currently supported? */
82 #define	DMU_STREAM_SUPPORTED(x)	(!((x) & ~DMU_BACKUP_FEATURE_MASK))
83 
84 /*
85  * The drr_versioninfo field of the dmu_replay_record has the
86  * following layout:
87  *
88  *	64	56	48	40	32	24	16	8	0
89  *	+-------+-------+-------+-------+-------+-------+-------+-------+
90  *  	|		reserved	|        feature-flags	    |C|S|
91  *	+-------+-------+-------+-------+-------+-------+-------+-------+
92  *
93  * The low order two bits indicate the header type: SUBSTREAM (0x1)
94  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
95  * this field used to be a version number, where the two version types
96  * were 1 and 2.  Using two bits for this allows earlier versions of
97  * the code to be able to recognize send streams that don't use any
98  * of the features indicated by feature flags.
99  */
100 
101 #define	DMU_BACKUP_MAGIC 0x2F5bacbacULL
102 
103 #define	DRR_FLAG_CLONE		(1<<0)
104 #define	DRR_FLAG_CI_DATA	(1<<1)
105 
106 /*
107  * flags in the drr_checksumflags field in the DRR_WRITE and
108  * DRR_WRITE_BYREF blocks
109  */
110 #define	DRR_CHECKSUM_DEDUP	(1<<0)
111 
112 #define	DRR_IS_DEDUP_CAPABLE(flags)	((flags) & DRR_CHECKSUM_DEDUP)
113 
114 /*
115  * zfs ioctl command structure
116  */
117 typedef struct dmu_replay_record {
118 	enum {
119 		DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
120 		DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
121 		DRR_NUMTYPES
122 	} drr_type;
123 	uint32_t drr_payloadlen;
124 	union {
125 		struct drr_begin {
126 			uint64_t drr_magic;
127 			uint64_t drr_versioninfo; /* was drr_version */
128 			uint64_t drr_creation_time;
129 			dmu_objset_type_t drr_type;
130 			uint32_t drr_flags;
131 			uint64_t drr_toguid;
132 			uint64_t drr_fromguid;
133 			char drr_toname[MAXNAMELEN];
134 		} drr_begin;
135 		struct drr_end {
136 			zio_cksum_t drr_checksum;
137 			uint64_t drr_toguid;
138 		} drr_end;
139 		struct drr_object {
140 			uint64_t drr_object;
141 			dmu_object_type_t drr_type;
142 			dmu_object_type_t drr_bonustype;
143 			uint32_t drr_blksz;
144 			uint32_t drr_bonuslen;
145 			uint8_t drr_checksumtype;
146 			uint8_t drr_compress;
147 			uint8_t drr_pad[6];
148 			uint64_t drr_toguid;
149 			/* bonus content follows */
150 		} drr_object;
151 		struct drr_freeobjects {
152 			uint64_t drr_firstobj;
153 			uint64_t drr_numobjs;
154 			uint64_t drr_toguid;
155 		} drr_freeobjects;
156 		struct drr_write {
157 			uint64_t drr_object;
158 			dmu_object_type_t drr_type;
159 			uint32_t drr_pad;
160 			uint64_t drr_offset;
161 			uint64_t drr_length;
162 			uint64_t drr_toguid;
163 			uint8_t drr_checksumtype;
164 			uint8_t drr_checksumflags;
165 			uint8_t drr_pad2[6];
166 			ddt_key_t drr_key; /* deduplication key */
167 			/* content follows */
168 		} drr_write;
169 		struct drr_free {
170 			uint64_t drr_object;
171 			uint64_t drr_offset;
172 			uint64_t drr_length;
173 			uint64_t drr_toguid;
174 		} drr_free;
175 		struct drr_write_byref {
176 			/* where to put the data */
177 			uint64_t drr_object;
178 			uint64_t drr_offset;
179 			uint64_t drr_length;
180 			uint64_t drr_toguid;
181 			/* where to find the prior copy of the data */
182 			uint64_t drr_refguid;
183 			uint64_t drr_refobject;
184 			uint64_t drr_refoffset;
185 			/* properties of the data */
186 			uint8_t drr_checksumtype;
187 			uint8_t drr_checksumflags;
188 			uint8_t drr_pad2[6];
189 			ddt_key_t drr_key; /* deduplication key */
190 		} drr_write_byref;
191 	} drr_u;
192 } dmu_replay_record_t;
193 
194 typedef struct zinject_record {
195 	uint64_t	zi_objset;
196 	uint64_t	zi_object;
197 	uint64_t	zi_start;
198 	uint64_t	zi_end;
199 	uint64_t	zi_guid;
200 	uint32_t	zi_level;
201 	uint32_t	zi_error;
202 	uint64_t	zi_type;
203 	uint32_t	zi_freq;
204 	uint32_t	zi_failfast;
205 	char		zi_func[MAXNAMELEN];
206 	uint32_t	zi_iotype;
207 	int32_t		zi_duration;
208 	uint64_t	zi_timer;
209 } zinject_record_t;
210 
211 #define	ZINJECT_NULL		0x1
212 #define	ZINJECT_FLUSH_ARC	0x2
213 #define	ZINJECT_UNLOAD_SPA	0x4
214 
215 typedef struct zfs_share {
216 	uint64_t	z_exportdata;
217 	uint64_t	z_sharedata;
218 	uint64_t	z_sharetype;	/* 0 = share, 1 = unshare */
219 	uint64_t	z_sharemax;  /* max length of share string */
220 } zfs_share_t;
221 
222 /*
223  * ZFS file systems may behave the usual, POSIX-compliant way, where
224  * name lookups are case-sensitive.  They may also be set up so that
225  * all the name lookups are case-insensitive, or so that only some
226  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
227  */
228 typedef enum zfs_case {
229 	ZFS_CASE_SENSITIVE,
230 	ZFS_CASE_INSENSITIVE,
231 	ZFS_CASE_MIXED
232 } zfs_case_t;
233 
234 typedef struct zfs_cmd {
235 	char		zc_name[MAXPATHLEN];
236 	char		zc_value[MAXPATHLEN * 2];
237 	char		zc_string[MAXNAMELEN];
238 	char		zc_top_ds[MAXPATHLEN];
239 	uint64_t	zc_guid;
240 	uint64_t	zc_nvlist_conf;		/* really (char *) */
241 	uint64_t	zc_nvlist_conf_size;
242 	uint64_t	zc_nvlist_src;		/* really (char *) */
243 	uint64_t	zc_nvlist_src_size;
244 	uint64_t	zc_nvlist_dst;		/* really (char *) */
245 	uint64_t	zc_nvlist_dst_size;
246 	uint64_t	zc_cookie;
247 	uint64_t	zc_objset_type;
248 	uint64_t	zc_perm_action;
249 	uint64_t 	zc_history;		/* really (char *) */
250 	uint64_t 	zc_history_len;
251 	uint64_t	zc_history_offset;
252 	uint64_t	zc_obj;
253 	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
254 	zfs_share_t	zc_share;
255 	dmu_objset_stats_t zc_objset_stats;
256 	struct drr_begin zc_begin_record;
257 	zinject_record_t zc_inject_record;
258 	boolean_t	zc_defer_destroy;
259 	boolean_t	zc_temphold;
260 } zfs_cmd_t;
261 
262 typedef struct zfs_useracct {
263 	char zu_domain[256];
264 	uid_t zu_rid;
265 	uint32_t zu_pad;
266 	uint64_t zu_space;
267 } zfs_useracct_t;
268 
269 #define	ZVOL_MAX_MINOR	(1 << 16)
270 #define	ZFS_MIN_MINOR	(ZVOL_MAX_MINOR + 1)
271 
272 #ifdef _KERNEL
273 
274 typedef struct zfs_creat {
275 	nvlist_t	*zct_zplprops;
276 	nvlist_t	*zct_props;
277 } zfs_creat_t;
278 
279 extern dev_info_t *zfs_dip;
280 
281 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
282 extern int zfs_secpolicy_rename_perms(const char *from,
283     const char *to, cred_t *cr);
284 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
285 extern int zfs_busy(void);
286 extern int zfs_unmount_snap(const char *, void *);
287 
288 #endif	/* _KERNEL */
289 
290 #ifdef	__cplusplus
291 }
292 #endif
293 
294 #endif	/* _SYS_ZFS_IOCTL_H */
295