diff mbox series

[RFC,v2,10/16] bcache: Add comments for blkdev_put() in registration code path

Message ID 20190419160509.66298-11-colyli@suse.de (mailing list archive)
State New, archived
Headers show
Series bcache: fix journal no-space deadlock | expand

Commit Message

Coly Li April 19, 2019, 4:05 p.m. UTC
Add comments to explain why in register_bcache() blkdev_put() won't
be called in two location. Add comments to explain why blkdev_put()
must be called in register_cache() when cache_alloc() failed.

Signed-off-by: Coly Li <colyli@suse.de>
---
 drivers/md/bcache/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Chaitanya Kulkarni April 21, 2019, 5:50 p.m. UTC | #1
Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>

On 04/19/2019 11:24 AM, Coly Li wrote:
> Add comments to explain why in register_bcache() blkdev_put() won't
> be called in two location. Add comments to explain why blkdev_put()
> must be called in register_cache() when cache_alloc() failed.
>
> Signed-off-by: Coly Li <colyli@suse.de>
> ---
>   drivers/md/bcache/super.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index a435c506edba..83a7cb0e0e45 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -2191,6 +2191,12 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
>
>   	ret = cache_alloc(ca);
>   	if (ret != 0) {
> +		/*
> +		 * If we failed here, it means ca->kobj is not initialzed yet,
> +		 * kobject_put() won't be called and there is no chance to
> +		 * call blkdev_put() to bdev in bch_cache_release(). So we
> +		 * explictly call blkdev_put() here.
> +		 */
>   		blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
>   		if (ret == -ENOMEM)
>   			err = "cache_alloc(): -ENOMEM";
> @@ -2331,6 +2337,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   		mutex_lock(&bch_register_lock);
>   		ret = register_bdev(sb, sb_page, bdev, dc);
>   		mutex_unlock(&bch_register_lock);
> +		/* blkdev_put() will be called in cached_dev_free() */
>   		if (ret < 0)
>   			goto err;
>   	} else {
> @@ -2339,6 +2346,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   		if (!ca)
>   			goto err_close;
>
> +		/* blkdev_put() will be called in bch_cache_release() */
>   		if (register_cache(sb, sb_page, bdev, ca) != 0)
>   			goto err;
>   	}
>
Hannes Reinecke April 23, 2019, 7:05 a.m. UTC | #2
On 4/19/19 6:05 PM, Coly Li wrote:
> Add comments to explain why in register_bcache() blkdev_put() won't
> be called in two location. Add comments to explain why blkdev_put()
> must be called in register_cache() when cache_alloc() failed.
> 
> Signed-off-by: Coly Li <colyli@suse.de>
> ---
>   drivers/md/bcache/super.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index a435c506edba..83a7cb0e0e45 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -2191,6 +2191,12 @@ static int register_cache(struct cache_sb *sb, struct page *sb_page,
>   
>   	ret = cache_alloc(ca);
>   	if (ret != 0) {
> +		/*
> +		 * If we failed here, it means ca->kobj is not initialzed yet,
> +		 * kobject_put() won't be called and there is no chance to
> +		 * call blkdev_put() to bdev in bch_cache_release(). So we
> +		 * explictly call blkdev_put() here.
> +		 */
>   		blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
>   		if (ret == -ENOMEM)
>   			err = "cache_alloc(): -ENOMEM";
> @@ -2331,6 +2337,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   		mutex_lock(&bch_register_lock);
>   		ret = register_bdev(sb, sb_page, bdev, dc);
>   		mutex_unlock(&bch_register_lock);
> +		/* blkdev_put() will be called in cached_dev_free() */
>   		if (ret < 0)
>   			goto err;
>   	} else {
> @@ -2339,6 +2346,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   		if (!ca)
>   			goto err_close;
>   
> +		/* blkdev_put() will be called in bch_cache_release() */
>   		if (register_cache(sb, sb_page, bdev, ca) != 0)
>   			goto err;
>   	}
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index a435c506edba..83a7cb0e0e45 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2191,6 +2191,12 @@  static int register_cache(struct cache_sb *sb, struct page *sb_page,
 
 	ret = cache_alloc(ca);
 	if (ret != 0) {
+		/*
+		 * If we failed here, it means ca->kobj is not initialzed yet,
+		 * kobject_put() won't be called and there is no chance to
+		 * call blkdev_put() to bdev in bch_cache_release(). So we
+		 * explictly call blkdev_put() here.
+		 */
 		blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
 		if (ret == -ENOMEM)
 			err = "cache_alloc(): -ENOMEM";
@@ -2331,6 +2337,7 @@  static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 		mutex_lock(&bch_register_lock);
 		ret = register_bdev(sb, sb_page, bdev, dc);
 		mutex_unlock(&bch_register_lock);
+		/* blkdev_put() will be called in cached_dev_free() */
 		if (ret < 0)
 			goto err;
 	} else {
@@ -2339,6 +2346,7 @@  static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 		if (!ca)
 			goto err_close;
 
+		/* blkdev_put() will be called in bch_cache_release() */
 		if (register_cache(sb, sb_page, bdev, ca) != 0)
 			goto err;
 	}