Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 Mar 2013 10:40:51 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r247882 - in projects/libzfs_core/cddl/contrib/opensolaris/lib: libzfs/common libzfs_core/common
Message-ID:  <201303061040.r26Aep0t078118@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Wed Mar  6 10:40:50 2013
New Revision: 247882
URL: http://svnweb.freebsd.org/changeset/base/247882

Log:
  Move libzfs compat functions to libzfs_compat.h
  This header is used by both libzfs_core and libzfs libraries

Added:
  projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h
Modified:
  projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
  projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
  projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h

Added: projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_compat.h	Wed Mar  6 10:40:50 2013	(r247882)
@@ -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 */

Modified: projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
==============================================================================
--- projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Wed Mar  6 10:23:56 2013	(r247881)
+++ projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Wed Mar  6 10:40:50 2013	(r247882)
@@ -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_
 
 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

Modified: projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c
==============================================================================
--- projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c	Wed Mar  6 10:23:56 2013	(r247881)
+++ projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.c	Wed Mar  6 10:40:50 2013	(r247882)
@@ -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;

Modified: projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h
==============================================================================
--- projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h	Wed Mar  6 10:23:56 2013	(r247881)
+++ projects/libzfs_core/cddl/contrib/opensolaris/lib/libzfs_core/common/libzfs_core.h	Wed Mar  6 10:40:50 2013	(r247882)
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303061040.r26Aep0t078118>