Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1551389

[PATCH 4.8 32/85] btrfs: clean the old superblocks before freeing the device

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 4.8 32/85] btrfs: clean the old superblocks before freeing the device
Date 2017-01-04 22:20 +0100
Message-ID <sW18v-1M9-73@gated-at.bofh.it> (permalink)
References <sW0P7-1np-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


4.8-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Jeff Mahoney <jeffm@suse.com>

commit cea67ab92d3d4da9f2b4141d87cb8664757daca0 upstream.

btrfs_rm_device frees the block device but then re-opens it using
the saved device name.  A race exists between the close and the
re-open that allows the block size to be changed.  The result
is getting stuck forever in the reclaim loop in __getblk_slow.

This patch moves the superblock cleanup before closing the block
device, which is also consistent with other callers.  We also don't
need a private copy of dev_name as the whole routine operates under
the uuid_mutex.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 fs/btrfs/volumes.c |   38 +++++++++++---------------------------
 1 file changed, 11 insertions(+), 27 deletions(-)

--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1846,7 +1846,6 @@ int btrfs_rm_device(struct btrfs_root *r
 	u64 num_devices;
 	int ret = 0;
 	bool clear_super = false;
-	char *dev_name = NULL;
 
 	mutex_lock(&uuid_mutex);
 
@@ -1882,11 +1881,6 @@ int btrfs_rm_device(struct btrfs_root *r
 		list_del_init(&device->dev_alloc_list);
 		device->fs_devices->rw_devices--;
 		unlock_chunks(root);
-		dev_name = kstrdup(device->name->str, GFP_KERNEL);
-		if (!dev_name) {
-			ret = -ENOMEM;
-			goto error_undo;
-		}
 		clear_super = true;
 	}
 
@@ -1936,14 +1930,21 @@ int btrfs_rm_device(struct btrfs_root *r
 		btrfs_sysfs_rm_device_link(root->fs_info->fs_devices, device);
 	}
 
-	btrfs_close_bdev(device);
-
-	call_rcu(&device->rcu, free_device);
-
 	num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
 	btrfs_set_super_num_devices(root->fs_info->super_copy, num_devices);
 	mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 
+	/*
+	 * at this point, the device is zero sized and detached from
+	 * the devices list.  All that's left is to zero out the old
+	 * supers and free the device.
+	 */
+	if (device->writeable)
+		btrfs_scratch_superblocks(device->bdev, device->name->str);
+
+	btrfs_close_bdev(device);
+	call_rcu(&device->rcu, free_device);
+
 	if (cur_devices->open_devices == 0) {
 		struct btrfs_fs_devices *fs_devices;
 		fs_devices = root->fs_info->fs_devices;
@@ -1962,24 +1963,7 @@ int btrfs_rm_device(struct btrfs_root *r
 	root->fs_info->num_tolerated_disk_barrier_failures =
 		btrfs_calc_num_tolerated_disk_barrier_failures(root->fs_info);
 
-	/*
-	 * at this point, the device is zero sized.  We want to
-	 * remove it from the devices list and zero out the old super
-	 */
-	if (clear_super) {
-		struct block_device *bdev;
-
-		bdev = blkdev_get_by_path(dev_name, FMODE_READ | FMODE_EXCL,
-						root->fs_info->bdev_holder);
-		if (!IS_ERR(bdev)) {
-			btrfs_scratch_superblocks(bdev, dev_name);
-			blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
-		}
-	}
-
 out:
-	kfree(dev_name);
-
 	mutex_unlock(&uuid_mutex);
 	return ret;
 

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.8 00/85] 4.8.16-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:10 +0100
  [PATCH 4.8 13/85] USB: cdc-acm: add device id for GW Instek AFG-125 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 27/85] clk: ti: omap36xx: Work around sprz319 advisory 2.1 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 24/85] ALSA: hda - fix headset-mic problem on a Dell laptop Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 21/85] ALSA: hiface: Fix M2Tech hiFace driver sampling rate change Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 02/85] btrfs: limit async_work allocation and worker func duration Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 33/85] Btrfs: fix memory leak in do_walk_down Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 29/85] Btrfs: bail out if block group has different mixed flag Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 28/85] Btrfs: fix memory leak in reading btree blocks Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 01/85] aoe: fix crash in page count manipulation Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 15/85] usb: hub: Fix auto-remount of safely removed or ejected USB-3 devices Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 26/85] ALSA: hda: when comparing pin configurations, ignore assoc in addition to seq Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 34/85] btrfs: fix a possible umount deadlock Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 31/85] Btrfs: dont leak reloc root nodes on error Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 32/85] btrfs: clean the old superblocks before freeing the device Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 18/85] USB: UHCI: report non-PME wakeup signalling for Intel hardware Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  [PATCH 4.8 11/85] USB: serial: option: add dlink dwm-158 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-01-04 22:20 +0100
  Re: [PATCH 4.8 00/85] 4.8.16-stable review Shuah Khan <shuah.kh@samsung.com> - 2017-01-05 01:50 +0100
  Re: [PATCH 4.8 00/85] 4.8.16-stable review Guenter Roeck <linux@roeck-us.net> - 2017-01-05 05:50 +0100

csiph-web