From: Timo Sirainen Date: Mon, 19 Aug 2024 09:29:56 +0000 (+0300) Subject: quota: Move namespaces list to quota_root X-Git-Tag: 2.4.0~394 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=abf8bfb00e302f0d96aef0c108dd9368f09e860c;p=thirdparty%2Fdovecot%2Fcore.git quota: Move namespaces list to quota_root It makes more sense in there. --- diff --git a/src/plugins/quota/quota-count.c b/src/plugins/quota/quota-count.c index 7aa1fb31f7..507d19cbf3 100644 --- a/src/plugins/quota/quota-count.c +++ b/src/plugins/quota/quota-count.c @@ -125,7 +125,7 @@ quota_mailbox_iter_next(struct quota_mailbox_iter *iter) unsigned int count; if (iter->iter == NULL) { - namespaces = array_get(&iter->root->quota->namespaces, &count); + namespaces = array_get(&iter->root->namespaces, &count); do { if (iter->ns_idx >= count) return NULL; diff --git a/src/plugins/quota/quota-maildir.c b/src/plugins/quota/quota-maildir.c index 75d79070cf..db00d81730 100644 --- a/src/plugins/quota/quota-maildir.c +++ b/src/plugins/quota/quota-maildir.c @@ -376,7 +376,7 @@ static int maildirsize_recalculate(struct maildir_quota_root *root, maildirsize_recalculate_init(root); /* count mails from all namespaces */ - namespaces = array_get(&root->root.quota->namespaces, &count); + namespaces = array_get(&root->root.namespaces, &count); for (i = 0; i < count; i++) { if (!quota_root_is_namespace_visible(&root->root, namespaces[i])) continue; diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index 34b1f8ce12..98ca47df2f 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -16,8 +16,6 @@ struct quota { struct event *event; ARRAY(struct quota_root *) roots; - ARRAY(struct mail_namespace *) namespaces; - struct mail_namespace *unwanted_ns; enum quota_alloc_result (*test_alloc)( struct quota_transaction_context *ctx, uoff_t size, @@ -115,6 +113,9 @@ struct quota_root { ns=NULL, so when checking if quota root applies only to a specific namespace use the ns_prefix!=NULL check. */ const char *ns_prefix; + /* All namespaces using this quota root */ + ARRAY(struct mail_namespace *) namespaces; + struct mail_namespace *unwanted_ns; /* initially the same as set->default_rule.*_limit, but some backends may change these by reading the limits elsewhere (e.g. imapc, diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 1337b2b08f..0ca5ea51a1 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -353,6 +353,7 @@ quota_root_init(struct quota_root_legacy_settings *root_set, struct 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; + p_array_init(&root->namespaces, root->pool, 4); array_create(&root->quota_module_contexts, root->pool, sizeof(void *), 10); @@ -397,7 +398,6 @@ int quota_init(struct quota_legacy_settings *quota_set, struct mail_user *user, i_array_init("a->roots, 8); root_sets = array_get("a_set->root_sets, &count); - i_array_init("a->namespaces, count); for (i = 0; i < count; i++) { ret = quota_root_init(root_sets[i], quota, &root, &error); if (ret < 0) { @@ -433,7 +433,6 @@ void quota_deinit(struct quota **_quota) *_quota = NULL; array_free("a->roots); - array_free("a->namespaces); event_unref("a->event); i_free(quota); } @@ -484,7 +483,7 @@ quota_root_get_rule_limits(struct quota_root *root, struct mailbox *box, } static bool -quota_is_duplicate_namespace(struct quota *quota, struct mail_namespace *ns) +quota_is_duplicate_namespace(struct quota_root *root, struct mail_namespace *ns) { struct mail_namespace *const *namespaces; unsigned int i, count; @@ -494,7 +493,7 @@ quota_is_duplicate_namespace(struct quota *quota, struct mail_namespace *ns) MAILBOX_LIST_PATH_TYPE_MAILBOX, &path)) path = NULL; - namespaces = array_get("a->namespaces, &count); + namespaces = array_get(&root->namespaces, &count); for (i = 0; i < count; i++) { /* Count namespace aliases only once. Don't rely only on non-empty alias_for, because the alias might have been @@ -524,8 +523,8 @@ quota_is_duplicate_namespace(struct quota *quota, struct mail_namespace *ns) an alternative would be to do a bit larger change so namespaces wouldn't be added until mail_namespaces_created() hook is called */ - i_assert(quota->unwanted_ns == NULL); - quota->unwanted_ns = namespaces[i]; + i_assert(root->unwanted_ns == NULL); + root->unwanted_ns = namespaces[i]; return FALSE; } } @@ -534,38 +533,25 @@ quota_is_duplicate_namespace(struct quota *quota, struct mail_namespace *ns) void quota_add_user_namespace(struct quota *quota, struct mail_namespace *ns) { - struct quota_root *const *roots; - struct quota_backend **backends; - unsigned int i, j, count; - - /* first check if there already exists a namespace with the exact same - path. we don't want to count them twice. */ - if (quota_is_duplicate_namespace(quota, ns)) - return; + struct quota_root *root; - array_push_back("a->namespaces, &ns); + array_foreach_elem("a->roots, root) { + /* first check if there already exists a namespace with the + exact same path. we don't want to count them twice. */ + if (quota_is_duplicate_namespace(root, ns)) + continue; - roots = array_get("a->roots, &count); - /* @UNSAFE: get different backends into one array */ - backends = t_new(struct quota_backend *, count + 1); - for (i = 0; i < count; i++) { - for (j = 0; backends[j] != NULL; j++) { - if (backends[j]->name == roots[i]->backend.name) - break; - } - if (backends[j] == NULL) - backends[j] = &roots[i]->backend; - } + array_push_back(&root->namespaces, &ns); - for (i = 0; backends[i] != NULL; i++) { - if (backends[i]->v.namespace_added != NULL) - backends[i]->v.namespace_added(quota, ns); + if (root->backend.v.namespace_added != NULL) + root->backend.v.namespace_added(quota, ns); } } void quota_remove_user_namespace(struct mail_namespace *ns) { struct quota *quota; + struct quota_root *root; struct mail_namespace *const *namespaces; unsigned int i, count; @@ -577,11 +563,13 @@ void quota_remove_user_namespace(struct mail_namespace *ns) return; } - namespaces = array_get("a->namespaces, &count); - for (i = 0; i < count; i++) { - if (namespaces[i] == ns) { - array_delete("a->namespaces, i, 1); - break; + array_foreach_elem("a->roots, root) { + namespaces = array_get(&root->namespaces, &count); + for (i = 0; i < count; i++) { + if (namespaces[i] == ns) { + array_delete(&root->namespaces, i, 1); + break; + } } } } @@ -620,7 +608,7 @@ bool quota_root_is_namespace_visible(struct quota_root *root, if (mailbox_list_get_storage(&list, &vname, 0, &storage) == 0 && (storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NOQUOTA) != 0) return FALSE; - if (root->quota->unwanted_ns == ns) + if (root->unwanted_ns == ns) return FALSE; if (root->ns_prefix != NULL) {