]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Fixed FS quota compiling and Maildir++ quota with multiple users.
authorTimo Sirainen <tss@iki.fi>
Wed, 13 Aug 2008 22:08:45 +0000 (18:08 -0400)
committerTimo Sirainen <tss@iki.fi>
Wed, 13 Aug 2008 22:08:45 +0000 (18:08 -0400)
--HG--
branch : HEAD

src/plugins/quota/quota-fs.c
src/plugins/quota/quota-maildir.c
src/plugins/quota/quota-private.h
src/plugins/quota/quota.c

index 7988c78117e3be4eb88b6070efde4dbfb688ab3e..7907a2a7e65d1d636abdab670922674f9023ce95 100644 (file)
@@ -661,9 +661,9 @@ fs_quota_get_resource(struct quota_root *_root, const char *name,
 
        /* update limit */
        if (bytes)
-               _root->default_rule.bytes_limit = limit;
+               _root->bytes_limit = limit;
        else
-               _root->default_rule.count_limit = limit;
+               _root->count_limit = limit;
        return 1;
 }
 
index 108bc3c2894d487f81a1f79565c62c07524b7d76..a90c0431c2de7b408f4426f16b68fa28abdac1ec 100644 (file)
@@ -217,7 +217,7 @@ maildirs_check_have_changed(struct maildir_quota_root *root,
 
 static int maildirsize_write(struct maildir_quota_root *root, const char *path)
 {
-       const struct quota_rule *rule = &root->root.set->default_rule;
+       struct quota_root *_root = &root->root;
        struct mail_storage *const *storages;
        unsigned int i, count;
        struct dotlock *dotlock;
@@ -257,15 +257,15 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
        }
 
        str = t_str_new(128);
-       if (rule->bytes_limit != 0) {
+       if (_root->bytes_limit != 0) {
                str_printfa(str, "%lluS",
-                           (unsigned long long)rule->bytes_limit);
+                           (unsigned long long)_root->bytes_limit);
        }
-       if (rule->count_limit != 0) {
+       if (_root->count_limit != 0) {
                if (str_len(str) > 0)
                        str_append_c(str, ',');
                str_printfa(str, "%lluC",
-                           (unsigned long long)rule->count_limit);
+                           (unsigned long long)_root->count_limit);
        }
        str_printfa(str, "\n%llu %llu\n",
                    (unsigned long long)root->total_bytes,
@@ -410,7 +410,7 @@ maildir_parse_limit(const char *str, uint64_t *bytes_r, uint64_t *count_r)
 static int maildirsize_parse(struct maildir_quota_root *root,
                             int fd, const char *const *lines)
 {
-       struct quota_rule *rule = &root->root.set->default_rule;
+       struct quota_root *_root = &root->root;
        uint64_t message_bytes_limit, message_count_limit;
        long long bytes_diff, total_bytes;
        int count_diff, total_count;
@@ -429,8 +429,8 @@ static int maildirsize_parse(struct maildir_quota_root *root,
        if (message_count_limit >= (1ULL << 63))
                message_count_limit = (1ULL << 63) - 1;
 
-       if (rule->bytes_limit == (int64_t)message_bytes_limit &&
-           rule->count_limit == (int64_t)message_count_limit) {
+       if (root->root.bytes_limit == (int64_t)message_bytes_limit &&
+           root->root.count_limit == (int64_t)message_count_limit) {
                /* limits haven't changed */
        } else if (root->root.set->force_default_rule) {
                /* we know the limits and they've changed.
@@ -438,8 +438,8 @@ static int maildirsize_parse(struct maildir_quota_root *root,
                return 0;
        } else {
                /* we're using limits from the file. */
-               rule->bytes_limit = message_bytes_limit;
-               rule->count_limit = message_count_limit;
+               root->root.bytes_limit = message_bytes_limit;
+               root->root.count_limit = message_count_limit;
                quota_root_recalculate_relative_rules(root->root.set);
        }
 
@@ -463,8 +463,8 @@ static int maildirsize_parse(struct maildir_quota_root *root,
                return -1;
        }
 
-       if ((total_bytes > rule->bytes_limit && rule->bytes_limit != 0) ||
-           (total_count > rule->count_limit && rule->count_limit != 0)) {
+       if ((total_bytes > _root->bytes_limit && _root->bytes_limit != 0) ||
+           (total_count > _root->count_limit && _root->count_limit != 0)) {
                /* we're over quota. don't trust these values if the file
                   contains more than the initial summary line, or if the file
                   is older than 15 minutes. */
index f72535e3d2604c62c0451f511aff74e45e354d47..30136b0b57ce204b54a38ae59a400278c1e07517 100644 (file)
@@ -96,6 +96,11 @@ struct quota_root {
        struct quota *quota;
        struct quota_backend backend;
 
+       /* initially the same as set->default_rule.*_limit, but some backends
+          may change these by reading the limits elsewhere (e.g. Maildir++,
+          FS quota) */
+       int64_t bytes_limit, count_limit;
+
        /* Module-specific contexts. See quota_module_id. */
        ARRAY_DEFINE(quota_module_contexts, void);
 
index 25c35f4b05c595692916112524cfeb7b6b623241..ff47f77e371701b467e2d6a7f74d0dc54eae2b60 100644 (file)
@@ -143,6 +143,8 @@ quota_root_init(struct quota_root_settings *root_set, struct quota *quota)
        root->set = root_set;
        root->quota = quota;
        root->backend = *root_set->backend;
+       root->bytes_limit = root_set->default_rule.bytes_limit;
+       root->count_limit = root_set->default_rule.count_limit;
 
        array_create(&root->quota_module_contexts, root->pool,
                     sizeof(void *), 10);
@@ -424,7 +426,7 @@ int quota_root_add_rule(struct quota_root_settings *root_set,
        return ret;
 }
 
-static bool quota_root_get_rule_limits(struct quota_root_settings *root_set,
+static bool quota_root_get_rule_limits(struct quota_root *root,
                                       const char *mailbox_name,
                                       uint64_t *bytes_limit_r,
                                       uint64_t *count_limit_r)
@@ -433,14 +435,14 @@ static bool quota_root_get_rule_limits(struct quota_root_settings *root_set,
        int64_t bytes_limit, count_limit;
        bool found;
 
-       bytes_limit = root_set->default_rule.bytes_limit;
-       count_limit = root_set->default_rule.count_limit;
+       bytes_limit = root->bytes_limit;
+       count_limit = root->count_limit;
 
        /* if default rule limits are 0, this rule applies only to specific
           mailboxes */
        found = bytes_limit != 0 || count_limit != 0;
 
-       rule = quota_root_rule_find(root_set, mailbox_name);
+       rule = quota_root_rule_find(root->set, mailbox_name);
        if (rule != NULL) {
                if (!rule->ignore) {
                        bytes_limit += rule->bytes_limit;
@@ -685,7 +687,7 @@ int quota_get_resource(struct quota_root *root, const char *mailbox_name,
        if (ret <= 0)
                return ret;
 
-       (void)quota_root_get_rule_limits(root->set, mailbox_name,
+       (void)quota_root_get_rule_limits(root, mailbox_name,
                                         &bytes_limit, &count_limit);
        if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
                *limit_r = bytes_limit;
@@ -914,7 +916,7 @@ static int quota_default_test_alloc(struct quota_transaction_context *ctx,
                if (!quota_root_is_visible(roots[i], ctx->box, TRUE))
                        continue;
 
-               if (!quota_root_get_rule_limits(roots[i]->set,
+               if (!quota_root_get_rule_limits(roots[i],
                                                mailbox_get_name(ctx->box),
                                                &bytes_limit, &count_limit))
                        continue;