From a540ad3104581425be5b74fce1e17f702c233f91 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 22 Aug 2024 11:26:15 +0300 Subject: [PATCH] quota: Move quota_args=noenforcing to quota_enforce=no --- src/plugins/quota/quota-imapc.c | 3 --- src/plugins/quota/quota-private.h | 2 -- src/plugins/quota/quota-settings.c | 9 +++++++++ src/plugins/quota/quota-settings.h | 2 ++ src/plugins/quota/quota.c | 14 ++------------ 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/plugins/quota/quota-imapc.c b/src/plugins/quota/quota-imapc.c index 3d9678d3ab..9d024e393d 100644 --- a/src/plugins/quota/quota-imapc.c +++ b/src/plugins/quota/quota-imapc.c @@ -74,9 +74,6 @@ static int imapc_quota_init(struct quota_root *_root, const char *args, if (root->box_name == NULL && root->root_name == NULL) root->box_name = "INBOX"; - /* we'll never try to enforce the quota - it's just a lot of - unnecessary remote GETQUOTA calls. */ - _root->no_enforcing = TRUE; return 0; } diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index 9887f10a6a..30f5bb242f 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -82,8 +82,6 @@ struct quota_root { /* Module-specific contexts. See quota_module_id. */ ARRAY(void) quota_module_contexts; - /* don't enforce quota when saving */ - bool no_enforcing:1; /* quota is automatically updated. update() should be called but the bytes won't be changed. count is still changed, because it's cheap to do and it's internally used to figure out whether there have diff --git a/src/plugins/quota/quota-settings.c b/src/plugins/quota/quota-settings.c index 59ffb00f30..f76f713e9c 100644 --- a/src/plugins/quota/quota-settings.c +++ b/src/plugins/quota/quota-settings.c @@ -29,6 +29,7 @@ static const struct setting_define quota_setting_defines[] = { DEF(STR, quota_args), DEF(BOOL, quota_ignore), DEF(BOOL, quota_ignore_unlimited), + DEF(BOOL, quota_enforce), DEF(BOOL, quota_hidden), DEF(SIZE, quota_storage_size), DEF(UINT, quota_storage_percentage), @@ -64,6 +65,7 @@ static const struct quota_settings quota_default_settings = { .quota_args = "", .quota_ignore = FALSE, .quota_ignore_unlimited = FALSE, + .quota_enforce = TRUE, .quota_hidden = FALSE, .quota_storage_size = SET_SIZE_UNLIMITED, .quota_storage_percentage = 100, @@ -88,10 +90,17 @@ static const struct quota_settings quota_default_settings = { .quota_exceeded_message = "Quota exceeded (mailbox for user is full)", }; +static const struct setting_keyvalue quota_default_settings_keyvalue[] = { + /* imapc should never try to enforce the quota - it's just a lot of + unnecessary remote GETQUOTA calls. */ + { "quota_imapc/quota_enforce", "no" }, + { NULL, NULL } +}; const struct setting_parser_info quota_setting_parser_info = { .name = "quota", .defines = quota_setting_defines, .defaults = "a_default_settings, + .default_settings = quota_default_settings_keyvalue, .struct_size = sizeof(struct quota_settings), #ifndef CONFIG_BINARY .check_func = quota_settings_check, diff --git a/src/plugins/quota/quota-settings.h b/src/plugins/quota/quota-settings.h index 0f13abba25..a059237a1f 100644 --- a/src/plugins/quota/quota-settings.h +++ b/src/plugins/quota/quota-settings.h @@ -28,6 +28,8 @@ struct quota_settings { bool quota_ignore; /* IF TRUE, quota is ignored only when quota is unlimited. */ bool quota_ignore_unlimited; + /* Whether to actually enforce quota limits. */ + bool quota_enforce; /* Quota root is hidden (to e.g. IMAP GETQUOTAROOT) */ bool quota_hidden; /* Quota storage size is counted as: diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 737721a049..b1a4f206a3 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -49,10 +49,6 @@ static const struct quota_backend *quota_internal_backends[] = { static ARRAY(const struct quota_backend*) quota_backends; -static void noenforcing_param_handler(struct quota_root *_root, const char *param_value); - -struct quota_param_parser quota_param_noenforcing = {.param_name = "noenforcing", .param_handler = noenforcing_param_handler}; - static enum quota_alloc_result quota_default_test_alloc( struct quota_transaction_context *ctx, uoff_t size, const char **error_r); @@ -149,7 +145,6 @@ int quota_root_default_init(struct quota_root *root, const char *args, const char **error_r) { const struct quota_param_parser default_params[] = { - quota_param_noenforcing, {.param_name = NULL} }; return quota_parse_parameters(root, &args, error_r, default_params, TRUE); @@ -783,7 +778,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx, bytes_limit = count_limit = 0; if (!quota_root_is_visible(roots[i], ctx->box)) continue; - else if (roots[i]->no_enforcing) { + else if (!roots[i]->set->quota_enforce) { ignored = FALSE; } else if (quota_root_get_rule_limits(roots[i], ctx->box->event, &bytes_limit, &count_limit, @@ -1236,7 +1231,7 @@ static enum quota_alloc_result quota_default_test_alloc( uint64_t bytes_limit, count_limit; if (!quota_root_is_visible(roots[i], ctx->box) || - roots[i]->no_enforcing) + !roots[i]->set->quota_enforce) continue; if (quota_root_get_rule_limits(roots[i], ctx->box->event, @@ -1284,11 +1279,6 @@ void quota_recalculate(struct quota_transaction_context *ctx, ctx->recalculate = recalculate; } -static void noenforcing_param_handler(struct quota_root *_root, const char *param_value ATTR_UNUSED) -{ - _root->no_enforcing = TRUE; -} - int quota_parse_parameters(struct quota_root *root, const char **args, const char **error_r, const struct quota_param_parser *valid_params, bool fail_on_unknown) { -- 2.47.3