From 555ef9422525d389eb716769b0cd66b94cc2d040 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 15 Aug 2024 13:02:21 +0300 Subject: [PATCH] quota: Drop support for percentage based quota_grace Also change the default from 10% to 10 MB. It's likely not necessary to support both, and having a fixed size makes usually more sense than a percentage that can be rather huge. If we wanted to support both, the settings redesign would require two separate grace settings, which seems a bit excessive. --- src/plugins/quota/quota-private.h | 5 ++--- src/plugins/quota/quota-util.c | 28 ++++++++-------------------- src/plugins/quota/quota.c | 2 +- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index 388af54450..e0a43755ae 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -97,8 +97,7 @@ struct quota_root_settings { /* If user is under quota before saving a mail, allow the last mail to bring the user over quota by this many bytes. */ - uint64_t last_mail_max_extra_bytes; - struct quota_rule grace_rule; + uint64_t quota_storage_grace; /* TRUE if any of the warning_rules have reverse==TRUE */ bool have_reverse_warnings:1; @@ -157,7 +156,7 @@ struct quota_transaction_context { /* how many bytes/mails can be saved until limit is reached. (set once, not updated by bytes_used/count_used). - if last_mail_max_extra_bytes>0, the bytes_ceil is initially + if quota_storage_grace>0, the bytes_ceil is initially increased by that much, while bytes_ceil2 contains the real ceiling. after the first allocation is done, bytes_ceil is set to bytes_ceil2. */ diff --git a/src/plugins/quota/quota-util.c b/src/plugins/quota/quota-util.c index 583726609a..4290aafaf1 100644 --- a/src/plugins/quota/quota-util.c +++ b/src/plugins/quota/quota-util.c @@ -1,12 +1,13 @@ /* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "str-parse.h" #include "wildcard-match.h" #include "quota-private.h" #include -#define QUOTA_DEFAULT_GRACE "10%" +#define QUOTA_DEFAULT_GRACE "10M" #define RULE_NAME_DEFAULT_FORCE "*" @@ -126,15 +127,11 @@ void quota_root_recalculate_relative_rules(struct event *event, quota_rule_recalculate_relative_rules(&warning_rule->rule, bytes_limit, count_limit); } - quota_rule_recalculate_relative_rules(&root_set->grace_rule, - bytes_limit, 0); - root_set->last_mail_max_extra_bytes = root_set->grace_rule.bytes_limit; e_debug(event, "Quota root %s: Recalculated relative rules with " - "bytes=%lld count=%lld. Now grace=%"PRIu64, root_set->name, - (long long)bytes_limit, (long long)count_limit, - root_set->last_mail_max_extra_bytes); + "bytes=%lld count=%lld.", root_set->name, + (long long)bytes_limit, (long long)count_limit); } static int @@ -344,25 +341,16 @@ int quota_root_parse_grace(struct event *event, struct quota_root_settings *root_set, const char *value, const char **error_r) { - const char *p; - if (value == NULL) { /* default */ value = QUOTA_DEFAULT_GRACE; } - if (str_parse_int64(value, &root_set->grace_rule.bytes_limit, &p) < 0) - return -1; - if (quota_limit_parse(root_set, &root_set->grace_rule, p, 1, - &root_set->grace_rule.bytes_limit, error_r) < 0) + if (str_parse_get_size(value, &root_set->quota_storage_grace, + error_r) < 0) return -1; - quota_rule_recalculate_relative_rules(&root_set->grace_rule, - root_set->default_rule.bytes_limit, 0); - root_set->last_mail_max_extra_bytes = root_set->grace_rule.bytes_limit; - e_debug(event, "Quota grace: root=%s bytes=%lld%s", - root_set->name, (long long)root_set->grace_rule.bytes_limit, - root_set->grace_rule.bytes_percent == 0 ? "" : - t_strdup_printf(" (%u%%)", root_set->grace_rule.bytes_percent)); + e_debug(event, "Quota grace: root=%s bytes=%"PRIu64, + root_set->name, root_set->quota_storage_grace); return 0; } diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 5251926807..68ffcb32b8 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -870,7 +870,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, if (ctx->bytes_ceil2 > diff) ctx->bytes_ceil2 = diff; diff += !use_grace ? 0 : - roots[i]->set->last_mail_max_extra_bytes; + roots[i]->set->quota_storage_grace; if (ctx->bytes_ceil > diff) ctx->bytes_ceil = diff; } -- 2.47.3