Simplify and document OpenZFS library dependencies

For those not already familiar with the code base it can be a
challenge to understand how the libraries are laid out.  This
has sometimes resulted in functionality being added in the
wrong place.  To help avoid that in the future this commit
documents the high-level dependencies for easy reference in
lib/Makefile.am.  It also simplifies a few things.

- Switched libzpool dependency on libzfs_core to libzutil.
  This change makes it clear libzpool should never depend
  on the ioctl() functionality provided by libzfs_core.

- Moved zfs_ioctl_fd() from libzutil to libzfs_core and
  renamed it lzc_ioctl_fd().  Normal access to the kmods
  should all be funneled through the libzfs_core library.
  The sole exception is the pool_active() which was updated
  to not use lzc_ioctl_fd() to remove the libzfs_core
  dependency.

- Removed libzfs_core dependency on libzutil.

- Removed the lib/libzfs/os/freebsd/libzfs_ioctl_compat.c
  source file which was all dead code.

- Removed libzfs_core dependency from mkbusy and ctime
  test utilities.  It was only needed for some trivial
  wrapper functions and that code is easy to replicate
  to shed the unneeded dependency.

Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Don Brady <don.brady@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #12602
This commit is contained in:
Brian Behlendorf
2021-10-07 10:31:26 -07:00
committed by GitHub
parent 48df24d4ce
commit 514498fef6
21 changed files with 1991 additions and 1436 deletions
-124
View File
@@ -1,124 +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
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/zfs_ioctl.h>
#include <os/freebsd/zfs/sys/zfs_ioctl_compat.h>
#include <libzutil.h>
#include <err.h>
int zfs_ioctl_version = ZFS_IOCVER_UNDEF;
/*
* Get zfs_ioctl_version
*/
static int
get_zfs_ioctl_version(void)
{
size_t ver_size;
int ver = ZFS_IOCVER_NONE;
ver_size = sizeof (ver);
sysctlbyname("vfs.zfs.version.ioctl", &ver, &ver_size, NULL, 0);
return (ver);
}
static int
zcmd_ioctl_compat(int fd, int request, zfs_cmd_t *zc, const int cflag)
{
int newrequest, ret;
void *zc_c = NULL;
unsigned long ncmd;
zfs_iocparm_t zp;
switch (cflag) {
case ZFS_CMD_COMPAT_NONE:
ncmd = _IOWR('Z', request, zfs_iocparm_t);
zp.zfs_cmd = (uint64_t)(uintptr_t)zc;
zp.zfs_cmd_size = sizeof (zfs_cmd_t);
zp.zfs_ioctl_version = ZFS_IOCVER_OZFS;
break;
case ZFS_CMD_COMPAT_LEGACY:
newrequest = zfs_ioctl_ozfs_to_legacy(request);
ncmd = _IOWR('Z', newrequest, zfs_iocparm_t);
zc_c = malloc(sizeof (zfs_cmd_legacy_t));
zfs_cmd_ozfs_to_legacy(zc, zc_c);
zp.zfs_cmd = (uint64_t)(uintptr_t)zc_c;
zp.zfs_cmd_size = sizeof (zfs_cmd_legacy_t);
zp.zfs_ioctl_version = ZFS_IOCVER_LEGACY;
break;
default:
abort();
return (EINVAL);
}
ret = ioctl(fd, ncmd, &zp);
if (ret) {
if (zc_c)
free(zc_c);
return (ret);
}
if (zc_c) {
zfs_cmd_legacy_to_ozfs(zc_c, zc);
free(zc_c);
}
return (ret);
}
/*
* This is FreeBSD version of ioctl, because Solaris' ioctl() updates
* zc_nvlist_dst_size even if an error is returned, on FreeBSD if an
* error is returned zc_nvlist_dst_size won't be updated.
*/
int
zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc)
{
size_t oldsize;
int ret, cflag = ZFS_CMD_COMPAT_NONE;
if (zfs_ioctl_version == ZFS_IOCVER_UNDEF)
zfs_ioctl_version = get_zfs_ioctl_version();
switch (zfs_ioctl_version) {
case ZFS_IOCVER_LEGACY:
cflag = ZFS_CMD_COMPAT_LEGACY;
break;
case ZFS_IOCVER_OZFS:
cflag = ZFS_CMD_COMPAT_NONE;
break;
default:
errx(1, "unrecognized zfs ioctl version %d",
zfs_ioctl_version);
}
oldsize = zc->zc_nvlist_dst_size;
ret = zcmd_ioctl_compat(fd, request, zc, cflag);
if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) {
ret = -1;
errno = ENOMEM;
}
return (ret);
}