diff options
| author | Tang Junhui <tang.junhui@zte.com.cn> | 2018-02-07 14:41:46 -0500 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2018-02-07 14:50:01 -0500 |
| commit | 73ac105be390c1de42a2f21643c9778a5e002930 (patch) | |
| tree | 9a9920614c0e4092f4479413d631912c58e5c952 | |
| parent | 7f4fc93d4713394ee8f1cd44c238e046e11b4f15 (diff) | |
bcache: fix for data collapse after re-attaching an attached device
back-end device sdm has already attached a cache_set with ID
f67ebe1f-f8bc-4d73-bfe5-9dc88607f119, then try to attach with
another cache set, and it returns with an error:
[root]# cd /sys/block/sdm/bcache
[root]# echo 5ccd0a63-148e-48b8-afa2-aca9cbd6279f > attach
-bash: echo: write error: Invalid argument
After that, execute a command to modify the label of bcache
device:
[root]# echo data_disk1 > label
Then we reboot the system, when the system power on, the back-end
device can not attach to cache_set, a messages show in the log:
Feb 5 12:05:52 ceph152 kernel: [922385.508498] bcache:
bch_cached_dev_attach() couldn't find uuid for sdm in set
In sysfs_attach(), dc->sb.set_uuid was assigned to the value
which input through sysfs, no matter whether it is success
or not in bch_cached_dev_attach(). For example, If the back-end
device has already attached to an cache set, bch_cached_dev_attach()
would fail, but dc->sb.set_uuid was changed. Then modify the
label of bcache device, it will call bch_write_bdev_super(),
which would write the dc->sb.set_uuid to the super block, so we
record a wrong cache set ID in the super block, after the system
reboot, the cache set couldn't find the uuid of the back-end
device, so the bcache device couldn't exist and use any more.
In this patch, we don't assigned cache set ID to dc->sb.set_uuid
in sysfs_attach() directly, but input it into bch_cached_dev_attach(),
and assigned dc->sb.set_uuid to the cache set ID after the back-end
device attached to the cache set successful.
Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
Reviewed-by: Michael Lyle <mlyle@lyle.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | drivers/md/bcache/bcache.h | 2 | ||||
| -rw-r--r-- | drivers/md/bcache/super.c | 10 | ||||
| -rw-r--r-- | drivers/md/bcache/sysfs.c | 6 |
3 files changed, 11 insertions, 7 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index b8c2e1bef1f1..12e5197f186c 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
| @@ -924,7 +924,7 @@ void bcache_write_super(struct cache_set *); | |||
| 924 | 924 | ||
| 925 | int bch_flash_dev_create(struct cache_set *c, uint64_t size); | 925 | int bch_flash_dev_create(struct cache_set *c, uint64_t size); |
| 926 | 926 | ||
| 927 | int bch_cached_dev_attach(struct cached_dev *, struct cache_set *); | 927 | int bch_cached_dev_attach(struct cached_dev *, struct cache_set *, uint8_t *); |
| 928 | void bch_cached_dev_detach(struct cached_dev *); | 928 | void bch_cached_dev_detach(struct cached_dev *); |
| 929 | void bch_cached_dev_run(struct cached_dev *); | 929 | void bch_cached_dev_run(struct cached_dev *); |
| 930 | void bcache_device_stop(struct bcache_device *); | 930 | void bcache_device_stop(struct bcache_device *); |
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index a2ad37a8afc0..312895788036 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c | |||
| @@ -957,7 +957,8 @@ void bch_cached_dev_detach(struct cached_dev *dc) | |||
| 957 | cached_dev_put(dc); | 957 | cached_dev_put(dc); |
| 958 | } | 958 | } |
| 959 | 959 | ||
| 960 | int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) | 960 | int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, |
| 961 | uint8_t *set_uuid) | ||
| 961 | { | 962 | { |
| 962 | uint32_t rtime = cpu_to_le32(get_seconds()); | 963 | uint32_t rtime = cpu_to_le32(get_seconds()); |
| 963 | struct uuid_entry *u; | 964 | struct uuid_entry *u; |
| @@ -965,7 +966,8 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) | |||
| 965 | 966 | ||
| 966 | bdevname(dc->bdev, buf); | 967 | bdevname(dc->bdev, buf); |
| 967 | 968 | ||
| 968 | if (memcmp(dc->sb.set_uuid, c->sb.set_uuid, 16)) | 969 | if ((set_uuid && memcmp(set_uuid, c->sb.set_uuid, 16)) || |
| 970 | (!set_uuid && memcmp(dc->sb.set_uuid, c->sb.set_uuid, 16))) | ||
| 969 | return -ENOENT; | 971 | return -ENOENT; |
| 970 | 972 | ||
| 971 | if (dc->disk.c) { | 973 | if (dc->disk.c) { |
| @@ -1194,7 +1196,7 @@ static void register_bdev(struct cache_sb *sb, struct page *sb_page, | |||
| 1194 | 1196 | ||
| 1195 | list_add(&dc->list, &uncached_devices); | 1197 | list_add(&dc->list, &uncached_devices); |
| 1196 | list_for_each_entry(c, &bch_cache_sets, list) | 1198 | list_for_each_entry(c, &bch_cache_sets, list) |
| 1197 | bch_cached_dev_attach(dc, c); | 1199 | bch_cached_dev_attach(dc, c, NULL); |
| 1198 | 1200 | ||
| 1199 | if (BDEV_STATE(&dc->sb) == BDEV_STATE_NONE || | 1201 | if (BDEV_STATE(&dc->sb) == BDEV_STATE_NONE || |
| 1200 | BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) | 1202 | BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) |
| @@ -1716,7 +1718,7 @@ static void run_cache_set(struct cache_set *c) | |||
| 1716 | bcache_write_super(c); | 1718 | bcache_write_super(c); |
| 1717 | 1719 | ||
| 1718 | list_for_each_entry_safe(dc, t, &uncached_devices, list) | 1720 | list_for_each_entry_safe(dc, t, &uncached_devices, list) |
| 1719 | bch_cached_dev_attach(dc, c); | 1721 | bch_cached_dev_attach(dc, c, NULL); |
| 1720 | 1722 | ||
| 1721 | flash_devs_run(c); | 1723 | flash_devs_run(c); |
| 1722 | 1724 | ||
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index a7552f509f50..78cd7bd50fdd 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c | |||
| @@ -272,12 +272,14 @@ STORE(__cached_dev) | |||
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | if (attr == &sysfs_attach) { | 274 | if (attr == &sysfs_attach) { |
| 275 | if (bch_parse_uuid(buf, dc->sb.set_uuid) < 16) | 275 | uint8_t set_uuid[16]; |
| 276 | |||
| 277 | if (bch_parse_uuid(buf, set_uuid) < 16) | ||
| 276 | return -EINVAL; | 278 | return -EINVAL; |
| 277 | 279 | ||
| 278 | v = -ENOENT; | 280 | v = -ENOENT; |
| 279 | list_for_each_entry(c, &bch_cache_sets, list) { | 281 | list_for_each_entry(c, &bch_cache_sets, list) { |
| 280 | v = bch_cached_dev_attach(dc, c); | 282 | v = bch_cached_dev_attach(dc, c, set_uuid); |
| 281 | if (!v) | 283 | if (!v) |
| 282 | return size; | 284 | return size; |
| 283 | } | 285 | } |
