|
@@ -1015,8 +1015,12 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
|
|
|
*/
|
|
|
atomic_set(&dc->count, 1);
|
|
|
|
|
|
- if (bch_cached_dev_writeback_start(dc))
|
|
|
+ /* Block writeback thread, but spawn it */
|
|
|
+ down_write(&dc->writeback_lock);
|
|
|
+ if (bch_cached_dev_writeback_start(dc)) {
|
|
|
+ up_write(&dc->writeback_lock);
|
|
|
return -ENOMEM;
|
|
|
+ }
|
|
|
|
|
|
if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY) {
|
|
|
bch_sectors_dirty_init(dc);
|
|
@@ -1028,6 +1032,9 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
|
|
|
bch_cached_dev_run(dc);
|
|
|
bcache_device_link(&dc->disk, c, "bdev");
|
|
|
|
|
|
+ /* Allow the writeback thread to proceed */
|
|
|
+ up_write(&dc->writeback_lock);
|
|
|
+
|
|
|
pr_info("Caching %s as %s on set %pU",
|
|
|
bdevname(dc->bdev, buf), dc->disk.disk->disk_name,
|
|
|
dc->disk.c->sb.set_uuid);
|