~ubuntu-branches/ubuntu/wily/spl-linux/wily-proposed

« back to all changes in this revision

Viewing changes to module/spl/spl-generic.c

  • Committer: Package Import Robot
  • Author(s): Liang Guo
  • Date: 2014-07-31 15:16:53 UTC
  • Revision ID: package-import@ubuntu.com-20140731151653-tgao12alohj26jcs
Tags: upstream-0.6.3+git20140731
ImportĀ upstreamĀ versionĀ 0.6.3+git20140731

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
53
53
EXPORT_SYMBOL(spl_version);
54
54
 
55
 
unsigned long spl_hostid = HW_INVALID_HOSTID;
 
55
unsigned long spl_hostid = 0;
56
56
EXPORT_SYMBOL(spl_hostid);
57
57
module_param(spl_hostid, ulong, 0644);
58
58
MODULE_PARM_DESC(spl_hostid, "The system hostid.");
59
59
 
60
 
char hw_serial[HW_HOSTID_LEN] = "<none>";
61
 
EXPORT_SYMBOL(hw_serial);
62
 
 
63
60
proc_t p0 = { 0 };
64
61
EXPORT_SYMBOL(p0);
65
62
 
100
97
}
101
98
EXPORT_SYMBOL(highbit);
102
99
 
 
100
int
 
101
highbit64(uint64_t i)
 
102
{
 
103
        register int h = 1;
 
104
        SENTRY;
 
105
 
 
106
        if (i == 0)
 
107
                SRETURN(0);
 
108
        if (i & 0xffffffff00000000ull) {
 
109
                h += 32; i >>= 32;
 
110
        }
 
111
        if (i & 0xffff0000) {
 
112
                h += 16; i >>= 16;
 
113
        }
 
114
        if (i & 0xff00) {
 
115
                h += 8; i >>= 8;
 
116
        }
 
117
        if (i & 0xf0) {
 
118
                h += 4; i >>= 4;
 
119
        }
 
120
        if (i & 0xc) {
 
121
                h += 2; i >>= 2;
 
122
        }
 
123
        if (i & 0x2) {
 
124
                h += 1;
 
125
        }
 
126
        SRETURN(h);
 
127
}
 
128
EXPORT_SYMBOL(highbit64);
 
129
 
103
130
#if BITS_PER_LONG == 32
104
131
/*
105
132
 * Support 64/64 => 64 division on a 32-bit platform.  While the kernel
467
494
        int result;
468
495
        uint64_t size;
469
496
        struct _buf *file;
470
 
        unsigned long hostid = 0;
 
497
        uint32_t hostid = 0;
471
498
 
472
499
        file = kobj_open_file(spl_hostid_path);
473
500
 
511
538
        return 0;
512
539
}
513
540
 
514
 
#define GET_HOSTID_CMD \
515
 
        "exec 0</dev/null " \
516
 
        "     1>/proc/sys/kernel/spl/hostid " \
517
 
        "     2>/dev/null; " \
518
 
        "hostid"
519
 
 
520
 
static int
521
 
hostid_exec(void)
522
 
{
523
 
        char *argv[] = { "/bin/sh",
524
 
                         "-c",
525
 
                         GET_HOSTID_CMD,
526
 
                         NULL };
527
 
        char *envp[] = { "HOME=/",
528
 
                         "TERM=linux",
529
 
                         "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
530
 
                         NULL };
531
 
        int rc;
532
 
 
533
 
        /* Doing address resolution in the kernel is tricky and just
534
 
         * not a good idea in general.  So to set the proper 'hw_serial'
535
 
         * use the usermodehelper support to ask '/bin/sh' to run
536
 
         * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
537
 
         * for us to use.  It's a horrific solution but it will do for now.
538
 
         */
539
 
        rc = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
540
 
        if (rc)
541
 
                printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
542
 
                       argv[0], argv[1], argv[2], rc);
543
 
 
544
 
        return rc;
545
 
}
546
 
 
547
541
uint32_t
548
542
zone_get_hostid(void *zone)
549
543
{
550
544
        static int first = 1;
551
 
        unsigned long hostid;
552
 
        int rc;
553
545
 
554
546
        /* Only the global zone is supported */
555
547
        ASSERT(zone == NULL);
559
551
 
560
552
                /*
561
553
                 * Get the hostid if it was not passed as a module parameter.
562
 
                 * Try reading the /etc/hostid file directly, and then fall
563
 
                 * back to calling the /usr/bin/hostid utility.
 
554
                 * Try reading the /etc/hostid file directly.
564
555
                 */
565
 
                if ((spl_hostid == HW_INVALID_HOSTID) &&
566
 
                    (rc = hostid_read()) && (rc = hostid_exec()))
567
 
                        return HW_INVALID_HOSTID;
 
556
                if (hostid_read())
 
557
                        spl_hostid = 0;
568
558
 
569
559
                printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
570
560
                        (unsigned int) spl_hostid);
571
561
        }
572
562
 
573
 
        if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
574
 
                return HW_INVALID_HOSTID;
575
 
 
576
 
        return (uint32_t)hostid;
 
563
        return spl_hostid;
577
564
}
578
565
EXPORT_SYMBOL(zone_get_hostid);
579
566
 
759
746
MODULE_AUTHOR("Lawrence Livermore National Labs");
760
747
MODULE_DESCRIPTION("Solaris Porting Layer");
761
748
MODULE_LICENSE("GPL");
 
749
MODULE_VERSION(SPL_META_VERSION "-" SPL_META_RELEASE);