Skip to content

Commit

Permalink
quota: Differentiate between forced and non-forced quota recalc
Browse files Browse the repository at this point in the history
The "count" backend doesn't need to recalc quota unless an explicit "doveadm
quota recalc" command is called.
  • Loading branch information
sirainen authored and GitLab committed Jun 6, 2016
1 parent e2e64c1 commit 39dea5f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/plugins/quota/doveadm-quota.c
Expand Up @@ -101,7 +101,7 @@ cmd_quota_recalc_run(struct doveadm_mail_cmd_context *ctx ATTR_UNUSED,

memset(&trans, 0, sizeof(trans));
trans.quota = quser->quota;
trans.recalculate = TRUE;
trans.recalculate = QUOTA_RECALCULATE_FORCED;

array_foreach(&quser->quota->roots, root)
(void)(*root)->backend.v.update(*root, &trans);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota-count.c
Expand Up @@ -310,7 +310,7 @@ count_quota_update(struct quota_root *root,
struct count_quota_root *croot = (struct count_quota_root *)root;

croot->cache_timeval.tv_sec = 0;
if (ctx->recalculate) {
if (ctx->recalculate == QUOTA_RECALCULATE_FORCED) {
if (quota_count_recalculate(root) < 0)
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota-dict.c
Expand Up @@ -221,7 +221,7 @@ dict_quota_update(struct quota_root *_root,
struct dict_transaction_context *dt;
uint64_t value;

if (ctx->recalculate) {
if (ctx->recalculate != QUOTA_RECALCULATE_DONT) {
if (dict_quota_count(root, TRUE, &value) < 0)
return -1;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota-maildir.c
Expand Up @@ -903,7 +903,7 @@ maildir_quota_update(struct quota_root *_root,
we wanted to do. */
} else if (root->fd == -1)
(void)maildirsize_recalculate(root);
else if (ctx->recalculate) {
else if (ctx->recalculate != QUOTA_RECALCULATE_DONT) {
i_close_fd(&root->fd);
(void)maildirsize_recalculate(root);
} else if (maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota-private.h
Expand Up @@ -175,10 +175,10 @@ struct quota_transaction_context {
uint64_t bytes_over, count_over;

struct mail *tmp_mail;
enum quota_recalculate recalculate;

unsigned int limits_set:1;
unsigned int failed:1;
unsigned int recalculate:1;
unsigned int sync_transaction:1;
/* TRUE if all roots have auto_updating=TRUE */
unsigned int auto_updating:1;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota-storage.c
Expand Up @@ -416,7 +416,7 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid,
index_mailbox_vsize_hdr_expunge(ibox->vsize_update, uid, size);
} else {
/* there's no way to get the size. recalculate the quota. */
quota_recalculate(qbox->expunge_qt);
quota_recalculate(qbox->expunge_qt, QUOTA_RECALCULATE_MISSING_FREES);
qbox->recalculate = TRUE;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/plugins/quota/quota.c
Expand Up @@ -956,7 +956,7 @@ int quota_transaction_commit(struct quota_transaction_context **_ctx)
if (ctx->failed)
ret = -1;
else if (ctx->bytes_used != 0 || ctx->count_used != 0 ||
ctx->recalculate) T_BEGIN {
ctx->recalculate != QUOTA_RECALCULATE_DONT) T_BEGIN {
ARRAY(struct quota_root *) warn_roots;

mailbox_name = mailbox_get_vname(ctx->box);
Expand Down Expand Up @@ -1181,7 +1181,7 @@ void quota_free(struct quota_transaction_context *ctx, struct mail *mail)
if (ctx->auto_updating)
return;
if (mail_get_physical_size(mail, &size) < 0)
quota_recalculate(ctx);
quota_recalculate(ctx, QUOTA_RECALCULATE_MISSING_FREES);
else
quota_free_bytes(ctx, size);
}
Expand All @@ -1193,7 +1193,8 @@ void quota_free_bytes(struct quota_transaction_context *ctx,
ctx->count_used--;
}

void quota_recalculate(struct quota_transaction_context *ctx)
void quota_recalculate(struct quota_transaction_context *ctx,
enum quota_recalculate recalculate)
{
ctx->recalculate = TRUE;
ctx->recalculate = recalculate;
}
14 changes: 13 additions & 1 deletion src/plugins/quota/quota.h
Expand Up @@ -19,6 +19,17 @@ struct quota_root;
struct quota_root_iter;
struct quota_transaction_context;

enum quota_recalculate {
QUOTA_RECALCULATE_DONT = 0,
/* We may want to recalculate quota because we weren't able to call
quota_free*() correctly for all mails. Quota needs to be
recalculated unless the backend does the quota tracking
internally. */
QUOTA_RECALCULATE_MISSING_FREES,
/* doveadm quota recalc called - make sure the quota is correct */
QUOTA_RECALCULATE_FORCED
};

int quota_user_read_settings(struct mail_user *user,
struct quota_settings **set_r,
const char **error_r);
Expand Down Expand Up @@ -81,7 +92,8 @@ void quota_free(struct quota_transaction_context *ctx, struct mail *mail);
void quota_free_bytes(struct quota_transaction_context *ctx,
uoff_t physical_size);
/* Mark the quota to be recalculated */
void quota_recalculate(struct quota_transaction_context *ctx);
void quota_recalculate(struct quota_transaction_context *ctx,
enum quota_recalculate recalculate);

/* Execute quota_over_scripts if needed. */
void quota_over_flag_check_startup(struct quota *quota);
Expand Down

0 comments on commit 39dea5f

Please sign in to comment.