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

[Xen-changelog] [linux-2.6.18-xen] Fix blk{back,tap} sysfs race



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1264064915 0
# Node ID f47c07325a56463fa052b4500b4a3c0056939d15
# Parent  0bec29c94ce9ed50d5d77f6e694576efd30e98eb
Fix blk{back,tap} sysfs race

Read blk{back,tap} statistics info after remove vbd device(s) kernel
will crash.

Signed-off-by: Joe Jin <joe.jin@xxxxxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxxxx>
---
 drivers/xen/blkback/xenbus.c |   19 ++++++++++++++++---
 drivers/xen/blktap/xenbus.c  |   18 +++++++++++++++---
 2 files changed, 31 insertions(+), 6 deletions(-)

diff -r 0bec29c94ce9 -r f47c07325a56 drivers/xen/blkback/xenbus.c
--- a/drivers/xen/blkback/xenbus.c      Mon Jan 18 14:50:43 2010 +0000
+++ b/drivers/xen/blkback/xenbus.c      Thu Jan 21 09:08:35 2010 +0000
@@ -26,6 +26,8 @@
 #define DPRINTK(fmt, args...)                          \
        pr_debug("blkback/xenbus (%s:%d) " fmt ".\n",   \
                 __FUNCTION__, __LINE__, ##args)
+
+static DEFINE_RWLOCK(sysfs_read_lock);
 
 struct backend_info
 {
@@ -104,10 +106,19 @@ static void update_blkif_status(blkif_t 
                                   struct device_attribute *attr,       \
                                   char *buf)                           \
        {                                                               \
-               struct xenbus_device *dev = to_xenbus_device(_dev);     \
-               struct backend_info *be = dev->dev.driver_data;         \
+               ssize_t ret = -ENODEV;                                  \
+               struct xenbus_device *dev;                              \
+               struct backend_info *be;                                \
                                                                        \
-               return sprintf(buf, format, ##args);                    \
+               if (!get_device(_dev))                                  \
+                       return ret;                                     \
+               dev = to_xenbus_device(_dev);                           \
+               read_lock(&sysfs_read_lock);                            \
+               if ((be = dev->dev.driver_data) != NULL)                \
+                       ret = sprintf(buf, format, ##args);             \
+               read_unlock(&sysfs_read_lock);                          \
+               put_device(_dev);                                       \
+               return ret;                                             \
        }                                                               \
        static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
 
@@ -173,6 +184,7 @@ static int blkback_remove(struct xenbus_
 
        DPRINTK("");
 
+       write_lock(&sysfs_read_lock);
        if (be->major || be->minor)
                xenvbd_sysfs_delif(dev);
 
@@ -191,6 +203,7 @@ static int blkback_remove(struct xenbus_
 
        kfree(be);
        dev->dev.driver_data = NULL;
+       write_unlock(&sysfs_read_lock);
        return 0;
 }
 
diff -r 0bec29c94ce9 -r f47c07325a56 drivers/xen/blktap/xenbus.c
--- a/drivers/xen/blktap/xenbus.c       Mon Jan 18 14:50:43 2010 +0000
+++ b/drivers/xen/blktap/xenbus.c       Thu Jan 21 09:08:35 2010 +0000
@@ -50,6 +50,7 @@ struct backend_info
        int group_added;
 };
 
+static DEFINE_RWLOCK(sysfs_read_lock);
 
 static void connect(struct backend_info *);
 static int connect_ring(struct backend_info *);
@@ -122,10 +123,19 @@ static int blktap_name(blkif_t *blkif, c
                                   struct device_attribute *attr,       \
                                   char *buf)                           \
        {                                                               \
-               struct xenbus_device *dev = to_xenbus_device(_dev);     \
-               struct backend_info *be = dev->dev.driver_data;         \
+               ssize_t ret = -ENODEV;                                  \
+               struct xenbus_device *dev;                              \
+               struct backend_info *be;                                \
                                                                        \
-               return sprintf(buf, format, ##args);                    \
+               if (!get_device(_dev))                                  \
+                       return ret;                                     \
+               dev = to_xenbus_device(_dev);                           \
+               read_lock(&sysfs_read_lock);                            \
+               if ((be = dev->dev.driver_data) != NULL)                \
+                       ret = sprintf(buf, format, ##args);             \
+               read_unlock(&sysfs_read_lock);                          \
+               put_device(_dev);                                       \
+               return ret;                                             \
        }                                                               \
        static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
 
@@ -170,6 +180,7 @@ static int blktap_remove(struct xenbus_d
 {
        struct backend_info *be = dev->dev.driver_data;
 
+       write_lock(&sysfs_read_lock);
        if (be->group_added)
                xentap_sysfs_delif(be->dev);
        if (be->backend_watch.node) {
@@ -187,6 +198,7 @@ static int blktap_remove(struct xenbus_d
        }
        kfree(be);
        dev->dev.driver_data = NULL;
+       write_unlock(&sysfs_read_lock);
        return 0;
 }
 

_______________________________________________
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®.