From 1f2f46be9576964c90ca25805c9741d56bbaccdf Mon Sep 17 00:00:00 2001 From: Matthew Macy Date: Tue, 12 Nov 2019 10:40:39 -0800 Subject: [PATCH] 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 Reviewed-by: Brian Behlendorf Signed-off-by: Matt Macy Closes #9511 --- include/libzutil.h | 3 +++ lib/libzfs_core/Makefile.am | 3 ++- lib/libzfs_core/libzfs_core.c | 11 +++++----- lib/libzpool/util.c | 2 +- lib/libzutil/Makefile.am | 3 ++- lib/libzutil/os/linux/zutil_compat.c | 30 ++++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 lib/libzutil/os/linux/zutil_compat.c diff --git a/include/libzutil.h b/include/libzutil.h index 93aac5f3c8..3dd4fcfb23 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -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 ***, uint_t *); +struct zfs_cmd; +int zfs_ioctl_fd(int fd, unsigned long request, struct zfs_cmd *zc); + #ifdef __cplusplus } #endif diff --git a/lib/libzfs_core/Makefile.am b/lib/libzfs_core/Makefile.am index bc3d309f82..dca81e01ab 100644 --- a/lib/libzfs_core/Makefile.am +++ b/lib/libzfs_core/Makefile.am @@ -9,7 +9,8 @@ nodist_libzfs_core_la_SOURCES = $(USER_C) libzfs_core_la_LIBADD = \ $(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 diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c index 7430a845a4..2f31edcc2a 100644 --- a/lib/libzfs_core/libzfs_core.c +++ b/lib/libzfs_core/libzfs_core.c @@ -84,6 +84,7 @@ #include #include #include +#include #include #include #include @@ -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 * increasing the size of the destination nvlist. @@ -297,7 +298,7 @@ lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen) VERIFY3S(g_fd, !=, -1); (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; if (error == EEXIST && snapnamebuf != NULL) (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen); @@ -315,7 +316,7 @@ lzc_rename(const char *source, const char *target) VERIFY3S(g_fd, !=, -1); (void) strlcpy(zc.zc_name, source, sizeof (zc.zc_name)); (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) error = errno; return (error); @@ -465,7 +466,7 @@ lzc_exists(const char *dataset) VERIFY3S(g_fd, !=, -1); (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) 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) { error = errno; } else { diff --git a/lib/libzpool/util.c b/lib/libzpool/util.c index 67bc209cee..df1084cb6d 100644 --- a/lib/libzpool/util.c +++ b/lib/libzpool/util.c @@ -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_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); free((void *)(uintptr_t)zcp->zc_nvlist_dst); diff --git a/lib/libzutil/Makefile.am b/lib/libzutil/Makefile.am index 8b53c374e1..e5c6a340d2 100644 --- a/lib/libzutil/Makefile.am +++ b/lib/libzutil/Makefile.am @@ -17,7 +17,8 @@ USER_C = \ if BUILD_LINUX USER_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 nodist_libzutil_la_SOURCES = $(USER_C) diff --git a/lib/libzutil/os/linux/zutil_compat.c b/lib/libzutil/os/linux/zutil_compat.c new file mode 100644 index 0000000000..173ae9cb61 --- /dev/null +++ b/lib/libzutil/os/linux/zutil_compat.c @@ -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 +#include +#include +#include + +int +zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) +{ + return (ioctl(fd, request, zc)); +}