Btrfs: nuke a bogus rw_devices decrement in __btrfs_close_devices
authorIlya Dryomov <idryomov@gmail.com>
Thu, 10 Oct 2013 17:37:29 +0000 (20:37 +0300)
committerChris Mason <chris.mason@fusionio.com>
Tue, 12 Nov 2013 03:00:24 +0000 (22:00 -0500)
On mount failures, __btrfs_close_devices can be called well before
dev-replace state is read and ->is_tgtdev_for_dev_replace is set.  This
leads to a bogus decrement of ->rw_devices and sets off a WARN_ON in
__btrfs_close_devices if replace target device happens to be on the
lists and we fail early in the mount sequence.  Fix this by checking
the devid instead of ->is_tgtdev_for_dev_replace before the decrement:
for replace targets devid is always equal to BTRFS_DEV_REPLACE_DEVID.

Cc: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
fs/btrfs/volumes.c

index c846cc8eb32cdc22930f5975df5c4e16daceee18..9dfe038015f7530bf74f1a960fd060f2afd94043 100644 (file)
@@ -666,7 +666,8 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
                if (device->bdev)
                        fs_devices->open_devices--;
 
-               if (device->writeable && !device->is_tgtdev_for_dev_replace) {
+               if (device->writeable &&
+                   device->devid != BTRFS_DEV_REPLACE_DEVID) {
                        list_del_init(&device->dev_alloc_list);
                        fs_devices->rw_devices--;
                }