dovecot-2.2: quota: doveadm quota recalc works now for "count" b...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 28 13:10:00 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/687dd4db9373
changeset: 19245:687dd4db9373
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 28 16:07:12 2015 +0300
description:
quota: doveadm quota recalc works now for "count" backend by rebuilding vsize header.

diffstat:

 src/plugins/quota/quota-count.c |  67 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 3 deletions(-)

diffs (80 lines):

diff -r 78a027250652 -r 687dd4db9373 src/plugins/quota/quota-count.c
--- a/src/plugins/quota/quota-count.c	Mon Sep 28 16:06:43 2015 +0300
+++ b/src/plugins/quota/quota-count.c	Mon Sep 28 16:07:12 2015 +0300
@@ -197,12 +197,73 @@
 	return 1;
 }
 
+static int quota_count_recalculate_box(struct mailbox *box)
+{
+	struct mail_index_transaction *trans;
+	struct mailbox_metadata metadata;
+	struct mailbox_index_vsize vsize_hdr;
+	const char *errstr;
+	enum mail_error error;
+
+	if (mailbox_open(box) < 0) {
+		errstr = mailbox_get_last_error(box, &error);
+		if (error != MAIL_ERROR_TEMP) {
+			/* non-temporary error, e.g. ACLs denied access. */
+			return 0;
+		}
+		i_error("Couldn't open mailbox %s: %s", box->vname, errstr);
+		return -1;
+	}
+
+	/* reset the vsize header first */
+	trans = mail_index_transaction_begin(box->view,
+				MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
+	memset(&vsize_hdr, 0, sizeof(vsize_hdr));
+	mail_index_update_header_ext(trans, box->vsize_hdr_ext_id,
+				     0, &vsize_hdr, sizeof(vsize_hdr));
+	if (mail_index_transaction_commit(&trans) < 0)
+		return -1;
+	/* getting the vsize now forces its recalculation */
+	if (mailbox_get_metadata(box, MAILBOX_METADATA_VIRTUAL_SIZE,
+				 &metadata) < 0) {
+		i_error("Couldn't get mailbox %s vsize: %s", box->vname,
+			mailbox_get_last_error(box, NULL));
+		return -1;
+	}
+	/* call sync to write the change to mailbox list index */
+	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FAST) < 0) {
+		i_error("Couldn't sync mailbox %s: %s", box->vname,
+			mailbox_get_last_error(box, NULL));
+		return -1;
+	}
+	return 0;
+}
+
+static int quota_count_recalculate(struct quota_root *root)
+{
+	struct quota_mailbox_iter *iter;
+	const struct mailbox_info *info;
+	struct mailbox *box;
+	int ret = 0;
+
+	iter = quota_mailbox_iter_begin(root);
+	while ((info = quota_mailbox_iter_next(iter)) != NULL) {
+		box = mailbox_alloc(info->ns->list, info->vname, 0);
+		if (quota_count_recalculate_box(box) < 0)
+			ret = -1;
+		mailbox_free(&box);
+	}
+	quota_mailbox_iter_deinit(&iter);
+	return ret;
+}
+
 static int
-count_quota_update(struct quota_root *root ATTR_UNUSED,
-		   struct quota_transaction_context *ctx ATTR_UNUSED)
+count_quota_update(struct quota_root *root,
+		   struct quota_transaction_context *ctx)
 {
 	if (ctx->recalculate) {
-		//FIXME: remove cached values from index
+		if (quota_count_recalculate(root) < 0)
+			return -1;
 	}
 	return 0;
 }


More information about the dovecot-cvs mailing list