bcache: set bcache device into read-only mode for BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET
authorColy Li <colyli@suse.de>
Mon, 4 Jan 2021 07:41:22 +0000 (15:41 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 9 Jan 2021 16:21:03 +0000 (09:21 -0700)
If BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET is set in incompat feature
set, it means the cache device is created with obsoleted layout with
obso_bucket_site_hi. Now bcache does not support this feature bit, a new
BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE incompat feature bit is added
for a better layout to support large bucket size.

For the legacy compatibility purpose, if a cache device created with
obsoleted BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET feature bit, all bcache
devices attached to this cache set should be set to read-only. Then the
dirty data can be written back to backing device before re-create the
cache device with BCH_FEATURE_INCOMPAT_LOG_LARGE_BUCKET_SIZE feature bit
by the latest bcache-tools.

This patch checks BCH_FEATURE_INCOMPAT_OBSO_LARGE_BUCKET feature bit
when running a cache set and attach a bcache device to the cache set. If
this bit is set,
- When run a cache set, print an error kernel message to indicate all
  following attached bcache device will be read-only.
- When attach a bcache device, print an error kernel message to indicate
  the attached bcache device will be read-only, and ask users to update
  to latest bcache-tools.

Such change is only for cache device whose bucket size >= 32MB, this is
for the zoned SSD and almost nobody uses such large bucket size at this
moment. If you don't explicit set a large bucket size for a zoned SSD,
such change is totally transparent to your bcache device.

Fixes: ffa470327572 ("bcache: add bucket_size_hi into struct cache_sb_disk for large bucket")
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/super.c

index 3999641..2047a9c 100644 (file)
@@ -1332,6 +1332,12 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
        bcache_device_link(&dc->disk, c, "bdev");
        atomic_inc(&c->attached_dev_nr);
 
+       if (bch_has_feature_obso_large_bucket(&(c->cache->sb))) {
+               pr_err("The obsoleted large bucket layout is unsupported, set the bcache device into read-only\n");
+               pr_err("Please update to the latest bcache-tools to create the cache device\n");
+               set_disk_ro(dc->disk.disk, 1);
+       }
+
        /* Allow the writeback thread to proceed */
        up_write(&dc->writeback_lock);
 
@@ -1554,6 +1560,12 @@ static int flash_dev_run(struct cache_set *c, struct uuid_entry *u)
 
        bcache_device_link(d, c, "volume");
 
+       if (bch_has_feature_obso_large_bucket(&c->cache->sb)) {
+               pr_err("The obsoleted large bucket layout is unsupported, set the bcache device into read-only\n");
+               pr_err("Please update to the latest bcache-tools to create the cache device\n");
+               set_disk_ro(d->disk, 1);
+       }
+
        return 0;
 err:
        kobject_put(&d->kobj);
@@ -2113,6 +2125,9 @@ static int run_cache_set(struct cache_set *c)
        c->cache->sb.last_mount = (u32)ktime_get_real_seconds();
        bcache_write_super(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);