ia64/xen-unstable
changeset 7257:2a3e10a132a2
The attached fixes a few things to make the blkfront and netfront
drivers better follow the Linux driver model. Changes include:
* Rename xenbus_register functions to more closely match what's used
with other buses. Adjust callers
* There's no need to wait for the first vbd of vif and do a timeout if
they fail, device probing is async
* Add sysfs attributes for examining type and nodename
* Set device of gendisk so /sys/block/foo/device points to the right
place
* Set device of net_device so that /sys/class/net/foo/device points to
the right place
Signed-off-by: Jeremy Katz <katzj@redhat.com>
drivers better follow the Linux driver model. Changes include:
* Rename xenbus_register functions to more closely match what's used
with other buses. Adjust callers
* There's no need to wait for the first vbd of vif and do a timeout if
they fail, device probing is async
* Add sysfs attributes for examining type and nodename
* Set device of gendisk so /sys/block/foo/device points to the right
place
* Set device of net_device so that /sys/class/net/foo/device points to
the right place
Signed-off-by: Jeremy Katz <katzj@redhat.com>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Fri Oct 07 11:16:28 2005 +0100 (2005-10-07) |
parents | 8b0958155380 |
children | 5eda9308b0ca b5c5360a61d0 |
files | linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/include/asm-xen/xenbus.h |
line diff
1.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Fri Oct 07 11:04:41 2005 +0100 1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Fri Oct 07 11:16:28 2005 +0100 1.3 @@ -53,8 +53,6 @@ 1.4 #define BLKIF_STATE_DISCONNECTED 0 1.5 #define BLKIF_STATE_CONNECTED 1 1.6 1.7 -static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED; 1.8 - 1.9 #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ 1.10 (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) 1.11 #define GRANT_INVALID_REF 0 1.12 @@ -472,8 +470,6 @@ static void watch_for_status(struct xenb 1.13 info->connected = BLKIF_STATE_CONNECTED; 1.14 xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); 1.15 1.16 - blkif_state = BLKIF_STATE_CONNECTED; 1.17 - 1.18 xenbus_dev_ok(info->xbdev); 1.19 1.20 /* Kick pending requests. */ 1.21 @@ -716,29 +712,7 @@ static struct xenbus_driver blkfront = { 1.22 1.23 static void __init init_blk_xenbus(void) 1.24 { 1.25 - xenbus_register_device(&blkfront); 1.26 -} 1.27 - 1.28 -static int wait_for_blkif(void) 1.29 -{ 1.30 - int err = 0; 1.31 - int i; 1.32 - 1.33 - /* 1.34 - * We should figure out how many and which devices we need to 1.35 - * proceed and only wait for those. For now, continue once the 1.36 - * first device is around. 1.37 - */ 1.38 - for (i = 0; blkif_state != BLKIF_STATE_CONNECTED && (i < 10*HZ); i++) { 1.39 - set_current_state(TASK_INTERRUPTIBLE); 1.40 - schedule_timeout(1); 1.41 - } 1.42 - 1.43 - if (blkif_state != BLKIF_STATE_CONNECTED) { 1.44 - WPRINTK("Timeout connecting to device!\n"); 1.45 - err = -ENOSYS; 1.46 - } 1.47 - return err; 1.48 + xenbus_register_driver(&blkfront); 1.49 } 1.50 1.51 static int __init xlblk_init(void) 1.52 @@ -751,8 +725,6 @@ static int __init xlblk_init(void) 1.53 1.54 init_blk_xenbus(); 1.55 1.56 - wait_for_blkif(); 1.57 - 1.58 return 0; 1.59 } 1.60
2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Fri Oct 07 11:04:41 2005 +0100 2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Fri Oct 07 11:16:28 2005 +0100 2.3 @@ -238,6 +238,7 @@ xlvbd_alloc_gendisk(int minor, blkif_sec 2.4 gd->first_minor = minor; 2.5 gd->fops = &xlvbd_block_fops; 2.6 gd->private_data = info; 2.7 + gd->driverfs_dev = &(info->xbdev->dev); 2.8 set_capacity(gd, capacity); 2.9 2.10 if (xlvbd_init_blk_queue(gd, sector_size)) {
3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Fri Oct 07 11:04:41 2005 +0100 3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Fri Oct 07 11:16:28 2005 +0100 3.3 @@ -88,11 +88,6 @@ 3.4 #endif 3.5 3.6 3.7 -#define NETIF_STATE_DISCONNECTED 0 3.8 -#define NETIF_STATE_CONNECTED 1 3.9 - 3.10 -static unsigned int netif_state = NETIF_STATE_DISCONNECTED; 3.11 - 3.12 static void network_tx_buf_gc(struct net_device *dev); 3.13 static void network_alloc_rx_buffers(struct net_device *dev); 3.14 3.15 @@ -858,7 +853,7 @@ static int create_netdev(int handle, str 3.16 np->user_state = UST_CLOSED; 3.17 np->handle = handle; 3.18 np->xbdev = dev; 3.19 - 3.20 + 3.21 spin_lock_init(&np->tx_lock); 3.22 spin_lock_init(&np->rx_lock); 3.23 3.24 @@ -902,7 +897,9 @@ static int create_netdev(int handle, str 3.25 netdev->features = NETIF_F_IP_CSUM; 3.26 3.27 SET_ETHTOOL_OPS(netdev, &network_ethtool_ops); 3.28 - 3.29 + SET_MODULE_OWNER(netdev); 3.30 + SET_NETDEV_DEV(netdev, &dev->dev); 3.31 + 3.32 if ((err = register_netdev(netdev)) != 0) { 3.33 printk(KERN_WARNING "%s> register_netdev err=%d\n", 3.34 __FUNCTION__, err); 3.35 @@ -1176,8 +1173,6 @@ again: 3.36 3.37 info->backend = backend; 3.38 3.39 - netif_state = NETIF_STATE_CONNECTED; 3.40 - 3.41 return 0; 3.42 3.43 abort_transaction: 3.44 @@ -1276,30 +1271,7 @@ static struct xenbus_driver netfront = { 3.45 3.46 static void __init init_net_xenbus(void) 3.47 { 3.48 - xenbus_register_device(&netfront); 3.49 -} 3.50 - 3.51 -static int wait_for_netif(void) 3.52 -{ 3.53 - int err = 0; 3.54 - int i; 3.55 - 3.56 - /* 3.57 - * We should figure out how many and which devices we need to 3.58 - * proceed and only wait for those. For now, continue once the 3.59 - * first device is around. 3.60 - */ 3.61 - for ( i=0; netif_state != NETIF_STATE_CONNECTED && (i < 10*HZ); i++ ) 3.62 - { 3.63 - set_current_state(TASK_INTERRUPTIBLE); 3.64 - schedule_timeout(1); 3.65 - } 3.66 - 3.67 - if (netif_state != NETIF_STATE_CONNECTED) { 3.68 - WPRINTK("Timeout connecting to device!\n"); 3.69 - err = -ENOSYS; 3.70 - } 3.71 - return err; 3.72 + xenbus_register_driver(&netfront); 3.73 } 3.74 3.75 static int __init netif_init(void) 3.76 @@ -1318,8 +1290,6 @@ static int __init netif_init(void) 3.77 3.78 init_net_xenbus(); 3.79 3.80 - wait_for_netif(); 3.81 - 3.82 return err; 3.83 } 3.84
4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Fri Oct 07 11:04:41 2005 +0100 4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Fri Oct 07 11:16:28 2005 +0100 4.3 @@ -527,7 +527,7 @@ static struct xenbus_driver tpmfront = { 4.4 4.5 static void __init init_tpm_xenbus(void) 4.6 { 4.7 - xenbus_register_device(&tpmfront); 4.8 + xenbus_register_driver(&tpmfront); 4.9 } 4.10 4.11
5.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Fri Oct 07 11:04:41 2005 +0100 5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Fri Oct 07 11:16:28 2005 +0100 5.3 @@ -226,8 +226,8 @@ static int xenbus_dev_remove(struct devi 5.4 return drv->remove(dev); 5.5 } 5.6 5.7 -static int xenbus_register_driver(struct xenbus_driver *drv, 5.8 - struct xen_bus_type *bus) 5.9 +static int xenbus_register_driver_common(struct xenbus_driver *drv, 5.10 + struct xen_bus_type *bus) 5.11 { 5.12 int err; 5.13 5.14 @@ -243,15 +243,15 @@ static int xenbus_register_driver(struct 5.15 return err; 5.16 } 5.17 5.18 -int xenbus_register_device(struct xenbus_driver *drv) 5.19 +int xenbus_register_driver(struct xenbus_driver *drv) 5.20 { 5.21 - return xenbus_register_driver(drv, &xenbus_frontend); 5.22 + return xenbus_register_driver_common(drv, &xenbus_frontend); 5.23 } 5.24 -EXPORT_SYMBOL(xenbus_register_device); 5.25 +EXPORT_SYMBOL(xenbus_register_driver); 5.26 5.27 int xenbus_register_backend(struct xenbus_driver *drv) 5.28 { 5.29 - return xenbus_register_driver(drv, &xenbus_backend); 5.30 + return xenbus_register_driver_common(drv, &xenbus_backend); 5.31 } 5.32 5.33 void xenbus_unregister_driver(struct xenbus_driver *drv) 5.34 @@ -260,6 +260,7 @@ void xenbus_unregister_driver(struct xen 5.35 driver_unregister(&drv->driver); 5.36 up(&xenbus_lock); 5.37 } 5.38 +EXPORT_SYMBOL(xenbus_unregister_driver); 5.39 5.40 struct xb_find_info 5.41 { 5.42 @@ -347,6 +348,18 @@ static char *kasprintf(const char *fmt, 5.43 return p; 5.44 } 5.45 5.46 +static ssize_t xendev_show_nodename(struct device *dev, char *buf) 5.47 +{ 5.48 + return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename); 5.49 +} 5.50 +DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL); 5.51 + 5.52 +static ssize_t xendev_show_devtype(struct device *dev, char *buf) 5.53 +{ 5.54 + return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype); 5.55 +} 5.56 +DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL); 5.57 + 5.58 static int xenbus_probe_node(struct xen_bus_type *bus, 5.59 const char *type, 5.60 const char *nodename) 5.61 @@ -383,6 +396,9 @@ static int xenbus_probe_node(struct xen_ 5.62 printk("XENBUS: Registering %s device %s: error %i\n", 5.63 bus->bus.name, xendev->dev.bus_id, err); 5.64 kfree(xendev); 5.65 + } else { 5.66 + device_create_file(&xendev->dev, &dev_attr_nodename); 5.67 + device_create_file(&xendev->dev, &dev_attr_devtype); 5.68 } 5.69 return err; 5.70 }
6.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Fri Oct 07 11:04:41 2005 +0100 6.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Fri Oct 07 11:16:28 2005 +0100 6.3 @@ -73,7 +73,7 @@ static inline struct xenbus_driver *to_x 6.4 return container_of(drv, struct xenbus_driver, driver); 6.5 } 6.6 6.7 -int xenbus_register_device(struct xenbus_driver *drv); 6.8 +int xenbus_register_driver(struct xenbus_driver *drv); 6.9 int xenbus_register_backend(struct xenbus_driver *drv); 6.10 void xenbus_unregister_driver(struct xenbus_driver *drv); 6.11