bcache: Fix a sysfs splat on shutdown
authorKent Overstreet <kmo@daterainc.com>
Thu, 11 Jul 2013 04:25:02 +0000 (21:25 -0700)
committerKent Overstreet <kmo@daterainc.com>
Fri, 12 Jul 2013 07:22:47 +0000 (00:22 -0700)
If we stopped a bcache device when we were already detaching (or
something like that), bcache_device_unlink() would try to remove a
symlink from sysfs that was already gone because the bcache dev kobject
had already been removed from sysfs.

So keep track of whether we've removed stuff from sysfs.

Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
drivers/md/bcache/bcache.h
drivers/md/bcache/super.c

index 342ba86c6e4f53f20ede7ba6cc2a81c5cb0800ca..68f1ded81ae0b98ec3cf2c604aac50a66ced3171 100644 (file)
@@ -434,6 +434,7 @@ struct bcache_device {
 
        /* If nonzero, we're detaching/unregistering from cache set */
        atomic_t                detaching;
+       int                     flush_done;
 
        uint64_t                nr_stripes;
        unsigned                stripe_size_bits;
index 728fdc673f31bdf2c3837d62ba82b1ec9903aef0..7a1dcdb2536eaa66e66a1876178262d18064b9c6 100644 (file)
@@ -706,7 +706,8 @@ static void bcache_device_detach(struct bcache_device *d)
                atomic_set(&d->detaching, 0);
        }
 
-       bcache_device_unlink(d);
+       if (!d->flush_done)
+               bcache_device_unlink(d);
 
        d->c->devices[d->id] = NULL;
        closure_put(&d->c->caching);
@@ -1055,6 +1056,14 @@ static void cached_dev_flush(struct closure *cl)
        struct cached_dev *dc = container_of(cl, struct cached_dev, disk.cl);
        struct bcache_device *d = &dc->disk;
 
+       mutex_lock(&bch_register_lock);
+       d->flush_done = 1;
+
+       if (d->c)
+               bcache_device_unlink(d);
+
+       mutex_unlock(&bch_register_lock);
+
        bch_cache_accounting_destroy(&dc->accounting);
        kobject_del(&d->kobj);