linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: xiaoshoukui <xiaoshoukui@gmail.com>
To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	xiaoshoukui <xiaoshoukui@gmail.com>,
	xiaoshoukui <xiaoshoukui@ruijie.com.cn>
Subject: [PATCH] btrfs: ioctl: fix inaccurate determination of exclusive_operation
Date: Thu, 23 Mar 2023 23:16:11 -0400	[thread overview]
Message-ID: <20230324031611.98986-1-xiaoshoukui@gmail.com> (raw)

with fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD enter
btrfs_ioctl_add_dev function , exclusive_operation will be classified
as in paused balance operation. After return from btrfs_ioctl_add_dev,
exclusive_operation will be restore to BTRFS_EXCLOP_BALANCE_PAUSED which
is not its original state.

Signed-off-by: xiaoshoukui <xiaoshoukui@ruijie.com.cn>
---
 fs/btrfs/ioctl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index a0ef1a1784c7..aab5fdb9445c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2629,7 +2629,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg)
 	}
 
 	if (!btrfs_exclop_start(fs_info, BTRFS_EXCLOP_DEV_ADD)) {
-		if (!btrfs_exclop_start_try_lock(fs_info, BTRFS_EXCLOP_DEV_ADD))
+		if (fs_info->exclusive_operation != BTRFS_EXCLOP_BALANCE_PAUSED)
 			return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
 
 		/*
@@ -2637,8 +2637,9 @@ static long btrfs_ioctl_add_dev(struct btrfs_fs_info *fs_info, void __user *arg)
 		 * change the exclusive op type and remember we should bring
 		 * back the paused balance
 		 */
+		spin_lock(&fs_info->super_lock);
 		fs_info->exclusive_operation = BTRFS_EXCLOP_DEV_ADD;
-		btrfs_exclop_start_unlock(fs_info);
+		spin_unlock(&fs_info->super_lock);
 		restore_op = true;
 	}
 
-- 
2.20.1


             reply	other threads:[~2023-03-24  3:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  3:16 xiaoshoukui [this message]
2023-03-27 23:05 ` [PATCH] btrfs: ioctl: fix inaccurate determination of exclusive_operation David Sterba
     [not found] <20230327230553.GJ10580 () twin ! jikos ! cz>
2023-03-28  9:43 ` xiaoshoukui
2023-03-31 17:45   ` David Sterba
     [not found] <20230331174533.GZ10580 () twin ! jikos ! cz>
2023-04-03  9:37 ` xiaoshoukui
2023-04-04 19:10   ` David Sterba
2023-04-06  6:58     ` xiaoshoukui

Reply instructions:

You may reply publicly 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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20230324031611.98986-1-xiaoshoukui@gmail.com \
    --to=xiaoshoukui@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xiaoshoukui@ruijie.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).