From: Timo Sirainen Date: Mon, 8 Apr 2013 12:13:39 +0000 (+0300) Subject: quota: dsync shouldn't trigger quota warnings X-Git-Tag: 2.2.rc7~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aaebcf0da12df7216be69961204fa64ec24c54b9;p=thirdparty%2Fdovecot%2Fcore.git quota: dsync shouldn't trigger quota warnings They would probably just be duplicates that were already triggered by the other replica. --- diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index ba73d5380d..285534082f 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -156,6 +156,7 @@ struct quota_transaction_context { unsigned int limits_set:1; unsigned int failed:1; unsigned int recalculate:1; + unsigned int sync_transaction:1; }; /* Register storage to all user's quota roots. */ diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index d5a31e2082..880a1553c3 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -32,6 +32,7 @@ struct quota_mailbox { ARRAY(uoff_t) expunge_sizes; unsigned int recalculate:1; + unsigned int sync_transaction_expunge:1; }; struct quota_user_module quota_user_module = @@ -61,6 +62,14 @@ static void quota_mail_expunge(struct mail *_mail) } array_append(&qbox->expunge_uids, &_mail->uid, 1); array_append(&qbox->expunge_sizes, &size, 1); + if ((_mail->transaction->flags & MAILBOX_TRANSACTION_FLAG_SYNC) != 0) { + /* we're running dsync. if this brings the quota below + a negative quota warning, don't execute it, because + it probably was already executed by the replica. */ + qbox->sync_transaction_expunge = TRUE; + } else { + qbox->sync_transaction_expunge = FALSE; + } } qmail->super.expunge(_mail); @@ -106,6 +115,7 @@ quota_mailbox_transaction_begin(struct mailbox *box, t = qbox->module_ctx.super.transaction_begin(box, flags); qt = quota_transaction_begin(box); + qt->sync_transaction = (flags & MAILBOX_TRANSACTION_FLAG_SYNC) != 0; MODULE_CONTEXT_SET(t, quota_storage_module, qt); return t; @@ -285,6 +295,7 @@ static void quota_mailbox_sync_cleanup(struct quota_mailbox *qbox) mail_free(&qbox->expunge_qt->tmp_mail); mailbox_transaction_rollback(&qbox->expunge_trans); } + qbox->sync_transaction_expunge = FALSE; } static void quota_mailbox_sync_commit(struct quota_mailbox *qbox) @@ -330,8 +341,11 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid, } } - if (qbox->expunge_qt == NULL) + if (qbox->expunge_qt == NULL) { qbox->expunge_qt = quota_transaction_begin(box); + qbox->expunge_qt->sync_transaction = + qbox->sync_transaction_expunge; + } if (i != count) { /* we already know the size */ diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 656f412e29..806d66362b 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -1210,12 +1210,15 @@ int quota_transaction_commit(struct quota_transaction_context **_ctx) if (roots[i]->backend.v.update(roots[i], ctx) < 0) ret = -1; - else + else if (!ctx->sync_transaction) array_append(&warn_roots, &roots[i], 1); } /* execute quota warnings after all updates. this makes it work correctly regardless of whether backend.get_resource() - returns updated values before backend.update() or not */ + returns updated values before backend.update() or not. + warnings aren't executed when dsync bring the user over, + because the user probably already got the warning on the + other replica. */ array_foreach(&warn_roots, roots) quota_warnings_execute(ctx, *roots); } T_END;