Blame SOURCES/quota-4.01-Recognize-units-at-inode-limits-by-setquota.patch

7c06a3
From fdcf21db852bc8d6c1d0b41f2812ba614851e2b4 Mon Sep 17 00:00:00 2001
7c06a3
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
7c06a3
Date: Wed, 9 Jan 2013 17:00:44 +0100
7c06a3
Subject: [PATCH 4/5] Recognize units at inode limits by setquota
7c06a3
MIME-Version: 1.0
7c06a3
Content-Type: text/plain; charset=UTF-8
7c06a3
Content-Transfer-Encoding: 8bit
7c06a3
7c06a3
This patch allows to specify suffixes at inode limits on setquota
7c06a3
command line and standard input. Decimal Units k, m, g, t are
7c06a3
implemented.  Numeric value without suffix is equivatent to single
7c06a3
inodes as before.  This is complementary functionality to `quota -s'.
7c06a3
7c06a3
Signed-off-by: Petr Písař <ppisar@redhat.com>
7c06a3
Signed-off-by: Jan Kara <jack@suse.cz>
7c06a3
---
7c06a3
 quotasys.c | 32 ++++++++++++++++++++++++++++++++
7c06a3
 quotasys.h |  3 +++
7c06a3
 setquota.8 |  6 ++++++
7c06a3
 setquota.c | 39 +++++++++++++++++++++++++++++++++++----
7c06a3
 4 files changed, 76 insertions(+), 4 deletions(-)
7c06a3
7c06a3
diff --git a/quotasys.c b/quotasys.c
7c06a3
index 5c1464f..e583437 100644
7c06a3
--- a/quotasys.c
7c06a3
+++ b/quotasys.c
7c06a3
@@ -416,6 +416,38 @@ void number2str(unsigned long long num, char *buf, int format)
7c06a3
 }
7c06a3
 
7c06a3
 /*
7c06a3
+ * Convert inode number with unit from string to quota inodes.
7c06a3
+ * Return NULL on success, static error message otherwise.
7c06a3
+ */
7c06a3
+const char *str2number(const char *string, qsize_t *inodes)
7c06a3
+{
7c06a3
+	char *unit;
7c06a3
+	unsigned long long int number, multiple;
7c06a3
+       
7c06a3
+	number = strtoull(string, &unit, 0);
7c06a3
+	if (ULLONG_MAX == number)
7c06a3
+		return _("Integer overflow while parsing number.");
7c06a3
+
7c06a3
+	if (!unit || unit[0] == '\0')
7c06a3
+		multiple = 1;
7c06a3
+	else if (!strcmp(unit, _("k")))
7c06a3
+		multiple = 1000;
7c06a3
+	else if (!strcmp(unit, _("m")))
7c06a3
+		multiple = 1000000;
7c06a3
+	else if (!strcmp(unit, _("g")))
7c06a3
+		multiple = 1000000000;
7c06a3
+	else if (!strcmp(unit, _("t")))
7c06a3
+		multiple = 1000000000000ULL;
7c06a3
+	else
7c06a3
+		return _("Unknown decimal unit. "
7c06a3
+			"Valid units are k, m, g, t.");
7c06a3
+	if (number > QSIZE_MAX / multiple)
7c06a3
+		return _("Integer overflow while interpreting decimal unit.");
7c06a3
+	*inodes = number * multiple;
7c06a3
+	return NULL;
7c06a3
+}
7c06a3
+
7c06a3
+/*
7c06a3
  *	Wrappers for mount options processing functions
7c06a3
  */
7c06a3
 
7c06a3
diff --git a/quotasys.h b/quotasys.h
7c06a3
index 0cc2c4c..505ea77 100644
7c06a3
--- a/quotasys.h
7c06a3
+++ b/quotasys.h
7c06a3
@@ -109,6 +109,9 @@ const char *str2space(const char *string, qsize_t *space);
7c06a3
 /* Convert number to short printable form */
7c06a3
 void number2str(unsigned long long, char *, int);
7c06a3
 
7c06a3
+/* Convert inode number with unit from string to quota inodes. */
7c06a3
+const char *str2number(const char *string, qsize_t *inodes);
7c06a3
+
7c06a3
 /* Return pointer to given mount option in mount option string */
7c06a3
 char *str_hasmntopt(const char *optstring, const char *opt);
7c06a3
 
7c06a3
diff --git a/setquota.8 b/setquota.8
7c06a3
index e4511c4..508309e 100644
7c06a3
--- a/setquota.8
7c06a3
+++ b/setquota.8
7c06a3
@@ -189,6 +189,12 @@ are interpreted as multiples of kibibyte (1024 bytes) blocks by default.
7c06a3
 Symbols K, M, G, and T can be appended to numeric value to express kibibytes,
7c06a3
 mebibytes, gibibytes, and tebibytes.
7c06a3
 .PP
7c06a3
+.I inode-softlimit
7c06a3
+and
7c06a3
+.I inode-hardlimit
7c06a3
+are interpreted literally. Symbols k, m, g, and t can be appended to numeric
7c06a3
+value to express multiples of 10^3, 10^6, 10^9, and 10^12 inodes.
7c06a3
+.PP
7c06a3
 To disable a quota, set the corresponding parameter to 0. To change quotas
7c06a3
 for several filesystems, invoke once for each filesystem.
7c06a3
 .PP
7c06a3
diff --git a/setquota.c b/setquota.c
7c06a3
index e55b79d..19449ad 100644
7c06a3
--- a/setquota.c
7c06a3
+++ b/setquota.c
7c06a3
@@ -106,6 +106,19 @@ static qsize_t parse_blocksize(const char *str, const char *msg)
7c06a3
 	return ret;
7c06a3
 }
7c06a3
 
7c06a3
+/* Convert inode count to number - print errstr message in case of failure */
7c06a3
+static qsize_t parse_inodecount(const char *str, const char *msg)
7c06a3
+{
7c06a3
+	qsize_t ret;
7c06a3
+	const char *error = str2number(str, &ret;;
7c06a3
+
7c06a3
+	if (error) {
7c06a3
+		errstr(_("%s: %s: %s\n"), msg, str, error);
7c06a3
+		usage();
7c06a3
+	}
7c06a3
+	return ret;
7c06a3
+}
7c06a3
+
7c06a3
 /* Convert our flags to quota type */
7c06a3
 static inline int flag2type(int flags)
7c06a3
 {
7c06a3
@@ -241,8 +254,8 @@ static void parse_options(int argcnt, char **argstr)
7c06a3
 		if (!(flags & (FL_GRACE | FL_INDIVIDUAL_GRACE | FL_PROTO))) {
7c06a3
 			toset.dqb_bsoftlimit = parse_blocksize(argstr[optind++], _("Bad block softlimit"));
7c06a3
 			toset.dqb_bhardlimit = parse_blocksize(argstr[optind++], _("Bad block hardlimit"));
7c06a3
-			toset.dqb_isoftlimit = parse_unum(argstr[optind++], _("Bad inode softlimit"));
7c06a3
-			toset.dqb_ihardlimit = parse_unum(argstr[optind++], _("Bad inode hardlimit"));
7c06a3
+			toset.dqb_isoftlimit = parse_inodecount(argstr[optind++], _("Bad inode softlimit"));
7c06a3
+			toset.dqb_ihardlimit = parse_inodecount(argstr[optind++], _("Bad inode hardlimit"));
7c06a3
 		}
7c06a3
 		else if (flags & FL_PROTO)
7c06a3
 			protoid = name2id(protoname, flag2type(flags), !!(flags & FL_NUMNAMES), NULL);
7c06a3
@@ -319,7 +332,7 @@ static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize
7c06a3
 	static int line = 0;
7c06a3
 	char name[MAXNAMELEN+1];
7c06a3
 	char linebuf[MAXLINELEN], *chptr;
7c06a3
-	unsigned long is, ih;
7c06a3
+	char is[MAXNAMELEN+1], ih[MAXNAMELEN+1];
7c06a3
 	char bs[MAXNAMELEN+1], bh[MAXNAMELEN+1];
7c06a3
 	const char *error;
7c06a3
 	int ret;
7c06a3
@@ -339,7 +352,7 @@ static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize
7c06a3
 			chptr++;
7c06a3
 		if (*chptr == '\n')
7c06a3
 			continue;
7c06a3
-		ret = sscanf(chptr, "%s %s %s %lu %lu", name, bs, bh, &is, &ih;;
7c06a3
+		ret = sscanf(chptr, "%s %s %s %s %s", name, bs, bh, is, ih);
7c06a3
 		if (ret != 5) {
7c06a3
 			errstr(_("Cannot parse input line %d.\n"), line);
7c06a3
 			if (!(flags & FL_CONTINUE_BATCH))
7c06a3
@@ -373,6 +386,24 @@ static int read_entry(qid_t *id, qsize_t *isoftlimit, qsize_t *ihardlimit, qsize
7c06a3
 			errstr(_("Skipping line.\n"));
7c06a3
 			continue;
7c06a3
 		}
7c06a3
+		error = str2number(is, isoftlimit);
7c06a3
+		if (error) {
7c06a3
+			errstr(_("Unable to parse inode soft limit '%s' "
7c06a3
+				    "on line %d: %s\n"), is, line, error);
7c06a3
+			if (!(flags & FL_CONTINUE_BATCH))
7c06a3
+				die(1, _("Exitting.\n"));
7c06a3
+			errstr(_("Skipping line.\n"));
7c06a3
+			continue;
7c06a3
+		}
7c06a3
+		error = str2number(ih, ihardlimit);
7c06a3
+		if (error) {
7c06a3
+			errstr(_("Unable to parse inode hard limit '%s' "
7c06a3
+				    "on line %d: %s\n"), ih, line, error);
7c06a3
+			if (!(flags & FL_CONTINUE_BATCH))
7c06a3
+				die(1, _("Exitting.\n"));
7c06a3
+			errstr(_("Skipping line.\n"));
7c06a3
+			continue;
7c06a3
+		}
7c06a3
 		break;
7c06a3
 	}
7c06a3
 	*isoftlimit = is;
7c06a3
-- 
7c06a3
1.8.1.4
7c06a3