]> git.proxmox.com Git - mirror_spl.git/blobdiff - module/spl/spl-generic.c
Retire legacy debugging infrastructure
[mirror_spl.git] / module / spl / spl-generic.c
index b83d753d8ab7da87584e9866c8a18c3d27417ebd..ecfb663de5e590fc5cb36d5df26a9945311d08c1 100644 (file)
@@ -6,7 +6,7 @@
  *  UCRL-CODE-235197
  *
  *  This file is part of the SPL, Solaris Porting Layer.
- *  For details, see <http://github.com/behlendorf/spl/>.
+ *  For details, see <http://zfsonlinux.org/>.
  *
  *  The SPL is free software; you can redistribute it and/or modify it
  *  under the terms of the GNU General Public License as published by the
 #include <sys/sysmacros.h>
 #include <sys/systeminfo.h>
 #include <sys/vmsystm.h>
-#include <sys/vnode.h>
+#include <sys/kobj.h>
 #include <sys/kmem.h>
 #include <sys/mutex.h>
 #include <sys/rwlock.h>
 #include <sys/taskq.h>
 #include <sys/tsd.h>
+#include <sys/zmod.h>
 #include <sys/debug.h>
 #include <sys/proc.h>
 #include <sys/kstat.h>
-#include <sys/utsname.h>
 #include <sys/file.h>
 #include <linux/kmod.h>
 #include <linux/proc_compat.h>
-#include <spl-debug.h>
 
-#ifdef SS_DEBUG_SUBSYS
-#undef SS_DEBUG_SUBSYS
-#endif
-
-#define SS_DEBUG_SUBSYS SS_GENERIC
-
-char spl_version[16] = "SPL v" SPL_META_VERSION;
+char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
 EXPORT_SYMBOL(spl_version);
 
-long spl_hostid = 0;
+unsigned long spl_hostid = 0;
 EXPORT_SYMBOL(spl_hostid);
-
-char hw_serial[HW_HOSTID_LEN] = "<none>";
-EXPORT_SYMBOL(hw_serial);
+module_param(spl_hostid, ulong, 0644);
+MODULE_PARM_DESC(spl_hostid, "The system hostid.");
 
 proc_t p0 = { 0 };
 EXPORT_SYMBOL(p0);
 
