All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs: fix get set label blocking against balance
Date: Thu, 18 Jul 2013 19:18:18 +0800	[thread overview]
Message-ID: <1374146298-30789-1-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <51E655D1.5020309@oracle.com>

btrfs_ioctl_get_fslabel() and btrfs_ioctl_set_fslabel()
used root->fs_info->volume_mutex mutex which caused operations
like balance to block set/get label operation until its
completion and generally balance operation takes a long
time to complete, so it will be annoying to the user when
cli appears hung

This patch will use mutex uuid_mutex. which is defined
in volume.c, and so it is moved to volume.h as well.

also this patch will add a bit of optimization within
the btrfs_ioctl_get_falabel() function.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 fs/btrfs/ioctl.c   | 16 ++++++++++------
 fs/btrfs/volumes.c |  1 -
 fs/btrfs/volumes.h |  1 +
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2177bea..d67d7d3 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4043,17 +4043,21 @@ static int btrfs_ioctl_get_fslabel(struct file *file, void __user *arg)
 {
 	struct btrfs_root *root = BTRFS_I(fdentry(file)->d_inode)->root;
 	const char *label = root->fs_info->super_copy->label;
-	size_t len = strnlen(label, BTRFS_LABEL_SIZE);
+	char label_copy[BTRFS_LABEL_SIZE];
+	size_t	len;
 	int ret;
 
+	mutex_lock(&uuid_mutex);
+	memcpy(label_copy, label, BTRFS_LABEL_SIZE);
+	mutex_unlock(&uuid_mutex);
+
+	len = strnlen(label_copy, BTRFS_LABEL_SIZE);
 	if (len == BTRFS_LABEL_SIZE) {
 		pr_warn("btrfs: label is too long, return the first %zu bytes\n",
 			--len);
 	}
 
-	mutex_lock(&root->fs_info->volume_mutex);
-	ret = copy_to_user(arg, label, len);
-	mutex_unlock(&root->fs_info->volume_mutex);
+	ret = copy_to_user(arg, label_copy, len);
 
 	return ret ? -EFAULT : 0;
 }
@@ -4082,7 +4086,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
 	if (ret)
 		return ret;
 
-	mutex_lock(&root->fs_info->volume_mutex);
+	mutex_lock(&uuid_mutex);
 	trans = btrfs_start_transaction(root, 0);
 	if (IS_ERR(trans)) {
 		ret = PTR_ERR(trans);
@@ -4093,7 +4097,7 @@ static int btrfs_ioctl_set_fslabel(struct file *file, void __user *arg)
 	ret = btrfs_end_transaction(trans, root);
 
 out_unlock:
-	mutex_unlock(&root->fs_info->volume_mutex);
+	mutex_unlock(&uuid_mutex);
 	mnt_drop_write_file(file);
 	return ret;
 }
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 557a743..a5b3eb3 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -49,7 +49,6 @@ static void __btrfs_reset_dev_stats(struct btrfs_device *dev);
 static void btrfs_dev_stat_print_on_error(struct btrfs_device *dev);
 static void btrfs_dev_stat_print_on_load(struct btrfs_device *device);
 
-static DEFINE_MUTEX(uuid_mutex);
 static LIST_HEAD(fs_uuids);
 
 static void lock_chunks(struct btrfs_root *root)
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 8670558..7855ef9 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -26,6 +26,7 @@
 
 #define BTRFS_STRIPE_LEN	(64 * 1024)
 
+static DEFINE_MUTEX(uuid_mutex);
 struct buffer_head;
 struct btrfs_pending_bios {
 	struct bio *head;
-- 
1.8.1.227.g44fe835


  parent reply	other threads:[~2013-07-18 11:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-17  8:29 [bug] label cli hangs until balance is completed Anand Jain
2013-07-17  9:09 ` Stefan Behrens
2013-07-17 17:49   ` Zach Brown
2013-07-18 11:18 ` Anand Jain [this message]
2013-07-18 12:47   ` [PATCH] btrfs: fix get set label blocking against balance Stefan Behrens
2013-07-19  9:31     ` Anand Jain
2013-07-19  9:39   ` [PATCH v2] " Anand Jain

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=1374146298-30789-1-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.