Add wrapper stub for zfs_cmd ioctl to libzpool

FreeBSD needs a wrapper for handling zfs_cmd ioctls.
In libzfs this is handled by zfs_ioctl. However, here
we need to wrap the call directly.

Reviewed-by: Allan Jude <allanjude@freebsd.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Matt Macy <mmacy@FreeBSD.org>
Closes #9511
This commit is contained in:
Matthew Macy 2019-11-12 10:40:39 -08:00 committed by Brian Behlendorf
parent 066e825221
commit 1f2f46be95
6 changed files with 44 additions and 8 deletions

View File

@ -143,6 +143,9 @@ extern void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***, extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
uint_t *); uint_t *);
struct zfs_cmd;
int zfs_ioctl_fd(int fd, unsigned long request, struct zfs_cmd *zc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -9,7 +9,8 @@ nodist_libzfs_core_la_SOURCES = $(USER_C)
libzfs_core_la_LIBADD = \ libzfs_core_la_LIBADD = \
$(top_builddir)/lib/libnvpair/libnvpair.la \ $(top_builddir)/lib/libnvpair/libnvpair.la \
$(top_builddir)/lib/libuutil/libuutil.la $(top_builddir)/lib/libuutil/libuutil.la \
$(top_builddir)/lib/libzutil/libzutil.la
libzfs_core_la_LDFLAGS = -version-info 1:0:0 libzfs_core_la_LDFLAGS = -version-info 1:0:0

View File

@ -84,6 +84,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <libzutil.h>
#include <sys/nvpair.h> #include <sys/nvpair.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
@ -208,7 +209,7 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name,
} }
} }
while (ioctl(g_fd, ioc, &zc) != 0) { while (zfs_ioctl_fd(g_fd, ioc, &zc) != 0) {
/* /*
* If ioctl exited with ENOMEM, we retry the ioctl after * If ioctl exited with ENOMEM, we retry the ioctl after
* increasing the size of the destination nvlist. * increasing the size of the destination nvlist.
@ -297,7 +298,7 @@ lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen)
VERIFY3S(g_fd, !=, -1); VERIFY3S(g_fd, !=, -1);
(void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name)); (void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name));
if (ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) { if (zfs_ioctl_fd(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
int error = errno; int error = errno;
if (error == EEXIST && snapnamebuf != NULL) if (error == EEXIST && snapnamebuf != NULL)
(void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen); (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen);
@ -315,7 +316,7 @@ lzc_rename(const char *source, const char *target)
VERIFY3S(g_fd, !=, -1); VERIFY3S(g_fd, !=, -1);
(void) strlcpy(zc.zc_name, source, sizeof (zc.zc_name)); (void) strlcpy(zc.zc_name, source, sizeof (zc.zc_name));
(void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value)); (void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value));
error = ioctl(g_fd, ZFS_IOC_RENAME, &zc); error = zfs_ioctl_fd(g_fd, ZFS_IOC_RENAME, &zc);
if (error != 0) if (error != 0)
error = errno; error = errno;
return (error); return (error);
@ -465,7 +466,7 @@ lzc_exists(const char *dataset)
VERIFY3S(g_fd, !=, -1); VERIFY3S(g_fd, !=, -1);
(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0); return (zfs_ioctl_fd(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0);
} }
/* /*
@ -937,7 +938,7 @@ recv_impl(const char *snapname, nvlist_t *recvdprops, nvlist_t *localprops,
zc.zc_nvlist_dst = (uint64_t)(uintptr_t) zc.zc_nvlist_dst = (uint64_t)(uintptr_t)
malloc(zc.zc_nvlist_dst_size); malloc(zc.zc_nvlist_dst_size);
error = ioctl(g_fd, ZFS_IOC_RECV, &zc); error = zfs_ioctl_fd(g_fd, ZFS_IOC_RECV, &zc);
if (error != 0) { if (error != 0) {
error = errno; error = errno;
} else { } else {

View File

@ -237,7 +237,7 @@ pool_active(void *unused, const char *name, uint64_t guid,
zcp->zc_nvlist_src = (uint64_t)(uintptr_t)packed; zcp->zc_nvlist_src = (uint64_t)(uintptr_t)packed;
zcp->zc_nvlist_src_size = size; zcp->zc_nvlist_src_size = size;
ret = ioctl(fd, ZFS_IOC_POOL_SYNC, zcp); ret = zfs_ioctl_fd(fd, ZFS_IOC_POOL_SYNC, zcp);
fnvlist_pack_free(packed, size); fnvlist_pack_free(packed, size);
free((void *)(uintptr_t)zcp->zc_nvlist_dst); free((void *)(uintptr_t)zcp->zc_nvlist_dst);

View File

@ -17,7 +17,8 @@ USER_C = \
if BUILD_LINUX if BUILD_LINUX
USER_C += \ USER_C += \
os/linux/zutil_device_path_os.c \ os/linux/zutil_device_path_os.c \
os/linux/zutil_import_os.c os/linux/zutil_import_os.c \
os/linux/zutil_compat.c
endif endif
nodist_libzutil_la_SOURCES = $(USER_C) nodist_libzutil_la_SOURCES = $(USER_C)

View File

@ -0,0 +1,30 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/zfs_ioctl.h>
#include <libzutil.h>
int
zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc)
{
return (ioctl(fd, request, zc));
}