-#ifndef HAVE_KALLSYMS_LOOKUP_NAME
-kallsyms_lookup_name_t spl_kallsyms_lookup_name_fn = SYMBOL_POISON;
-#endif
-
-int
-highbit(unsigned long i)
-{
-        register int h = 1;
-        SENTRY;
-
-        if (i == 0)
-                SRETURN(0);
-#if BITS_PER_LONG == 64
-        if (i & 0xffffffff00000000ul) {
-                h += 32; i >>= 32;
-        }
-#endif
-        if (i & 0xffff0000) {
-                h += 16; i >>= 16;
-        }
-        if (i & 0xff00) {
-                h += 8; i >>= 8;
-        }
-        if (i & 0xf0) {
-                h += 4; i >>= 4;
-        }
-        if (i & 0xc) {
-                h += 2; i >>= 2;
-        }
-        if (i & 0x2) {
-                h += 1;
-        }
-        SRETURN(h);
-}
-EXPORT_SYMBOL(highbit);
-
 #if BITS_PER_LONG == 32
 /*
  * Support 64/64 => 64 division on a 32-bit platform.  While the kernel
@@ -180,7 +136,7 @@ __udivdi3(uint64_t u, uint64_t v)
                        q0 = q0 - 1;            // too small by 1.
                if ((u - q0 * v) >= v)
                        q0 = q0 + 1;            // Now q0 is correct.
-       
+
                return q0;
        }
 }
@@ -209,6 +165,62 @@ __umoddi3(uint64_t dividend, uint64_t divisor)
 }
 EXPORT_SYMBOL(__umoddi3);
 
+#if defined(__arm) || defined(__arm__)
+/*
+ * Implementation of 64-bit (un)signed division for 32-bit arm machines.
+ *
+ * Run-time ABI for the ARM Architecture (page 20).  A pair of (unsigned)
+ * long longs is returned in {{r0, r1}, {r2,r3}}, the quotient in {r0, r1},
+ * and the remainder in {r2, r3}.  The return type is specifically left
+ * set to 'void' to ensure the compiler does not overwrite these registers
+ * during the return.  All results are in registers as per ABI
+ */
+void
+__aeabi_uldivmod(uint64_t u, uint64_t v)
+{
+       uint64_t res;
+       uint64_t mod;
+
+       res = __udivdi3(u, v);
+       mod = __umoddi3(u, v);
+       {
+               register uint32_t r0 asm("r0") = (res & 0xFFFFFFFF);
+               register uint32_t r1 asm("r1") = (res >> 32);
+               register uint32_t r2 asm("r2") = (mod & 0xFFFFFFFF);
+               register uint32_t r3 asm("r3") = (mod >> 32);
+
+               asm volatile(""
+                   : "+r"(r0), "+r"(r1), "+r"(r2),"+r"(r3)  /* output */
+                   : "r"(r0), "r"(r1), "r"(r2), "r"(r3));   /* input */
+
+               return; /* r0; */
+       }
+}
+EXPORT_SYMBOL(__aeabi_uldivmod);
+
+void
+__aeabi_ldivmod(int64_t u, int64_t v)
+{
+       int64_t res;
+       uint64_t mod;
+
+       res =  __divdi3(u, v);
+       mod = __umoddi3(u, v);
+       {
+               register uint32_t r0 asm("r0") = (res & 0xFFFFFFFF);
+               register uint32_t r1 asm("r1") = (res >> 32);
+               register uint32_t r2 asm("r2") = (mod & 0xFFFFFFFF);
+               register uint32_t r3 asm("r3") = (mod >> 32);
+
+               asm volatile(""
+                   : "+r"(r0), "+r"(r1), "+r"(r2),"+r"(r3)  /* output */
+                   : "r"(r0), "r"(r1), "r"(r2), "r"(r3));   /* input */
+
+               return; /* r0; */
+       }
+}
+EXPORT_SYMBOL(__aeabi_ldivmod);
+#endif /* __arm || __arm__ */
 #endif /* BITS_PER_LONG */
 
 /* NOTE: The strtoxx behavior is solely based on my reading of the Solaris
@@ -351,148 +363,165 @@ __put_task_struct(struct task_struct *t)
 EXPORT_SYMBOL(__put_task_struct);
 #endif /* HAVE_PUT_TASK_STRUCT */
 
-struct new_utsname *__utsname(void)
-{
-#ifdef HAVE_INIT_UTSNAME
-       return init_utsname();
-#else
-       return &system_utsname;
-#endif
-}
-EXPORT_SYMBOL(__utsname);
+/*
+ * Read the unique system identifier from the /etc/hostid file.
+ *
+ * The behavior of /usr/bin/hostid on Linux systems with the
+ * regular eglibc and coreutils is:
+ *
+ *   1. Generate the value if the /etc/hostid file does not exist
+ *      or if the /etc/hostid file is less than four bytes in size.
+ *
+ *   2. If the /etc/hostid file is at least 4 bytes, then return
+ *      the first four bytes [0..3] in native endian order.
+ *
+ *   3. Always ignore bytes [4..] if they exist in the file.
+ *
+ * Only the first four bytes are significant, even on systems that
+ * have a 64-bit word size.
+ *
+ * See:
+ *
+ *   eglibc: sysdeps/unix/sysv/linux/gethostid.c
+ *   coreutils: src/hostid.c
+ *
+ * Notes:
+ *
+ * The /etc/hostid file on Solaris is a text file that often reads:
+ *
+ *   # DO NOT EDIT
+ *   "0123456789"
+ *
+ * Directly copying this file to Linux results in a constant
+ * hostid of 4f442023 because the default comment constitutes
+ * the first four bytes of the file.
+ *
+ */
+
+char *spl_hostid_path = HW_HOSTID_PATH;
+module_param(spl_hostid_path, charp, 0444);
+MODULE_PARM_DESC(spl_hostid_path, "The system hostid file (/etc/hostid)");
 
 static int
