diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h new file mode 100644 index 000000000000..b6654b456c3a --- /dev/null +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h @@ -0,0 +1,94 @@ +/* + * CDDL HEADER SART + * + * 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 (c) 2013 Martin Matuska . All rights reserved. + */ + +#ifndef _LIBZFS_COMPAT_H +#define _LIBZFS_COMPAT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static int zfs_kernel_version = 0; +static int zfs_ioctl_version = 0; + +/* + * 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. + */ +static __inline int +zcmd_ioctl(int fd, int request, zfs_cmd_t *zc) +{ + unsigned long cmd; + size_t oldsize, zfs_kernel_version_size, zfs_ioctl_version_size; + int version, ret, cflag = ZFS_CMD_COMPAT_NONE; + + cmd = _IOWR('Z', request, struct zfs_cmd); + + zfs_ioctl_version_size = sizeof(zfs_ioctl_version); + if (zfs_ioctl_version == 0) { + sysctlbyname("vfs.zfs.version.ioctl", &zfs_ioctl_version, + &zfs_ioctl_version_size, NULL, 0); + } + + /* + * If vfs.zfs.version.ioctl is not defined, assume we have v28 + * compatible binaries and use vfs.zfs.version.spa to test for v15 + */ + if (zfs_ioctl_version < ZFS_IOCVER_DEADMAN) { + cflag = ZFS_CMD_COMPAT_V28; + zfs_kernel_version_size = sizeof(zfs_kernel_version); + + if (zfs_kernel_version == 0) { + sysctlbyname("vfs.zfs.version.spa", + &zfs_kernel_version, + &zfs_kernel_version_size, NULL, 0); + } + + if (zfs_kernel_version == SPA_VERSION_15 || + zfs_kernel_version == SPA_VERSION_14 || + zfs_kernel_version == SPA_VERSION_13) + cflag = ZFS_CMD_COMPAT_V15; + } + + oldsize = zc->zc_nvlist_dst_size; + ret = zcmd_ioctl_compat(fd, cmd, zc, cflag); + + if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) { + ret = -1; + errno = ENOMEM; + } + + return (ret); +} +#define ioctl(fd, cmd, zc) zcmd_ioctl((fd), (cmd), (zc)) + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBZFS_COMPAT_H */ diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h index d55e942856d4..11a57a98ae60 100644 --- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h +++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h @@ -40,8 +40,7 @@ #include #include #include - -#include "zfs_ioctl_compat.h" +#include #ifdef __cplusplus extern "C" { @@ -215,63 +214,6 @@ extern int zfs_unshare_proto(zfs_handle_t *, extern void libzfs_fru_clear(libzfs_handle_t *, boolean_t); -#ifndef sun -static int zfs_kernel_version = 0; -static int zfs_ioctl_version = 0; - -/* - * 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. - */ -static __inline int -zcmd_ioctl(int fd, int request, zfs_cmd_t *zc) -{ - unsigned long cmd; - size_t oldsize, zfs_kernel_version_size, zfs_ioctl_version_size; - int version, ret, cflag = ZFS_CMD_COMPAT_NONE; - - cmd = _IOWR('Z', request, struct zfs_cmd); - - zfs_ioctl_version_size = sizeof(zfs_ioctl_version); - if (zfs_ioctl_version == 0) { - sysctlbyname("vfs.zfs.version.ioctl", &zfs_ioctl_version, - &zfs_ioctl_version_size, NULL, 0); - } - - /* - * If vfs.zfs.version.ioctl is not defined, assume we have v28 - * compatible binaries and use vfs.zfs.version.spa to test for v15 - */ - if (zfs_ioctl_version < ZFS_IOCVER_DEADMAN) { - cflag = ZFS_CMD_COMPAT_V28; - zfs_kernel_version_size = sizeof(zfs_kernel_version); - - if (zfs_kernel_version == 0) { - sysctlbyname("vfs.zfs.version.spa", - &zfs_kernel_version, - &zfs_kernel_version_size, NULL, 0); - } - - if (zfs_kernel_version == SPA_VERSION_15 || - zfs_kernel_version == SPA_VERSION_14 || - zfs_kernel_version == SPA_VERSION_13) - cflag = ZFS_CMD_COMPAT_V15; - } - - oldsize = zc->zc_nvlist_dst_size; - ret = zcmd_ioctl_compat(fd, cmd, zc, cflag); - - if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) { - ret = -1; - errno = ENOMEM; - } - - return (ret); -} -#define ioctl(fd, cmd, zc) zcmd_ioctl((fd), (cmd), (zc)) -#endif /* !sun */ - #ifdef __cplusplus } #endif diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c index 364d92ad4726..b6c28bee01ab 100644 --- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c +++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c @@ -84,7 +84,7 @@ #include #include #include -#include +#include static int g_fd; static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; diff --git a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h index 9edc884a14d1..c8bfbefbdaf5 100644 --- a/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h +++ b/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h @@ -21,6 +21,7 @@ /* * Copyright (c) 2012 by Delphix. All rights reserved. + * Copyright (c) 2013 by Martin Matuska . All rights reserved. */ #ifndef _LIBZFS_CORE_H