From: behlendo Date: Sun, 10 Aug 2008 03:50:36 +0000 (+0000) Subject: Add class / device portability code. Two autoconf tests X-Git-Tag: zfs-0.8.0-rc1~152^2~838 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46c685d0c47df8c6271c8914a03d256a5b1f7bd3;p=zfs Add class / device portability code. Two autoconf tests were added to cover the 3 possible APIs from 2.6.9 to 2.6.26. We attempt to use the newest interfaces and if not available fallback to the oldest. This a rework of some changes proposed by Ricardo for RHEL4. git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@150 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c --- diff --git a/autoconf/spl-build.m4 b/autoconf/spl-build.m4 index b311902e9..cb782f9d4 100644 --- a/autoconf/spl-build.m4 +++ b/autoconf/spl-build.m4 @@ -457,3 +457,31 @@ AC_DEFUN([SPL_AC_FLS64], AC_MSG_RESULT(no) ]) ]) + +dnl # +dnl # 2.6.18 API change, check whether device_create() is available. +dnl # Device_create() was introduced in 2.6.18 and depricated +dnl # class_device_create() which was fully removed in 2.6.26. +dnl # +AC_DEFUN([SPL_AC_DEVICE_CREATE], [ + SPL_CHECK_SYMBOL_EXPORT( + [device_create], + [drivers/base/core.c], + [AC_DEFINE(HAVE_DEVICE_CREATE, 1, + [device_create() is available])], + []) +]) + +dnl # +dnl # 2.6.13 API change, check whether class_device_create() is available. +dnl # Class_device_create() was introduced in 2.6.13 and depricated +dnl # class_simple_device_add() which was fully removed in 2.6.13. +dnl # +AC_DEFUN([SPL_AC_CLASS_DEVICE_CREATE], [ + SPL_CHECK_SYMBOL_EXPORT( + [class_device_create], + [drivers/base/class.c], + [AC_DEFINE(HAVE_CLASS_DEVICE_CREATE, 1, + [class_device_create() is available])], + []) +]) diff --git a/configure.ac b/configure.ac index 99d341a66..1e8c4c0f5 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,8 @@ SPL_AC_PATH_IN_NAMEIDATA SPL_AC_TASK_CURR SPL_AC_CTL_UNNUMBERED SPL_AC_FLS64 +SPL_AC_DEVICE_CREATE +SPL_AC_CLASS_DEVICE_CREATE TOPDIR=`/bin/pwd` diff --git a/include/spl-device.h b/include/spl-device.h new file mode 100644 index 000000000..2bbd299b8 --- /dev/null +++ b/include/spl-device.h @@ -0,0 +1,53 @@ +#ifndef _SPL_DEVICE_H +#define _SPL_DEVICE_H + +#include + +/* + * Preferred API from 2.6.18 to 2.6.26+ + */ +#ifdef HAVE_DEVICE_CREATE + +typedef struct class spl_class; + +#define spl_class_create(mod, name) class_create(mod, name) +#define spl_class_destroy(cls) class_destroy(cls) +#define spl_device_create(cls, parent, devt, device, fmt, args...) \ + device_create(cls, parent, devt, fmt, ## args) +#define spl_device_destroy(cls, devt) device_destroy(cls, devt) + +/* + * Preferred API from 2.6.13 to 2.6.17 + * Depricated in 2.6.18 + * Removed in 2.6.26 + */ +#else +#ifdef HAVE_CLASS_DEVICE_CREATE + +typedef struct class spl_class; + +#define spl_class_create(mod, name) class_create(mod, name) +#define spl_class_destroy(cls) class_destroy(cls) +#define spl_device_create(cls, parent, devt, device, fmt, args...) \ + class_device_create(cls, parent, devt, device, fmt, ## args) +#define spl_device_destroy(cls, devt) class_device_destroy(cls, devt) + +/* + * Prefered API from 2.6.0 to 2.6.12 + * Depricated in 2.6.13 + * Removed in 2.6.13 + */ +#else /* Legacy API */ + +typedef struct class_simple spl_class; + +#define spl_class_create(mod, name) class_simple_create(mod, name) +#define spl_class_destroy(cls) class_simple_destroy(cls) +#define spl_device_create(cls, parent, devt, device, fmt, args...) \ + class_simple_device_add(cls, devt, device, fmt, ## args) +#define spl_device_destroy(cls, devt) class_simple_device_remove(devt) + +#endif +#endif + +#endif /* _SPL_DEVICE_H */ diff --git a/include/splat-ctl.h b/include/splat-ctl.h index bd7fdb658..7f2c6d94d 100644 --- a/include/splat-ctl.h +++ b/include/splat-ctl.h @@ -33,6 +33,7 @@ #define SPLAT_MAJOR 229 /* XXX - Arbitrary */ #define SPLAT_MINORS 1 +#define SPLAT_NAME "splatctl" #define SPLAT_DEV "/dev/splatctl" #define SPLAT_NAME_SIZE 12 diff --git a/include/sys/sunddi.h b/include/sys/sunddi.h index a80ae454d..764ae3820 100644 --- a/include/sys/sunddi.h +++ b/include/sys/sunddi.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include typedef int ddi_devid_t; @@ -81,7 +81,7 @@ typedef struct dev_info { kmutex_t di_lock; struct dev_ops *di_ops; struct cdev *di_cdev; - struct class *di_class; + spl_class *di_class; major_t di_major; minor_t di_minor; dev_t di_dev; diff --git a/modules/spl/spl-module.c b/modules/spl/spl-module.c index a1c31e182..19c5db2cd 100644 --- a/modules/spl/spl-module.c +++ b/modules/spl/spl-module.c @@ -153,7 +153,7 @@ __ddi_create_minor_node(dev_info_t *di, char *name, int spec_type, RETURN(DDI_FAILURE); } - di->di_class = class_create(THIS_MODULE, name); + di->di_class = spl_class_create(THIS_MODULE, name); if (IS_ERR(di->di_class)) { rc = PTR_ERR(di->di_class); CERROR("Error creating %s class, %d\n", name, rc); @@ -165,11 +165,11 @@ __ddi_create_minor_node(dev_info_t *di, char *name, int spec_type, /* Do not append a 0 to devices with minor nums of 0 */ if (di->di_minor == 0) { - class_device_create(di->di_class, NULL, di->di_dev, - NULL, "%s", name); + spl_device_create(di->di_class, NULL, di->di_dev, + NULL, "%s", name); } else { - class_device_create(di->di_class, NULL, di->di_dev, - NULL, "%s%d", name, di->di_minor); + spl_device_create(di->di_class, NULL, di->di_dev, + NULL, "%s%d", name, di->di_minor); } di->di_cdev = cdev; @@ -188,8 +188,8 @@ static void __ddi_remove_minor_node_locked(dev_info_t *di, char *name) { if (di->di_class) { - class_device_destroy(di->di_class, di->di_dev); - class_destroy(di->di_class); + spl_device_destroy(di->di_class, di->di_dev); + spl_class_destroy(di->di_class); di->di_class = NULL; di->di_dev = 0; diff --git a/modules/splat/splat-ctl.c b/modules/splat/splat-ctl.c index f29a98dfa..0c8b673d9 100644 --- a/modules/splat/splat-ctl.c +++ b/modules/splat/splat-ctl.c @@ -42,18 +42,7 @@ #include "splat-internal.h" -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) -#include -#endif - -#include - - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) -static struct class_simple *splat_class; -#else -static struct class *splat_class; -#endif +static spl_class *splat_class; static struct list_head splat_module_list; static spinlock_t splat_module_lock; @@ -594,7 +583,7 @@ static struct file_operations splat_fops = { static struct cdev splat_cdev = { .owner = THIS_MODULE, - .kobj = { .name = "splatctl", }, + .kobj = { .name = SPLAT_NAME, }, }; static int __init @@ -619,7 +608,7 @@ splat_init(void) SPLAT_SUBSYSTEM_INIT(atomic); dev = MKDEV(SPLAT_MAJOR, 0); - if ((rc = register_chrdev_region(dev, SPLAT_MINORS, "splatctl"))) + if ((rc = register_chrdev_region(dev, SPLAT_MINORS, SPLAT_NAME))) goto error; /* Support for registering a character driver */ @@ -632,11 +621,7 @@ splat_init(void) } /* Support for udev make driver info available in sysfs */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) - splat_class = class_simple_create(THIS_MODULE, "splat"); -#else - splat_class = class_create(THIS_MODULE, "splat"); -#endif + splat_class = spl_class_create(THIS_MODULE, "splat"); if (IS_ERR(splat_class)) { rc = PTR_ERR(splat_class); printk(KERN_ERR "splat: Error creating splat class, %d\n", rc); @@ -645,13 +630,8 @@ splat_init(void) goto error; } -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) - class_simple_device_add(splat_class, MKDEV(SPLAT_MAJOR, 0), - NULL, "splatctl"); -#else - class_device_create(splat_class, NULL, MKDEV(SPLAT_MAJOR, 0), - NULL, "splatctl"); -#endif + spl_device_create(splat_class, NULL, MKDEV(SPLAT_MAJOR, 0), + NULL, SPLAT_NAME); printk(KERN_INFO "splat: Loaded Solaris Porting LAyer " "Tests v%s\n", VERSION); @@ -666,15 +646,8 @@ splat_fini(void) { dev_t dev = MKDEV(SPLAT_MAJOR, 0); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) - class_simple_device_remove(dev); - class_simple_destroy(splat_class); - devfs_remove("splat/splatctl"); - devfs_remove("splat"); -#else - class_device_destroy(splat_class, dev); - class_destroy(splat_class); -#endif + spl_device_destroy(splat_class, dev); + spl_class_destroy(splat_class); cdev_del(&splat_cdev); unregister_chrdev_region(dev, SPLAT_MINORS); diff --git a/modules/splat/splat-internal.h b/modules/splat/splat-internal.h index af5fc6e57..8a7447685 100644 --- a/modules/splat/splat-internal.h +++ b/modules/splat/splat-internal.h @@ -60,7 +60,9 @@ #include #include #include +#include +#include "spl-device.h" #include "splat-ctl.h" #define SPLAT_SUBSYSTEM_INIT(type) \