Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8029:796307638449 HEAD
FS quota: Handle quota only for the quota roots which apply to the mailbox
when there are multiple roots. With a single quota root the check is usually
unnecessary. Based on patch by Ralf Becker.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 20 Jul 2008 21:36:13 +0300 |
parents | ea4821b4e29a |
children | 7fdb5f222d95 |
files | src/plugins/quota/quota-dict.c src/plugins/quota/quota-dirsize.c src/plugins/quota/quota-fs.c src/plugins/quota/quota-maildir.c src/plugins/quota/quota-private.h src/plugins/quota/quota.c |
diffstat | 6 files changed, 71 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-dict.c Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota-dict.c Sun Jul 20 21:36:13 2008 +0300 @@ -182,6 +182,7 @@ NULL, dict_quota_root_get_resources, dict_quota_get_resource, - dict_quota_update + dict_quota_update, + NULL } };
--- a/src/plugins/quota/quota-dirsize.c Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota-dirsize.c Sun Jul 20 21:36:13 2008 +0300 @@ -212,6 +212,7 @@ NULL, dirsize_quota_root_get_resources, dirsize_quota_get_resource, - dirsize_quota_update + dirsize_quota_update, + NULL } };
--- a/src/plugins/quota/quota-fs.c Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota-fs.c Sun Jul 20 21:36:13 2008 +0300 @@ -30,7 +30,11 @@ #endif #ifndef DEV_BSIZE -# define DEV_BSIZE 512 +# ifdef DQBSIZE +# define DEV_BSIZE DQBSIZE /* AIX */ +# else +# define DEV_BSIZE 512 +# endif #endif #ifdef HAVE_STRUCT_DQBLK_CURSPACE @@ -584,6 +588,35 @@ #endif } +static bool fs_quota_match_box(struct quota_root *_root, struct mailbox *box) +{ + struct fs_quota_root *root = (struct fs_quota_root *)_root; + struct stat mst, rst; + const char *mailbox_path; + bool is_file, match; + + mailbox_path = mail_storage_get_mailbox_path(box->storage, box->name, + &is_file); + if (stat(mailbox_path, &mst) < 0) { + if (errno != ENOENT) + i_error("stat(%s) failed: %m", mailbox_path); + return FALSE; + } + if (stat(root->storage_mount_path, &rst) < 0) { + if (getenv("DEBUG") != NULL) { + i_error("stat(%s) failed: %m", + root->storage_mount_path); + } + return FALSE; + } + match = CMP_DEV_T(mst.st_dev, rst.st_dev); + if (getenv("DEBUG") != NULL) { + i_info("box=%s mount=%s match=%s", mailbox_path, + root->storage_mount_path, match ? "yes" : "no"); + } + return match; +} + static int fs_quota_get_resource(struct quota_root *_root, const char *name, uint64_t *value_r) @@ -648,7 +681,9 @@ fs_quota_root_get_resources, fs_quota_get_resource, - fs_quota_update + fs_quota_update, + + fs_quota_match_box } };
--- a/src/plugins/quota/quota-maildir.c Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota-maildir.c Sun Jul 20 21:36:13 2008 +0300 @@ -758,6 +758,7 @@ maildir_quota_storage_added, maildir_quota_root_get_resources, maildir_quota_get_resource, - maildir_quota_update + maildir_quota_update, + NULL } };
--- a/src/plugins/quota/quota-private.h Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota-private.h Sun Jul 20 21:36:13 2008 +0300 @@ -54,6 +54,8 @@ int (*update)(struct quota_root *root, struct quota_transaction_context *ctx); + bool (*match_box)(struct quota_root *root, struct mailbox *box); + }; struct quota_backend {
--- a/src/plugins/quota/quota.c Sun Jul 20 21:17:31 2008 +0300 +++ b/src/plugins/quota/quota.c Sun Jul 20 21:36:13 2008 +0300 @@ -551,6 +551,22 @@ return iter; } +static bool +quota_root_is_visible(struct quota_root *root, struct mailbox *box, + bool enforce) +{ + if (root->no_enforcing && enforce) { + /* we don't want to include this root in quota enforcing */ + return FALSE; + } + if (array_count(&root->quota->roots) == 1) { + /* a single quota root: don't bother checking further */ + return TRUE; + } + return root->backend.v.match_box == NULL ? TRUE : + root->backend.v.match_box(root, box); +} + struct quota_root *quota_root_iter_next(struct quota_root_iter *iter) { struct quota_root *const *roots, *root = NULL; @@ -563,6 +579,9 @@ return NULL; for (; iter->i < count; iter->i++) { + if (!quota_root_is_visible(roots[iter->i], iter->box, FALSE)) + continue; + ret = quota_get_resource(roots[iter->i], "", QUOTA_NAME_STORAGE_KILOBYTES, &value, &limit); @@ -684,10 +703,8 @@ /* find the lowest quota limits from all roots and use them */ roots = array_get(&ctx->quota->roots, &count); for (i = 0; i < count; i++) { - if (roots[i]->no_enforcing) { - /* we don't care what the current quota is */ + if (!quota_root_is_visible(roots[i], ctx->box, TRUE)) continue; - } ret = quota_get_resource(roots[i], mailbox_name, QUOTA_NAME_STORAGE_BYTES, @@ -781,6 +798,9 @@ mailbox_name = mailbox_get_name(ctx->box); roots = array_get(&ctx->quota->roots, &count); for (i = 0; i < count; i++) { + if (!quota_root_is_visible(roots[i], ctx->box, TRUE)) + continue; + rule = quota_root_rule_find(roots[i], mailbox_name); if (rule != NULL && rule->ignore) { /* mailbox not included in quota */ @@ -854,6 +874,9 @@ for (i = 0; i < count; i++) { uint64_t bytes_limit, count_limit; + if (!quota_root_is_visible(roots[i], ctx->box, TRUE)) + continue; + if (!quota_root_get_rule_limits(roots[i], mailbox_get_name(ctx->box), &bytes_limit, &count_limit))