The UUID room will be exhausted fake when loop attach/dettach backing dev.

Using zero_uuid to the UUID room after dettach normaly.
And attach dev can request UUID room successfully.

Signed-off-by: Yi Li <y...@winhong.com>
Signed-off-by: Li bing <lib...@winhong.com>
---
 drivers/md/bcache/super.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 0e06d721cd8e..f7ad1e26b013 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -34,10 +34,7 @@ static const char bcache_magic[] = {
        0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81
 };
 
-static const char invalid_uuid[] = {
-       0xa0, 0x3e, 0xf8, 0xed, 0x3e, 0xe1, 0xb8, 0x78,
-       0xc8, 0x50, 0xfc, 0x5e, 0xcb, 0x16, 0xcd, 0x99
-};
+static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
 
 static struct kobject *bcache_kobj;
 struct mutex bch_register_lock;
@@ -515,13 +512,6 @@ static struct uuid_entry *uuid_find(struct cache_set *c, 
const char *uuid)
        return NULL;
 }
 
-static struct uuid_entry *uuid_find_empty(struct cache_set *c)
-{
-       static const char zero_uuid[16] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
-
-       return uuid_find(c, zero_uuid);
-}
-
 /*
  * Bucket priorities/gens:
  *
@@ -803,7 +793,7 @@ static void bcache_device_detach(struct bcache_device *d)
                struct uuid_entry *u = d->c->uuids + d->id;
 
                SET_UUID_FLASH_ONLY(u, 0);
-               memcpy(u->uuid, invalid_uuid, 16);
+               memcpy(u->uuid, zero_uuid, 16);
                u->invalidated = cpu_to_le32((u32)ktime_get_real_seconds());
                bch_uuid_write(d->c);
        }
@@ -1211,7 +1201,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct 
cache_set *c,
        if (u &&
            (BDEV_STATE(&dc->sb) == BDEV_STATE_STALE ||
             BDEV_STATE(&dc->sb) == BDEV_STATE_NONE)) {
-               memcpy(u->uuid, invalid_uuid, 16);
+               memcpy(u->uuid, zero_uuid, 16);
                u->invalidated = cpu_to_le32((u32)ktime_get_real_seconds());
                u = NULL;
        }
@@ -1223,7 +1213,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct 
cache_set *c,
                        return -ENOENT;
                }
 
-               u = uuid_find_empty(c);
+               u = uuid_find(c, zero_uuid);
                if (!u) {
                        pr_err("Not caching %s, no room for UUID\n",
                               dc->backing_dev_name);
@@ -1554,7 +1544,7 @@ int bch_flash_dev_create(struct cache_set *c, uint64_t 
size)
        if (!test_bit(CACHE_SET_RUNNING, &c->flags))
                return -EPERM;
 
-       u = uuid_find_empty(c);
+       u = uuid_find(c, zero_uuid);
        if (!u) {
                pr_err("Can't create volume, no room for UUID\n");
                return -EINVAL;
-- 
2.25.3



Reply via email to