Skip to content

Commit 07cc6ef

Browse files
Eric Wheeleraxboe
authored andcommitted
bcache: fix race of writeback thread starting before complete initialization
The bch_writeback_thread might BUG_ON in read_dirty() if dc->sb==BDEV_STATE_DIRTY and bch_sectors_dirty_init has not yet completed its related initialization. This patch downs the dc->writeback_lock until after initialization is complete, thus preventing bch_writeback_thread from proceeding prematurely. See this thread: http://thread.gmane.org/gmane.linux.kernel.bcache.devel/3453 Signed-off-by: Eric Wheeler <bcache@linux.ewheeler.net> Tested-by: Marc MERLIN <marc@merlins.org> Cc: <stable@vger.kernel.org> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 08095e7 commit 07cc6ef

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

drivers/md/bcache/super.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,12 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
10151015
*/
10161016
atomic_set(&dc->count, 1);
10171017

1018-
if (bch_cached_dev_writeback_start(dc))
1018+
/* Block writeback thread, but spawn it */
1019+
down_write(&dc->writeback_lock);
1020+
if (bch_cached_dev_writeback_start(dc)) {
1021+
up_write(&dc->writeback_lock);
10191022
return -ENOMEM;
1023+
}
10201024

10211025
if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
10221026
bch_sectors_dirty_init(dc);
@@ -1028,6 +1032,9 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
10281032
bch_cached_dev_run(dc);
10291033
bcache_device_link(&dc->disk, c, "bdev");
10301034

1035+
/* Allow the writeback thread to proceed */
1036+
up_write(&dc->writeback_lock);
1037+
10311038
pr_info("Caching %s as %s on set %pU",
10321039
bdevname(dc->bdev, buf), dc->disk.disk->disk_name,
10331040
dc->disk.c->sb.set_uuid);

0 commit comments

Comments
 (0)