-set_hostid(void)
+hostid_read(void)
 {
-       char sh_path[] = "/bin/sh";
-       char *argv[] = { sh_path,
-                        "-c",
-                        "/usr/bin/hostid >/proc/sys/kernel/spl/hostid",
-                        NULL };
-       char *envp[] = { "HOME=/",
-                        "TERM=linux",
-                        "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
-                        NULL };
-       int rc;
-
-       /* Doing address resolution in the kernel is tricky and just
-        * not a good idea in general.  So to set the proper 'hw_serial'
-        * use the usermodehelper support to ask '/bin/sh' to run
-        * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
-        * for us to use.  It's a horrific solution but it will do for now.
-        */
-       rc = call_usermodehelper(sh_path, argv, envp, 1);
-       if (rc)
-               printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
-                      argv[0], argv[1], argv[2], rc);
+       int result;
+       uint64_t size;
+       struct _buf *file;
+       uint32_t hostid = 0;
 
-       return rc;
+       file = kobj_open_file(spl_hostid_path);
+
+       if (file == (struct _buf *)-1)
+               return -1;
+
+       result = kobj_get_filesize(file, &size);
+
+       if (result != 0) {
+               printk(KERN_WARNING
+                      "SPL: kobj_get_filesize returned %i on %s\n",
+                      result, spl_hostid_path);
+               kobj_close_file(file);
+               return -2;
+       }
+
+       if (size < sizeof(HW_HOSTID_MASK)) {
+               printk(KERN_WARNING
+                      "SPL: Ignoring the %s file because it is %llu bytes; "
+                      "expecting %lu bytes instead.\n", spl_hostid_path,
+                      size, (unsigned long)sizeof(HW_HOSTID_MASK));
+               kobj_close_file(file);
+               return -3;
+       }
+
+       /* Read directly into the variable like eglibc does. */
+       /* Short reads are okay; native behavior is preserved. */
+       result = kobj_read_file(file, (char *)&hostid, sizeof(hostid), 0);
+
+       if (result < 0) {
+               printk(KERN_WARNING
+                      "SPL: kobj_read_file returned %i on %s\n",
+                      result, spl_hostid_path);
+               kobj_close_file(file);
+               return -4;
+       }
+
+       /* Mask down to 32 bits like coreutils does. */
+       spl_hostid = hostid & HW_HOSTID_MASK;
+       kobj_close_file(file);
+       return 0;
 }
 
 uint32_t
 zone_get_hostid(void *zone)
 {
-       unsigned long hostid;
+       static int first = 1;
 
        /* Only the global zone is supported */
        ASSERT(zone == NULL);
 
-       if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
-               return HW_INVALID_HOSTID;
-
-       return (uint32_t)hostid;
-}
-EXPORT_SYMBOL(zone_get_hostid);
+       if (first) {
+               first = 0;
 
-#ifndef HAVE_KALLSYMS_LOOKUP_NAME
-/*
- * Because kallsyms_lookup_name() is no longer exported in the
- * mainline kernel we are forced to resort to somewhat drastic
- * measures.  This function replaces the functionality by performing
- * an upcall to user space where /proc/kallsyms is consulted for
- * the requested address.
- */
-#define GET_KALLSYMS_ADDR_CMD                                          \
-       "gawk '{ if ( $3 == \"kallsyms_lookup_name\") { print $1 } }' " \
-       "/proc/kallsyms >/proc/sys/kernel/spl/kallsyms_lookup_name"
+               /*
+                * Get the hostid if it was not passed as a module parameter.
+                * Try reading the /etc/hostid file directly.
+                */
+               if (hostid_read())
+                       spl_hostid = 0;
 
-static int
-set_kallsyms_lookup_name(void)
-{
-       char sh_path[] = "/bin/sh";
-       char *argv[] = { sh_path,
-                        "-c",
-                        GET_KALLSYMS_ADDR_CMD,
-                        NULL };
-       char *envp[] = { "HOME=/",
-                        "TERM=linux",
-                        "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
-                        NULL };
-       int rc;
-
-       rc = call_usermodehelper(sh_path, argv, envp, 1);
-       if (rc)
-               printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
-                      argv[0], argv[1], argv[2], rc);
+               printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
+                       (unsigned int) spl_hostid);
+       }
 
-       return rc;
+       return spl_hostid;
 }
