From: Martti Rannanjärvi Date: Thu, 23 Mar 2017 08:16:30 +0000 (+0200) Subject: quota: Use quota_alloc_result in quota_settings.test_alloc X-Git-Tag: 2.2.29.rc1~98 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9edefd429576dc07298d525f7d01feaa755642cd;p=thirdparty%2Fdovecot%2Fcore.git quota: Use quota_alloc_result in quota_settings.test_alloc --- diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index d685ee3d49..a9184c8a87 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -22,8 +22,8 @@ struct quota_settings { pool_t pool; ARRAY(struct quota_root_settings *) root_sets; - int (*test_alloc)(struct quota_transaction_context *ctx, - uoff_t size, bool *too_large_r); + enum quota_alloc_result (*test_alloc)( + struct quota_transaction_context *ctx, uoff_t size); const char *quota_exceeded_msg; unsigned int debug:1; diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 63206eb9d5..bcc8ea4fbe 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -50,8 +50,8 @@ static const struct quota_backend *quota_backends[] = { "a_backend_maildir }; -static int quota_default_test_alloc(struct quota_transaction_context *ctx, - uoff_t size, bool *too_large_r); +static enum quota_alloc_result quota_default_test_alloc( + struct quota_transaction_context *ctx, uoff_t size); static void quota_over_flag_check_root(struct quota_root *root); static const struct quota_backend *quota_backend_find(const char *name) @@ -1215,33 +1215,21 @@ enum quota_alloc_result quota_test_alloc(struct quota_transaction_context *ctx, return QUOTA_ALLOC_RESULT_OK; /* this is a virtual function mainly for trash plugin and similar, which may automatically delete mails to stay under quota. */ - bool too_large = FALSE; - int ret = ctx->quota->set->test_alloc(ctx, size, &too_large); - if (ret < 0) { - return QUOTA_ALLOC_RESULT_TEMPFAIL; - } else if (ret == 0 && too_large) { - return QUOTA_ALLOC_RESULT_OVER_QUOTA_LIMIT; - } else if (ret == 0 && !too_large) { - return QUOTA_ALLOC_RESULT_OVER_QUOTA; - } else { /* (ret > 0) */ - return QUOTA_ALLOC_RESULT_OK; - } + return ctx->quota->set->test_alloc(ctx, size); } -static int quota_default_test_alloc(struct quota_transaction_context *ctx, - uoff_t size, bool *too_large_r) +static enum quota_alloc_result quota_default_test_alloc( + struct quota_transaction_context *ctx, uoff_t size) { struct quota_root *const *roots; unsigned int i, count; bool ignore; int ret; - *too_large_r = FALSE; - if (!quota_transaction_is_over(ctx, size)) - return 1; + return QUOTA_ALLOC_RESULT_OK; - /* limit reached. only thing left to do now is to set too_large_r. */ + /* limit reached. */ roots = array_get(&ctx->quota->roots, &count); for (i = 0; i < count; i++) { uint64_t bytes_limit, count_limit; @@ -1254,16 +1242,14 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx, &bytes_limit, &count_limit, &ignore); if (ret < 0) - return -1; + return QUOTA_ALLOC_RESULT_TEMPFAIL; /* if size is bigger than any limit, then it is bigger than the lowest limit */ - if (bytes_limit > 0 && size > bytes_limit) { - *too_large_r = TRUE; - break; - } + if (bytes_limit > 0 && size > bytes_limit) + return QUOTA_ALLOC_RESULT_OVER_QUOTA_LIMIT; } - return 0; + return QUOTA_ALLOC_RESULT_OVER_QUOTA; } void quota_alloc(struct quota_transaction_context *ctx, struct mail *mail) diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index 3bb07bb370..a851be90f2 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -44,8 +44,8 @@ const char *trash_plugin_version = DOVECOT_ABI_VERSION; static MODULE_CONTEXT_DEFINE_INIT(trash_user_module, &mail_user_module_register); -static int (*trash_next_quota_test_alloc)(struct quota_transaction_context *, - uoff_t, bool *); +static enum quota_alloc_result (*trash_next_quota_test_alloc)( + struct quota_transaction_context *, uoff_t); static int trash_clean_mailbox_open(struct trash_mailbox *trash) { @@ -217,21 +217,22 @@ err: return 1; } -static int +static enum quota_alloc_result trash_quota_test_alloc(struct quota_transaction_context *ctx, - uoff_t size, bool *too_large_r) + uoff_t size) { - int ret, i; + int i; uint64_t size_needed = 0; unsigned int count_needed = 0; for (i = 0; ; i++) { - ret = trash_next_quota_test_alloc(ctx, size, too_large_r); - if (ret != 0 || *too_large_r) { - if (ctx->quota->user->mail_debug && *too_large_r) { + enum quota_alloc_result ret; + ret = trash_next_quota_test_alloc(ctx, size); + if (ret != QUOTA_ALLOC_RESULT_OVER_QUOTA) { + if (ret == QUOTA_ALLOC_RESULT_OVER_QUOTA_LIMIT && + ctx->quota->user->mail_debug) i_debug("trash plugin: Mail is larger than " "quota, won't even try to handle"); - } return ret; } @@ -251,11 +252,10 @@ trash_quota_test_alloc(struct quota_transaction_context *ctx, count_needed = 1 + ctx->count_over - ctx->count_ceil; /* not enough space. try deleting some from mailbox. */ - ret = trash_try_clean_mails(ctx, size_needed, count_needed); - if (ret <= 0) - return 0; + if (trash_try_clean_mails(ctx, size_needed, count_needed) <= 0) + return QUOTA_ALLOC_RESULT_OVER_QUOTA; } - return 0; + return QUOTA_ALLOC_RESULT_OVER_QUOTA; } static bool trash_find_storage(struct mail_user *user,