All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Gabríel Arthúr Pétursson" <gabriel@system.is>
To: linux-btrfs@vger.kernel.org
Subject: Add stripes filter
Date: Mon, 28 Sep 2015 17:57:05 +0000	[thread overview]
Message-ID: <1443463025.16163.6.camel@system.is> (raw)

[-- Attachment #1: Type: text/plain, Size: 398 bytes --]

Hello everyone!

The attached patches to linux and btrfs-progs add support for filtering
based on the number of strips in a block when balancing.

This is my first attempt at kernel development, I'd love if you could
please point out any mistakes that I've made.

Thanks,
Gabríel

P.S. I could not figure out how to subscribe to this mailing list, so
please remember to include me in your replies.

[-- Attachment #2: btrfs-progs.diff --]
[-- Type: text/x-patch, Size: 2903 bytes --]

diff --git a/Documentation/btrfs-balance.asciidoc b/Documentation/btrfs-balance.asciidoc
index 6d2fd0c..8663855 100644
--- a/Documentation/btrfs-balance.asciidoc
+++ b/Documentation/btrfs-balance.asciidoc
@@ -110,6 +110,10 @@ Process only given number of chunks, after all filters apply. This can be used
 to specifically target a chunk in connection with other filters (drange,
 vrange) or just simply limit the amount of work done by a single balance run.
 
+*stripes*::
+Balances only block groups which have the given number of stripes. The
+parameter is either a range specified as <start..end>, or a single integer.
+
 *soft*::
 Takes no parameters. Only has meaning when converting between profiles.
 When doing convert from one profile to another and soft mode is on,
diff --git a/cmds-balance.c b/cmds-balance.c
index 9af218b..c47f8b7 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -226,6 +226,21 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
 				return 1;
 			}
 			args->flags |= BTRFS_BALANCE_ARGS_LIMIT;
+		} else if (!strcmp(this_char, "stripes")) {
+			if (!value || !*value) {
+				fprintf(stderr,
+					"the stripes filter requires an argument\n");
+				return 1;
+			}
+			if (parse_u64(value, &args->sstart)) {
+				if (parse_range(value, &args->sstart, &args->send)) {
+					fprintf(stderr, "Invalid stripes argument\n");
+					return 1;
+				}
+			} else {
+				args->send = args->sstart;
+			}
+			args->flags |= BTRFS_BALANCE_ARGS_STRIPES;
 		} else {
 			fprintf(stderr, "Unrecognized balance option '%s'\n",
 				this_char);
@@ -262,6 +277,15 @@ static void dump_balance_args(struct btrfs_balance_args *args)
 		       (unsigned long long)args->vend);
 	if (args->flags & BTRFS_BALANCE_ARGS_LIMIT)
 		printf(", limit=%llu", (unsigned long long)args->limit);
+	if (args->flags & BTRFS_BALANCE_ARGS_STRIPES) {
+		if (args->sstart == args->send) {
+			printf(", stripes=%llu", (unsigned long long)args->sstart);
+		} else {
+			printf(", stripes=%llu..%llu",
+			        (unsigned long long)args->sstart,
+			        (unsigned long long)args->send);
+		}
+	}
 
 	printf("\n");
 }
diff --git a/ioctl.h b/ioctl.h
index dff015a..c1f6aec 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -228,7 +228,11 @@ struct btrfs_balance_args {
 	__u64 flags;
 
 	__u64 limit;		/* limit number of processed chunks */
-	__u64 unused[7];
+
+	__u64 sstart;
+	__u64 send;
+
+	__u64 unused[5];
 } __attribute__ ((__packed__));
 
 /* report balance progress to userspace */
diff --git a/volumes.h b/volumes.h
index 4ecb993..a809a78 100644
--- a/volumes.h
+++ b/volumes.h
@@ -136,6 +136,7 @@ struct map_lookup {
 #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
+#define BTRFS_BALANCE_ARGS_STRIPES	(1ULL << 6)
 
 /*
  * Profile changing flags.  When SOFT is set we won't relocate chunk if

[-- Attachment #3: linux.diff --]
[-- Type: text/x-patch, Size: 2277 bytes --]

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 938efe3..78573e5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -849,7 +849,11 @@ struct btrfs_disk_balance_args {
 	/* BTRFS_BALANCE_ARGS_LIMIT value */
 	__le64 limit;
 
-	__le64 unused[7];
+	/* btrfs stripes filter */
+	__le64 sstart;
+	__le64 send;
+
+	__le64 unused[5];
 } __attribute__ ((__packed__));
 
 /*
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 6fc73586..dc65fbb 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -3170,6 +3170,18 @@ static int chunk_vrange_filter(struct extent_buffer *leaf,
 	return 1;
 }
 
+static int chunk_stripes_filter(struct extent_buffer *leaf,
+			       struct btrfs_chunk *chunk,
+			       struct btrfs_balance_args *bargs)
+{
+	int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
+
+	if (bargs->sstart <= num_stripes && num_stripes <= bargs->send)
+		return 0;
+
+	return 1;
+}
+
 static int chunk_soft_convert_filter(u64 chunk_type,
 				     struct btrfs_balance_args *bargs)
 {
@@ -3236,6 +3248,12 @@ static int should_balance_chunk(struct btrfs_root *root,
 		return 0;
 	}
 
+	/* stripes filter */
+	if ((bargs->flags & BTRFS_BALANCE_ARGS_STRIPES) &&
+	    chunk_stripes_filter(leaf, chunk, bargs)) {
+		return 0;
+	}
+
 	/* soft profile changing mode */
 	if ((bargs->flags & BTRFS_BALANCE_ARGS_SOFT) &&
 	    chunk_soft_convert_filter(chunk_type, bargs)) {
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2ca784a..fb6b89a 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -375,6 +375,7 @@ struct map_lookup {
 #define BTRFS_BALANCE_ARGS_DRANGE	(1ULL << 3)
 #define BTRFS_BALANCE_ARGS_VRANGE	(1ULL << 4)
 #define BTRFS_BALANCE_ARGS_LIMIT	(1ULL << 5)
+#define BTRFS_BALANCE_ARGS_STRIPES	(1ULL << 6)
 
 /*
  * Profile changing flags.  When SOFT is set we won't relocate chunk if
diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h
index b6dec05..a7819d0 100644
--- a/include/uapi/linux/btrfs.h
+++ b/include/uapi/linux/btrfs.h
@@ -218,7 +218,11 @@ struct btrfs_balance_args {
 	__u64 flags;
 
 	__u64 limit;		/* limit number of processed chunks */
-	__u64 unused[7];
+
+	__u64 sstart;
+	__u64 send;
+
+	__u64 unused[5];
 } __attribute__ ((__packed__));
 
 /* report balance progress to userspace */

             reply	other threads:[~2015-09-28 17:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28 17:57 Gabríel Arthúr Pétursson [this message]
2015-09-28 21:11 ` Add stripes filter Omar Sandoval
2015-09-28 22:32 ` [PATCH] btrfs: add " Gabríel Arthúr Pétursson
2015-09-30 15:50   ` David Sterba
2015-09-28 22:33 ` [PATCH] btrfs-progs: " Gabríel Arthúr Pétursson
2015-09-29 12:00 ` Add " David Sterba
2015-09-29 12:10   ` Austin S Hemmelgarn
2015-09-29 12:21     ` Hugo Mills
2015-09-30 15:28       ` David Sterba
2015-09-30 15:16     ` David Sterba
2015-10-12 14:10 ` David Sterba

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=1443463025.16163.6.camel@system.is \
    --to=gabriel@system.is \
    --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.