]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Update utsname support
authorBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 1 Oct 2014 19:02:12 +0000 (15:02 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 17 Oct 2014 21:58:57 +0000 (14:58 -0700)
Modify the code to use the utsname() kernel function rather than
a global variable.  This results is cleaner more portable code
because utsname() is already provided by the kernel and can be
easily emulated in user space via uname(2).  This means that it
will behave consistently in both contexts.

This is also has the benefit that it allows the removal of a few
_KERNEL pre-processor conditions.  And it also is a pre-requisite
for a proper FUSE port because we need to provide a valid utsname.

Finally, it allows us to remove this functionality from the SPL
and all the related compatibility code.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2757

include/linux/Makefile.am
include/linux/utsname_compat.h [new file with mode: 0644]
include/sys/zfs_context.h
lib/libspl/include/sys/Makefile.am
lib/libspl/include/sys/utsname.h [deleted file]
lib/libzpool/kernel.c
module/zfs/spa_config.c
module/zfs/spa_history.c

index c2a74912180c624d290001b56ec979302fa856c6..fc2df090ef9de2a058fd7ec164fcf07144afea14 100644 (file)
@@ -4,7 +4,8 @@ KERNEL_H = \
        $(top_srcdir)/include/linux/dcache_compat.h \
        $(top_srcdir)/include/linux/xattr_compat.h \
        $(top_srcdir)/include/linux/vfs_compat.h \
-       $(top_srcdir)/include/linux/blkdev_compat.h
+       $(top_srcdir)/include/linux/blkdev_compat.h \
+       $(top_srcdir)/include/linux/utsname_compat.h
 
 USER_H =
 
diff --git a/include/linux/utsname_compat.h b/include/linux/utsname_compat.h
new file mode 100644 (file)
index 0000000..88da45c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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
+ */
+
+#ifndef        _ZFS_UTSNAME_H
+#define        _ZFS_UTSNAME_H
+
+#include <linux/utsname.h>
+
+typedef struct new_utsname     utsname_t;
+
+#endif /* _ZFS_UTSNAME_H */
index f26c827dc76dbe5be94a542d15523997514054b0..ee8221d534dde6a2934aa3b3fd40f60999d66e60 100644 (file)
@@ -67,6 +67,7 @@
 #include <sys/ctype.h>
 #include <sys/disp.h>
 #include <linux/dcache_compat.h>
+#include <linux/utsname_compat.h>
 
 #else /* _KERNEL */
 
 #include <sys/fm/fs/zfs.h>
 #include <sys/sunddi.h>
 #include <sys/debug.h>
+#include <sys/utsname.h>
 
 /*
  * Stack
@@ -673,6 +675,9 @@ extern int ddi_strtoul(const char *str, char **nptr, int base,
 extern int ddi_strtoull(const char *str, char **nptr, int base,
     u_longlong_t *result);
 
+typedef struct utsname utsname_t;
+extern utsname_t *utsname(void);
+
 /* ZFS Boot Related stuff. */
 
 struct _buf {
index f55abc8fae8df268955d186ca0371d56d2654747..d86cc6a5601a5e79a58516488b4517477dba93c6 100644 (file)
@@ -47,7 +47,6 @@ libspl_HEADERS = \
        $(top_srcdir)/lib/libspl/include/sys/types.h \
        $(top_srcdir)/lib/libspl/include/sys/tzfile.h \
        $(top_srcdir)/lib/libspl/include/sys/uio.h \
-       $(top_srcdir)/lib/libspl/include/sys/utsname.h \
        $(top_srcdir)/lib/libspl/include/sys/va_list.h \
        $(top_srcdir)/lib/libspl/include/sys/varargs.h \
        $(top_srcdir)/lib/libspl/include/sys/vnode.h \
diff --git a/lib/libspl/include/sys/utsname.h b/lib/libspl/include/sys/utsname.h
deleted file mode 100644 (file)
index e16e22d..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (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/OPENLIBSPLARIS.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/OPENLIBSPLARIS.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 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-
-#ifndef _LIBSPL_UTSNAME_H
-#define        _LIBSPL_UTSNAME_H
-
-#include_next <sys/utsname.h>
-
-struct utsname utsname;
-
-#endif  /* _LIBSPL_UTSNAME_H */
index 5adcfa617ab89cbb574d257a04ee0ec848cc9eb2..995f61d05de2b0c82377b281da97a7255d8d8a4e 100644 (file)
@@ -47,10 +47,7 @@ int aok;
 uint64_t physmem;
 vnode_t *rootdir = (vnode_t *)0xabcd1234;
 char hw_serial[HW_HOSTID_LEN];
-
-struct utsname utsname = {
-       "userland", "libzpool", "1", "1", "na"
-};
+struct utsname hw_utsname;
 
 /* this only exists to have its address taken */
 struct proc p0;
@@ -1089,6 +1086,12 @@ ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
        return (0);
 }
 
+utsname_t *
+utsname(void)
+{
+       return (&hw_utsname);
+}
+
 /*
  * =========================================================================
  * kernel emulation setup & teardown
@@ -1121,6 +1124,7 @@ kernel_init(int mode)
 
        VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
        VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);
+       VERIFY0(uname(&hw_utsname));
 
        thread_init();
        system_taskq_init();
index c8fe79ed5278960a95afa12c624c9f4fc13014ce..a08456d56f60a776f99f2c41ef00bebd97823b84 100644 (file)
@@ -32,7 +32,6 @@
 #include <sys/fs/zfs.h>
 #include <sys/vdev_impl.h>
 #include <sys/zfs_ioctl.h>
-#include <sys/utsname.h>
 #include <sys/systeminfo.h>
 #include <sys/sunddi.h>
 #include <sys/zfeature.h>
@@ -408,8 +407,8 @@ spa_config_generate(spa_t *spa, vdev_t *vd, uint64_t txg, int getstats)
                VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_HOSTID,
                    hostid) == 0);
        }
-       VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME,
-           utsname.nodename) == 0);
+       VERIFY0(nvlist_add_string(config, ZPOOL_CONFIG_HOSTNAME,
+           utsname()->nodename));
 
        if (vd != rvd) {
                VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_TOP_GUID,
index 5b82238b90f9a44c7def302ffe58fa7f34aca504..1c434197d898b4c14cbc0c5fdd985fd042b870d5 100644 (file)
@@ -32,7 +32,6 @@
 #include <sys/dmu_objset.h>
 #include <sys/dsl_dataset.h>
 #include <sys/dsl_dir.h>
-#include <sys/utsname.h>
 #include <sys/cmn_err.h>
 #include <sys/sunddi.h>
 #include <sys/cred.h>
@@ -236,9 +235,8 @@ spa_history_log_sync(void *arg, dmu_tx_t *tx)
 #endif
 
        fnvlist_add_uint64(nvl, ZPOOL_HIST_TIME, gethrestime_sec());
-#ifdef _KERNEL
-       fnvlist_add_string(nvl, ZPOOL_HIST_HOST, utsname.nodename);
-#endif
+       fnvlist_add_string(nvl, ZPOOL_HIST_HOST, utsname()->nodename);
+
        if (nvlist_exists(nvl, ZPOOL_HIST_CMD)) {
                zfs_dbgmsg("command: %s",
                    fnvlist_lookup_string(nvl, ZPOOL_HIST_CMD));
@@ -546,11 +544,12 @@ spa_history_log_internal_dd(dsl_dir_t *dd, const char *operation,
 void
 spa_history_log_version(spa_t *spa, const char *operation)
 {
+       utsname_t *u = utsname();
+
        spa_history_log_internal(spa, operation, NULL,
            "pool version %llu; software version %llu/%d; uts %s %s %s %s",
            (u_longlong_t)spa_version(spa), SPA_VERSION, ZPL_VERSION,
-           utsname.nodename, utsname.release, utsname.version,
-           utsname.machine);
+           u->nodename, u->release, u->version, u->machine);
 }
 
 #if defined(_KERNEL) && defined(HAVE_SPL)