Re: [PATCH v2 3/3] bcache: check bch_cached_dev_attach() return value

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

 




在 2022/4/11 11:04, mingzhe.zou@xxxxxxxxxxxx 写道:
From: ZouMingzhe <mingzhe.zou@xxxxxxxxxxxx>

handle error when call bch_cached_dev_attach() function

Signed-off-by: Mingzhe Zou <mingzhe.zou@xxxxxxxxxxxx>
---
  drivers/md/bcache/super.c | 25 +++++++++++++++++++------
  1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index e4a53c849fa6..940eea5f94de 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1460,7 +1460,7 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
  {
  	const char *err = "cannot allocate memory";
  	struct cache_set *c;
-	int ret = -ENOMEM;
+	int ret = -ENOMEM, ret_tmp;
memcpy(&dc->sb, sb, sizeof(struct cache_sb));
  	dc->bdev = bdev;
@@ -1480,8 +1480,14 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk,
list_add(&dc->list, &uncached_devices);
  	/* attach to a matched cache set if it exists */
-	list_for_each_entry(c, &bch_cache_sets, list)
-		bch_cached_dev_attach(dc, c, NULL);
+	err = "failed to attach cached device";
+	list_for_each_entry(c, &bch_cache_sets, list) {
+		ret_tmp = bch_cached_dev_attach(dc, c, NULL);
+		if (ret_tmp)
+			ret = ret_tmp;
+	}
+	if (ret)
+		goto err;

Hi, coly

Wrong here.

I have send v3.

mingzhe

if (BDEV_STATE(&dc->sb) == BDEV_STATE_NONE ||
  	    BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) {
@@ -1981,6 +1987,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
static int run_cache_set(struct cache_set *c)
  {
+	int ret = -EIO, ret_tmp;
  	const char *err = "cannot allocate memory";
  	struct cached_dev *dc, *t;
  	struct cache *ca = c->cache;
@@ -2133,8 +2140,14 @@ static int run_cache_set(struct cache_set *c)
  	if (bch_has_feature_obso_large_bucket(&c->cache->sb))
  		pr_err("Detect obsoleted large bucket layout, all attached bcache device will be read-only\n");
- list_for_each_entry_safe(dc, t, &uncached_devices, list)
-		bch_cached_dev_attach(dc, c, NULL);
+	err = "failed to attach cached device";
+	list_for_each_entry_safe(dc, t, &uncached_devices, list) {
+		ret_tmp = bch_cached_dev_attach(dc, c, NULL);
+		if (ret_tmp)
+			ret = ret_tmp;
+	}
+	if (ret)
+		goto err;
flash_devs_run(c); @@ -2151,7 +2164,7 @@ static int run_cache_set(struct cache_set *c) bch_cache_set_error(c, "%s", err); - return -EIO;
+	return ret;
  }
static const char *register_cache_set(struct cache *ca)



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux ARM Kernel]     [Linux Filesystem Development]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux