Skip to contentSkip to conversation

bcache: move calc_cached_dev_sectors to proper place on backing device detach

PATCH In review Lin Feng 2 participants 2 messages Oct 15, 2021 – Oct 18, 2021 bcache (block layer cache)

lore
Share & tools
lore

Lin Feng

author
#0 lore raw

PATCH 1/1 bcache: move calc_cached_dev_sectors to proper place on backing device detach

Calculation of cache_set's cached sectors is done by travelling cached_devs list as shown below:

static void calc_cached_dev_sectors(struct cache_set *c) {
...

        list_for_each_entry(dc, &c->cached_devs, list)
                sectors += bdev_sectors(dc->bdev);

        c->cached_dev_sectors = sectors;
}

But cached_dev won't be unlinked from c->cached_devs list until we call following list_move(&dc->list, &uncached_devices),
so previous fix in 'commit 46010141da6677b81cc77f9b47f8ac62bd1cbfd3 ("bcache: recal cached_dev_sectors on detach")' is wrong, now we move it to its right palce.

---
 drivers/md/bcache/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index f2874c77ff79..8543e6997770 100644
@@ -1154,9 +1154,9 @@ static void cached_dev_detach_finish(struct work_struct *w)
 
 	mutex_lock(&bch_register_lock);
 
-	calc_cached_dev_sectors(dc->disk.c);
 	bcache_device_detach(&dc->disk);
 	list_move(&dc->list, &uncached_devices);
+	calc_cached_dev_sectors(dc->disk.c);
 
 	clear_bit(BCACHE_DEV_DETACHING, &dc->disk.flags);
 	clear_bit(BCACHE_DEV_UNLINK_DONE, &dc->disk.flags);
Signature · 1 line
2.31.1
#1 lore raw
Quoted 12 lines · Lin Feng

Calculation of cache_set's cached sectors is done by travelling cached_devs list as shown below:

static void calc_cached_dev_sectors(struct cache_set *c) {
...

         list_for_each_entry(dc, &c->cached_devs, list)
                 sectors += bdev_sectors(dc->bdev);

         c->cached_dev_sectors = sectors;
}
Quoted 7 lines

But cached_dev won't be unlinked from c->cached_devs list until we call following list_move(&dc->list, &uncached_devices),
so previous fix in 'commit 46010141da6677b81cc77f9b47f8ac62bd1cbfd3 ("bcache: recal cached_dev_sectors on detach")' is wrong, now we move it to its right palce.

Nice catch! I added it in my testing series. Thanks.

Coly Li

Quoted 19 lines
---
  drivers/md/bcache/super.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/super.c +1 -1
index f2874c77ff79..8543e6997770 100644
@@ -1154,9 +1154,9 @@ static void cached_dev_detach_finish(struct work_struct *w)
 
  	mutex_lock(&bch_register_lock);
 
-	calc_cached_dev_sectors(dc->disk.c);
  	bcache_device_detach(&dc->disk);
  	list_move(&dc->list, &uncached_devices);
+	calc_cached_dev_sectors(dc->disk.c);
 
  	clear_bit(BCACHE_DEV_DETACHING, &dc->disk.flags);
  	clear_bit(BCACHE_DEV_UNLINK_DONE, &dc->disk.flags);