[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions
This is a port of a patch in the XenoLinux 2.6.18 tree: http://xenbits.xen.org/hg/linux-2.6.18-xen.hg/rev/f47c07325a56 Fix blkback sysfs race Read blkback statistics info after remove vbd device(s) kernel will crash. Signed-off-by: Joe Jin <joe.jin@xxxxxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxxxx> [Ported to Linux 3.x] Signed-off-by: Matt Wilson <msw@xxxxxxxxxx> --- drivers/block/xen-blkback/xenbus.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index da19506..74d4810 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -21,6 +21,8 @@ #include <xen/grant_table.h> #include "common.h" +static DEFINE_RWLOCK(sysfs_read_lock); + struct backend_info { struct xenbus_device *dev; struct xen_blkif *blkif; @@ -225,10 +227,20 @@ int __init xen_blkif_interface_init(void) struct device_attribute *attr, \ char *buf) \ { \ - struct xenbus_device *dev = to_xenbus_device(_dev); \ - struct backend_info *be = dev_get_drvdata(&dev->dev); \ + 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); \ + be = (struct backend_info *) dev_get_drvdata(&dev->dev);\ + if (be != 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) @@ -353,6 +365,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev) DPRINTK(""); + write_lock(&sysfs_read_lock); if (be->major || be->minor) xenvbd_sysfs_delif(dev); @@ -371,6 +384,7 @@ static int xen_blkbk_remove(struct xenbus_device *dev) kfree(be); dev_set_drvdata(&dev->dev, NULL); + write_unlock(&sysfs_read_lock); return 0; } -- 1.7.2.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |