|
|
370c56 |
From 0ada9c13f9b8299ff607b66c37022ce2a3c4444b Mon Sep 17 00:00:00 2001
|
|
|
370c56 |
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
|
|
|
370c56 |
Date: Wed, 9 Jan 2013 17:00:44 +0100
|
|
|
370c56 |
Subject: [PATCH 1/5] Recognize units at block limits by setquota
|
|
|
370c56 |
MIME-Version: 1.0
|
|
|
370c56 |
Content-Type: text/plain; charset=UTF-8
|
|
|
370c56 |
Content-Transfer-Encoding: 8bit
|
|
|
370c56 |
|
|
|
370c56 |
This patch allows to specify suffixes at block limits on setquota
|
|
|
370c56 |
command line. Binary units K, M, G, T are implemented. Numeric value
|
|
|
370c56 |
without suffix is equivatent to kibibytes as before. This is
|
|
|
370c56 |
complementary functionality to `quota -s'.
|
|
|
370c56 |
|
|
|
370c56 |
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
370c56 |
Signed-off-by: Jan Kara <jack@suse.cz>
|
|
|
370c56 |
---
|
|
|
370c56 |
quota.h | 2 ++
|
|
|
370c56 |
quotasys.c | 31 +++++++++++++++++++++++++++++++
|
|
|
370c56 |
quotasys.h | 3 +++
|
|
|
370c56 |
setquota.8 | 7 +++++++
|
|
|
370c56 |
setquota.c | 17 +++++++++++++++--
|
|
|
370c56 |
5 files changed, 58 insertions(+), 2 deletions(-)
|
|
|
370c56 |
|
|
|
370c56 |
diff --git a/quota.h b/quota.h
|
|
|
370c56 |
index ac034d0..6787eab 100644
|
|
|
370c56 |
--- a/quota.h
|
|
|
370c56 |
+++ b/quota.h
|
|
|
370c56 |
@@ -2,9 +2,11 @@
|
|
|
370c56 |
#define GUARD_QUOTA_H
|
|
|
370c56 |
|
|
|
370c56 |
#include <sys/types.h>
|
|
|
370c56 |
+#include <stdint.h>
|
|
|
370c56 |
|
|
|
370c56 |
typedef u_int32_t qid_t; /* Type in which we store ids in memory */
|
|
|
370c56 |
typedef int64_t qsize_t; /* Type in which we store size limitations */
|
|
|
370c56 |
+#define QSIZE_MAX INT64_MAX /* Maximum value storable in qsize_t */
|
|
|
370c56 |
|
|
|
370c56 |
#define MAXQUOTAS 2
|
|
|
370c56 |
#define USRQUOTA 0 /* element used for user quotas */
|
|
|
370c56 |
diff --git a/quotasys.c b/quotasys.c
|
|
|
370c56 |
index 03f678a..5c1464f 100644
|
|
|
370c56 |
--- a/quotasys.c
|
|
|
370c56 |
+++ b/quotasys.c
|
|
|
370c56 |
@@ -367,6 +367,37 @@ void space2str(qsize_t space, char *buf, int format)
|
|
|
370c56 |
}
|
|
|
370c56 |
|
|
|
370c56 |
/*
|
|
|
370c56 |
+ * Convert block number with unit from string to quota blocks.
|
|
|
370c56 |
+ * Return NULL on success, static error message otherwise.
|
|
|
370c56 |
+ */
|
|
|
370c56 |
+const char *str2space(const char *string, qsize_t *space)
|
|
|
370c56 |
+{
|
|
|
370c56 |
+ char *unit;
|
|
|
370c56 |
+ unsigned long long int number;
|
|
|
370c56 |
+ int unit_shift;
|
|
|
370c56 |
+
|
|
|
370c56 |
+ number = strtoull(string, &unit, 0);
|
|
|
370c56 |
+ if (ULLONG_MAX == number)
|
|
|
370c56 |
+ return _("Integer overflow while parsing space number.");
|
|
|
370c56 |
+
|
|
|
370c56 |
+ if (!unit || unit[0] == '\0' || !strcmp(unit, _("K")))
|
|
|
370c56 |
+ unit_shift = 0;
|
|
|
370c56 |
+ else if (!strcmp(unit, _("M")))
|
|
|
370c56 |
+ unit_shift = 10;
|
|
|
370c56 |
+ else if (!strcmp(unit, _("G")))
|
|
|
370c56 |
+ unit_shift = 20;
|
|
|
370c56 |
+ else if (!strcmp(unit, _("T")))
|
|
|
370c56 |
+ unit_shift = 30;
|
|
|
370c56 |
+ else
|
|
|
370c56 |
+ return _("Unknown space binary unit. "
|
|
|
370c56 |
+ "Valid units are K, M, G, T.");
|
|
|
370c56 |
+ if (number > (QSIZE_MAX >> unit_shift))
|
|
|
370c56 |
+ return _("Integer overflow while interpreting space unit.");
|
|
|
370c56 |
+ *space = number << unit_shift;
|
|
|
370c56 |
+ return NULL;
|
|
|
370c56 |
+}
|
|
|
370c56 |
+
|
|
|
370c56 |
+/*
|
|
|
370c56 |
* Convert number to some nice short form for printing
|
|
|
370c56 |
*/
|
|
|
370c56 |
void number2str(unsigned long long num, char *buf, int format)
|
|
|
370c56 |
diff --git a/quotasys.h b/quotasys.h
|
|
|
370c56 |
index 1cebf7e..0cc2c4c 100644
|
|
|
370c56 |
--- a/quotasys.h
|
|
|
370c56 |
+++ b/quotasys.h
|
|
|
370c56 |
@@ -103,6 +103,9 @@ int str2timeunits(time_t, char *, time_t *);
|
|
|
370c56 |
/* Convert number in quota blocks to short printable form */
|
|
|
370c56 |
void space2str(qsize_t, char *, int);
|
|
|
370c56 |
|
|
|
370c56 |
+/* Convert block number with unit from string to quota blocks */
|
|
|
370c56 |
+const char *str2space(const char *string, qsize_t *space);
|
|
|
370c56 |
+
|
|
|
370c56 |
/* Convert number to short printable form */
|
|
|
370c56 |
void number2str(unsigned long long, char *, int);
|
|
|
370c56 |
|
|
|
370c56 |
diff --git a/setquota.8 b/setquota.8
|
|
|
370c56 |
index db9d054..e4511c4 100644
|
|
|
370c56 |
--- a/setquota.8
|
|
|
370c56 |
+++ b/setquota.8
|
|
|
370c56 |
@@ -182,6 +182,13 @@ Go through all filesystems with quota in
|
|
|
370c56 |
.B /etc/mtab
|
|
|
370c56 |
and perform setting.
|
|
|
370c56 |
.PP
|
|
|
370c56 |
+.I block-softlimit
|
|
|
370c56 |
+and
|
|
|
370c56 |
+.I block-hardlimit
|
|
|
370c56 |
+are interpreted as multiples of kibibyte (1024 bytes) blocks by default.
|
|
|
370c56 |
+Symbols K, M, G, and T can be appended to numeric value to express kibibytes,
|
|
|
370c56 |
+mebibytes, gibibytes, and tebibytes.
|
|
|
370c56 |
+.PP
|
|
|
370c56 |
To disable a quota, set the corresponding parameter to 0. To change quotas
|
|
|
370c56 |
for several filesystems, invoke once for each filesystem.
|
|
|
370c56 |
.PP
|
|
|
370c56 |
diff --git a/setquota.c b/setquota.c
|
|
|
370c56 |
index f609dc7..ccac7f7 100644
|
|
|
370c56 |
--- a/setquota.c
|
|
|
370c56 |
+++ b/setquota.c
|
|
|
370c56 |
@@ -93,6 +93,19 @@ static qsize_t parse_unum(char *str, char *msg)
|
|
|
370c56 |
return ret;
|
|
|
370c56 |
}
|
|
|
370c56 |
|
|
|
370c56 |
+/* Convert block size to number - print errstr message in case of failure */
|
|
|
370c56 |
+static qsize_t parse_blocksize(const char *str, const char *msg)
|
|
|
370c56 |
+{
|
|
|
370c56 |
+ qsize_t ret;
|
|
|
370c56 |
+ const char *error = str2space(str, &ret;;
|
|
|
370c56 |
+
|
|
|
370c56 |
+ if (error) {
|
|
|
370c56 |
+ errstr(_("%s: %s: %s\n"), msg, str, error);
|
|
|
370c56 |
+ usage();
|
|
|
370c56 |
+ }
|
|
|
370c56 |
+ return ret;
|
|
|
370c56 |
+}
|
|
|
370c56 |
+
|
|
|
370c56 |
/* Convert our flags to quota type */
|
|
|
370c56 |
static inline int flag2type(int flags)
|
|
|
370c56 |
{
|
|
|
370c56 |
@@ -226,8 +239,8 @@ static void parse_options(int argcnt, char **argstr)
|
|
|
370c56 |
if (!(flags & (FL_GRACE | FL_BATCH))) {
|
|
|
370c56 |
id = name2id(argstr[optind++], flag2type(flags), !!(flags & FL_NUMNAMES), NULL);
|
|
|
370c56 |
if (!(flags & (FL_GRACE | FL_INDIVIDUAL_GRACE | FL_PROTO))) {
|
|
|
370c56 |
- toset.dqb_bsoftlimit = parse_unum(argstr[optind++], _("Bad block softlimit"));
|
|
|
370c56 |
- toset.dqb_bhardlimit = parse_unum(argstr[optind++], _("Bad block hardlimit"));
|
|
|
370c56 |
+ toset.dqb_bsoftlimit = parse_blocksize(argstr[optind++], _("Bad block softlimit"));
|
|
|
370c56 |
+ toset.dqb_bhardlimit = parse_blocksize(argstr[optind++], _("Bad block hardlimit"));
|
|
|
370c56 |
toset.dqb_isoftlimit = parse_unum(argstr[optind++], _("Bad inode softlimit"));
|
|
|
370c56 |
toset.dqb_ihardlimit = parse_unum(argstr[optind++], _("Bad inode hardlimit"));
|
|
|
370c56 |
}
|
|
|
370c56 |
--
|
|
|
370c56 |
1.8.1.4
|
|
|
370c56 |
|