2 * Copyright (c) 2020 iXsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
32 #include <sys/param.h>
34 #include <sys/eventhandler.h>
35 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/mutex.h>
39 #include <sys/errno.h>
41 #include <sys/cmn_err.h>
43 #include <sys/zfs_ioctl_compat.h>
46 ZFS_IOC_LEGACY_NONE
= -1,
47 ZFS_IOC_LEGACY_FIRST
= 0,
48 ZFS_LEGACY_IOC
= ZFS_IOC_LEGACY_FIRST
,
49 ZFS_IOC_LEGACY_POOL_CREATE
= ZFS_IOC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OC_LEGACY_OBJ_TO_PATH
,
88 ZFS_IOC_LEGACY_POOL_SET_PROPS
,
89 ZFS_IOC_LEGACY_POOL_GET_PROPS
,
90 ZFS_IOC_LEGACY_SET_FSACL
,
91 ZFS_IOC_LEGACY_GET_FSACL
,
93 ZFS_IOC_LEGACY_INHERIT_PROP
,
94 ZFS_IOC_LEGACY_SMB_ACL
,
95 ZFS_IOC_LEGACY_USERSPACE_ONE
,
96 ZFS_IOC_LEGACY_USERSPACE_MANY
,
97 ZFS_IOC_LEGACY_USERSPACE_UPGRADE
,
99 ZFS_IOC_LEGACY_RELEASE
,
100 ZFS_IOC_LEGACY_GET_HOLDS
,
101 ZFS_IOC_LEGACY_OBJSET_RECVD_PROPS
,
102 ZFS_IOC_LEGACY_VDEV_SPLIT
,
103 ZFS_IOC_LEGACY_NEXT_OBJ
,
105 ZFS_IOC_LEGACY_TMP_SNAPSHOT
,
106 ZFS_IOC_LEGACY_OBJ_TO_STATS
,
108 ZFS_IOC_LEGACY_UNJAIL
,
109 ZFS_IOC_LEGACY_POOL_REGUID
,
110 ZFS_IOC_LEGACY_SPACE_WRITTEN
,
111 ZFS_IOC_LEGACY_SPACE_SNAPS
,
112 ZFS_IOC_LEGACY_SEND_PROGRESS
,
113 ZFS_IOC_LEGACY_POOL_REOPEN
,
114 ZFS_IOC_LEGACY_LOG_HISTORY
,
115 ZFS_IOC_LEGACY_SEND_NEW
,
116 ZFS_IOC_LEGACY_SEND_SPACE
,
117 ZFS_IOC_LEGACY_CLONE
,
118 ZFS_IOC_LEGACY_BOOKMARK
,
119 ZFS_IOC_LEGACY_GET_BOOKMARKS
,
120 ZFS_IOC_LEGACY_DESTROY_BOOKMARKS
,
121 ZFS_IOC_LEGACY_NEXTBOOT
,
122 ZFS_IOC_LEGACY_CHANNEL_PROGRAM
,
123 ZFS_IOC_LEGACY_REMAP
,
124 ZFS_IOC_LEGACY_POOL_CHECKPOINT
,
125 ZFS_IOC_LEGACY_POOL_DISCARD_CHECKPOINT
,
126 ZFS_IOC_LEGACY_POOL_INITIALIZE
,
127 ZFS_IOC_LEGACY_POOL_SYNC
,
131 unsigned static long zfs_ioctl_legacy_to_ozfs_
[] = {
132 ZFS_IOC_POOL_CREATE
, /* 0x00 */
133 ZFS_IOC_POOL_DESTROY
, /* 0x01 */
134 ZFS_IOC_POOL_IMPORT
, /* 0x02 */
135 ZFS_IOC_POOL_EXPORT
, /* 0x03 */
136 ZFS_IOC_POOL_CONFIGS
, /* 0x04 */
137 ZFS_IOC_POOL_STATS
, /* 0x05 */
138 ZFS_IOC_POOL_TRYIMPORT
, /* 0x06 */
139 ZFS_IOC_POOL_SCAN
, /* 0x07 */
140 ZFS_IOC_POOL_FREEZE
, /* 0x08 */
141 ZFS_IOC_POOL_UPGRADE
, /* 0x09 */
142 ZFS_IOC_POOL_GET_HISTORY
, /* 0x0a */
143 ZFS_IOC_VDEV_ADD
, /* 0x0b */
144 ZFS_IOC_VDEV_REMOVE
, /* 0x0c */
145 ZFS_IOC_VDEV_SET_STATE
, /* 0x0d */
146 ZFS_IOC_VDEV_ATTACH
, /* 0x0e */
147 ZFS_IOC_VDEV_DETACH
, /* 0x0f */
148 ZFS_IOC_VDEV_SETPATH
, /* 0x10 */
149 ZFS_IOC_VDEV_SETFRU
, /* 0x11 */
150 ZFS_IOC_OBJSET_STATS
, /* 0x12 */
151 ZFS_IOC_OBJSET_ZPLPROPS
, /* 0x13 */
152 ZFS_IOC_DATASET_LIST_NEXT
, /* 0x14 */
153 ZFS_IOC_SNAPSHOT_LIST_NEXT
, /* 0x15 */
154 ZFS_IOC_SET_PROP
, /* 0x16 */
155 ZFS_IOC_CREATE
, /* 0x17 */
156 ZFS_IOC_DESTROY
, /* 0x18 */
157 ZFS_IOC_ROLLBACK
, /* 0x19 */
158 ZFS_IOC_RENAME
, /* 0x1a */
159 ZFS_IOC_RECV
, /* 0x1b */
160 ZFS_IOC_SEND
, /* 0x1c */
161 ZFS_IOC_INJECT_FAULT
, /* 0x1d */
162 ZFS_IOC_CLEAR_FAULT
, /* 0x1e */
163 ZFS_IOC_INJECT_LIST_NEXT
, /* 0x1f */
164 ZFS_IOC_ERROR_LOG
, /* 0x20 */
165 ZFS_IOC_CLEAR
, /* 0x21 */
166 ZFS_IOC_PROMOTE
, /* 0x22 */
167 /* start of mismatch */
169 ZFS_IOC_DESTROY_SNAPS
, /* 0x23:0x3b */
170 ZFS_IOC_SNAPSHOT
, /* 0x24:0x23 */
171 ZFS_IOC_DSOBJ_TO_DSNAME
, /* 0x25:0x24 */
172 ZFS_IOC_OBJ_TO_PATH
, /* 0x26:0x25 */
173 ZFS_IOC_POOL_SET_PROPS
, /* 0x27:0x26 */
174 ZFS_IOC_POOL_GET_PROPS
, /* 0x28:0x27 */
175 ZFS_IOC_SET_FSACL
, /* 0x29:0x28 */
176 ZFS_IOC_GET_FSACL
, /* 0x30:0x29 */
177 ZFS_IOC_SHARE
, /* 0x2b:0x2a */
178 ZFS_IOC_INHERIT_PROP
, /* 0x2c:0x2b */
179 ZFS_IOC_SMB_ACL
, /* 0x2d:0x2c */
180 ZFS_IOC_USERSPACE_ONE
, /* 0x2e:0x2d */
181 ZFS_IOC_USERSPACE_MANY
, /* 0x2f:0x2e */
182 ZFS_IOC_USERSPACE_UPGRADE
, /* 0x30:0x2f */
183 ZFS_IOC_HOLD
, /* 0x31:0x30 */
184 ZFS_IOC_RELEASE
, /* 0x32:0x31 */
185 ZFS_IOC_GET_HOLDS
, /* 0x33:0x32 */
186 ZFS_IOC_OBJSET_RECVD_PROPS
, /* 0x34:0x33 */
187 ZFS_IOC_VDEV_SPLIT
, /* 0x35:0x34 */
188 ZFS_IOC_NEXT_OBJ
, /* 0x36:0x35 */
189 ZFS_IOC_DIFF
, /* 0x37:0x36 */
190 ZFS_IOC_TMP_SNAPSHOT
, /* 0x38:0x37 */
191 ZFS_IOC_OBJ_TO_STATS
, /* 0x39:0x38 */
192 ZFS_IOC_JAIL
, /* 0x3a:0xc2 */
193 ZFS_IOC_UNJAIL
, /* 0x3b:0xc3 */
194 ZFS_IOC_POOL_REGUID
, /* 0x3c:0x3c */
195 ZFS_IOC_SPACE_WRITTEN
, /* 0x3d:0x39 */
196 ZFS_IOC_SPACE_SNAPS
, /* 0x3e:0x3a */
197 ZFS_IOC_SEND_PROGRESS
, /* 0x3f:0x3e */
198 ZFS_IOC_POOL_REOPEN
, /* 0x40:0x3d */
199 ZFS_IOC_LOG_HISTORY
, /* 0x41:0x3f */
200 ZFS_IOC_SEND_NEW
, /* 0x42:0x40 */
201 ZFS_IOC_SEND_SPACE
, /* 0x43:0x41 */
202 ZFS_IOC_CLONE
, /* 0x44:0x42 */
203 ZFS_IOC_BOOKMARK
, /* 0x45:0x43 */
204 ZFS_IOC_GET_BOOKMARKS
, /* 0x46:0x44 */
205 ZFS_IOC_DESTROY_BOOKMARKS
, /* 0x47:0x45 */
206 ZFS_IOC_NEXTBOOT
, /* 0x48:0xc1 */
207 ZFS_IOC_CHANNEL_PROGRAM
, /* 0x49:0x48 */
208 ZFS_IOC_REMAP
, /* 0x4a:0x4c */
209 ZFS_IOC_POOL_CHECKPOINT
, /* 0x4b:0x4d */
210 ZFS_IOC_POOL_DISCARD_CHECKPOINT
, /* 0x4c:0x4e */
211 ZFS_IOC_POOL_INITIALIZE
, /* 0x4d:0x4f */
214 unsigned static long zfs_ioctl_ozfs_to_legacy_common_
[] = {
215 ZFS_IOC_POOL_CREATE
, /* 0x00 */
216 ZFS_IOC_POOL_DESTROY
, /* 0x01 */
217 ZFS_IOC_POOL_IMPORT
, /* 0x02 */
218 ZFS_IOC_POOL_EXPORT
, /* 0x03 */
219 ZFS_IOC_POOL_CONFIGS
, /* 0x04 */
220 ZFS_IOC_POOL_STATS
, /* 0x05 */
221 ZFS_IOC_POOL_TRYIMPORT
, /* 0x06 */
222 ZFS_IOC_POOL_SCAN
, /* 0x07 */
223 ZFS_IOC_POOL_FREEZE
, /* 0x08 */
224 ZFS_IOC_POOL_UPGRADE
, /* 0x09 */
225 ZFS_IOC_POOL_GET_HISTORY
, /* 0x0a */
226 ZFS_IOC_VDEV_ADD
, /* 0x0b */
227 ZFS_IOC_VDEV_REMOVE
, /* 0x0c */
228 ZFS_IOC_VDEV_SET_STATE
, /* 0x0d */
229 ZFS_IOC_VDEV_ATTACH
, /* 0x0e */
230 ZFS_IOC_VDEV_DETACH
, /* 0x0f */
231 ZFS_IOC_VDEV_SETPATH
, /* 0x10 */
232 ZFS_IOC_VDEV_SETFRU
, /* 0x11 */
233 ZFS_IOC_OBJSET_STATS
, /* 0x12 */
234 ZFS_IOC_OBJSET_ZPLPROPS
, /* 0x13 */
235 ZFS_IOC_DATASET_LIST_NEXT
, /* 0x14 */
236 ZFS_IOC_SNAPSHOT_LIST_NEXT
, /* 0x15 */
237 ZFS_IOC_SET_PROP
, /* 0x16 */
238 ZFS_IOC_CREATE
, /* 0x17 */
239 ZFS_IOC_DESTROY
, /* 0x18 */
240 ZFS_IOC_ROLLBACK
, /* 0x19 */
241 ZFS_IOC_RENAME
, /* 0x1a */
242 ZFS_IOC_RECV
, /* 0x1b */
243 ZFS_IOC_SEND
, /* 0x1c */
244 ZFS_IOC_INJECT_FAULT
, /* 0x1d */
245 ZFS_IOC_CLEAR_FAULT
, /* 0x1e */
246 ZFS_IOC_INJECT_LIST_NEXT
, /* 0x1f */
247 ZFS_IOC_ERROR_LOG
, /* 0x20 */
248 ZFS_IOC_CLEAR
, /* 0x21 */
249 ZFS_IOC_PROMOTE
, /* 0x22 */
250 /* start of mismatch */
251 ZFS_IOC_LEGACY_SNAPSHOT
, /* 0x23 */
252 ZFS_IOC_LEGACY_DSOBJ_TO_DSNAME
, /* 0x24 */
253 ZFS_IOC_LEGACY_OBJ_TO_PATH
, /* 0x25 */
254 ZFS_IOC_LEGACY_POOL_SET_PROPS
, /* 0x26 */
255 ZFS_IOC_LEGACY_POOL_GET_PROPS
, /* 0x27 */
256 ZFS_IOC_LEGACY_SET_FSACL
, /* 0x28 */
257 ZFS_IOC_LEGACY_GET_FSACL
, /* 0x29 */
258 ZFS_IOC_LEGACY_SHARE
, /* 0x2a */
259 ZFS_IOC_LEGACY_INHERIT_PROP
, /* 0x2b */
260 ZFS_IOC_LEGACY_SMB_ACL
, /* 0x2c */
261 ZFS_IOC_LEGACY_USERSPACE_ONE
, /* 0x2d */
262 ZFS_IOC_LEGACY_USERSPACE_MANY
, /* 0x2e */
263 ZFS_IOC_LEGACY_USERSPACE_UPGRADE
, /* 0x2f */
264 ZFS_IOC_LEGACY_HOLD
, /* 0x30 */
265 ZFS_IOC_LEGACY_RELEASE
, /* 0x31 */
266 ZFS_IOC_LEGACY_GET_HOLDS
, /* 0x32 */
267 ZFS_IOC_LEGACY_OBJSET_RECVD_PROPS
, /* 0x33 */
268 ZFS_IOC_LEGACY_VDEV_SPLIT
, /* 0x34 */
269 ZFS_IOC_LEGACY_NEXT_OBJ
, /* 0x35 */
270 ZFS_IOC_LEGACY_DIFF
, /* 0x36 */
271 ZFS_IOC_LEGACY_TMP_SNAPSHOT
, /* 0x37 */
272 ZFS_IOC_LEGACY_OBJ_TO_STATS
, /* 0x38 */
273 ZFS_IOC_LEGACY_SPACE_WRITTEN
, /* 0x39 */
274 ZFS_IOC_LEGACY_SPACE_SNAPS
, /* 0x3a */
275 ZFS_IOC_LEGACY_DESTROY_SNAPS
, /* 0x3b */
276 ZFS_IOC_LEGACY_POOL_REGUID
, /* 0x3c */
277 ZFS_IOC_LEGACY_POOL_REOPEN
, /* 0x3d */
278 ZFS_IOC_LEGACY_SEND_PROGRESS
, /* 0x3e */
279 ZFS_IOC_LEGACY_LOG_HISTORY
, /* 0x3f */
280 ZFS_IOC_LEGACY_SEND_NEW
, /* 0x40 */
281 ZFS_IOC_LEGACY_SEND_SPACE
, /* 0x41 */
282 ZFS_IOC_LEGACY_CLONE
, /* 0x42 */
283 ZFS_IOC_LEGACY_BOOKMARK
, /* 0x43 */
284 ZFS_IOC_LEGACY_GET_BOOKMARKS
, /* 0x44 */
285 ZFS_IOC_LEGACY_DESTROY_BOOKMARKS
, /* 0x45 */
286 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_RECV_NEW */
287 ZFS_IOC_LEGACY_POOL_SYNC
, /* 0x47 */
288 ZFS_IOC_LEGACY_CHANNEL_PROGRAM
, /* 0x48 */
289 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_LOAD_KEY */
290 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_UNLOAD_KEY */
291 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_CHANGE_KEY */
292 ZFS_IOC_LEGACY_REMAP
, /* 0x4c */
293 ZFS_IOC_LEGACY_POOL_CHECKPOINT
, /* 0x4d */
294 ZFS_IOC_LEGACY_POOL_DISCARD_CHECKPOINT
, /* 0x4e */
295 ZFS_IOC_LEGACY_POOL_INITIALIZE
, /* 0x4f */
296 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_POOL_TRIM */
297 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_REDACT */
298 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_GET_BOOKMARK_PROPS */
299 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_WAIT */
300 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_WAIT_FS */
303 unsigned static long zfs_ioctl_ozfs_to_legacy_platform_
[] = {
304 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_EVENTS_NEXT */
305 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_EVENTS_CLEAR */
306 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_EVENTS_SEEK */
307 ZFS_IOC_LEGACY_NEXTBOOT
,
309 ZFS_IOC_LEGACY_UNJAIL
,
310 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_SET_BOOTENV */
311 ZFS_IOC_LEGACY_NONE
, /* ZFS_IOC_GET_BOOTENV */
315 zfs_ioctl_legacy_to_ozfs(int request
)
317 if (request
>= sizeof (zfs_ioctl_legacy_to_ozfs_
)/sizeof (long))
319 return (zfs_ioctl_legacy_to_ozfs_
[request
]);
323 zfs_ioctl_ozfs_to_legacy(int request
)
325 if (request
> ZFS_IOC_LAST
)
328 if (request
> ZFS_IOC_PLATFORM
)
329 return (zfs_ioctl_ozfs_to_legacy_platform_
[request
]);
330 if (request
>= sizeof (zfs_ioctl_ozfs_to_legacy_common_
)/sizeof (long))
332 return (zfs_ioctl_ozfs_to_legacy_common_
[request
]);
336 zfs_cmd_legacy_to_ozfs(zfs_cmd_legacy_t
*src
, zfs_cmd_t
*dst
)
338 memcpy(dst
, src
, offsetof(zfs_cmd_t
, zc_objset_stats
));
339 *&dst
->zc_objset_stats
= *&src
->zc_objset_stats
;
340 memcpy(&dst
->zc_begin_record
, &src
->zc_begin_record
,
341 offsetof(zfs_cmd_t
, zc_sendobj
) -
342 offsetof(zfs_cmd_t
, zc_begin_record
));
343 memcpy(&dst
->zc_sendobj
, &src
->zc_sendobj
,
344 sizeof (zfs_cmd_t
) - 8 - offsetof(zfs_cmd_t
, zc_sendobj
));
345 dst
->zc_zoneid
= src
->zc_jailid
;
349 zfs_cmd_ozfs_to_legacy(zfs_cmd_t
*src
, zfs_cmd_legacy_t
*dst
)
351 memcpy(dst
, src
, offsetof(zfs_cmd_t
, zc_objset_stats
));
352 *&dst
->zc_objset_stats
= *&src
->zc_objset_stats
;
353 *&dst
->zc_begin_record
.drr_u
.drr_begin
= *&src
->zc_begin_record
;
354 dst
->zc_begin_record
.drr_payloadlen
= 0;
355 dst
->zc_begin_record
.drr_type
= 0;
357 memcpy(&dst
->zc_inject_record
, &src
->zc_inject_record
,
358 offsetof(zfs_cmd_t
, zc_sendobj
) -
359 offsetof(zfs_cmd_t
, zc_inject_record
));
360 dst
->zc_resumable
= B_FALSE
;
361 memcpy(&dst
->zc_sendobj
, &src
->zc_sendobj
,
362 sizeof (zfs_cmd_t
) - 8 - offsetof(zfs_cmd_t
, zc_sendobj
));
363 dst
->zc_jailid
= src
->zc_zoneid
;