linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Dryomov <idryomov@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Chris Mason <chris.mason@oracle.com>, idryomov@gmail.com
Subject: [PATCH 06/21] Btrfs: add basic infrastructure for selective balancing
Date: Fri,  6 Jan 2012 16:30:54 +0200	[thread overview]
Message-ID: <1325860269-15013-7-git-send-email-idryomov@gmail.com> (raw)
In-Reply-To: <1325860269-15013-1-git-send-email-idryomov@gmail.com>

This allows to have a separate set of filters for each chunk type
(data,meta,sys).  The code however is generic and switch on chunk type
is only done once.

This commit also adds a type filter: it allows to balance for example
meta and system chunks w/o touching data ones.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 fs/btrfs/ioctl.c   |    3 ++
 fs/btrfs/volumes.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/btrfs/volumes.h |   11 +++++++++
 3 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 221bae0..e20d0cb 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3101,6 +3101,9 @@ static long btrfs_ioctl_balance(struct btrfs_root *root, void __user *arg)
 		memcpy(&bctl->sys, &bargs->sys, sizeof(bctl->sys));
 
 		bctl->flags = bargs->flags;
+	} else {
+		/* balance everything - no filters */
+		bctl->flags |= BTRFS_BALANCE_TYPE_MASK;
 	}
 
 	ret = btrfs_balance(bctl, 0);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e8d6e78..0e6cddd 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2102,6 +2102,30 @@ static void unset_balance_control(struct btrfs_fs_info *fs_info)
 	kfree(bctl);
 }
 
+static int should_balance_chunk(struct btrfs_root *root,
+				struct extent_buffer *leaf,
+				struct btrfs_chunk *chunk, u64 chunk_offset)
+{
+	struct btrfs_balance_control *bctl = root->fs_info->balance_ctl;
+	struct btrfs_balance_args *bargs = NULL;
+	u64 chunk_type = btrfs_chunk_type(leaf, chunk);
+
+	/* type filter */
+	if (!((chunk_type & BTRFS_BLOCK_GROUP_TYPE_MASK) &
+	      (bctl->flags & BTRFS_BALANCE_TYPE_MASK))) {
+		return 0;
+	}
+
+	if (chunk_type & BTRFS_BLOCK_GROUP_DATA)
+		bargs = &bctl->data;
+	else if (chunk_type & BTRFS_BLOCK_GROUP_SYSTEM)
+		bargs = &bctl->sys;
+	else if (chunk_type & BTRFS_BLOCK_GROUP_METADATA)
+		bargs = &bctl->meta;
+
+	return 1;
+}
+
 static u64 div_factor(u64 num, int factor)
 {
 	if (factor == 10)
@@ -2119,10 +2143,13 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
 	struct btrfs_device *device;
 	u64 old_size;
 	u64 size_to_free;
+	struct btrfs_chunk *chunk;
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	struct btrfs_key found_key;
 	struct btrfs_trans_handle *trans;
+	struct extent_buffer *leaf;
+	int slot;
 	int ret;
 	int enospc_errors = 0;
 
@@ -2177,8 +2204,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
 		if (ret)
 			BUG(); /* FIXME break ? */
 
-		btrfs_item_key_to_cpu(path->nodes[0], &found_key,
-				      path->slots[0]);
+		leaf = path->nodes[0];
+		slot = path->slots[0];
+		btrfs_item_key_to_cpu(leaf, &found_key, slot);
+
 		if (found_key.objectid != key.objectid)
 			break;
 
@@ -2186,7 +2215,14 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
 		if (found_key.offset == 0)
 			break;
 
+		chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
+
+		ret = should_balance_chunk(chunk_root, leaf, chunk,
+					   found_key.offset);
 		btrfs_release_path(path);
+		if (!ret)
+			goto loop;
+
 		ret = btrfs_relocate_chunk(chunk_root,
 					   chunk_root->root_key.objectid,
 					   found_key.objectid,
@@ -2195,6 +2231,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
 			goto error;
 		if (ret == -ENOSPC)
 			enospc_errors++;
+loop:
 		key.offset = found_key.offset - 1;
 	}
 
@@ -2221,11 +2258,28 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info)
 int btrfs_balance(struct btrfs_balance_control *bctl, int resume)
 {
 	struct btrfs_fs_info *fs_info = bctl->fs_info;
+	u64 allowed;
 	int ret;
 
 	if (btrfs_fs_closing(fs_info)) {
 		ret = -EINVAL;
 		goto out;
+
+	/*
+	 * In case of mixed groups both data and meta should be picked,
+	 * and identical options should be given for both of them.
+	 */
+	allowed = btrfs_super_incompat_flags(fs_info->super_copy);
+	if ((allowed & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS) &&
+	    (bctl->flags & (BTRFS_BALANCE_DATA | BTRFS_BALANCE_METADATA))) {
+		if (!(bctl->flags & BTRFS_BALANCE_DATA) ||
+		    !(bctl->flags & BTRFS_BALANCE_METADATA) ||
+		    memcmp(&bctl->data, &bctl->meta, sizeof(bctl->data))) {
+			printk(KERN_ERR "btrfs: with mixed groups data and "
+			       "metadata balance options must be the same\n");
+			ret = -EINVAL;
+			goto out;
+		}
 	}
 
 	if (!resume)
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index b9daddc..7a78051 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -186,6 +186,17 @@ struct map_lookup {
 #define map_lookup_size(n) (sizeof(struct map_lookup) + \
 			    (sizeof(struct btrfs_bio_stripe) * (n)))
 
+/*
+ * Restriper's general type filter
+ */
+#define BTRFS_BALANCE_DATA		(1ULL << 0)
+#define BTRFS_BALANCE_SYSTEM		(1ULL << 1)
+#define BTRFS_BALANCE_METADATA		(1ULL << 2)
+
+#define BTRFS_BALANCE_TYPE_MASK		(BTRFS_BALANCE_DATA |	    \
+					 BTRFS_BALANCE_SYSTEM |	    \
+					 BTRFS_BALANCE_METADATA)
+
 struct btrfs_balance_args;
 struct btrfs_balance_control {
 	struct btrfs_fs_info *fs_info;
-- 
1.7.6.3


  parent reply	other threads:[~2012-01-06 14:30 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-06 14:30 [PATCH 00/21] Btrfs: restriper Ilya Dryomov
2012-01-06 14:30 ` [PATCH 01/21] Btrfs: get rid of *_alloc_profile fields Ilya Dryomov
2012-01-06 14:30 ` [PATCH 02/21] Btrfs: introduce masks for chunk type and profile Ilya Dryomov
2012-01-06 14:30 ` [PATCH 03/21] Btrfs: add BTRFS_AVAIL_ALLOC_BIT_SINGLE bit Ilya Dryomov
2012-01-06 14:30 ` [PATCH 04/21] Btrfs: make avail_*_alloc_bits fields dynamic Ilya Dryomov
2012-01-06 14:30 ` [PATCH 05/21] Btrfs: add basic restriper infrastructure Ilya Dryomov
2012-01-06 14:30 ` Ilya Dryomov [this message]
2012-01-06 14:30 ` [PATCH 07/21] Btrfs: profiles filter Ilya Dryomov
2012-01-06 14:30 ` [PATCH 08/21] Btrfs: usage filter Ilya Dryomov
2012-01-06 14:30 ` [PATCH 09/21] Btrfs: devid filter Ilya Dryomov
2012-01-06 14:30 ` [PATCH 10/21] Btrfs: devid subset filter Ilya Dryomov
2012-01-06 14:30 ` [PATCH 11/21] Btrfs: virtual address space " Ilya Dryomov
2012-01-06 14:31 ` [PATCH 12/21] Btrfs: do not reduce profile in do_chunk_alloc() Ilya Dryomov
2012-01-06 14:31 ` [PATCH 13/21] Btrfs: implement online profile changing Ilya Dryomov
2012-01-06 14:31 ` [PATCH 14/21] Btrfs: soft profile changing mode (aka soft convert) Ilya Dryomov
2012-01-06 14:31 ` [PATCH 15/21] Btrfs: save balance parameters to disk Ilya Dryomov
2012-01-06 14:31 ` [PATCH 16/21] Btrfs: recover balance on mount Ilya Dryomov
2012-01-12 14:00   ` David Sterba
2012-01-12 14:29     ` Ilya Dryomov
2012-01-06 14:31 ` [PATCH 17/21] Btrfs: add skip_balance mount option Ilya Dryomov
2012-01-06 14:31 ` [PATCH 18/21] Btrfs: allow for pausing restriper Ilya Dryomov
2012-01-06 14:31 ` [PATCH 19/21] Btrfs: allow for cancelling restriper Ilya Dryomov
2012-01-06 14:31 ` [PATCH 20/21] Btrfs: allow for resuming restriper after it was paused Ilya Dryomov
2012-01-06 14:31 ` [PATCH 21/21] Btrfs: add balance progress reporting Ilya Dryomov
2012-01-09  6:50 ` [PATCH 00/21] Btrfs: restriper Marios Titas
2012-01-09 13:44   ` Ilya Dryomov
2012-01-10 18:31     ` Ilya Dryomov
2012-02-14  2:31 ` Jérôme Poulin
2012-02-14 14:18   ` Ilya Dryomov
2012-02-14 16:15     ` Jérôme Poulin
2012-02-14 16:44       ` Ilya Dryomov

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=1325860269-15013-7-git-send-email-idryomov@gmail.com \
    --to=idryomov@gmail.com \
    --cc=chris.mason@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 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).