Linux bcache driver list
 help / color / mirror / Atom feed
* [PATCH] bcache: remove problematic code block from register_bcache()
@ 2017-09-05  7:10 Coly Li
  2017-09-05  8:03 ` Coly Li
  0 siblings, 1 reply; 2+ messages in thread
From: Coly Li @ 2017-09-05  7:10 UTC (permalink / raw)
  To: linux-bcache; +Cc: Coly Li, Jan Kara, Christoph Hellwig

There is a leak of bdev reference in register_bcache(), and Jan Kara
posted a patch to fix it. Discussion happened on bcache mailing list,
Christoph Hellwig pointed out that whole chunk of code where the bdev
reference leak lied was problematic,

	"adding a lookup_bdev and resulting mess just for a
	 slightly different error message is just insane"

This patch jsut removes whole chunk of the problematic code, of cause
the leak of bdev reference is removed too.

Signed-off-by: Coly Li <colyli@suse.de>
Cc: Jan Kara <jack@suse.cz>
Cc: Christoph Hellwig <hch@infradead.org>
---
 drivers/md/bcache/super.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 8352fad765f6..85262f2628fb 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1955,20 +1955,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 	bdev = blkdev_get_by_path(strim(path),
 				  FMODE_READ|FMODE_WRITE|FMODE_EXCL,
 				  sb);
-	if (IS_ERR(bdev)) {
-		if (bdev == ERR_PTR(-EBUSY)) {
-			bdev = lookup_bdev(strim(path));
-			mutex_lock(&bch_register_lock);
-			if (!IS_ERR(bdev) && bch_is_open(bdev))
-				err = "device already registered";
-			else
-				err = "device busy";
-			mutex_unlock(&bch_register_lock);
-			if (attr == &ksysfs_register_quiet)
-				goto out;
-		}
+	if (IS_ERR(bdev))
 		goto err;
-	}
 
 	err = "failed to set blocksize";
 	if (set_blocksize(bdev, 4096))
-- 
2.13.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] bcache: remove problematic code block from register_bcache()
  2017-09-05  7:10 [PATCH] bcache: remove problematic code block from register_bcache() Coly Li
@ 2017-09-05  8:03 ` Coly Li
  0 siblings, 0 replies; 2+ messages in thread
From: Coly Li @ 2017-09-05  8:03 UTC (permalink / raw)
  To: Coly Li, linux-bcache; +Cc: Jan Kara, Christoph Hellwig

On 2017/9/5 下午3:10, Coly Li wrote:
> There is a leak of bdev reference in register_bcache(), and Jan Kara
> posted a patch to fix it. Discussion happened on bcache mailing list,
> Christoph Hellwig pointed out that whole chunk of code where the bdev
> reference leak lied was problematic,
> 
> 	"adding a lookup_bdev and resulting mess just for a
> 	 slightly different error message is just insane"
> 
> This patch jsut removes whole chunk of the problematic code, of cause
> the leak of bdev reference is removed too.
> 
> Signed-off-by: Coly Li <colyli@suse.de>
> Cc: Jan Kara <jack@suse.cz>
> Cc: Christoph Hellwig <hch@infradead.org>
> ---
>  drivers/md/bcache/super.c | 14 +-------------
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 8352fad765f6..85262f2628fb 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1955,20 +1955,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>  	bdev = blkdev_get_by_path(strim(path),
>  				  FMODE_READ|FMODE_WRITE|FMODE_EXCL,
>  				  sb);
> -	if (IS_ERR(bdev)) {
> -		if (bdev == ERR_PTR(-EBUSY)) {
> -			bdev = lookup_bdev(strim(path));
> -			mutex_lock(&bch_register_lock);
> -			if (!IS_ERR(bdev) && bch_is_open(bdev))
> -				err = "device already registered";
> -			else
> -				err = "device busy";
> -			mutex_unlock(&bch_register_lock);
> -			if (attr == &ksysfs_register_quiet)
> -				goto out;
> -		}
> +	if (IS_ERR(bdev))
>  		goto err;
> -	}
>  
>  	err = "failed to set blocksize";
>  	if (set_blocksize(bdev, 4096))
> 

Hi Jan and Christoph,

There are other three functions only referenced in the above chunk of code,
- bch_is_open()
- bch_is_open_cache()
- bch_is_open_backing()
they should be removed as well.

So you may ignore this email, an update version of this patch will be
posted to linux-bache and linux-block mailing lists for review.

Thanks.

-- 
Coly Li

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-05  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-05  7:10 [PATCH] bcache: remove problematic code block from register_bcache() Coly Li
2017-09-05  8:03 ` Coly Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox