bcache: correct dirty data statistics
authorTang Junhui <tang.junhui.linux@gmail.com>
Mon, 8 Oct 2018 12:41:12 +0000 (20:41 +0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 8 Oct 2018 14:19:45 +0000 (08:19 -0600)
When bcache device is clean, dirty keys may still exist after
journal replay, so we need to count these dirty keys even
device in clean status, otherwise after writeback, the amount
of dirty data would be incorrect.

Signed-off-by: Tang Junhui <tang.junhui.linux@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/super.c

index 9de6695..c116b6e 100644 (file)
@@ -1153,11 +1153,12 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c,
        }
 
        if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
-               bch_sectors_dirty_init(&dc->disk);
                atomic_set(&dc->has_dirty, 1);
                bch_writeback_queue(dc);
        }
 
+       bch_sectors_dirty_init(&dc->disk);
+
        bch_cached_dev_run(dc);
        bcache_device_link(&dc->disk, c, "bdev");
        atomic_inc(&c->attached_dev_nr);