]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Use quota_alloc_result in quota_settings.test_alloc
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Thu, 23 Mar 2017 08:16:30 +0000 (10:16 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 27 Mar 2017 09:57:11 +0000 (12:57 +0300)
src/plugins/quota/quota-private.h
src/plugins/quota/quota.c
src/plugins/trash/trash-plugin.c

index d685ee3d492512668f265b48010472dbe5038321..a9184c8a875b97d05c1c5832ea8404ce71ed1def 100644 (file)
@@ -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;
index 63206eb9d5364dd52f9797dd3b00df13b3bea1f6..bcc8ea4fbeaad92946e1dd493681cc9aec6f978a 100644 (file)
@@ -50,8 +50,8 @@ static const struct quota_backend *quota_backends[] = {
        &quota_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)
index 3bb07bb370d466d1f2e43e2d84d6af33e81af545..a851be90f2d6f8d631f947877690c97f39e4a0d2 100644 (file)
@@ -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,