linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>
Subject: [PATCH 2/7] btrfs-progs: extend parse_range API to accept a relaxed range
Date: Tue, 13 Oct 2015 17:42:23 +0200	[thread overview]
Message-ID: <7edb64ff3707c11e1deaa2556db16f788fbc9011.1444750808.git.dsterba@suse.com> (raw)
In-Reply-To: <cover.1444750808.git.dsterba@suse.com>

In some cases we want to accept a range of type [a..a]. Add a new
function to do the 'a < b' check for the caller and use it.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 cmds-balance.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index 798b533aa7d6..62bee3cc78b6 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -126,9 +126,10 @@ static int parse_range(const char *range, u64 *start, u64 *end)
 			return 1;
 	}
 
-	if (*start >= *end) {
-		fprintf(stderr, "Range %llu..%llu doesn't make "
-			"sense\n", (unsigned long long)*start,
+	if (*start > *end) {
+		fprintf(stderr,
+			"ERROR: range %llu..%llu doesn't make sense\n",
+			(unsigned long long)*start,
 			(unsigned long long)*end);
 		return 1;
 	}
@@ -139,6 +140,25 @@ static int parse_range(const char *range, u64 *start, u64 *end)
 	return 1;
 }
 
+/*
+ * Parse range and check if start < end
+ */
+static int parse_range_strict(const char *range, u64 *start, u64 *end)
+{
+	if (parse_range(range, start, end) == 0) {
+		if (*start >= *end) {
+			fprintf(stderr,
+				"ERROR: range %llu..%llu not allowed\n",
+				(unsigned long long)*start,
+				(unsigned long long)*end);
+			return 1;
+		}
+		return 0;
+	}
+
+	return 1;
+}
+
 static int parse_filters(char *filters, struct btrfs_balance_args *args)
 {
 	char *this_char;
@@ -196,7 +216,7 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
 				       "an argument\n");
 				return 1;
 			}
-			if (parse_range(value, &args->pstart, &args->pend)) {
+			if (parse_range_strict(value, &args->pstart, &args->pend)) {
 				fprintf(stderr, "Invalid drange argument\n");
 				return 1;
 			}
@@ -207,7 +227,7 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
 				       "an argument\n");
 				return 1;
 			}
-			if (parse_range(value, &args->vstart, &args->vend)) {
+			if (parse_range_strict(value, &args->vstart, &args->vend)) {
 				fprintf(stderr, "Invalid vrange argument\n");
 				return 1;
 			}
-- 
2.6.1


  parent reply	other threads:[~2015-10-13 15:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-13 15:42 [PATCH 0/7] Btrfs-progs, balance filters: stripes, limits David Sterba
2015-10-13 15:42 ` [PATCH 1/7] btrfs-progs: cleanup and comment parse_range David Sterba
2015-10-13 15:42 ` David Sterba [this message]
2015-10-13 15:42 ` [PATCH 3/7] btrfs-progs: add helpers for parsing 32bit ranges David Sterba
2015-10-13 15:42 ` [PATCH 4/7] btrfs-progs: add helpers to print ranges David Sterba
2015-10-13 15:42 ` [PATCH 5/7] btrfs-progs: extend balance args to take min/max limit filter David Sterba
2015-10-13 15:42 ` [PATCH 6/7] btrfs-progs: balance: enhance the limit fiter with range David Sterba
2015-10-13 15:42 ` [PATCH 7/7] btrfs-progs: balance: add stripes filter 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=7edb64ff3707c11e1deaa2556db16f788fbc9011.1444750808.git.dsterba@suse.com \
    --to=dsterba@suse.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).