Skip to content

Commit

Permalink
quota: Don't get message sizes when updating mailbox that ignores quo…
Browse files Browse the repository at this point in the history
…tas.

Nothing is done with the size anyway.
  • Loading branch information
sirainen committed Aug 10, 2016
1 parent 8e4f094 commit ad759d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/plugins/quota/quota-private.h
Expand Up @@ -182,6 +182,8 @@ struct quota_transaction_context {
bool sync_transaction:1;
/* TRUE if all roots have auto_updating=TRUE */
bool auto_updating:1;
/* Quota doesn't need to be updated within this transaction. */
bool no_quota_updates:1;
};

/* Register storage to all user's quota roots. */
Expand Down
34 changes: 27 additions & 7 deletions src/plugins/quota/quota.c
Expand Up @@ -399,12 +399,15 @@ void quota_deinit(struct quota **_quota)
static int quota_root_get_rule_limits(struct quota_root *root,
const char *mailbox_name,
uint64_t *bytes_limit_r,
uint64_t *count_limit_r)
uint64_t *count_limit_r,
bool *ignored_r)
{
struct quota_rule *rule;
int64_t bytes_limit, count_limit;
bool enabled;

*ignored_r = FALSE;

if (!root->set->force_default_rule) {
if (root->backend.v.init_limits != NULL) {
if (root->backend.v.init_limits(root) < 0)
Expand All @@ -429,6 +432,7 @@ static int quota_root_get_rule_limits(struct quota_root *root,
} else {
bytes_limit = 0;
count_limit = 0;
*ignored_r = TRUE;
}
}

Expand Down Expand Up @@ -671,7 +675,7 @@ int quota_get_resource(struct quota_root *root, const char *mailbox_name,
const char *name, uint64_t *value_r, uint64_t *limit_r)
{
uint64_t bytes_limit, count_limit;
bool kilobytes = FALSE;
bool ignored, kilobytes = FALSE;
int ret;

*value_r = *limit_r = 0;
Expand All @@ -688,7 +692,8 @@ int quota_get_resource(struct quota_root *root, const char *mailbox_name,
return ret;

if (quota_root_get_rule_limits(root, mailbox_name,
&bytes_limit, &count_limit) < 0)
&bytes_limit, &count_limit,
&ignored) < 0)
return -1;

if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
Expand Down Expand Up @@ -785,13 +790,14 @@ static int quota_transaction_set_limits(struct quota_transaction_context *ctx)
const char *mailbox_name;
unsigned int i, count;
uint64_t bytes_limit, count_limit, current, limit, diff;
bool use_grace;
bool use_grace, ignored;
int ret;

ctx->limits_set = TRUE;
mailbox_name = mailbox_get_vname(ctx->box);
/* use quota_grace only for LDA/LMTP */
use_grace = (ctx->box->flags & MAILBOX_FLAG_POST_SESSION) != 0;
ctx->no_quota_updates = TRUE;

/* find the lowest quota limits from all roots and use them */
roots = array_get(&ctx->quota->roots, &count);
Expand All @@ -800,11 +806,13 @@ static int quota_transaction_set_limits(struct quota_transaction_context *ctx)
continue;

if (quota_root_get_rule_limits(roots[i], mailbox_name,
&bytes_limit,
&count_limit) < 0) {
&bytes_limit, &count_limit,
&ignored) < 0) {
ctx->failed = TRUE;
return -1;
}
if (!ignored)
ctx->no_quota_updates = FALSE;

if (bytes_limit > 0) {
ret = quota_get_resource(roots[i], mailbox_name,
Expand Down Expand Up @@ -1094,6 +1102,14 @@ int quota_try_alloc(struct quota_transaction_context *ctx,
uoff_t size;
int ret;

if (!ctx->limits_set) {
if (quota_transaction_set_limits(ctx) < 0)
return -1;
}

if (ctx->no_quota_updates)
return 1;

if (mail_get_physical_size(mail, &size) < 0) {
i_error("quota: Failed to get mail size (box=%s, uid=%u): %s",
mail->box->vname, mail->uid,
Expand Down Expand Up @@ -1124,6 +1140,8 @@ int quota_test_alloc(struct quota_transaction_context *ctx,
if (quota_transaction_set_limits(ctx) < 0)
return -1;
}
if (ctx->no_quota_updates)
return 1;
/* this is a virtual function mainly for trash plugin and similar,
which may automatically delete mails to stay under quota. */
return ctx->quota->set->test_alloc(ctx, size, too_large_r);
Expand All @@ -1134,6 +1152,7 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx,
{
struct quota_root *const *roots;
unsigned int i, count;
bool ignore;
int ret;

*too_large_r = FALSE;
Expand All @@ -1151,7 +1170,8 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx,

ret = quota_root_get_rule_limits(roots[i],
mailbox_get_vname(ctx->box),
&bytes_limit, &count_limit);
&bytes_limit, &count_limit,
&ignore);
if (ret < 0)
return -1;

Expand Down

0 comments on commit ad759d5

Please sign in to comment.