annotate src/plugins/quota/quota-dirsize.c @ 4509:e5e79558ac2d HEAD

Added support for multiple quota roots, rules and storages. The configuration has changed, userdb now needs to return "quota_rule" settings instead. Much of the code changes were done by Tianyan Liu.
author Timo Sirainen <timo.sirainen@movial.fi>
date Sun, 30 Jul 2006 20:58:38 +0300
parents 1a35d53c18fc
children e92ae6d532f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
1 /* Copyright (C) 2005-2006 Timo Sirainen */
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 /* Quota reporting based on simply summing sizes of all files in mailbox
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 together. */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "lib.h"
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
7 #include "array.h"
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "str.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "quota-private.h"
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include <stdlib.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include <unistd.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <dirent.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <sys/stat.h>
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
16 struct quota_count_path {
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
17 const char *path;
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
18 bool is_file;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 };
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
20 ARRAY_DEFINE_TYPE(quota_count_path, struct quota_count_path);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
22 extern struct quota_backend quota_backend_dirsize;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
24 static struct quota_root *dirsize_quota_alloc(void)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
26 return i_new(struct quota_root, 1);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
29 static void dirsize_quota_deinit(struct quota_root *_root)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
31 i_free(_root);
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 static const char *const *
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 dirsize_quota_root_get_resources(struct quota_root *root __attr_unused__)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 static const char *resources[] = { QUOTA_NAME_STORAGE, NULL };
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 return resources;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 static int get_dir_usage(const char *dir, uint64_t *value)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 DIR *dirp;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 string_t *path;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 struct dirent *d;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 struct stat st;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 unsigned int path_pos;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 int ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 dirp = opendir(dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 if (dirp == NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 if (errno == ENOENT)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 i_error("opendir(%s) failed: %m", dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 return -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 path = t_str_new(128);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 str_append(path, dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 str_append_c(path, '/');
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 path_pos = str_len(path);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 ret = 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 while ((d = readdir(dirp)) != NULL) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 if (d->d_name[0] == '.' &&
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 (d->d_name[1] == '\0' ||
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 (d->d_name[1] == '.' && d->d_name[2] == '\0'))) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 /* skip . and .. */
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 continue;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 str_truncate(path, path_pos);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 str_append(path, d->d_name);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 if (lstat(str_c(path), &st) < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 if (errno == ENOENT)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 continue;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 i_error("lstat(%s) failed: %m", dir);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 ret = -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 } else if (S_ISDIR(st.st_mode)) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 if (get_dir_usage(str_c(path), value) < 0) {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 ret = -1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 break;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 } else {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 *value += st.st_size;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 (void)closedir(dirp);
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 return ret;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
98 static int get_usage(const char *path, bool is_file, uint64_t *value_r)
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
99 {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
100 struct stat st;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
101
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
102 if (is_file) {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
103 if (lstat(path, &st) < 0) {
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
104 if (errno == ENOENT)
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
105 return 0;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
106
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
107 i_error("lstat(%s) failed: %m", path);
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
108 return -1;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
109 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
110 *value_r += st.st_size;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
111 } else {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
112 if (get_dir_usage(path, value_r) < 0)
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
113 return -1;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
114 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
115 return 0;
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
116 }
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
117
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
118 static void quota_count_path_add(ARRAY_TYPE(quota_count_path) *paths,
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
119 const char *path, bool is_file)
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
120 {
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
121 struct quota_count_path *count_path;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
122 unsigned int i, count;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
123
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
124 count_path = array_get_modifiable(paths, &count);
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
125 for (i = 0; i < count; i++) {
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
126 if (strncmp(count_path[i].path, path,
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
127 strlen(count_path[i].path)) == 0) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
128 /* this path has already been counted */
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
129 return;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
130 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
131 if (strncmp(count_path[i].path, path, strlen(path)) == 0) {
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
132 /* the new path contains the existing path */
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
133 i_assert(!is_file);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
134 count_path += i;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
135 break;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
136 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
137 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
138
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
139 if (i == count)
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
140 count_path = array_append_space(paths);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
141 count_path->path = t_strdup(path);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
142 count_path->is_file = is_file;
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
143 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
144
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 static int
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
146 get_quota_root_usage(struct quota_root *root, uint64_t *value_r)
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
147 {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
148 struct mail_storage *const *storages;
4451
1a35d53c18fc Array API redesigned to work using unions. It now provides type safety
Timo Sirainen <tss@iki.fi>
parents: 4330
diff changeset
149 ARRAY_TYPE(quota_count_path) paths;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
150 const struct quota_count_path *count_paths;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
151 unsigned int i, count;
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
152 const char *path;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
153 bool is_file;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
154
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
155 t_push();
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
156 ARRAY_CREATE(&paths, pool_datastack_create(),
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
157 struct quota_count_path, 8);
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
158 storages = array_get(&root->quota->storages, &count);
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
159 for (i = 0; i < count; i++) {
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
160 path = mail_storage_get_mailbox_path(storages[i], "", &is_file);
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
161 quota_count_path_add(&paths, path, is_file);
4181
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
162
b58eedd18662 Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents: 4087
diff changeset
163 /* INBOX may be in different path. */
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
164 path = mail_storage_get_mailbox_path(storages[i], "INBOX",
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
165 &is_file);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
166 quota_count_path_add(&paths, path, is_file);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
167 }
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
168
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
169 /* now sum up the found paths */
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
170 count_paths = array_get(&paths, &count);
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
171 for (i = 0; i < count; i++) {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
172 if (get_usage(count_paths[i].path, count_paths[i].is_file,
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
173 value_r) < 0) {
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
174 t_pop();
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
175 return -1;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
176 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
177 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
178
4182
85efed60baef When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents: 4181
diff changeset
179 t_pop();
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
180 return 0;
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
181 }
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
182
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
183 static int
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
184 dirsize_quota_get_resource(struct quota_root *_root, const char *name,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
185 uint64_t *value_r, uint64_t *limit __attr_unused__)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 {
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0)
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 return 0;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
190 if (get_quota_root_usage(_root, value_r) < 0)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 return -1;
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
192
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 *value_r /= 1024;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 return 1;
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
197 static int
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
198 dirsize_quota_update(struct quota_root *root __attr_unused__,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
199 struct quota_transaction_context *ctx __attr_unused__)
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
201 return 0;
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 }
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
204 struct quota_backend quota_backend_dirsize = {
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 "dirsize",
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
207 {
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
208 dirsize_quota_alloc,
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
209 NULL,
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
210 dirsize_quota_deinit,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
211 NULL,
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
212 dirsize_quota_root_get_resources,
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
213 dirsize_quota_get_resource,
4509
e5e79558ac2d Added support for multiple quota roots, rules and storages. The configuration
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4451
diff changeset
214 dirsize_quota_update
4084
51306837698b Quota API redesign. Still not perfect, but better than before. Quota backends no longer need to be told where the mails exist. fs backend doesn't work correctly with multiple partitions (if you've multiple namespaces).
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4044
diff changeset
215 }
3738
732b62dc1976 Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
216 };