-#endif
+EXPORT_SYMBOL(zone_get_hostid);
 
 static int
 __init spl_init(void)
 {
        int rc = 0;
 
-       if ((rc = debug_init()))
-               return rc;
-
        if ((rc = spl_kmem_init()))
-               SGOTO(out1, rc);
+               goto out1;
 
        if ((rc = spl_mutex_init()))
-               SGOTO(out2, rc);
+               goto out2;
 
        if ((rc = spl_rw_init()))
-               SGOTO(out3, rc);
+               goto out3;
 
        if ((rc = spl_taskq_init()))
-               SGOTO(out4, rc);
-
-       if ((rc = vn_init()))
-               SGOTO(out5, rc);
+               goto out4;
 
-       if ((rc = proc_init()))
-               SGOTO(out6, rc);
+       if ((rc = spl_vn_init()))
+               goto out5;
 
-       if ((rc = kstat_init()))
-               SGOTO(out7, rc);
+       if ((rc = spl_proc_init()))
+               goto out6;
 
-       if ((rc = tsd_init()))
-               SGOTO(out8, rc);
+       if ((rc = spl_kstat_init()))
+               goto out7;
 
-       if ((rc = set_hostid()))
-               SGOTO(out9, rc = -EADDRNOTAVAIL);
+       if ((rc = spl_tsd_init()))
+               goto out8;
 
-#ifndef HAVE_KALLSYMS_LOOKUP_NAME
-       if ((rc = set_kallsyms_lookup_name()))
-               SGOTO(out9, rc = -EADDRNOTAVAIL);
-#endif /* HAVE_KALLSYMS_LOOKUP_NAME */
+       if ((rc = spl_zlib_init()))
+               goto out9;
 
-       if ((rc = spl_kmem_init_kallsyms_lookup()))
-               SGOTO(out9, rc);
+       printk(KERN_NOTICE "SPL: Loaded module v%s-%s%s\n", SPL_META_VERSION,
+              SPL_META_RELEASE, SPL_DEBUG_STR);
+       return (rc);
 
-       printk(KERN_NOTICE "SPL: Loaded Solaris Porting Layer v%s%s\n",
-              SPL_META_VERSION, SPL_DEBUG_STR);
-       SRETURN(rc);
 out9:
-       tsd_fini();
+       spl_tsd_fini();
 out8:
-       kstat_fini();
+       spl_kstat_fini();
 out7:
-       proc_fini();
+       spl_proc_fini();
 out6:
-       vn_fini();
+       spl_vn_fini();
 out5:
        spl_taskq_fini();
 out4:
@@ -502,29 +531,27 @@ out3:
 out2:
        spl_kmem_fini();
 out1:
-       debug_fini();
+       printk(KERN_NOTICE "SPL: Failed to Load Solaris Porting Layer "
+              "v%s-%s%s, rc = %d\n", SPL_META_VERSION, SPL_META_RELEASE,
+              SPL_DEBUG_STR, rc);
 
-       printk(KERN_NOTICE "SPL: Failed to Load Solaris Porting Layer v%s%s"
-              ", rc = %d\n", SPL_META_VERSION, SPL_DEBUG_STR, rc);
        return rc;
 }
 
 static void
 spl_fini(void)
 {
-       SENTRY;
-
-       printk(KERN_NOTICE "SPL: Unloaded Solaris Porting Layer v%s%s\n",
-              SPL_META_VERSION, SPL_DEBUG_STR);
-       tsd_fini();
-       kstat_fini();
-       proc_fini();
-       vn_fini();
+       printk(KERN_NOTICE "SPL: Unloaded module v%s-%s%s\n",
+              SPL_META_VERSION, SPL_META_RELEASE, SPL_DEBUG_STR);
+       spl_zlib_fini();
+       spl_tsd_fini();
+       spl_kstat_fini();
+       spl_proc_fini();
+       spl_vn_fini();
        spl_taskq_fini();
        spl_rw_fini();
        spl_mutex_fini();
        spl_kmem_fini();
-       debug_fini();
 }
 
 /* Called when a dependent module is loaded */
@@ -554,6 +581,7 @@ EXPORT_SYMBOL(spl_cleanup);
 module_init(spl_init);
 module_exit(spl_fini);
 
-MODULE_AUTHOR("Lawrence Livermore National Labs");
 MODULE_DESCRIPTION("Solaris Porting Layer");
-MODULE_LICENSE("GPL");
+MODULE_AUTHOR(SPL_META_AUTHOR);
+MODULE_LICENSE(SPL_META_LICENSE);
+MODULE_VERSION(SPL_META_VERSION "-" SPL_META_RELEASE);