changeset 6031:b272eff19a18 HEAD

Allow non-default rule limits to be percentages of the default rule limit.
author Timo Sirainen <tss@iki.fi>
date Mon, 16 Jul 2007 02:00:35 +0300
parents d22be94225b1
children 6edca218d48a
files src/plugins/quota/quota.c
diffstat 1 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/quota/quota.c	Mon Jul 16 01:53:18 2007 +0300
+++ b/src/plugins/quota/quota.c	Mon Jul 16 02:00:35 2007 +0300
@@ -174,6 +174,32 @@
 }
 
 static int
+quota_rule_parse_percentage(struct quota_root *root, struct quota_rule *rule,
+			    int64_t *limit, const char **error_r)
+{
+	int64_t percentage = *limit;
+
+	if (percentage < 0) {
+		*error_r = p_strdup_printf(root->pool,
+			"Invalid rule percentage: %lld", (long long)percentage);
+		return -1;
+	}
+
+	if (rule == &root->default_rule) {
+		*error_r = "Default rule can't be a percentage";
+		return -1;
+	}
+
+	if (limit == &rule->bytes_limit)
+		*limit = rule->bytes_limit * percentage / 100;
+	else if (limit == &rule->count_limit)
+		*limit = rule->count_limit * percentage / 100;
+	else
+		i_unreached();
+	return 0;
+}
+
+static int
 quota_rule_parse_limits(struct quota_root *root, struct quota_rule *rule,
 			const char *limits, const char **error_r)
 {
@@ -221,6 +247,12 @@
 		case 'T':
 			multiply = 1024ULL*1024*1024*1024;
 			break;
+		case '%':
+			multiply = 1;
+			if (quota_rule_parse_percentage(root, rule, limit,
+							error_r) < 0)
+				return -1;
+			break;
 		default:
 			*error_r = p_strdup_printf(root->pool,
 					"Invalid rule limit value: %s", *args);