diff --git a/include/libzfs_core.h b/include/libzfs_core.h index 83d8211ab6..9020d70db3 100644 --- a/include/libzfs_core.h +++ b/include/libzfs_core.h @@ -41,6 +41,9 @@ extern "C" { _LIBZFS_CORE_H int libzfs_core_init(void); _LIBZFS_CORE_H void libzfs_core_fini(void); +struct zfs_cmd; +_LIBZFS_CORE_H int lzc_ioctl_fd(int, unsigned long, struct zfs_cmd *); + /* * NB: this type should be kept binary-compatible with dmu_objset_type_t. */ diff --git a/include/libzutil.h b/include/libzutil.h index 2329458760..c0a660ea70 100644 --- a/include/libzutil.h +++ b/include/libzutil.h @@ -146,7 +146,6 @@ _LIBZUTIL_H int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***, uint_t *); struct zfs_cmd; -_LIBZUTIL_H int zfs_ioctl_fd(int fd, unsigned long request, struct zfs_cmd *zc); /* * List of colors to use diff --git a/include/os/freebsd/zfs/sys/zfs_ioctl_compat.h b/include/os/freebsd/zfs/sys/zfs_ioctl_compat.h index 91bc48effe..d36a6d2ce7 100644 --- a/include/os/freebsd/zfs/sys/zfs_ioctl_compat.h +++ b/include/os/freebsd/zfs/sys/zfs_ioctl_compat.h @@ -148,7 +148,6 @@ nvlist_t *zfs_ioctl_compat_outnvl(zfs_cmd_t *, nvlist_t *, const int, int zfs_ioctl_legacy_to_ozfs(int request); int zfs_ioctl_ozfs_to_legacy(int request); void zfs_cmd_legacy_to_ozfs(zfs_cmd_legacy_t *src, zfs_cmd_t *dst); -void zfs_cmd_compat_get(zfs_cmd_t *, caddr_t, const int); void zfs_cmd_ozfs_to_legacy(zfs_cmd_t *src, zfs_cmd_legacy_t *dst); void zfs_cmd_compat_put(zfs_cmd_t *, caddr_t, const int, const int); diff --git a/lib/Makefile.am b/lib/Makefile.am index db7a3fa31d..f07975cc03 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,5 +1,44 @@ +# +# Shown below is a simplified dependency graph of the OpenZFS provided +# libraries. Administrative commands (`zfs`, `zpool`, etc) interface with +# the kernel modules using the `libzfs.so` and `libzfs_core.so` libraries. +# These libraries provide a stable ABI across OpenZFS point releases. +# +# The `libzpool.so` library is a user space build of the DMU and SPA layers +# used to implement debugging tools (zdb) and code validation tools (ztest). +# These library interfaces are subject to change at any time. +# +# +# CMDS: zhack/ztest/zdb/ zfs/zpool/zed/ +# raidz_{test,bench} zinject/zstream +# | | +# LIBS: | | libzfsbootenv* +# | | | +# | | | +# libzpool libzfs* ----------------+ +# | | | \ / | | | +# libicp --/ | | \ / | | \------- libshare +# | | \ / | | +# libzstd ---/ | \ / | \--------- libuutil +# | \ / \ | | +# libunicode --/ \ / \ | | +# \ / \ | | +# libzutil libzfs_core* | | +# | | | | \ | | | | +# | | | | | | | | | +# | | | | | | | | | +# libtpool -------------/ | | | \---- libnvpair* | | | +# | | | | | | +# libefi -----------------/ | \------ libavl* --------/ | +# | | | +# \-------- libspl ----+------/ +# +# * - A stable ABI is provided for these libraries +# +# # NB: GNU Automake Manual, Chapter 8.3.5: Libtool Convenience Libraries # These nine libraries are intermediary build components. +# SUBDIRS = libavl libicp libshare libspl libtpool libzstd CPPCHECKDIRS = libavl libicp libnvpair libshare libspl libtpool libunicode CPPCHECKDIRS += libuutil libzfs libzfs_core libzfsbootenv libzpool libzutil diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am index e3527ffe70..e23f7c162a 100644 --- a/lib/libzfs/Makefile.am +++ b/lib/libzfs/Makefile.am @@ -35,7 +35,6 @@ USER_C = \ if BUILD_FREEBSD USER_C += \ os/freebsd/libzfs_compat.c \ - os/freebsd/libzfs_ioctl_compat.c \ os/freebsd/libzfs_zmount.c endif @@ -75,6 +74,7 @@ libzfs_la_LIBADD = \ $(abs_top_builddir)/lib/libshare/libshare.la \ $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la \ + $(abs_top_builddir)/lib/libzutil/libzutil.la \ $(abs_top_builddir)/lib/libuutil/libuutil.la libzfs_la_LIBADD += -lm $(LIBCRYPTO_LIBS) $(ZLIB_LIBS) $(LIBFETCH_LIBS) $(LTLIBINTL) diff --git a/lib/libzfs/libzfs.abi b/lib/libzfs/libzfs.abi index c5b0975258..86d612f5e3 100644 --- a/lib/libzfs/libzfs.abi +++ b/lib/libzfs/libzfs.abi @@ -2,22 +2,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -33,8 +185,15 @@ + + + + + + + @@ -54,9 +213,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + @@ -65,6 +248,19 @@ + + + + + + + + + + + + + @@ -72,6 +268,8 @@ + + @@ -98,10 +296,17 @@ + + + + + + + @@ -110,6 +315,7 @@ + @@ -120,6 +326,7 @@ + @@ -135,7 +342,12 @@ + + + + + @@ -181,6 +393,7 @@ + @@ -205,6 +418,9 @@ + + + @@ -229,11 +445,13 @@ + + @@ -243,6 +461,7 @@ + @@ -260,6 +479,7 @@ + @@ -269,6 +489,7 @@ + @@ -296,10 +517,12 @@ + + @@ -342,6 +565,7 @@ + @@ -350,6 +574,7 @@ + @@ -358,6 +583,307 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -391,16 +917,7 @@ - - - - - - - - - @@ -430,7 +947,1019 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -614,8 +2143,6 @@ - - @@ -634,9 +2161,6 @@ - - - @@ -718,7 +2242,6 @@ - @@ -913,7 +2436,6 @@ - @@ -4178,4 +5700,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/libzfs/os/freebsd/libzfs_compat.c b/lib/libzfs/os/freebsd/libzfs_compat.c index 2c9d52bb0f..f143f9cb63 100644 --- a/lib/libzfs/os/freebsd/libzfs_compat.c +++ b/lib/libzfs/os/freebsd/libzfs_compat.c @@ -22,7 +22,6 @@ /* * Copyright (c) 2013 Martin Matuska . All rights reserved. */ -#include #include "../../libzfs_impl.h" #include #include @@ -224,7 +223,7 @@ libzfs_error_init(int error) int zfs_ioctl(libzfs_handle_t *hdl, int request, zfs_cmd_t *zc) { - return (zfs_ioctl_fd(hdl->libzfs_fd, request, zc)); + return (lzc_ioctl_fd(hdl->libzfs_fd, request, zc)); } /* diff --git a/lib/libzfs/os/freebsd/libzfs_ioctl_compat.c b/lib/libzfs/os/freebsd/libzfs_ioctl_compat.c deleted file mode 100644 index 18b93fe279..0000000000 --- a/lib/libzfs/os/freebsd/libzfs_ioctl_compat.c +++ /dev/null @@ -1,432 +0,0 @@ -/* - * 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 - */ -/* - * Copyright 2013 Xin Li . All rights reserved. - * Copyright 2013 Martin Matuska . All rights reserved. - * Portions Copyright 2005, 2010, Oracle and/or its affiliates. - * All rights reserved. - * Use is subject to license terms. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "zfs_namecheck.h" -#include - -/* - * FreeBSD zfs_cmd compatibility with older binaries - * appropriately remap/extend the zfs_cmd_t structure - */ -void -zfs_cmd_compat_get(zfs_cmd_t *zc, caddr_t addr, const int cflag) -{ - -} -#if 0 -static int -zfs_ioctl_compat_get_nvlist(uint64_t nvl, size_t size, int iflag, - nvlist_t **nvp) -{ - char *packed; - int error; - nvlist_t *list = NULL; - - /* - * Read in and unpack the user-supplied nvlist. - */ - if (size == 0) - return (EINVAL); - -#ifdef _KERNEL - packed = kmem_alloc(size, KM_SLEEP); - if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size, - iflag)) != 0) { - kmem_free(packed, size); - return (error); - } -#else - packed = (void *)(uintptr_t)nvl; -#endif - - error = nvlist_unpack(packed, size, &list, 0); - -#ifdef _KERNEL - kmem_free(packed, size); -#endif - - if (error != 0) - return (error); - - *nvp = list; - return (0); -} - -static int -zfs_ioctl_compat_put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl) -{ - char *packed = NULL; - int error = 0; - size_t size; - - VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0); - -#ifdef _KERNEL - packed = kmem_alloc(size, KM_SLEEP); - VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE, - KM_SLEEP) == 0); - - if (ddi_copyout(packed, - (void *)(uintptr_t)zc->zc_nvlist_dst, size, zc->zc_iflags) != 0) - error = EFAULT; - kmem_free(packed, size); -#else - packed = (void *)(uintptr_t)zc->zc_nvlist_dst; - VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE, - 0) == 0); -#endif - - zc->zc_nvlist_dst_size = size; - return (error); -} - -static void -zfs_ioctl_compat_fix_stats_nvlist(nvlist_t *nvl) -{ - nvlist_t **child; - nvlist_t *nvroot = NULL; - vdev_stat_t *vs; - uint_t c, children, nelem; - - if (nvlist_lookup_nvlist_array(nvl, ZPOOL_CONFIG_CHILDREN, - &child, &children) == 0) { - for (c = 0; c < children; c++) { - zfs_ioctl_compat_fix_stats_nvlist(child[c]); - } - } - - if (nvlist_lookup_nvlist(nvl, ZPOOL_CONFIG_VDEV_TREE, - &nvroot) == 0) - zfs_ioctl_compat_fix_stats_nvlist(nvroot); - if ((nvlist_lookup_uint64_array(nvl, "stats", - (uint64_t **)&vs, &nelem) == 0)) { - nvlist_add_uint64_array(nvl, - ZPOOL_CONFIG_VDEV_STATS, - (uint64_t *)vs, nelem); - nvlist_remove(nvl, "stats", - DATA_TYPE_UINT64_ARRAY); - } -} - - -static int -zfs_ioctl_compat_fix_stats(zfs_cmd_t *zc, const int nc) -{ - nvlist_t *nv, *nvp = NULL; - nvpair_t *elem; - int error; - - if ((error = zfs_ioctl_compat_get_nvlist(zc->zc_nvlist_dst, - zc->zc_nvlist_dst_size, zc->zc_iflags, &nv)) != 0) - return (error); - - if (nc == 5) { /* ZFS_IOC_POOL_STATS */ - elem = NULL; - while ((elem = nvlist_next_nvpair(nv, elem)) != NULL) { - if (nvpair_value_nvlist(elem, &nvp) == 0) - zfs_ioctl_compat_fix_stats_nvlist(nvp); - } - elem = NULL; - } else - zfs_ioctl_compat_fix_stats_nvlist(nv); - - error = zfs_ioctl_compat_put_nvlist(zc, nv); - - nvlist_free(nv); - - return (error); -} - -static int -zfs_ioctl_compat_pool_get_props(zfs_cmd_t *zc) -{ - nvlist_t *nv, *nva = NULL; - int error; - - if ((error = zfs_ioctl_compat_get_nvlist(zc->zc_nvlist_dst, - zc->zc_nvlist_dst_size, zc->zc_iflags, &nv)) != 0) - return (error); - - if (nvlist_lookup_nvlist(nv, "used", &nva) == 0) { - nvlist_add_nvlist(nv, "allocated", nva); - nvlist_remove(nv, "used", DATA_TYPE_NVLIST); - } - - if (nvlist_lookup_nvlist(nv, "available", &nva) == 0) { - nvlist_add_nvlist(nv, "free", nva); - nvlist_remove(nv, "available", DATA_TYPE_NVLIST); - } - - error = zfs_ioctl_compat_put_nvlist(zc, nv); - - nvlist_free(nv); - - return (error); -} -#endif - -#ifdef _KERNEL -int -zfs_ioctl_compat_pre(zfs_cmd_t *zc, int *vec, const int cflag) -{ - int error = 0; - - /* are we creating a clone? */ - if (*vec == ZFS_IOC_CREATE && zc->zc_value[0] != '\0') - *vec = ZFS_IOC_CLONE; - - if (cflag == ZFS_CMD_COMPAT_V15) { - switch (*vec) { - - case 7: /* ZFS_IOC_POOL_SCRUB (v15) */ - zc->zc_cookie = POOL_SCAN_SCRUB; - break; - } - } - - return (error); -} - -void -zfs_ioctl_compat_post(zfs_cmd_t *zc, int vec, const int cflag) -{ - if (cflag == ZFS_CMD_COMPAT_V15) { - switch (vec) { - case ZFS_IOC_POOL_CONFIGS: - case ZFS_IOC_POOL_STATS: - case ZFS_IOC_POOL_TRYIMPORT: - zfs_ioctl_compat_fix_stats(zc, vec); - break; - case 41: /* ZFS_IOC_POOL_GET_PROPS (v15) */ - zfs_ioctl_compat_pool_get_props(zc); - break; - } - } -} - -nvlist_t * -zfs_ioctl_compat_innvl(zfs_cmd_t *zc, nvlist_t *innvl, const int vec, - const int cflag) -{ - nvlist_t *nvl, *tmpnvl, *hnvl; - nvpair_t *elem; - char *poolname, *snapname; - int err; - - if (cflag == ZFS_CMD_COMPAT_NONE || cflag == ZFS_CMD_COMPAT_LZC || - cflag == ZFS_CMD_COMPAT_ZCMD || cflag == ZFS_CMD_COMPAT_EDBP || - cflag == ZFS_CMD_COMPAT_RESUME || cflag == ZFS_CMD_COMPAT_INLANES) - goto out; - - switch (vec) { - case ZFS_IOC_CREATE: - nvl = fnvlist_alloc(); - fnvlist_add_int32(nvl, "type", zc->zc_objset_type); - if (innvl != NULL) { - fnvlist_add_nvlist(nvl, "props", innvl); - nvlist_free(innvl); - } - return (nvl); - break; - case ZFS_IOC_CLONE: - nvl = fnvlist_alloc(); - fnvlist_add_string(nvl, "origin", zc->zc_value); - if (innvl != NULL) { - fnvlist_add_nvlist(nvl, "props", innvl); - nvlist_free(innvl); - } - return (nvl); - break; - case ZFS_IOC_SNAPSHOT: - if (innvl == NULL) - goto out; - nvl = fnvlist_alloc(); - fnvlist_add_nvlist(nvl, "props", innvl); - tmpnvl = fnvlist_alloc(); - snapname = kmem_asprintf("%s@%s", zc->zc_name, zc->zc_value); - fnvlist_add_boolean(tmpnvl, snapname); - kmem_free(snapname, strlen(snapname + 1)); - /* check if we are doing a recursive snapshot */ - if (zc->zc_cookie) - dmu_get_recursive_snaps_nvl(zc->zc_name, zc->zc_value, - tmpnvl); - fnvlist_add_nvlist(nvl, "snaps", tmpnvl); - fnvlist_free(tmpnvl); - nvlist_free(innvl); - /* strip dataset part from zc->zc_name */ - zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0'; - return (nvl); - break; - case ZFS_IOC_SPACE_SNAPS: - nvl = fnvlist_alloc(); - fnvlist_add_string(nvl, "firstsnap", zc->zc_value); - if (innvl != NULL) - nvlist_free(innvl); - return (nvl); - break; - case ZFS_IOC_DESTROY_SNAPS: - if (innvl == NULL && cflag == ZFS_CMD_COMPAT_DEADMAN) - goto out; - nvl = fnvlist_alloc(); - if (innvl != NULL) { - fnvlist_add_nvlist(nvl, "snaps", innvl); - } else { - /* - * We are probably called by even older binaries, - * allocate and populate nvlist with recursive - * snapshots - */ - if (zfs_component_namecheck(zc->zc_value, NULL, - NULL) == 0) { - tmpnvl = fnvlist_alloc(); - if (dmu_get_recursive_snaps_nvl(zc->zc_name, - zc->zc_value, tmpnvl) == 0) - fnvlist_add_nvlist(nvl, "snaps", - tmpnvl); - nvlist_free(tmpnvl); - } - } - if (innvl != NULL) - nvlist_free(innvl); - /* strip dataset part from zc->zc_name */ - zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0'; - return (nvl); - break; - case ZFS_IOC_HOLD: - nvl = fnvlist_alloc(); - tmpnvl = fnvlist_alloc(); - if (zc->zc_cleanup_fd != -1) - fnvlist_add_int32(nvl, "cleanup_fd", - (int32_t)zc->zc_cleanup_fd); - if (zc->zc_cookie) { - hnvl = fnvlist_alloc(); - if (dmu_get_recursive_snaps_nvl(zc->zc_name, - zc->zc_value, hnvl) == 0) { - elem = NULL; - while ((elem = nvlist_next_nvpair(hnvl, - elem)) != NULL) { - nvlist_add_string(tmpnvl, - nvpair_name(elem), zc->zc_string); - } - } - nvlist_free(hnvl); - } else { - snapname = kmem_asprintf("%s@%s", zc->zc_name, - zc->zc_value); - nvlist_add_string(tmpnvl, snapname, zc->zc_string); - kmem_free(snapname, strlen(snapname + 1)); - } - fnvlist_add_nvlist(nvl, "holds", tmpnvl); - nvlist_free(tmpnvl); - if (innvl != NULL) - nvlist_free(innvl); - /* strip dataset part from zc->zc_name */ - zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0'; - return (nvl); - break; - case ZFS_IOC_RELEASE: - nvl = fnvlist_alloc(); - tmpnvl = fnvlist_alloc(); - if (zc->zc_cookie) { - hnvl = fnvlist_alloc(); - if (dmu_get_recursive_snaps_nvl(zc->zc_name, - zc->zc_value, hnvl) == 0) { - elem = NULL; - while ((elem = nvlist_next_nvpair(hnvl, - elem)) != NULL) { - fnvlist_add_boolean(tmpnvl, - zc->zc_string); - fnvlist_add_nvlist(nvl, - nvpair_name(elem), tmpnvl); - } - } - nvlist_free(hnvl); - } else { - snapname = kmem_asprintf("%s@%s", zc->zc_name, - zc->zc_value); - fnvlist_add_boolean(tmpnvl, zc->zc_string); - fnvlist_add_nvlist(nvl, snapname, tmpnvl); - kmem_free(snapname, strlen(snapname + 1)); - } - nvlist_free(tmpnvl); - if (innvl != NULL) - nvlist_free(innvl); - /* strip dataset part from zc->zc_name */ - zc->zc_name[strcspn(zc->zc_name, "/@")] = '\0'; - return (nvl); - break; - } -out: - return (innvl); -} - -nvlist_t * -zfs_ioctl_compat_outnvl(zfs_cmd_t *zc, nvlist_t *outnvl, const int vec, - const int cflag) -{ - nvlist_t *tmpnvl; - - if (cflag == ZFS_CMD_COMPAT_NONE || cflag == ZFS_CMD_COMPAT_LZC || - cflag == ZFS_CMD_COMPAT_ZCMD || cflag == ZFS_CMD_COMPAT_EDBP || - cflag == ZFS_CMD_COMPAT_RESUME || cflag == ZFS_CMD_COMPAT_INLANES) - return (outnvl); - - switch (vec) { - case ZFS_IOC_SPACE_SNAPS: - (void) nvlist_lookup_uint64(outnvl, "used", &zc->zc_cookie); - (void) nvlist_lookup_uint64(outnvl, "compressed", - &zc->zc_objset_type); - (void) nvlist_lookup_uint64(outnvl, "uncompressed", - &zc->zc_perm_action); - nvlist_free(outnvl); - /* return empty outnvl */ - tmpnvl = fnvlist_alloc(); - return (tmpnvl); - break; - case ZFS_IOC_CREATE: - case ZFS_IOC_CLONE: - case ZFS_IOC_HOLD: - case ZFS_IOC_RELEASE: - nvlist_free(outnvl); - /* return empty outnvl */ - tmpnvl = fnvlist_alloc(); - return (tmpnvl); - break; - } - - return (outnvl); -} -#endif /* KERNEL */ diff --git a/lib/libzfs_core/Makefile.am b/lib/libzfs_core/Makefile.am index b2101e2114..64cb76f199 100644 --- a/lib/libzfs_core/Makefile.am +++ b/lib/libzfs_core/Makefile.am @@ -11,11 +11,27 @@ include $(top_srcdir)/config/Abigail.am USER_C = \ libzfs_core.c +if BUILD_LINUX +USER_C += \ + os/linux/libzfs_core_ioctl.c +endif + +if BUILD_FREEBSD +DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/freebsd/zfs + +USER_C += \ + os/freebsd/libzfs_core_ioctl.c + +VPATH += $(top_srcdir)/module/os/freebsd/zfs + +nodist_libzfs_core_la_SOURCES = zfs_ioctl_compat.c +endif + libzfs_core_la_SOURCES = $(USER_C) libzfs_core_la_LIBADD = \ - $(abs_top_builddir)/lib/libzutil/libzutil.la \ - $(abs_top_builddir)/lib/libnvpair/libnvpair.la + $(abs_top_builddir)/lib/libnvpair/libnvpair.la \ + $(abs_top_builddir)/lib/libspl/libspl.la libzfs_core_la_LIBADD += $(LTLIBINTL) diff --git a/lib/libzfs_core/libzfs_core.abi b/lib/libzfs_core/libzfs_core.abi index 6abec9a8ab..b3ae682efc 100644 --- a/lib/libzfs_core/libzfs_core.abi +++ b/lib/libzfs_core/libzfs_core.abi @@ -1,11 +1,5 @@ - - - - - - @@ -135,38 +129,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -204,6 +171,7 @@ + @@ -243,355 +211,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -604,17 +227,26 @@ + + + + + + + + + @@ -943,12 +575,16 @@ - - - + + + + - + + + + @@ -968,6 +604,7 @@ + @@ -1068,12 +705,12 @@ + - @@ -1160,7 +797,6 @@ - @@ -1352,265 +988,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2542,7 +1919,7 @@ - + @@ -2772,290 +2149,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/lib/libzfs_core/libzfs_core.c b/lib/libzfs_core/libzfs_core.c index ce33b21530..cbe486d08b 100644 --- a/lib/libzfs_core/libzfs_core.c +++ b/lib/libzfs_core/libzfs_core.c @@ -209,7 +209,7 @@ lzc_ioctl(zfs_ioc_t ioc, const char *name, } } - while (zfs_ioctl_fd(g_fd, ioc, &zc) != 0) { + while (lzc_ioctl_fd(g_fd, ioc, &zc) != 0) { /* * If ioctl exited with ENOMEM, we retry the ioctl after * increasing the size of the destination nvlist. @@ -298,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 (zfs_ioctl_fd(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) { + if (lzc_ioctl_fd(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) { int error = errno; if (error == EEXIST && snapnamebuf != NULL) (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen); @@ -317,7 +317,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 = zfs_ioctl_fd(g_fd, ZFS_IOC_RENAME, &zc); + error = lzc_ioctl_fd(g_fd, ZFS_IOC_RENAME, &zc); if (error != 0) error = errno; return (error); @@ -468,7 +468,7 @@ lzc_exists(const char *dataset) VERIFY3S(g_fd, !=, -1); (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); - return (zfs_ioctl_fd(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0); + return (lzc_ioctl_fd(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0); } /* @@ -925,7 +925,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 = zfs_ioctl_fd(g_fd, ZFS_IOC_RECV, &zc); + error = lzc_ioctl_fd(g_fd, ZFS_IOC_RECV, &zc); if (error != 0) { error = errno; } else { diff --git a/lib/libzutil/os/freebsd/zutil_compat.c b/lib/libzfs_core/os/freebsd/libzfs_core_ioctl.c similarity index 97% rename from lib/libzutil/os/freebsd/zutil_compat.c rename to lib/libzfs_core/os/freebsd/libzfs_core_ioctl.c index baaf4b598a..b8394886d0 100644 --- a/lib/libzutil/os/freebsd/zutil_compat.c +++ b/lib/libzfs_core/os/freebsd/libzfs_core_ioctl.c @@ -23,9 +23,8 @@ #include #include #include -#include - #include +#include int zfs_ioctl_version = ZFS_IOCVER_UNDEF; @@ -92,7 +91,7 @@ zcmd_ioctl_compat(int fd, int request, zfs_cmd_t *zc, const int cflag) * error is returned zc_nvlist_dst_size won't be updated. */ int -zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) +lzc_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) { size_t oldsize; int ret, cflag = ZFS_CMD_COMPAT_NONE; diff --git a/lib/libzutil/os/linux/zutil_compat.c b/lib/libzfs_core/os/linux/libzfs_core_ioctl.c similarity index 91% rename from lib/libzutil/os/linux/zutil_compat.c rename to lib/libzfs_core/os/linux/libzfs_core_ioctl.c index 173ae9cb61..9b44a4e3be 100644 --- a/lib/libzutil/os/linux/zutil_compat.c +++ b/lib/libzfs_core/os/linux/libzfs_core_ioctl.c @@ -21,10 +21,10 @@ #include #include #include -#include +#include int -zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) +lzc_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) { return (ioctl(fd, request, zc)); } diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index c9a55591e5..3cc0c2f2ec 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -214,9 +214,9 @@ nodist_libzpool_la_SOURCES = \ libzpool_la_LIBADD = \ $(abs_top_builddir)/lib/libicp/libicp.la \ $(abs_top_builddir)/lib/libunicode/libunicode.la \ - $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la \ $(abs_top_builddir)/lib/libnvpair/libnvpair.la \ - $(abs_top_builddir)/lib/libzstd/libzstd.la + $(abs_top_builddir)/lib/libzstd/libzstd.la \ + $(abs_top_builddir)/lib/libzutil/libzutil.la libzpool_la_LIBADD += $(LIBCLOCK_GETTIME) $(ZLIB_LIBS) -ldl -lm diff --git a/lib/libzpool/util.c b/lib/libzpool/util.c index 20cabe7c2e..a2bdfec1d1 100644 --- a/lib/libzpool/util.c +++ b/lib/libzpool/util.c @@ -245,39 +245,96 @@ refresh_config(void *unused, nvlist_t *tryconfig) return (spa_tryimport(tryconfig)); } +#if defined(__FreeBSD__) + +#include +#include +#include + +static int +pool_active(void *unused, const char *name, uint64_t guid, boolean_t *isactive) +{ + zfs_iocparm_t zp; + zfs_cmd_t *zc = NULL; + zfs_cmd_legacy_t *zcl = NULL; + unsigned long request; + int ret; + + int fd = open(ZFS_DEV, O_RDWR | O_CLOEXEC); + if (fd < 0) + return (-1); + + /* + * Use ZFS_IOC_POOL_STATS to check if the pool is active. We want to + * avoid adding a dependency on libzfs_core solely for this ioctl(), + * therefore we manually craft the stats command. Note that the command + * ID is identical between the openzfs and legacy ioctl() formats. + */ + int ver = ZFS_IOCVER_NONE; + size_t ver_size = sizeof (ver); + + sysctlbyname("vfs.zfs.version.ioctl", &ver, &ver_size, NULL, 0); + + switch (ver) { + case ZFS_IOCVER_OZFS: + zc = umem_zalloc(sizeof (zfs_cmd_t), UMEM_NOFAIL); + + (void) strlcpy(zc->zc_name, name, sizeof (zc->zc_name)); + zp.zfs_cmd = (uint64_t)(uintptr_t)zc; + zp.zfs_cmd_size = sizeof (zfs_cmd_t); + zp.zfs_ioctl_version = ZFS_IOCVER_OZFS; + + request = _IOWR('Z', ZFS_IOC_POOL_STATS, zfs_iocparm_t); + ret = ioctl(fd, request, &zp); + + free((void *)(uintptr_t)zc->zc_nvlist_dst); + umem_free(zc, sizeof (zfs_cmd_t)); + + break; + case ZFS_IOCVER_LEGACY: + zcl = umem_zalloc(sizeof (zfs_cmd_legacy_t), UMEM_NOFAIL); + + (void) strlcpy(zcl->zc_name, name, sizeof (zcl->zc_name)); + zp.zfs_cmd = (uint64_t)(uintptr_t)zcl; + zp.zfs_cmd_size = sizeof (zfs_cmd_legacy_t); + zp.zfs_ioctl_version = ZFS_IOCVER_LEGACY; + + request = _IOWR('Z', ZFS_IOC_POOL_STATS, zfs_iocparm_t); + ret = ioctl(fd, request, &zp); + + free((void *)(uintptr_t)zcl->zc_nvlist_dst); + umem_free(zcl, sizeof (zfs_cmd_legacy_t)); + + break; + default: + fprintf(stderr, "unrecognized zfs ioctl version %d", ver); + exit(1); + } + + (void) close(fd); + + *isactive = (ret == 0); + + return (0); +} +#else static int pool_active(void *unused, const char *name, uint64_t guid, boolean_t *isactive) { - zfs_cmd_t *zcp; - nvlist_t *innvl; - char *packed = NULL; - size_t size = 0; - int fd, ret; - - /* - * Use ZFS_IOC_POOL_SYNC to confirm if a pool is active - */ - - fd = open(ZFS_DEV, O_RDWR | O_CLOEXEC); + int fd = open(ZFS_DEV, O_RDWR | O_CLOEXEC); if (fd < 0) return (-1); - zcp = umem_zalloc(sizeof (zfs_cmd_t), UMEM_NOFAIL); - - innvl = fnvlist_alloc(); - fnvlist_add_boolean_value(innvl, "force", B_FALSE); - + /* + * Use ZFS_IOC_POOL_STATS to check if a pool is active. + */ + zfs_cmd_t *zcp = umem_zalloc(sizeof (zfs_cmd_t), UMEM_NOFAIL); (void) strlcpy(zcp->zc_name, name, sizeof (zcp->zc_name)); - packed = fnvlist_pack(innvl, &size); - zcp->zc_nvlist_src = (uint64_t)(uintptr_t)packed; - zcp->zc_nvlist_src_size = size; - ret = zfs_ioctl_fd(fd, ZFS_IOC_POOL_SYNC, zcp); + int ret = ioctl(fd, ZFS_IOC_POOL_STATS, zcp); - fnvlist_pack_free(packed, size); free((void *)(uintptr_t)zcp->zc_nvlist_dst); - nvlist_free(innvl); umem_free(zcp, sizeof (zfs_cmd_t)); (void) close(fd); @@ -286,6 +343,7 @@ pool_active(void *unused, const char *name, uint64_t guid, return (0); } +#endif const pool_config_ops_t libzpool_config_ops = { .pco_refresh_config = refresh_config, diff --git a/lib/libzutil/Makefile.am b/lib/libzutil/Makefile.am index 0bc29f05e0..b163250619 100644 --- a/lib/libzutil/Makefile.am +++ b/lib/libzutil/Makefile.am @@ -19,21 +19,13 @@ USER_C = \ if BUILD_LINUX USER_C += \ os/linux/zutil_device_path_os.c \ - os/linux/zutil_import_os.c \ - os/linux/zutil_compat.c + os/linux/zutil_import_os.c endif if BUILD_FREEBSD -DEFAULT_INCLUDES += -I$(top_srcdir)/include/os/freebsd/zfs - USER_C += \ os/freebsd/zutil_device_path_os.c \ - os/freebsd/zutil_import_os.c \ - os/freebsd/zutil_compat.c - -VPATH += $(top_srcdir)/module/os/freebsd/zfs - -nodist_libzutil_la_SOURCES = zfs_ioctl_compat.c + os/freebsd/zutil_import_os.c endif libzutil_la_SOURCES = $(USER_C) diff --git a/tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c b/tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c index b671af7d8f..0e552c2680 100644 --- a/tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c +++ b/tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c @@ -159,7 +159,7 @@ lzc_ioctl_run(zfs_ioc_t ioc, const char *name, nvlist_t *innvl, int expected) zc.zc_nvlist_dst_size = MAX(size * 2, 128 * 1024); zc.zc_nvlist_dst = (uint64_t)(uintptr_t)malloc(zc.zc_nvlist_dst_size); - if (zfs_ioctl_fd(zfs_fd, ioc, &zc) != 0) + if (lzc_ioctl_fd(zfs_fd, ioc, &zc) != 0) error = errno; if (error != expected) { @@ -692,7 +692,7 @@ zfs_destroy(const char *dataset) (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); zc.zc_name[sizeof (zc.zc_name) - 1] = '\0'; - err = zfs_ioctl_fd(zfs_fd, ZFS_IOC_DESTROY, &zc); + err = lzc_ioctl_fd(zfs_fd, ZFS_IOC_DESTROY, &zc); return (err == 0 ? 0 : errno); } @@ -900,7 +900,7 @@ zfs_ioc_input_tests(const char *pool) if (ioc_tested[cmd]) continue; - if (zfs_ioctl_fd(zfs_fd, ioc, &zc) != 0 && + if (lzc_ioctl_fd(zfs_fd, ioc, &zc) != 0 && errno != ZFS_ERR_IOC_CMD_UNAVAIL) { (void) fprintf(stderr, "cmd %d is missing a test case " "(%d)\n", cmd, errno); diff --git a/tests/zfs-tests/cmd/mkbusy/Makefile.am b/tests/zfs-tests/cmd/mkbusy/Makefile.am index 8d5885e084..abae69dea8 100644 --- a/tests/zfs-tests/cmd/mkbusy/Makefile.am +++ b/tests/zfs-tests/cmd/mkbusy/Makefile.am @@ -4,5 +4,3 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin pkgexec_PROGRAMS = mkbusy mkbusy_SOURCES = mkbusy.c - -mkbusy_LDADD = $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la diff --git a/tests/zfs-tests/cmd/mkbusy/mkbusy.c b/tests/zfs-tests/cmd/mkbusy/mkbusy.c index 58ea1d07a4..e1cbd95cd1 100644 --- a/tests/zfs-tests/cmd/mkbusy/mkbusy.c +++ b/tests/zfs-tests/cmd/mkbusy/mkbusy.c @@ -29,7 +29,6 @@ #include #include #include -#include static __attribute__((noreturn)) void @@ -64,6 +63,21 @@ daemonize(void) (void) close(2); } + +static const char * +get_basename(const char *path) +{ + const char *bn = strrchr(path, '/'); + return (bn ? bn + 1 : path); +} + +static ssize_t +get_dirnamelen(const char *path) +{ + const char *end = strrchr(path, '/'); + return (end ? end - path : -1); +} + int main(int argc, char *argv[]) { @@ -103,9 +117,9 @@ main(int argc, char *argv[]) arg[arglen - 1] = '\0'; /* Get the directory and file names. */ - fname = zfs_basename(arg); + fname = get_basename(arg); dname = arg; - if ((dnamelen = zfs_dirnamelen(arg)) != -1) + if ((dnamelen = get_dirnamelen(arg)) != -1) arg[dnamelen] = '\0'; else dname = "."; diff --git a/tests/zfs-tests/tests/functional/ctime/Makefile.am b/tests/zfs-tests/tests/functional/ctime/Makefile.am index 3174f78c62..e7479ae810 100644 --- a/tests/zfs-tests/tests/functional/ctime/Makefile.am +++ b/tests/zfs-tests/tests/functional/ctime/Makefile.am @@ -11,5 +11,3 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/ctime pkgexec_PROGRAMS = ctime ctime_SOURCES = ctime.c - -ctime_LDADD = $(abs_top_builddir)/lib/libzfs_core/libzfs_core.la diff --git a/tests/zfs-tests/tests/functional/ctime/ctime.c b/tests/zfs-tests/tests/functional/ctime/ctime.c index 2d515d957a..b755be2feb 100644 --- a/tests/zfs-tests/tests/functional/ctime/ctime.c +++ b/tests/zfs-tests/tests/functional/ctime/ctime.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -98,6 +97,13 @@ get_file_time(const char *pfile, int what, time_t *ptr) } } +static ssize_t +get_dirnamelen(const char *path) +{ + const char *end = strrchr(path, '/'); + return (end ? end - path : -1); +} + static int do_read(const char *pfile) { @@ -161,7 +167,7 @@ do_link(const char *pfile) * the link file in the same directory. */ (void) snprintf(link_file, sizeof (link_file), - "%.*s/%s", (int)zfs_dirnamelen(pfile), pfile, "link_file"); + "%.*s/%s", (int)get_dirnamelen(pfile), pfile, "link_file"); if (link(pfile, link_file) == -1) { (void) fprintf(stderr, "link(%s, %s) failed with errno %d\n",