Linux-BTRFS Archive on
 help / color / Atom feed
From: Johannes Thumshirn <>
To: David Sterba <>
Cc: Nikolay Borisov <>, Qu Wenruo <>,
	Linux BTRFS Mailinglist <>,
	Johannes Thumshirn <>
Subject: [PATCH v5 1/2] btrfs: decrement number of open devices after closing the device not before
Date: Wed,  4 Dec 2019 14:36:38 +0100
Message-ID: <> (raw)
In-Reply-To: <>

From: Johannes Thumshirn <>

In btrfs_close_one_device we're decrementing the number of open devices
before we're calling btrfs_close_bdev().

As there is no intermediate exit between these points in this function it
is technically OK to do so, but it makes the code a bit harder to understand.

Move both operations closer together and move the decrement step after

Signed-off-by: Johannes Thumshirn <>
Reviewed-by: Qu Wenruo <>
 fs/btrfs/volumes.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c565650639ee..ae3980ba3a87 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1069,9 +1069,6 @@ static void btrfs_close_one_device(struct btrfs_device *device)
 	struct btrfs_device *new_device;
 	struct rcu_string *name;
-	if (device->bdev)
-		fs_devices->open_devices--;
 	if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state) &&
 	    device->devid != BTRFS_DEV_REPLACE_DEVID) {
@@ -1082,6 +1079,8 @@ static void btrfs_close_one_device(struct btrfs_device *device)
+	if (device->bdev)
+		fs_devices->open_devices--;
 	new_device = btrfs_alloc_device(NULL, &device->devid,
2.20.1 (Apple Git-117)

  reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-04 13:36 [PATCH v5 0/2] remove BUG_ON()s in btrfs_close_one_device() Johannes Thumshirn
2019-12-04 13:36 ` Johannes Thumshirn [this message]
2019-12-04 13:36 ` [PATCH v5 2/2] btrfs: reset device back to allocation state when removing Johannes Thumshirn
2019-12-10 10:10 ` [PATCH v5 0/2] remove BUG_ON()s in btrfs_close_one_device() David Sterba

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-BTRFS Archive on

Archives are clonable:
	git clone --mirror linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ \
	public-inbox-index linux-btrfs

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone