Patchwork [3.5.y.z,extended,stable] Patch "btrfs: use rcu_barrier() to wait for bdev puts at unmount" has been added to staging queue

mail settings
Submitter Luis Henriques
Date March 19, 2013, 12:22 p.m.
Message ID <>
Download mbox | patch
Permalink /patch/229037/
State New
Headers show


Luis Henriques - March 19, 2013, 12:22 p.m.
This is a note to let you know that I have just added a patch titled

    btrfs: use rcu_barrier() to wait for bdev puts at unmount

to the linux-3.5.y-queue branch of the 3.5.y.z extended stable tree 
which can be found at:;a=shortlog;h=refs/heads/linux-3.5.y-queue

If you, or anyone else, feels it should not be added to this tree, please 
reply to this email.

For more information about the 3.5.y.z tree, see



From fb5e30677089e58d058977d56fc63afcd3a1d32b Mon Sep 17 00:00:00 2001
From: Eric Sandeen <>
Date: Sat, 9 Mar 2013 15:18:39 +0000
Subject: [PATCH] btrfs: use rcu_barrier() to wait for bdev puts at unmount

commit bc178622d40d87e75abc131007342429c9b03351 upstream.

Doing this would reliably fail with -EBUSY for me:

# mount /dev/sdb2 /mnt/scratch; umount /mnt/scratch; mkfs.btrfs -f /dev/sdb2
unable to open /dev/sdb2: Device or resource busy

because mkfs.btrfs tries to open the device O_EXCL, and somebody still has it.

Using systemtap to track bdev gets & puts shows a kworker thread doing a
blkdev put after mkfs attempts a get; this is left over from the unmount

		call_rcu(&device->rcu, free_device);
				INIT_WORK(&device->rcu_work, __free_device);

so unmount might complete before __free_device fires & does its blkdev_put.

Adding an rcu_barrier() to btrfs_close_devices() causes unmount to wait
until all blkdev_put()s are done, and the device is truly free once
unmount completes.

Signed-off-by: Eric Sandeen <>
Signed-off-by: Josef Bacik <>
Signed-off-by: Chris Mason <>
Luis Henriques <>
 fs/btrfs/volumes.c | 6 ++++++
 1 file changed, 6 insertions(+)



diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2208f0f..446896d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -609,6 +609,12 @@  int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
+	/*
+	 * Wait for rcu kworkers under __btrfs_close_devices
+	 * to finish all blkdev_puts so device is really
+	 * free when umount is done.
+	 */
+	rcu_barrier();
 	return ret;