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

[Xen-changelog] The attached fixes a few things to make the blkfront and netfront



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 2a3e10a132a2a57795ff9a46e465f99793c31da5
# Parent  8b095815538060dc1bf5f07ed897010ee880f207
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@xxxxxxxxxx>

diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Fri Oct  7 
10:04:41 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c      Fri Oct  7 
10:16:28 2005
@@ -53,8 +53,6 @@
 #define BLKIF_STATE_DISCONNECTED 0
 #define BLKIF_STATE_CONNECTED    1
 
-static unsigned int blkif_state = BLKIF_STATE_DISCONNECTED;
-
 #define MAXIMUM_OUTSTANDING_BLOCK_REQS \
     (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE)
 #define GRANT_INVALID_REF      0
@@ -472,8 +470,6 @@
        info->connected = BLKIF_STATE_CONNECTED;
        xlvbd_add(sectors, info->vdevice, binfo, sector_size, info);
 
-       blkif_state = BLKIF_STATE_CONNECTED;
-
        xenbus_dev_ok(info->xbdev);
 
        /* Kick pending requests. */
@@ -716,29 +712,7 @@
 
 static void __init init_blk_xenbus(void)
 {
-       xenbus_register_device(&blkfront);
-}
-
-static int wait_for_blkif(void)
-{
-       int err = 0;
-       int i;
-
-       /*
-        * We should figure out how many and which devices we need to
-        * proceed and only wait for those.  For now, continue once the
-        * first device is around.
-        */
-       for (i = 0; blkif_state != BLKIF_STATE_CONNECTED && (i < 10*HZ); i++) {
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(1);
-       }
-
-       if (blkif_state != BLKIF_STATE_CONNECTED) {
-               WPRINTK("Timeout connecting to device!\n");
-               err = -ENOSYS;
-       }
-       return err;
+       xenbus_register_driver(&blkfront);
 }
 
 static int __init xlblk_init(void)
@@ -750,8 +724,6 @@
        IPRINTK("Initialising virtual block device driver\n");
 
        init_blk_xenbus();
-
-       wait_for_blkif();
 
        return 0;
 }
diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c   Fri Oct  7 10:04:41 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c   Fri Oct  7 10:16:28 2005
@@ -238,6 +238,7 @@
        gd->first_minor = minor;
        gd->fops = &xlvbd_block_fops;
        gd->private_data = info;
+       gd->driverfs_dev = &(info->xbdev->dev);
        set_capacity(gd, capacity);
 
        if (xlvbd_init_blk_queue(gd, sector_size)) {
diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Fri Oct  7 
10:04:41 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Fri Oct  7 
10:16:28 2005
@@ -87,11 +87,6 @@
 #define TX_TEST_IDX req_cons  /* conservative: not seen all our requests? */
 #endif
 
-
-#define NETIF_STATE_DISCONNECTED 0
-#define NETIF_STATE_CONNECTED    1
-
-static unsigned int netif_state = NETIF_STATE_DISCONNECTED;
 
 static void network_tx_buf_gc(struct net_device *dev);
 static void network_alloc_rx_buffers(struct net_device *dev);
@@ -858,7 +853,7 @@
        np->user_state    = UST_CLOSED;
        np->handle        = handle;
        np->xbdev         = dev;
-    
+
        spin_lock_init(&np->tx_lock);
        spin_lock_init(&np->rx_lock);
 
@@ -902,7 +897,9 @@
        netdev->features        = NETIF_F_IP_CSUM;
 
        SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
-
+       SET_MODULE_OWNER(netdev);
+       SET_NETDEV_DEV(netdev, &dev->dev);
+    
        if ((err = register_netdev(netdev)) != 0) {
                printk(KERN_WARNING "%s> register_netdev err=%d\n",
                       __FUNCTION__, err);
@@ -1176,8 +1173,6 @@
 
        info->backend = backend;
 
-       netif_state = NETIF_STATE_CONNECTED;
-
        return 0;
 
  abort_transaction:
@@ -1276,30 +1271,7 @@
 
 static void __init init_net_xenbus(void)
 {
-       xenbus_register_device(&netfront);
-}
-
-static int wait_for_netif(void)
-{
-       int err = 0;
-       int i;
-
-       /*
-        * We should figure out how many and which devices we need to
-        * proceed and only wait for those.  For now, continue once the
-        * first device is around.
-        */
-       for ( i=0; netif_state != NETIF_STATE_CONNECTED && (i < 10*HZ); i++ )
-       {
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(1);
-       }
-
-       if (netif_state != NETIF_STATE_CONNECTED) {
-               WPRINTK("Timeout connecting to device!\n");
-               err = -ENOSYS;
-       }
-       return err;
+       xenbus_register_driver(&netfront);
 }
 
 static int __init netif_init(void)
@@ -1317,8 +1289,6 @@
        (void)register_inetaddr_notifier(&notifier_inetdev);
 
        init_net_xenbus();
-
-       wait_for_netif();
 
        return err;
 }
diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Fri Oct  7 
10:04:41 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c      Fri Oct  7 
10:16:28 2005
@@ -527,7 +527,7 @@
 
 static void __init init_tpm_xenbus(void)
 {
-       xenbus_register_device(&tpmfront);
+       xenbus_register_driver(&tpmfront);
 }
 
 
diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Fri Oct  7 
10:04:41 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Fri Oct  7 
10:16:28 2005
@@ -226,8 +226,8 @@
        return drv->remove(dev);
 }
 
