[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [linux-2.6.18-xen] consolidate and simplify struct xenbus_driver instantiation
# HG changeset patch # User Jan Beulich <jbeulich@xxxxxxxx> # Date 1324285700 -3600 # Node ID a7851a465b41332cf7871cc41fe7a95580816ed9 # Parent 0639ecd91ca3399f3d13d16cbe2fd832237fff1e 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). v2: Eliminate further redundancy by allowing the drvname argument to DEFINE_XENBUS_DRIVER() to be blank (in which case the first entry from the ID table will be used for .driver.name). Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- diff -r 0639ecd91ca3 -r a7851a465b41 drivers/char/tpm/tpm_xen.c --- a/drivers/char/tpm/tpm_xen.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/char/tpm/tpm_xen.c Mon Dec 19 10:08:20 2011 +0100 @@ -475,26 +475,24 @@ 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, , .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) +static int __init init_tpm_xenbus(void) { - xenbus_register_frontend(&tpmfront); + return xenbus_register_frontend(&tpmfront_driver); } static int tpmif_allocate_tx_buffers(struct tpm_private *tp) diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/blkback/xenbus.c --- a/drivers/xen/blkback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/blkback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -542,18 +542,14 @@ { "" } }; - -static struct xenbus_driver blkback = { - .name = "vbd", - .owner = THIS_MODULE, - .ids = blkback_ids, +static DEFINE_XENBUS_DRIVER(blkback, , .probe = blkback_probe, .remove = blkback_remove, .otherend_changed = frontend_changed -}; +); void blkif_xenbus_init(void) { - xenbus_register_backend(&blkback); + WARN_ON(xenbus_register_backend(&blkback_driver)); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/blkfront/blkfront.c --- a/drivers/xen/blkfront/blkfront.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/blkfront/blkfront.c Mon Dec 19 10:08:20 2011 +0100 @@ -934,16 +934,13 @@ }; MODULE_ALIAS("xen:vbd"); -static struct xenbus_driver blkfront = { - .name = "vbd", - .owner = THIS_MODULE, - .ids = blkfront_ids, +static DEFINE_XENBUS_DRIVER(blkfront, , .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 @@ 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); diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/blktap/xenbus.c --- a/drivers/xen/blktap/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/blktap/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -490,18 +490,14 @@ { "" } }; - -static struct xenbus_driver blktap = { - .name = "tap", - .owner = THIS_MODULE, - .ids = blktap_ids, +static DEFINE_XENBUS_DRIVER(blktap, , .probe = blktap_probe, .remove = blktap_remove, .otherend_changed = tap_frontend_changed -}; +); void tap_blkif_xenbus_init(void) { - xenbus_register_backend(&blktap); + WARN_ON(xenbus_register_backend(&blktap_driver)); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/fbfront/xenfb.c --- a/drivers/xen/fbfront/xenfb.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/fbfront/xenfb.c Mon Dec 19 10:08:20 2011 +0100 @@ -857,15 +857,12 @@ }; MODULE_ALIAS("xen:vfb"); -static struct xenbus_driver xenfb_driver = { - .name = "vfb", - .owner = THIS_MODULE, - .ids = xenfb_ids, +static DEFINE_XENBUS_DRIVER(xenfb, , .probe = xenfb_probe, .remove = xenfb_remove, .resume = xenfb_resume, .otherend_changed = xenfb_backend_changed, -}; +); static int __init xenfb_init(void) { diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/fbfront/xenkbd.c --- a/drivers/xen/fbfront/xenkbd.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/fbfront/xenkbd.c Mon Dec 19 10:08:20 2011 +0100 @@ -335,15 +335,12 @@ }; MODULE_ALIAS("xen:vkbd"); -static struct xenbus_driver xenkbd_driver = { - .name = "vkbd", - .owner = THIS_MODULE, - .ids = xenkbd_ids, +static DEFINE_XENBUS_DRIVER(xenkbd, , .probe = xenkbd_probe, .remove = xenkbd_remove, .resume = xenkbd_resume, .otherend_changed = xenkbd_backend_changed, -}; +); static int __init xenkbd_init(void) { diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/netback/xenbus.c --- a/drivers/xen/netback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/netback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -437,19 +437,15 @@ { "" } }; - -static struct xenbus_driver netback = { - .name = "vif", - .owner = THIS_MODULE, - .ids = netback_ids, +static DEFINE_XENBUS_DRIVER(netback, , .probe = netback_probe, .remove = netback_remove, .uevent = netback_uevent, .otherend_changed = frontend_changed, -}; +); void netif_xenbus_init(void) { - xenbus_register_backend(&netback); + WARN_ON(xenbus_register_backend(&netback_driver)); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/netfront/netfront.c --- a/drivers/xen/netfront/netfront.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/netfront/netfront.c Mon Dec 19 10:08:20 2011 +0100 @@ -2197,18 +2197,14 @@ }; MODULE_ALIAS("xen:vif"); - -static struct xenbus_driver netfront_driver = { - .name = "vif", - .owner = THIS_MODULE, - .ids = netfront_ids, +static DEFINE_XENBUS_DRIVER(netfront, , .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) diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/pciback/xenbus.c --- a/drivers/xen/pciback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/pciback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -676,19 +676,16 @@ 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 @@ "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); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/pcifront/xenbus.c --- a/drivers/xen/pcifront/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/pcifront/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -456,27 +456,24 @@ 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 */ diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/scsiback/xenbus.c --- a/drivers/xen/scsiback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/scsiback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -352,26 +352,23 @@ } -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, , .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); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/scsifront/xenbus.c --- a/drivers/xen/scsifront/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/scsifront/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -398,21 +398,18 @@ } -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, , .probe = scsifront_probe, .remove = scsifront_remove, /* .resume = scsifront_resume, */ .otherend_changed = scsifront_backend_changed, -}; +); int scsifront_xenbus_init(void) { diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/tpmback/common.h --- a/drivers/xen/tpmback/common.h Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/tpmback/common.h Mon Dec 19 10:08:20 2011 +0100 @@ -67,7 +67,7 @@ void tpmif_interface_exit(void); void tpmif_schedule_work(tpmif_t * tpmif); void tpmif_deschedule_work(tpmif_t * tpmif); -void tpmif_xenbus_init(void); +int tpmif_xenbus_init(void); void tpmif_xenbus_exit(void); int tpmif_map(tpmif_t *, grant_ref_t, evtchn_port_t); irqreturn_t tpmif_be_int(int irq, void *dev_id, struct pt_regs *regs); diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/tpmback/xenbus.c --- a/drivers/xen/tpmback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/tpmback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -251,23 +251,19 @@ { "" } }; - -static struct xenbus_driver tpmback = { - .name = "vtpm", - .owner = THIS_MODULE, - .ids = tpmback_ids, +static DEFINE_XENBUS_DRIVER(tpmback, , .probe = tpmback_probe, .remove = tpmback_remove, .otherend_changed = frontend_changed, -}; +); -void tpmif_xenbus_init(void) +int tpmif_xenbus_init(void) { - xenbus_register_backend(&tpmback); + return xenbus_register_backend(&tpmback_driver); } void tpmif_xenbus_exit(void) { - xenbus_unregister_driver(&tpmback); + xenbus_unregister_driver(&tpmback_driver); } diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/usbback/xenbus.c --- a/drivers/xen/usbback/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/usbback/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -317,14 +317,11 @@ { "" }, }; -static struct xenbus_driver usbback_driver = { - .name = "vusb", - .owner = THIS_MODULE, - .ids = usbback_ids, +static DEFINE_XENBUS_DRIVER(usbback, , .probe = usbback_probe, .otherend_changed = frontend_changed, .remove = usbback_remove, -}; +); int __init usbback_xenbus_init(void) { diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/usbfront/xenbus.c --- a/drivers/xen/usbfront/xenbus.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/usbfront/xenbus.c Mon Dec 19 10:08:20 2011 +0100 @@ -379,14 +379,11 @@ }; MODULE_ALIAS("xen:vusb"); -static struct xenbus_driver usbfront_driver = { - .name = "vusb", - .owner = THIS_MODULE, - .ids = usbfront_ids, +static DEFINE_XENBUS_DRIVER(usbfront, , .probe = usbfront_probe, .otherend_changed = backend_changed, .remove = usbfront_remove, -}; +); static int __init usbfront_init(void) { diff -r 0639ecd91ca3 -r a7851a465b41 drivers/xen/xenbus/xenbus_probe.c --- a/drivers/xen/xenbus/xenbus_probe.c Wed Dec 14 11:04:22 2011 +0100 +++ b/drivers/xen/xenbus/xenbus_probe.c Mon Dec 19 10:08:20 2011 +0100 @@ -382,11 +382,7 @@ 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; diff -r 0639ecd91ca3 -r a7851a465b41 include/xen/xenbus.h --- a/include/xen/xenbus.h Wed Dec 14 11:04:22 2011 +0100 +++ b/include/xen/xenbus.h Mon Dec 19 10:08:20 2011 +0100 @@ -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 @@ /* 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 @@ 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 + 0 ?: var ## _ids->devicetype, \ + 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); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |