dovecot-1.2: FS quota: Handle quota only for the quota roots whi...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Jul 20 21:36:16 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/796307638449
changeset: 8029:796307638449
user: Timo Sirainen <tss at iki.fi>
date: Sun Jul 20 21:36:13 2008 +0300
description:
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.
diffstat:
6 files changed, 71 insertions(+), 8 deletions(-)
src/plugins/quota/quota-dict.c | 3 +-
src/plugins/quota/quota-dirsize.c | 3 +-
src/plugins/quota/quota-fs.c | 39 +++++++++++++++++++++++++++++++++++--
src/plugins/quota/quota-maildir.c | 3 +-
src/plugins/quota/quota-private.h | 2 +
src/plugins/quota/quota.c | 29 ++++++++++++++++++++++++---
diffs (179 lines):
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota-dict.c
--- 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 @@ struct quota_backend quota_backend_dict
NULL,
dict_quota_root_get_resources,
dict_quota_get_resource,
- dict_quota_update
+ dict_quota_update,
+ NULL
}
};
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota-dirsize.c
--- 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 @@ struct quota_backend quota_backend_dirsi
NULL,
dirsize_quota_root_get_resources,
dirsize_quota_get_resource,
- dirsize_quota_update
+ dirsize_quota_update,
+ NULL
}
};
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota-fs.c
--- 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 @@ fs_quota_get_one_resource(struct fs_quot
#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 @@ struct quota_backend quota_backend_fs =
fs_quota_root_get_resources,
fs_quota_get_resource,
- fs_quota_update
+ fs_quota_update,
+
+ fs_quota_match_box
}
};
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota-maildir.c
--- 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 @@ struct quota_backend quota_backend_maild
maildir_quota_storage_added,
maildir_quota_root_get_resources,
maildir_quota_get_resource,
- maildir_quota_update
+ maildir_quota_update,
+ NULL
}
};
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota-private.h
--- 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 @@ struct quota_backend_vfuncs {
int (*update)(struct quota_root *root,
struct quota_transaction_context *ctx);
+ bool (*match_box)(struct quota_root *root, struct mailbox *box);
+
};
struct quota_backend {
diff -r ea4821b4e29a -r 796307638449 src/plugins/quota/quota.c
--- 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 @@ quota_root_iter_init(struct quota *quota
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 @@ struct quota_root *quota_root_iter_next(
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 @@ static int quota_transaction_set_limits(
/* 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 @@ int quota_transaction_commit(struct quot
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 @@ static int quota_default_test_alloc(stru
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))
More information about the dovecot-cvs
mailing list