-static int xenbus_register_driver(struct xenbus_driver *drv,
-                                 struct xen_bus_type *bus)
+static int xenbus_register_driver_common(struct xenbus_driver *drv,
+                                        struct xen_bus_type *bus)
 {
        int err;
 
@@ -243,15 +243,15 @@
        return err;
 }
 
-int xenbus_register_device(struct xenbus_driver *drv)
-{
-       return xenbus_register_driver(drv, &xenbus_frontend);
-}
-EXPORT_SYMBOL(xenbus_register_device);
+int xenbus_register_driver(struct xenbus_driver *drv)
+{
+       return xenbus_register_driver_common(drv, &xenbus_frontend);
+}
+EXPORT_SYMBOL(xenbus_register_driver);
 
 int xenbus_register_backend(struct xenbus_driver *drv)
 {
-       return xenbus_register_driver(drv, &xenbus_backend);
+       return xenbus_register_driver_common(drv, &xenbus_backend);
 }
 
 void xenbus_unregister_driver(struct xenbus_driver *drv)
@@ -260,6 +260,7 @@
        driver_unregister(&drv->driver);
        up(&xenbus_lock);
 }
+EXPORT_SYMBOL(xenbus_unregister_driver);
 
 struct xb_find_info
 {
@@ -347,6 +348,18 @@
        return p;
 }
 
+static ssize_t xendev_show_nodename(struct device *dev, char *buf)
+{
+       return sprintf(buf, "%s\n", to_xenbus_device(dev)->nodename);
+}
+DEVICE_ATTR(nodename, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_nodename, NULL);
+
+static ssize_t xendev_show_devtype(struct device *dev, char *buf)
+{
+       return sprintf(buf, "%s\n", to_xenbus_device(dev)->devicetype);
+}
+DEVICE_ATTR(devtype, S_IRUSR | S_IRGRP | S_IROTH, xendev_show_devtype, NULL);
+
 static int xenbus_probe_node(struct xen_bus_type *bus,
                             const char *type,
                             const char *nodename)
@@ -383,6 +396,9 @@
                printk("XENBUS: Registering %s device %s: error %i\n",
                       bus->bus.name, xendev->dev.bus_id, err);
                kfree(xendev);
+       } else {
+               device_create_file(&xendev->dev, &dev_attr_nodename);
+               device_create_file(&xendev->dev, &dev_attr_devtype);
        }
        return err;
 }
diff -r 8b0958155380 -r 2a3e10a132a2 
linux-2.6-xen-sparse/include/asm-xen/xenbus.h
--- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h     Fri Oct  7 10:04:41 2005
+++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h     Fri Oct  7 10:16:28 2005
@@ -73,7 +73,7 @@
        return container_of(drv, struct xenbus_driver, driver);
 }
 
-int xenbus_register_device(struct xenbus_driver *drv);
+int xenbus_register_driver(struct xenbus_driver *drv);
 int xenbus_register_backend(struct xenbus_driver *drv);
 void xenbus_unregister_driver(struct xenbus_driver *drv);
 

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


 


Rackspace

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