aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2013-03-06 10:40:50 +0000
committerMartin Matuska <mm@FreeBSD.org>2013-03-06 10:40:50 +0000
commitdb49d41d8ac7121b181555f8b485f5696d7a86a5 (patch)
tree010157780fa43bcd3edd2a2e2c6d6efaa5985ce9 /cddl/contrib/opensolaris/lib
parent2f79ac7f21545d993cde29ab9a38c4aaae470034 (diff)
downloadsrc-db49d41d8ac7121b181555f8b485f5696d7a86a5.tar.gz
src-db49d41d8ac7121b181555f8b485f5696d7a86a5.zip
Move libzfs compat functions to libzfs_compat.h
This header is used by both libzfs_core and libzfs libraries
Notes
Notes: svn path=/projects/libzfs_core/; revision=247882
Diffstat (limited to 'cddl/contrib/opensolaris/lib')
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h94
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h60
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c2
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h1
4 files changed, 97 insertions, 60 deletions
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 <mm@FreeBSD.org>. All rights reserved.
+ */
+
+#ifndef _LIBZFS_COMPAT_H
+#define _LIBZFS_COMPAT_H
+
+#include <zfs_ioctl_compat.h>
+
+#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 <libuutil.h>
#include <libzfs.h>
#include <libzfs_core.h>
-
-#include "zfs_ioctl_compat.h"
+#include <libzfs_compat.h>
#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 <sys/types.h>
#include <sys/stat.h>
#include <sys/zfs_ioctl.h>
-#include <libzfs_impl.h>
+#include <libzfs_compat.h>
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 <mm@FreeBSD.org>. All rights reserved.
*/
#ifndef _LIBZFS_CORE_H