Re: [RFC PATCH v2 09/16] bcache: add error check for calling register_bdev()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 04/19/2019 11:24 AM, Coly Li wrote:
> This patch adds return value to register_bdev(). Then if failure happens
> inside register_bdev(), its caller register_bcache() may detect and
> handle the failure more properly.
>
> Signed-off-by: Coly Li <colyli@xxxxxxx>
> ---
>   drivers/md/bcache/super.c | 16 ++++++++++------
>   1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index 400af446c372..a435c506edba 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1281,7 +1281,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size)
>
>   /* Cached device - bcache superblock */
>
> -static void register_bdev(struct cache_sb *sb, struct page *sb_page,
> +static int register_bdev(struct cache_sb *sb, struct page *sb_page,
>   				 struct block_device *bdev,
>   				 struct cached_dev *dc)
>   {
> @@ -1319,10 +1319,11 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,
>   	    BDEV_STATE(&dc->sb) == BDEV_STATE_STALE)
>   		bch_cached_dev_run(dc);
>
> -	return;
> +	return 0;
>   err:
>   	pr_notice("error %s: %s", dc->backing_dev_name, err);
>   	bcache_device_stop(&dc->disk);
So register_bdev has couple of goto err; calls where kobject interface 
is used directly :-

register_bdev
	kobject_add

and

indirectly :-
register_bdev
	bch_cache_accounting_add_kobjs

		kobject_add
Here we return -EIO, we should catch the error code from kobject calls 
and return that error instead of -EIO. Any thoughts ?

> +	return -EIO;
>   }
>
>   /* Flash only volumes */
> @@ -2273,7 +2274,7 @@ static bool bch_is_open(struct block_device *bdev)
>   static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   			       const char *buffer, size_t size)
>   {
> -	ssize_t ret = size;
> +	ssize_t ret = -EINVAL;
>   	const char *err = "cannot allocate memory";
>   	char *path = NULL;
>   	struct cache_sb *sb = NULL;
> @@ -2307,7 +2308,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   			if (!IS_ERR(bdev))
>   				bdput(bdev);
>   			if (attr == &ksysfs_register_quiet)
> -				goto out;
> +				goto quiet_out;
>   		}
>   		goto err;
>   	}
> @@ -2328,8 +2329,10 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   			goto err_close;
>
>   		mutex_lock(&bch_register_lock);
> -		register_bdev(sb, sb_page, bdev, dc);
> +		ret = register_bdev(sb, sb_page, bdev, dc);
>   		mutex_unlock(&bch_register_lock);
> +		if (ret < 0)
> +			goto err;
>   	} else {
>   		struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
>
> @@ -2339,6 +2342,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   		if (register_cache(sb, sb_page, bdev, ca) != 0)
>   			goto err;
>   	}
> +quiet_out:
> +	ret = size;
>   out:
>   	if (sb_page)
>   		put_page(sb_page);
> @@ -2351,7 +2356,6 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
>   	blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
>   err:
>   	pr_info("error %s: %s", path, err);
> -	ret = -EINVAL;
>   	goto out;
>   }
>
>





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux