diff mbox

[v2,15/16] btrfs: use mutex in btrfs_resume_balance_async

Message ID a17bb1118ad18ab1b823cfd472dbb57bce6e1e88.1524146556.git.dsterba@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Sterba April 19, 2018, 4:33 p.m. UTC
While the spinlock does not cause problems, using the mutex is more
correct and consistent with others. The global status of balance is eg.
checked from btrfs_pause_balance or btrfs_cancel_balance with mutex.

Resuming balance happens during mount or ro->rw remount. In the former
case, no other user of the balance_ctl exists, in the latter, balance
cannot run until the ro/rw transition is finished.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/volumes.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Anand Jain April 20, 2018, 9:25 a.m. UTC | #1
On 04/20/2018 12:33 AM, David Sterba wrote:
> While the spinlock does not cause problems, using the mutex is more
> correct and consistent with others. The global status of balance is eg.
> checked from btrfs_pause_balance or btrfs_cancel_balance with mutex.
> 
> Resuming balance happens during mount or ro->rw remount. In the former
> case, no other user of the balance_ctl exists, in the latter, balance
> cannot run until the ro/rw transition is finished.
> 
> Signed-off-by: David Sterba <dsterba@suse.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>

Thanks, Anand
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 1abe0fc5c105..445380c4ac72 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3938,12 +3938,12 @@  int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
 {
 	struct task_struct *tsk;
 
-	spin_lock(&fs_info->balance_lock);
+	mutex_lock(&fs_info->balance_mutex);
 	if (!fs_info->balance_ctl) {
-		spin_unlock(&fs_info->balance_lock);
+		mutex_unlock(&fs_info->balance_mutex);
 		return 0;
 	}
-	spin_unlock(&fs_info->balance_lock);
+	mutex_unlock(&fs_info->balance_mutex);
 
 	if (btrfs_test_opt(fs_info, SKIP_BALANCE)) {
 		btrfs_info(fs_info, "force skipping balance");