mirror of https://gitee.com/openkylin/linux.git
bcache: add error check for calling register_bdev()
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@suse.de> Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
68d10e6979
commit
88c12d42d2
|
@ -1279,7 +1279,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size)
|
||||||
|
|
||||||
/* Cached device - bcache superblock */
|
/* 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 block_device *bdev,
|
||||||
struct cached_dev *dc)
|
struct cached_dev *dc)
|
||||||
{
|
{
|
||||||
|
@ -1317,10 +1317,11 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page,
|
||||||
BDEV_STATE(&dc->sb) == BDEV_STATE_STALE)
|
BDEV_STATE(&dc->sb) == BDEV_STATE_STALE)
|
||||||
bch_cached_dev_run(dc);
|
bch_cached_dev_run(dc);
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
err:
|
err:
|
||||||
pr_notice("error %s: %s", dc->backing_dev_name, err);
|
pr_notice("error %s: %s", dc->backing_dev_name, err);
|
||||||
bcache_device_stop(&dc->disk);
|
bcache_device_stop(&dc->disk);
|
||||||
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flash only volumes */
|
/* Flash only volumes */
|
||||||
|
@ -2271,7 +2272,7 @@ static bool bch_is_open(struct block_device *bdev)
|
||||||
static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
||||||
const char *buffer, size_t size)
|
const char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
ssize_t ret = size;
|
ssize_t ret = -EINVAL;
|
||||||
const char *err = "cannot allocate memory";
|
const char *err = "cannot allocate memory";
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
struct cache_sb *sb = NULL;
|
struct cache_sb *sb = NULL;
|
||||||
|
@ -2305,7 +2306,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
||||||
if (!IS_ERR(bdev))
|
if (!IS_ERR(bdev))
|
||||||
bdput(bdev);
|
bdput(bdev);
|
||||||
if (attr == &ksysfs_register_quiet)
|
if (attr == &ksysfs_register_quiet)
|
||||||
goto out;
|
goto quiet_out;
|
||||||
}
|
}
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -2326,8 +2327,10 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
||||||
goto err_close;
|
goto err_close;
|
||||||
|
|
||||||
mutex_lock(&bch_register_lock);
|
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);
|
mutex_unlock(&bch_register_lock);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
|
struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
|
||||||
|
|
||||||
|
@ -2337,6 +2340,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
||||||
if (register_cache(sb, sb_page, bdev, ca) != 0)
|
if (register_cache(sb, sb_page, bdev, ca) != 0)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
quiet_out:
|
||||||
|
ret = size;
|
||||||
out:
|
out:
|
||||||
if (sb_page)
|
if (sb_page)
|
||||||
put_page(sb_page);
|
put_page(sb_page);
|
||||||
|
@ -2349,7 +2354,6 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
|
||||||
blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
|
blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
|
||||||
err:
|
err:
|
||||||
pr_info("error %s: %s", path, err);
|
pr_info("error %s: %s", path, err);
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue