[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18: consolidate and simplify struct xenbus_driver instantiation



The 'name' and 'owner' members are redundant with the identically named
fields in the 'driver' sub-structure. Rather than switching each
instance to specify these fields explicitly, introduce a macro to
simplify this (and at once to abstract out - for the unmodified drivers
build - the absence of the 'owner' field in Linux prior to 2.6.10).

Also add a module alias for the vtpm frontend driver (overlooked in
141:5e294e29a43e).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/drivers/char/tpm/tpm_xen.c
+++ b/drivers/char/tpm/tpm_xen.c
@@ -475,26 +475,24 @@ static int tpmif_connect(struct xenbus_d
        return 0;
 }
 
-static struct xenbus_device_id tpmfront_ids[] = {
+static const struct xenbus_device_id tpmfront_ids[] = {
        { "vtpm" },
        { "" }
 };
+MODULE_ALIAS("xen:vtpm");
 
-static struct xenbus_driver tpmfront = {
-       .name = "vtpm",
-       .owner = THIS_MODULE,
-       .ids = tpmfront_ids,
+static DEFINE_XENBUS_DRIVER(tpmfront, "vtpm",
        .probe = tpmfront_probe,
        .remove =  tpmfront_remove,
        .resume = tpmfront_resume,
        .otherend_changed = backend_changed,
        .suspend = tpmfront_suspend,
        .suspend_cancel = tpmfront_suspend_cancel,
-};
+);
 
 static void __init init_tpm_xenbus(void)
 {
-       xenbus_register_frontend(&tpmfront);
+       xenbus_register_frontend(&tpmfront_driver);
 }
 
 static int tpmif_allocate_tx_buffers(struct tpm_private *tp)
--- a/drivers/xen/blkback/xenbus.c
+++ b/drivers/xen/blkback/xenbus.c
@@ -542,18 +542,14 @@ static const struct xenbus_device_id blk
        { "" }
 };
 
-
-static struct xenbus_driver blkback = {
-       .name = "vbd",
-       .owner = THIS_MODULE,
-       .ids = blkback_ids,
+static DEFINE_XENBUS_DRIVER(blkback, "vbd",
        .probe = blkback_probe,
        .remove = blkback_remove,
        .otherend_changed = frontend_changed
-};
+);
 
 
 void blkif_xenbus_init(void)
 {
-       xenbus_register_backend(&blkback);
+       xenbus_register_backend(&blkback_driver);
 }
--- a/drivers/xen/blkfront/blkfront.c
+++ b/drivers/xen/blkfront/blkfront.c
@@ -934,16 +934,13 @@ static const struct xenbus_device_id blk
 };
 MODULE_ALIAS("xen:vbd");
 
-static struct xenbus_driver blkfront = {
-       .name = "vbd",
-       .owner = THIS_MODULE,
-       .ids = blkfront_ids,
+static DEFINE_XENBUS_DRIVER(blkfront, "vbd",
        .probe = blkfront_probe,
        .remove = blkfront_remove,
        .resume = blkfront_resume,
        .otherend_changed = backend_changed,
        .is_ready = blkfront_is_ready,
-};
+);
 
 
 static int __init xlblk_init(void)
@@ -951,14 +948,14 @@ static int __init xlblk_init(void)
        if (!is_running_on_xen())
                return -ENODEV;
 
-       return xenbus_register_frontend(&blkfront);
+       return xenbus_register_frontend(&blkfront_driver);
 }
 module_init(xlblk_init);
 
 
 static void __exit xlblk_exit(void)
 {
-       return xenbus_unregister_driver(&blkfront);
+       return xenbus_unregister_driver(&blkfront_driver);
 }
 module_exit(xlblk_exit);
 
--- a/drivers/xen/blktap/xenbus.c
+++ b/drivers/xen/blktap/xenbus.c
@@ -490,18 +490,14 @@ static const struct xenbus_device_id blk
        { "" }
 };
 
-
-static struct xenbus_driver blktap = {
-       .name = "tap",
-       .owner = THIS_MODULE,
-       .ids = blktap_ids,
+static DEFINE_XENBUS_DRIVER(blktap, "tap",
        .probe = blktap_probe,
        .remove = blktap_remove,
        .otherend_changed = tap_frontend_changed
-};
+);
 
 
 void tap_blkif_xenbus_init(void)
 {
-       xenbus_register_backend(&blktap);
+       xenbus_register_backend(&blktap_driver);
 }
--- a/drivers/xen/fbfront/xenfb.c
+++ b/drivers/xen/fbfront/xenfb.c
@@ -857,15 +857,12 @@ static const struct xenbus_device_id xen
 };
 MODULE_ALIAS("xen:vfb");
 
-static struct xenbus_driver xenfb_driver = {
-       .name = "vfb",
-       .owner = THIS_MODULE,
-       .ids = xenfb_ids,
+static DEFINE_XENBUS_DRIVER(xenfb, "vfb",
        .probe = xenfb_probe,
        .remove = xenfb_remove,
        .resume = xenfb_resume,
        .otherend_changed = xenfb_backend_changed,
-};
+);
 
 static int __init xenfb_init(void)
 {
--- a/drivers/xen/fbfront/xenkbd.c
+++ b/drivers/xen/fbfront/xenkbd.c
@@ -335,15 +335,12 @@ static const struct xenbus_device_id xen
 };
 MODULE_ALIAS("xen:vkbd");
 
-static struct xenbus_driver xenkbd_driver = {
-       .name = "vkbd",
-       .owner = THIS_MODULE,
-       .ids = xenkbd_ids,
+static DEFINE_XENBUS_DRIVER(xenkbd, "vkbd",
        .probe = xenkbd_probe,
        .remove = xenkbd_remove,
        .resume = xenkbd_resume,
        .otherend_changed = xenkbd_backend_changed,
-};
+);
 
 static int __init xenkbd_init(void)
 {
--- a/drivers/xen/netback/xenbus.c
+++ b/drivers/xen/netback/xenbus.c
@@ -437,19 +437,15 @@ static const struct xenbus_device_id net
        { "" }
 };
 
-
-static struct xenbus_driver netback = {
-       .name = "vif",
-       .owner = THIS_MODULE,
-       .ids = netback_ids,
+static DEFINE_XENBUS_DRIVER(netback, "vif",
        .probe = netback_probe,
        .remove = netback_remove,
        .uevent = netback_uevent,
        .otherend_changed = frontend_changed,
-};
+);
 
 
 void netif_xenbus_init(void)
 {
-       xenbus_register_backend(&netback);
+       xenbus_register_backend(&netback_driver);
 }
--- a/drivers/xen/netfront/netfront.c
+++ b/drivers/xen/netfront/netfront.c
@@ -2197,18 +2197,14 @@ static const struct xenbus_device_id net
 };
 MODULE_ALIAS("xen:vif");
 
-
-static struct xenbus_driver netfront_driver = {
-       .name = "vif",
-       .owner = THIS_MODULE,
-       .ids = netfront_ids,
+static DEFINE_XENBUS_DRIVER(netfront, "vif",
        .probe = netfront_probe,
        .remove = __devexit_p(netfront_remove),
        .suspend = netfront_suspend,
        .suspend_cancel = netfront_suspend_cancel,
        .resume = netfront_resume,
        .otherend_changed = backend_changed,
-};
+);
 
 
 static int __init netif_init(void)
--- a/drivers/xen/pciback/xenbus.c
+++ b/drivers/xen/pciback/xenbus.c
@@ -676,19 +676,16 @@ static int pciback_xenbus_remove(struct 
        return 0;
 }
 
-static const struct xenbus_device_id xenpci_ids[] = {
+static const struct xenbus_device_id pciback_ids[] = {
        {"pci"},
        {{0}},
 };
 
-static struct xenbus_driver xenbus_pciback_driver = {
-       .name                   = "pciback",
-       .owner                  = THIS_MODULE,
-       .ids                    = xenpci_ids,
+static DEFINE_XENBUS_DRIVER(pciback, "pciback",
        .probe                  = pciback_xenbus_probe,
        .remove                 = pciback_xenbus_remove,
        .otherend_changed       = pciback_frontend_changed,
-};
+);
 
 int __init pciback_xenbus_register(void)
 {
@@ -700,11 +697,11 @@ int __init pciback_xenbus_register(void)
                        "pciback_workqueue failed\n");
                return -EFAULT;
        }
-       return xenbus_register_backend(&xenbus_pciback_driver);
+       return xenbus_register_backend(&pciback_driver);
 }
 
 void __exit pciback_xenbus_unregister(void)
 {
        destroy_workqueue(pciback_wq);
-       xenbus_unregister_driver(&xenbus_pciback_driver);
+       xenbus_unregister_driver(&pciback_driver);
 }
--- a/drivers/xen/pcifront/xenbus.c
+++ b/drivers/xen/pcifront/xenbus.c
@@ -456,27 +456,24 @@ static int pcifront_xenbus_remove(struct
        return 0;
 }
 
-static const struct xenbus_device_id xenpci_ids[] = {
+static const struct xenbus_device_id pcifront_ids[] = {
        {"pci"},
        {{0}},
 };
 MODULE_ALIAS("xen:pci");
 
-static struct xenbus_driver xenbus_pcifront_driver = {
-       .name                   = "pcifront",
-       .owner                  = THIS_MODULE,
-       .ids                    = xenpci_ids,
+static DEFINE_XENBUS_DRIVER(pcifront, "pcifront",
        .probe                  = pcifront_xenbus_probe,
        .remove                 = pcifront_xenbus_remove,
        .otherend_changed       = pcifront_backend_changed,
-};
+);
 
 static int __init pcifront_init(void)
 {
        if (!is_running_on_xen())
                return -ENODEV;
 
-       return xenbus_register_frontend(&xenbus_pcifront_driver);
+       return xenbus_register_frontend(&pcifront_driver);
 }
 
 /* Initialize after the Xen PCI Frontend Stub is initialized */
--- a/drivers/xen/scsiback/xenbus.c
+++ b/drivers/xen/scsiback/xenbus.c
@@ -352,26 +352,23 @@ fail:
 }
 
 
-static struct xenbus_device_id scsiback_ids[] = {
+static const struct xenbus_device_id scsiback_ids[] = {
        { "vscsi" },
        { "" }
 };
 
-static struct xenbus_driver scsiback = {
-       .name                   = "vscsi",
-       .owner                  = THIS_MODULE,
-       .ids                    = scsiback_ids,
+static DEFINE_XENBUS_DRIVER(scsiback, "vscsi",
        .probe                  = scsiback_probe,
        .remove                 = scsiback_remove,
        .otherend_changed       = scsiback_frontend_changed
-};
+);
 
 int scsiback_xenbus_init(void)
 {
-       return xenbus_register_backend(&scsiback);
+       return xenbus_register_backend(&scsiback_driver);
 }
 
 void scsiback_xenbus_unregister(void)
 {
-       xenbus_unregister_driver(&scsiback);
+       xenbus_unregister_driver(&scsiback_driver);
 }
--- a/drivers/xen/scsifront/xenbus.c
+++ b/drivers/xen/scsifront/xenbus.c
@@ -398,21 +398,18 @@ static void scsifront_backend_changed(st
 }
 
 
-static struct xenbus_device_id scsifront_ids[] = {
+static const struct xenbus_device_id scsifront_ids[] = {
        { "vscsi" },
        { "" }
 };
 MODULE_ALIAS("xen:vscsi");
 
-static struct xenbus_driver scsifront_driver = {
-       .name                   = "vscsi",
-       .owner                  = THIS_MODULE,
-       .ids                    = scsifront_ids,
+static DEFINE_XENBUS_DRIVER(scsifront, "vscsi",
        .probe                  = scsifront_probe,
        .remove                 = scsifront_remove,
 /*     .resume                 = scsifront_resume, */
        .otherend_changed       = scsifront_backend_changed,
-};
+);
 
 int scsifront_xenbus_init(void)
 {
--- a/drivers/xen/tpmback/xenbus.c
+++ b/drivers/xen/tpmback/xenbus.c
@@ -251,23 +251,19 @@ static const struct xenbus_device_id tpm
        { "" }
 };
 
-
-static struct xenbus_driver tpmback = {
-       .name = "vtpm",
-       .owner = THIS_MODULE,
-       .ids = tpmback_ids,
+static DEFINE_XENBUS_DRIVER(tpmback, "vtpm",
        .probe = tpmback_probe,
        .remove = tpmback_remove,
        .otherend_changed = frontend_changed,
-};
+);
 
 
 void tpmif_xenbus_init(void)
 {
-       xenbus_register_backend(&tpmback);
+       xenbus_register_backend(&tpmback_driver);
 }
 
 void tpmif_xenbus_exit(void)
 {
-       xenbus_unregister_driver(&tpmback);
+       xenbus_unregister_driver(&tpmback_driver);
 }
--- a/drivers/xen/usbback/xenbus.c
+++ b/drivers/xen/usbback/xenbus.c
@@ -317,14 +317,11 @@ static const struct xenbus_device_id usb
        { "" },
 };
 
-static struct xenbus_driver usbback_driver = {
-       .name = "vusb",
-       .owner = THIS_MODULE,
-       .ids = usbback_ids,
+static DEFINE_XENBUS_DRIVER(usbback, "vusb",
        .probe = usbback_probe,
        .otherend_changed = frontend_changed,
        .remove = usbback_remove,
-};
+);
 
 int __init usbback_xenbus_init(void)
 {
--- a/drivers/xen/usbfront/xenbus.c
+++ b/drivers/xen/usbfront/xenbus.c
@@ -379,14 +379,11 @@ static const struct xenbus_device_id usb
 };
 MODULE_ALIAS("xen:vusb");
 
-static struct xenbus_driver usbfront_driver = {
-       .name = "vusb",
-       .owner = THIS_MODULE,
-       .ids = usbfront_ids,
+static DEFINE_XENBUS_DRIVER(usbfront, "vusb",
        .probe = usbfront_probe,
        .otherend_changed = backend_changed,
        .remove = usbfront_remove,
-};
+);
 
 static int __init usbfront_init(void)
 {
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -382,11 +382,7 @@ int xenbus_register_driver_common(struct
        if (bus->error)
                return bus->error;
 
-       drv->driver.name = drv->name;
        drv->driver.bus = &bus->bus;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
-       drv->driver.owner = drv->owner;
-#endif
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16)
        drv->driver.probe = xenbus_dev_probe;
        drv->driver.remove = xenbus_dev_remove;
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -40,6 +40,7 @@
 #include <linux/completion.h>
 #include <linux/init.h>
 #include <linux/err.h>
+#include <linux/version.h>
 #include <xen/interface/xen.h>
 #include <xen/interface/grant_table.h>
 #include <xen/interface/io/xenbus.h>
@@ -93,8 +94,6 @@ struct xenbus_device_id
 
 /* A xenbus driver. */
 struct xenbus_driver {
-       char *name;
-       struct module *owner;
        const struct xenbus_device_id *ids;
        int (*probe)(struct xenbus_device *dev,
                     const struct xenbus_device_id *id);
@@ -110,6 +109,19 @@ struct xenbus_driver {
        int (*is_ready)(struct xenbus_device *dev);
 };
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
+# define XENBUS_DRIVER_SET_OWNER(mod) .driver.owner = mod,
+#else
+# define XENBUS_DRIVER_SET_OWNER(mod)
+#endif
+
+#define DEFINE_XENBUS_DRIVER(var, drvname, methods...) \
+struct xenbus_driver var ## _driver = {                        \
+       .driver.name = drvname,                         \
+       XENBUS_DRIVER_SET_OWNER(THIS_MODULE)            \
+       .ids = var ## _ids, ## methods                  \
+}
+
 static inline struct xenbus_driver *to_xenbus_driver(struct device_driver *drv)
 {
        return container_of(drv, struct xenbus_driver, driver);


Attachment: xen-xenbus-driver-cleanup.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.