From: Timo Sirainen Date: Fri, 29 Apr 2016 16:25:52 +0000 (+0300) Subject: quota: Added quota_over_flag_lazy_check flag. X-Git-Tag: 2.3.0.rc1~3900 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c16f2d0725a16559cdeedec7628ce616725000cb;p=thirdparty%2Fdovecot%2Fcore.git quota: Added quota_over_flag_lazy_check flag. 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. --- diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index f1e7a2e1b7..60683f7d89 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -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 { diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index bc594f0582..34a6c21f47 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -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); } diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 0b9799c20b..4e356f0216 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -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("a->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) diff --git a/src/plugins/quota/quota.h b/src/plugins/quota/quota.h index 460d5af7c6..04847d1f90 100644 --- a/src/plugins/quota/quota.h +++ b/src/plugins/quota/quota.h @@ -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