zfs_ioctl_compat.h revision 268649
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 2014 Xin Li <delphij@FreeBSD.org>.  All rights reserved.
23 * Copyright 2013 Martin Matuska <mm@FreeBSD.org>.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef	_SYS_ZFS_IOCTL_COMPAT_H
28#define	_SYS_ZFS_IOCTL_COMPAT_H
29
30#include <sys/cred.h>
31#include <sys/dmu.h>
32#include <sys/zio.h>
33#include <sys/dsl_deleg.h>
34#include <sys/zfs_ioctl.h>
35
36#ifdef _KERNEL
37#include <sys/nvpair.h>
38#endif  /* _KERNEL */
39
40#ifdef	__cplusplus
41extern "C" {
42#endif
43
44/*
45 * Backwards ioctl compatibility
46 */
47
48/* ioctl versions for vfs.zfs.version.ioctl */
49#define	ZFS_IOCVER_UNDEF	-1
50#define	ZFS_IOCVER_NONE		0
51#define	ZFS_IOCVER_DEADMAN	1
52#define	ZFS_IOCVER_LZC		2
53#define	ZFS_IOCVER_ZCMD		3
54#define	ZFS_IOCVER_EDBP		4
55#define	ZFS_IOCVER_CURRENT	ZFS_IOCVER_EDBP
56
57/* compatibility conversion flag */
58#define	ZFS_CMD_COMPAT_NONE	0
59#define	ZFS_CMD_COMPAT_V15	1
60#define	ZFS_CMD_COMPAT_V28	2
61#define	ZFS_CMD_COMPAT_DEADMAN	3
62#define	ZFS_CMD_COMPAT_LZC	4
63#define	ZFS_CMD_COMPAT_ZCMD	5
64
65#define	ZFS_IOC_COMPAT_PASS	254
66#define	ZFS_IOC_COMPAT_FAIL	255
67
68#define	ZFS_IOCREQ(ioreq)	((ioreq) & 0xff)
69
70typedef struct zfs_iocparm {
71	uint32_t	zfs_ioctl_version;
72	uint64_t	zfs_cmd;
73	uint64_t	zfs_cmd_size;
74} zfs_iocparm_t;
75
76typedef struct zinject_record_v15 {
77	uint64_t	zi_objset;
78	uint64_t	zi_object;
79	uint64_t	zi_start;
80	uint64_t	zi_end;
81	uint64_t	zi_guid;
82	uint32_t	zi_level;
83	uint32_t	zi_error;
84	uint64_t	zi_type;
85	uint32_t	zi_freq;
86	uint32_t	zi_failfast;
87} zinject_record_v15_t;
88
89typedef struct zfs_cmd_v15 {
90	char		zc_name[MAXPATHLEN];
91	char		zc_value[MAXPATHLEN];
92	char		zc_string[MAXNAMELEN];
93	uint64_t	zc_guid;
94	uint64_t	zc_nvlist_conf;		/* really (char *) */
95	uint64_t	zc_nvlist_conf_size;
96	uint64_t	zc_nvlist_src;		/* really (char *) */
97	uint64_t	zc_nvlist_src_size;
98	uint64_t	zc_nvlist_dst;		/* really (char *) */
99	uint64_t	zc_nvlist_dst_size;
100	uint64_t	zc_cookie;
101	uint64_t	zc_objset_type;
102	uint64_t	zc_perm_action;
103	uint64_t 	zc_history;		/* really (char *) */
104	uint64_t 	zc_history_len;
105	uint64_t	zc_history_offset;
106	uint64_t	zc_obj;
107	zfs_share_t	zc_share;
108	uint64_t	zc_jailid;
109	dmu_objset_stats_t zc_objset_stats;
110	struct drr_begin zc_begin_record;
111	zinject_record_v15_t zc_inject_record;
112} zfs_cmd_v15_t;
113
114typedef struct zinject_record_v28 {
115	uint64_t	zi_objset;
116	uint64_t	zi_object;
117	uint64_t	zi_start;
118	uint64_t	zi_end;
119	uint64_t	zi_guid;
120	uint32_t	zi_level;
121	uint32_t	zi_error;
122	uint64_t	zi_type;
123	uint32_t	zi_freq;
124	uint32_t	zi_failfast;
125	char		zi_func[MAXNAMELEN];
126	uint32_t	zi_iotype;
127	int32_t		zi_duration;
128	uint64_t	zi_timer;
129} zinject_record_v28_t;
130
131typedef struct zfs_cmd_v28 {
132	char		zc_name[MAXPATHLEN];
133	char		zc_value[MAXPATHLEN * 2];
134	char		zc_string[MAXNAMELEN];
135	char		zc_top_ds[MAXPATHLEN];
136	uint64_t	zc_guid;
137	uint64_t	zc_nvlist_conf;		/* really (char *) */
138	uint64_t	zc_nvlist_conf_size;
139	uint64_t	zc_nvlist_src;		/* really (char *) */
140	uint64_t	zc_nvlist_src_size;
141	uint64_t	zc_nvlist_dst;		/* really (char *) */
142	uint64_t	zc_nvlist_dst_size;
143	uint64_t	zc_cookie;
144	uint64_t	zc_objset_type;
145	uint64_t	zc_perm_action;
146	uint64_t 	zc_history;		/* really (char *) */
147	uint64_t 	zc_history_len;
148	uint64_t	zc_history_offset;
149	uint64_t	zc_obj;
150	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
151	zfs_share_t	zc_share;
152	uint64_t	zc_jailid;
153	dmu_objset_stats_t zc_objset_stats;
154	struct drr_begin zc_begin_record;
155	zinject_record_v28_t zc_inject_record;
156	boolean_t	zc_defer_destroy;
157	boolean_t	zc_temphold;
158	uint64_t	zc_action_handle;
159	int		zc_cleanup_fd;
160	uint8_t		zc_simple;
161	uint8_t		zc_pad[3];		/* alignment */
162	uint64_t	zc_sendobj;
163	uint64_t	zc_fromobj;
164	uint64_t	zc_createtxg;
165	zfs_stat_t	zc_stat;
166} zfs_cmd_v28_t;
167
168typedef struct zfs_cmd_deadman {
169	char		zc_name[MAXPATHLEN];
170	char		zc_value[MAXPATHLEN * 2];
171	char		zc_string[MAXNAMELEN];
172	char		zc_top_ds[MAXPATHLEN];
173	uint64_t	zc_guid;
174	uint64_t	zc_nvlist_conf;		/* really (char *) */
175	uint64_t	zc_nvlist_conf_size;
176	uint64_t	zc_nvlist_src;		/* really (char *) */
177	uint64_t	zc_nvlist_src_size;
178	uint64_t	zc_nvlist_dst;		/* really (char *) */
179	uint64_t	zc_nvlist_dst_size;
180	uint64_t	zc_cookie;
181	uint64_t	zc_objset_type;
182	uint64_t	zc_perm_action;
183	uint64_t 	zc_history;		/* really (char *) */
184	uint64_t 	zc_history_len;
185	uint64_t	zc_history_offset;
186	uint64_t	zc_obj;
187	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
188	zfs_share_t	zc_share;
189	uint64_t	zc_jailid;
190	dmu_objset_stats_t zc_objset_stats;
191	struct drr_begin zc_begin_record;
192	/* zc_inject_record doesn't change in libzfs_core */
193	zinject_record_t zc_inject_record;
194	boolean_t	zc_defer_destroy;
195	boolean_t	zc_temphold;
196	uint64_t	zc_action_handle;
197	int		zc_cleanup_fd;
198	uint8_t		zc_simple;
199	uint8_t		zc_pad[3];		/* alignment */
200	uint64_t	zc_sendobj;
201	uint64_t	zc_fromobj;
202	uint64_t	zc_createtxg;
203	zfs_stat_t	zc_stat;
204} zfs_cmd_deadman_t;
205
206typedef struct zfs_cmd_zcmd {
207	char		zc_name[MAXPATHLEN];	/* name of pool or dataset */
208	uint64_t	zc_nvlist_src;		/* really (char *) */
209	uint64_t	zc_nvlist_src_size;
210	uint64_t	zc_nvlist_dst;		/* really (char *) */
211	uint64_t	zc_nvlist_dst_size;
212	boolean_t	zc_nvlist_dst_filled;	/* put an nvlist in dst? */
213	int		zc_pad2;
214
215	/*
216	 * The following members are for legacy ioctls which haven't been
217	 * converted to the new method.
218	 */
219	uint64_t	zc_history;		/* really (char *) */
220	char		zc_value[MAXPATHLEN * 2];
221	char		zc_string[MAXNAMELEN];
222	uint64_t	zc_guid;
223	uint64_t	zc_nvlist_conf;		/* really (char *) */
224	uint64_t	zc_nvlist_conf_size;
225	uint64_t	zc_cookie;
226	uint64_t	zc_objset_type;
227	uint64_t	zc_perm_action;
228	uint64_t	zc_history_len;
229	uint64_t	zc_history_offset;
230	uint64_t	zc_obj;
231	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
232	zfs_share_t	zc_share;
233	uint64_t	zc_jailid;
234	dmu_objset_stats_t zc_objset_stats;
235	struct drr_begin zc_begin_record;
236	zinject_record_t zc_inject_record;
237	boolean_t	zc_defer_destroy;
238	boolean_t	zc_temphold;
239	uint64_t	zc_action_handle;
240	int		zc_cleanup_fd;
241	uint8_t		zc_simple;
242	uint8_t		zc_pad[3];		/* alignment */
243	uint64_t	zc_sendobj;
244	uint64_t	zc_fromobj;
245	uint64_t	zc_createtxg;
246	zfs_stat_t	zc_stat;
247} zfs_cmd_zcmd_t;
248
249#ifdef _KERNEL
250unsigned static long zfs_ioctl_v15_to_v28[] = {
251	0,	/*  0 ZFS_IOC_POOL_CREATE */
252	1,	/*  1 ZFS_IOC_POOL_DESTROY */
253	2,	/*  2 ZFS_IOC_POOL_IMPORT */
254	3,	/*  3 ZFS_IOC_POOL_EXPORT */
255	4,	/*  4 ZFS_IOC_POOL_CONFIGS */
256	5,	/*  5 ZFS_IOC_POOL_STATS */
257	6,	/*  6 ZFS_IOC_POOL_TRYIMPORT */
258	7,	/*  7 ZFS_IOC_POOL_SCRUB */
259	8,	/*  8 ZFS_IOC_POOL_FREEZE */
260	9,	/*  9 ZFS_IOC_POOL_UPGRADE */
261	10,	/* 10 ZFS_IOC_POOL_GET_HISTORY */
262	11,	/* 11 ZFS_IOC_VDEV_ADD */
263	12,	/* 12 ZFS_IOC_VDEV_REMOVE */
264	13,	/* 13 ZFS_IOC_VDEV_SET_STATE */
265	14,	/* 14 ZFS_IOC_VDEV_ATTACH */
266	15,	/* 15 ZFS_IOC_VDEV_DETACH */
267	16,	/* 16 ZFS_IOC_VDEV_SETPATH */
268	18,	/* 17 ZFS_IOC_OBJSET_STATS */
269	19,	/* 18 ZFS_IOC_OBJSET_ZPLPROPS */
270	20, 	/* 19 ZFS_IOC_DATASET_LIST_NEXT */
271	21,	/* 20 ZFS_IOC_SNAPSHOT_LIST_NEXT */
272	22,	/* 21 ZFS_IOC_SET_PROP */
273	ZFS_IOC_COMPAT_PASS,	/* 22 ZFS_IOC_CREATE_MINOR */
274	ZFS_IOC_COMPAT_PASS,	/* 23 ZFS_IOC_REMOVE_MINOR */
275	23,	/* 24 ZFS_IOC_CREATE */
276	24,	/* 25 ZFS_IOC_DESTROY */
277	25,	/* 26 ZFS_IOC_ROLLBACK */
278	26,	/* 27 ZFS_IOC_RENAME */
279	27,	/* 28 ZFS_IOC_RECV */
280	28,	/* 29 ZFS_IOC_SEND */
281	29,	/* 30 ZFS_IOC_INJECT_FAULT */
282	30,	/* 31 ZFS_IOC_CLEAR_FAULT */
283	31,	/* 32 ZFS_IOC_INJECT_LIST_NEXT */
284	32,	/* 33 ZFS_IOC_ERROR_LOG */
285	33,	/* 34 ZFS_IOC_CLEAR */
286	34,	/* 35 ZFS_IOC_PROMOTE */
287	35,	/* 36 ZFS_IOC_DESTROY_SNAPS */
288	36,	/* 37 ZFS_IOC_SNAPSHOT */
289	37,	/* 38 ZFS_IOC_DSOBJ_TO_DSNAME */
290	38,	/* 39 ZFS_IOC_OBJ_TO_PATH */
291	39,	/* 40 ZFS_IOC_POOL_SET_PROPS */
292	40,	/* 41 ZFS_IOC_POOL_GET_PROPS */
293	41,	/* 42 ZFS_IOC_SET_FSACL */
294	42,	/* 43 ZFS_IOC_GET_FSACL */
295	ZFS_IOC_COMPAT_PASS,	/* 44 ZFS_IOC_ISCSI_PERM_CHECK */
296	43,	/* 45 ZFS_IOC_SHARE */
297	44,	/* 46 ZFS_IOC_IHNERIT_PROP */
298	58,	/* 47 ZFS_IOC_JAIL */
299	59,	/* 48 ZFS_IOC_UNJAIL */
300	45,	/* 49 ZFS_IOC_SMB_ACL */
301	46,	/* 50 ZFS_IOC_USERSPACE_ONE */
302	47,	/* 51 ZFS_IOC_USERSPACE_MANY */
303	48,	/* 52 ZFS_IOC_USERSPACE_UPGRADE */
304	17,	/* 53 ZFS_IOC_SETFRU */
305};
306
307#else	/* KERNEL */
308unsigned static long zfs_ioctl_v28_to_v15[] = {
309	0,	/*  0 ZFS_IOC_POOL_CREATE */
310	1,	/*  1 ZFS_IOC_POOL_DESTROY */
311	2,	/*  2 ZFS_IOC_POOL_IMPORT */
312	3,	/*  3 ZFS_IOC_POOL_EXPORT */
313	4,	/*  4 ZFS_IOC_POOL_CONFIGS */
314	5,	/*  5 ZFS_IOC_POOL_STATS */
315	6,	/*  6 ZFS_IOC_POOL_TRYIMPORT */
316	7,	/*  7 ZFS_IOC_POOL_SCAN */
317	8,	/*  8 ZFS_IOC_POOL_FREEZE */
318	9,	/*  9 ZFS_IOC_POOL_UPGRADE */
319	10,	/* 10 ZFS_IOC_POOL_GET_HISTORY */
320	11,	/* 11 ZFS_IOC_VDEV_ADD */
321	12,	/* 12 ZFS_IOC_VDEV_REMOVE */
322	13,	/* 13 ZFS_IOC_VDEV_SET_STATE */
323	14,	/* 14 ZFS_IOC_VDEV_ATTACH */
324	15,	/* 15 ZFS_IOC_VDEV_DETACH */
325	16,	/* 16 ZFS_IOC_VDEV_SETPATH */
326	53,	/* 17 ZFS_IOC_VDEV_SETFRU */
327	17,	/* 18 ZFS_IOC_OBJSET_STATS */
328	18,	/* 19 ZFS_IOC_OBJSET_ZPLPROPS */
329	19, 	/* 20 ZFS_IOC_DATASET_LIST_NEXT */
330	20,	/* 21 ZFS_IOC_SNAPSHOT_LIST_NEXT */
331	21,	/* 22 ZFS_IOC_SET_PROP */
332	24,	/* 23 ZFS_IOC_CREATE */
333	25,	/* 24 ZFS_IOC_DESTROY */
334	26,	/* 25 ZFS_IOC_ROLLBACK */
335	27,	/* 26 ZFS_IOC_RENAME */
336	28,	/* 27 ZFS_IOC_RECV */
337	29,	/* 28 ZFS_IOC_SEND */
338	30,	/* 39 ZFS_IOC_INJECT_FAULT */
339	31,	/* 30 ZFS_IOC_CLEAR_FAULT */
340	32,	/* 31 ZFS_IOC_INJECT_LIST_NEXT */
341	33,	/* 32 ZFS_IOC_ERROR_LOG */
342	34,	/* 33 ZFS_IOC_CLEAR */
343	35,	/* 34 ZFS_IOC_PROMOTE */
344	36,	/* 35 ZFS_IOC_DESTROY_SNAPS */
345	37,	/* 36 ZFS_IOC_SNAPSHOT */
346	38,	/* 37 ZFS_IOC_DSOBJ_TO_DSNAME */
347	39,	/* 38 ZFS_IOC_OBJ_TO_PATH */
348	40,	/* 39 ZFS_IOC_POOL_SET_PROPS */
349	41,	/* 40 ZFS_IOC_POOL_GET_PROPS */
350	42,	/* 41 ZFS_IOC_SET_FSACL */
351	43,	/* 42 ZFS_IOC_GET_FSACL */
352	45,	/* 43 ZFS_IOC_SHARE */
353	46,	/* 44 ZFS_IOC_IHNERIT_PROP */
354	49,	/* 45 ZFS_IOC_SMB_ACL */
355	50,	/* 46 ZFS_IOC_USERSPACE_ONE */
356	51,	/* 47 ZFS_IOC_USERSPACE_MANY */
357	52,	/* 48 ZFS_IOC_USERSPACE_UPGRADE */
358	ZFS_IOC_COMPAT_FAIL,	/* 49 ZFS_IOC_HOLD */
359	ZFS_IOC_COMPAT_FAIL,	/* 50 ZFS_IOC_RELEASE */
360	ZFS_IOC_COMPAT_FAIL,	/* 51 ZFS_IOC_GET_HOLDS */
361	ZFS_IOC_COMPAT_FAIL,	/* 52 ZFS_IOC_OBJSET_RECVD_PROPS */
362	ZFS_IOC_COMPAT_FAIL,	/* 53 ZFS_IOC_VDEV_SPLIT */
363	ZFS_IOC_COMPAT_FAIL,	/* 54 ZFS_IOC_NEXT_OBJ */
364	ZFS_IOC_COMPAT_FAIL,	/* 55 ZFS_IOC_DIFF */
365	ZFS_IOC_COMPAT_FAIL,	/* 56 ZFS_IOC_TMP_SNAPSHOT */
366	ZFS_IOC_COMPAT_FAIL,	/* 57 ZFS_IOC_OBJ_TO_STATS */
367	47,	/* 58 ZFS_IOC_JAIL */
368	48,	/* 59 ZFS_IOC_UNJAIL */
369};
370#endif	/* ! _KERNEL */
371
372#ifdef _KERNEL
373int zfs_ioctl_compat_pre(zfs_cmd_t *, int *, const int);
374void zfs_ioctl_compat_post(zfs_cmd_t *, const int, const int);
375nvlist_t *zfs_ioctl_compat_innvl(zfs_cmd_t *, nvlist_t *, const int,
376    const int);
377nvlist_t *zfs_ioctl_compat_outnvl(zfs_cmd_t *, nvlist_t *, const int,
378    const int);
379#else
380int zcmd_ioctl_compat(int, int, zfs_cmd_t *, const int);
381#endif	/* _KERNEL */
382void zfs_cmd_compat_get(zfs_cmd_t *, caddr_t, const int);
383void zfs_cmd_compat_put(zfs_cmd_t *, caddr_t, const int, const int);
384
385#ifdef	__cplusplus
386}
387#endif
388
389#endif	/* _SYS_ZFS_IOCTL_COMPAT_H */
390