]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Added quota_over_flag_lazy_check flag.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 16:25:52 +0000 (19:25 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 16:25:52 +0000 (19:25 +0300)
By default the quota_over_flag is checked immediately at startup. With this
option the check is done only at a time when the quota is anyway being read.

src/plugins/quota/quota-private.h
src/plugins/quota/quota-storage.c
src/plugins/quota/quota.c
src/plugins/quota/quota.h

index f1e7a2e1b71eab5dfe9acec45f83b067abb4aa41..60683f7d89d597a1211c8a1b1e3b62574c6baf2d 100644 (file)
@@ -143,8 +143,12 @@ struct quota_root {
        unsigned int recounting:1;
        /* Quota root is hidden (to e.g. IMAP GETQUOTAROOT) */
        unsigned int hidden:1;
+       /* Is quota_over_flag* initialized yet? */
+       unsigned int quota_over_flag_initialized:1;
        /* Is user currently over quota? */
        unsigned int quota_over_flag_status:1;
+       /* Did we already check quota_over_flag correctness? */
+       unsigned int quota_over_flag_checked:1;
 };
 
 struct quota_transaction_context {
index bc594f05823ac47d55e95a23ce938230f02f4a28..34a6c21f47b3be1441b9a56e0308bf1f07b2ecf4 100644 (file)
@@ -663,5 +663,5 @@ void quota_mail_namespaces_created(struct mail_namespace *namespaces)
        for (i = 0; i < count; i++)
                quota_root_set_namespace(roots[i], namespaces);
 
-       quota_over_flag_check(quota);
+       quota_over_flag_check_startup(quota);
 }
index 0b9799c20b681d8ccdc4664c40597ab2c8baee52..4e356f0216b23197c6f7670faa4b149dbb2b5f00 100644 (file)
@@ -656,6 +656,9 @@ const char *quota_root_get_name(struct quota_root *root)
 
 const char *const *quota_root_get_resources(struct quota_root *root)
 {
+       /* if we haven't checked the quota_over_flag yet, do it now */
+       quota_over_flag_check_root(root);
+
        return root->backend.v.get_resources(root);
 }
 
@@ -988,6 +991,10 @@ static void quota_over_flag_init_root(struct quota_root *root)
 {
        const char *name, *flag_mask;
 
+       if (root->quota_over_flag_initialized)
+               return;
+       root->quota_over_flag_initialized = TRUE;
+
        /* e.g.: quota_over_flag_value=TRUE or quota_over_flag_value=*  */
        name = t_strconcat(root->set->set_name, "_over_flag_value", NULL);
        flag_mask = mail_user_plugin_getenv(root->quota->user, name);
@@ -1012,6 +1019,9 @@ static void quota_over_flag_check_root(struct quota_root *root)
        bool cur_overquota = FALSE;
        int ret;
 
+       if (root->quota_over_flag_checked)
+               return;
+       root->quota_over_flag_checked = TRUE;
        quota_over_flag_init_root(root);
 
        resources = quota_root_get_resources(root);
@@ -1048,14 +1058,18 @@ static void quota_over_flag_check_root(struct quota_root *root)
        }
 }
 
-void quota_over_flag_check(struct quota *quota)
+void quota_over_flag_check_startup(struct quota *quota)
 {
        struct quota_root *const *roots;
        unsigned int i, count;
+       const char *name;
 
        roots = array_get(&quota->roots, &count);
-       for (i = 0; i < count; i++)
-               quota_over_flag_check_root(roots[i]);
+       for (i = 0; i < count; i++) {
+               name = t_strconcat(roots[i]->set->set_name, "_over_flag_lazy_check", NULL);
+               if (mail_user_plugin_getenv(roots[i]->quota->user, name) == NULL)
+                       quota_over_flag_check_root(roots[i]);
+       }
 }
 
 void quota_transaction_rollback(struct quota_transaction_context **_ctx)
index 460d5af7c6c26d7f7974096e453c2033088c7e04..04847d1f90de6882a32eca96a0504d06e5ab2bb5 100644 (file)
@@ -84,6 +84,6 @@ void quota_free_bytes(struct quota_transaction_context *ctx,
 void quota_recalculate(struct quota_transaction_context *ctx);
 
 /* Execute quota_over_scripts if needed. */
-void quota_over_flag_check(struct quota *quota);
+void quota_over_flag_check_startup(struct quota *quota);
 
 #endif