xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Matt Wilson <msw@amazon.com>
Cc: Joe Jin <joe.jin@oracle.com>, xen-devel@lists.xen.org
Subject: Re: [RFC] [PATCH] xen/blkback: add locking in statistics sysfs show functions
Date: Thu, 26 Apr 2012 16:51:42 -0400	[thread overview]
Message-ID: <20120426205142.GA30926@phenom.dumpdata.com> (raw)
In-Reply-To: <1334949673-25632-2-git-send-email-msw@amazon.com>

On Fri, Apr 20, 2012 at 07:21:13PM +0000, Matt Wilson wrote:
> 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.

Looks pretty reasonable.

> 
> Signed-off-by: Joe Jin <joe.jin@oracle.com>
> Acked-by: Jan Beulich <jbeulich@novell.com>
> [Ported to Linux 3.x]
> Signed-off-by: Matt Wilson <msw@amazon.com>
> ---
>  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

  reply	other threads:[~2012-04-26 20:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-20 19:21 [RFC] [PATCH] add locking in statistics sysfs show functions Matt Wilson
2012-04-20 19:21 ` [RFC] [PATCH] xen/blkback: " Matt Wilson
2012-04-26 20:51   ` Konrad Rzeszutek Wilk [this message]
2012-04-27  2:24   ` Konrad Rzeszutek Wilk
2012-04-27 16:30     ` Matt Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120426205142.GA30926@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=msw@amazon.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).