lzc: move lzc_ioctl_fd() into lzc proper

Name the OS-specific call lzc_ioctl_fd_os(), and make lzc_ioctl_fd()
wrap it, so we can do more in the wrapper.

Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #17344
This commit is contained in:
Rob Norris 2025-05-17 14:06:44 +10:00 committed by Brian Behlendorf
parent f454cc1723
commit c4c3917b2a
5 changed files with 53 additions and 4 deletions

View File

@ -1,18 +1,21 @@
libzfs_core_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS) libzfs_core_la_CFLAGS = $(AM_CFLAGS) $(LIBRARY_CFLAGS)
libzfs_core_la_CFLAGS += -fvisibility=hidden libzfs_core_la_CFLAGS += -fvisibility=hidden
libzfs_core_la_CPPFLAGS = $(AM_CPPFLAGS)
libzfs_core_la_CPPFLAGS += -I$(srcdir)/%D%
lib_LTLIBRARIES += libzfs_core.la lib_LTLIBRARIES += libzfs_core.la
CPPCHECKTARGETS += libzfs_core.la CPPCHECKTARGETS += libzfs_core.la
libzfs_core_la_SOURCES = \ libzfs_core_la_SOURCES = \
%D%/libzfs_core.c %D%/libzfs_core.c \
%D%/libzfs_core_impl.h
if BUILD_LINUX if BUILD_LINUX
libzfs_core_la_SOURCES += \ libzfs_core_la_SOURCES += \
%D%/os/linux/libzfs_core_ioctl.c %D%/os/linux/libzfs_core_ioctl.c
endif endif
libzfs_core_la_CPPFLAGS = $(AM_CPPFLAGS)
if BUILD_FREEBSD if BUILD_FREEBSD
libzfs_core_la_CPPFLAGS += -Iinclude/os/freebsd/zfs libzfs_core_la_CPPFLAGS += -Iinclude/os/freebsd/zfs

View File

@ -96,6 +96,8 @@
#define BIG_PIPE_SIZE (64 * 1024) /* From sys/pipe.h */ #define BIG_PIPE_SIZE (64 * 1024) /* From sys/pipe.h */
#endif #endif
#include "libzfs_core_impl.h"
static int g_fd = -1; static int g_fd = -1;
static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER;
static int g_refcount; static int g_refcount;
@ -171,6 +173,12 @@ libzfs_core_fini(void)
(void) pthread_mutex_unlock(&g_lock); (void) pthread_mutex_unlock(&g_lock);
} }
int
lzc_ioctl_fd(int fd, unsigned long ioc, zfs_cmd_t *zc)
{
return (lzc_ioctl_fd_os(fd, ioc, zc));
}
static int static int
lzc_ioctl(zfs_ioc_t ioc, const char *name, lzc_ioctl(zfs_ioc_t ioc, const char *name,
nvlist_t *source, nvlist_t **resultp) nvlist_t *source, nvlist_t **resultp)

View File

@ -0,0 +1,36 @@
// SPDX-License-Identifier: CDDL-1.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 https://opensource.org/licenses/CDDL-1.0.
* 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 (c) 2012, 2020 by Delphix. All rights reserved.
* Copyright 2017 RackTop Systems.
* Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
* Copyright (c) 2019 Datto Inc.
*/
#ifndef _LIBZFS_CORE_IMPL_H
#define _LIBZFS_CORE_IMPL_H
struct zfs_cmd;
int lzc_ioctl_fd_os(int, unsigned long, struct zfs_cmd *);
#endif /* _LIBZFS_CORE_IMPL_H */

View File

@ -26,6 +26,7 @@
#include <os/freebsd/zfs/sys/zfs_ioctl_compat.h> #include <os/freebsd/zfs/sys/zfs_ioctl_compat.h>
#include <err.h> #include <err.h>
#include <libzfs_core.h> #include <libzfs_core.h>
#include "libzfs_core_impl.h"
int zfs_ioctl_version = ZFS_IOCVER_UNDEF; int zfs_ioctl_version = ZFS_IOCVER_UNDEF;
@ -101,7 +102,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. * error is returned zc_nvlist_dst_size won't be updated.
*/ */
int int
lzc_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) lzc_ioctl_fd_os(int fd, unsigned long request, zfs_cmd_t *zc)
{ {
size_t oldsize; size_t oldsize;
int ret, cflag = ZFS_CMD_COMPAT_NONE; int ret, cflag = ZFS_CMD_COMPAT_NONE;

View File

@ -23,9 +23,10 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/zfs_ioctl.h> #include <sys/zfs_ioctl.h>
#include <libzfs_core.h> #include <libzfs_core.h>
#include "libzfs_core_impl.h"
int int
lzc_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc) lzc_ioctl_fd_os(int fd, unsigned long request, zfs_cmd_t *zc)
{ {
return (ioctl(fd, request, zc)); return (ioctl(fd, request, zc));
} }