From d1ff2312b05852d2190afd1da216b4e0e1b0c7d4 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 25 Feb 2009 13:20:40 -0800 Subject: Linux VM Integration Cleanup Remove all instances of functions being reimplemented in the SPL. When the prototypes are available in the linux headers but the function address itself is not exported use kallsyms_lookup_name() to find the address. The function name itself can them become a define which calls a function pointer. This is preferable to reimplementing the function in the SPL because it ensures we get the correct version of the function for the running kernel. This is actually pretty safe because the prototype is defined in the headers so we know we are calling the function properly. This patch also includes a rhel5 kernel patch we exports the needed symbols so we don't need to use kallsyms_lookup_name(). There are autoconf checks to detect if the symbol is exported and if so to use it directly. We should add patches for stock upstream kernels as needed if for no other reason than so we can easily track which additional symbols we needed exported. Those patches can also be used by anyone willing to rebuild their kernel, but this should not be a requirement. The rhel5 version of the export-symbols patch has been applied to the chaos kernel. Additional fixes: 1) Implement vmem_size() function using get_vmalloc_info() 2) SPL_CHECK_SYMBOL_EXPORT macro updated to use $LINUX_OBJ instead of $LINUX because Module.symvers is a build product. When $LINUX_OBJ != $LINUX we will not properly detect exported symbols. 3) SPL_LINUX_COMPILE_IFELSE macro updated to add include2 and $LINUX/include search paths to allow proper compilation when the kernel target build directory is not the source directory. --- module/spl/spl-generic.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'module/spl/spl-generic.c') diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c index 96a14c62e..c23abf6ff 100644 --- a/module/spl/spl-generic.c +++ b/module/spl/spl-generic.c @@ -54,6 +54,10 @@ EXPORT_SYMBOL(hw_serial); int p0 = 0; EXPORT_SYMBOL(p0); +#ifndef HAVE_KALLSYMS_LOOKUP_NAME +kallsyms_lookup_name_t spl_kallsyms_lookup_name_fn = NULL; +#endif + int highbit(unsigned long i) { @@ -269,6 +273,42 @@ zone_get_hostid(void *zone) } EXPORT_SYMBOL(zone_get_hostid); +#ifdef HAVE_KALLSYMS_LOOKUP_NAME +#define set_kallsyms_lookup_name() (0) +#else +/* + * 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 \ + "awk '{ if ( $3 == \"kallsyms_lookup_name\") { print $1 } }' " \ + "/proc/kallsyms >/proc/sys/kernel/spl/kallsyms_lookup_name" + +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) + return rc; + + return spl_kmem_init_kallsyms_lookup(); +} +#endif + static int __init spl_init(void) { int rc = 0; @@ -297,6 +337,9 @@ static int __init spl_init(void) if ((rc = set_hostid())) GOTO(out7, rc = -EADDRNOTAVAIL); + if ((rc = set_kallsyms_lookup_name())) + GOTO(out7, rc = -EADDRNOTAVAIL); + printk("SPL: Loaded Solaris Porting Layer v%s\n", VERSION); RETURN(rc); out7: -- cgit v1.2.3