Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Xen: Devel
[RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions
 

Index | Next | Previous | View Flat


msw at amazon

Apr 20, 2012, 12:21 PM


Views: 164
Permalink
[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 [at] oracle>
Acked-by: Jan Beulich <jbeulich [at] novell>
[Ported to Linux 3.x]
Signed-off-by: Matt Wilson <msw [at] amazon>
---
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 [at] lists
http://lists.xen.org/xen-devel

Subject User Time
[RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions msw at amazon Apr 20, 2012, 12:21 PM
    Re: [RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions konrad.wilk at oracle Apr 26, 2012, 1:51 PM
    Re: [RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions konrad.wilk at oracle Apr 26, 2012, 7:24 PM
        Re: [RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions msw at amazon Apr 27, 2012, 9:30 AM

  Index | Next | Previous | View Flat
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.