All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hugo Mills <hugo@carfax.org.uk>
Subject: [PATCH v6 6/8] Balance filter by device ID
Date: Sun,  1 May 2011 16:47:14 +0100	[thread overview]
Message-ID: <725a6071db510f6483100baced12834942438020.1304262467.git.hugo@carfax.org.uk> (raw)
In-Reply-To: <cover.1304262467.git.hugo@carfax.org.uk>
In-Reply-To: <cover.1304262467.git.hugo@carfax.org.uk>

Add the userspace implementation for filtering balances by device ID.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
---
 btrfs_cmds.c   |   13 +++++++++++++
 ioctl.h        |    8 ++++++--
 man/btrfs.8.in |    7 +++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/btrfs_cmds.c b/btrfs_cmds.c
index 279d93a..0f1434f 100644
--- a/btrfs_cmds.c
+++ b/btrfs_cmds.c
@@ -775,6 +775,10 @@ const struct filter_class_desc filter_class[] = {
 	  "\t\tmeta, sys, data, raid0, raid1, raid10, dup\n"
 	  "\tPrefix a <flagname> with ~ to negate the match.\n",
 	  BTRFS_BALANCE_FILTER_CHUNK_TYPE },
+	{ "devid",
+	  "devid=<n>\n"
+	  "\tBalance only chunks which have a stripe on device <n>.\n",
+	  BTRFS_BALANCE_FILTER_DEVID },
 	{ NULL, NULL, 0 }
 };
 
@@ -870,6 +874,15 @@ int parse_filter(struct btrfs_ioctl_balance_start *args, char *filters_string)
 				part = strtok_r(NULL, "=,", &subsave);
 			}
 			break;
+
+		case BTRFS_BALANCE_FILTER_DEVID:
+			errno = 0;
+			args->devid = strtoull(part, NULL, 10);
+			if (errno != 0) {
+				fprintf(stderr, "ERROR: '%s' is not a valid device ID\n", part);
+				return 15;
+			}
+			break;
 		}
 
 		this_filter_string = strtok_r(NULL, ":", &saveptr);
diff --git a/ioctl.h b/ioctl.h
index 230c314..e30687c 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -141,7 +141,8 @@ struct btrfs_ioctl_balance_progress {
 #define BTRFS_BALANCE_FILTER_COUNT_ONLY 0x1
 
 #define BTRFS_BALANCE_FILTER_CHUNK_TYPE 0x2
-#define BTRFS_BALANCE_FILTER_MASK 0x3
+#define BTRFS_BALANCE_FILTER_DEVID 0x4
+#define BTRFS_BALANCE_FILTER_MASK 0x7
 
 /* All the possible options for a filter */
 struct btrfs_ioctl_balance_start {
@@ -155,7 +156,10 @@ struct btrfs_ioctl_balance_start {
 	__u64 chunk_type;      /* Flag bits required */
 	__u64 chunk_type_mask; /* Mask of bits to examine */
 
-	__u64 spare[507]; /* Make up the size of the structure to 4088
+	/* For FILTER_DEVID */
+	__u64 devid;
+
+	__u64 spare[506]; /* Make up the size of the structure to 4088
 					   * bytes for future expansion */
 };
 
diff --git a/man/btrfs.8.in b/man/btrfs.8.in
index 5ac0694..020260f 100644
--- a/man/btrfs.8.in
+++ b/man/btrfs.8.in
@@ -203,6 +203,13 @@ chunk types.
 \fBraid0\fR, \fBraid1\fR, \fBraid10\fR, \fBdup\fR for chunks of the
 given replication levels.
 
+.TP
+\fBdevid\fR=\fI<n>\fR
+
+Select chunks which have data on device ID \fI<n>\fR. This can be
+used, for example, to reduplicate data in a mirrored configuration
+where one drive has been lost due to hardware failure.
+
 .SH EXIT STATUS
 \fBbtrfs\fR returns a zero exist status if it succeeds. Non zero is returned in
 case of failure.
-- 
1.7.2.5


  parent reply	other threads:[~2011-05-01 15:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-01 15:47 [PATCH v6 0/8] Balance management userspace Hugo Mills
2011-05-01 15:47 ` [PATCH v6 1/8] Balance progress monitoring Hugo Mills
2011-05-01 15:47 ` [PATCH v6 2/8] Add --monitor option to btrfs balance progress Hugo Mills
2011-06-30 22:18   ` Andreas Philipp
2011-06-30 22:22   ` Andreas Philipp
2011-05-01 15:47 ` [PATCH v6 3/8] User-space tool for cancelling balance operations Hugo Mills
2011-05-01 15:47 ` [PATCH v6 4/8] Run userspace tool in background for balances Hugo Mills
2011-05-01 15:47 ` [PATCH v6 5/8] Initial implementation of userspace interface for filtered balancing Hugo Mills
2011-05-01 15:47 ` Hugo Mills [this message]
2011-05-01 15:47 ` [PATCH v6 7/8] Balance filter for virtual address range Hugo Mills
2011-05-01 15:47 ` [PATCH v6 8/8] Interface for device range balance filter Hugo Mills

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=725a6071db510f6483100baced12834942438020.1304262467.git.hugo@carfax.org.uk \
    --to=hugo@carfax.org.uk \
    /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.