Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/plugins/quota/quota-dirsize.c @ 4330:823648215520 HEAD
If size of the mail was known before saving started, we allocated
the quota twice for it.
author | Timo Sirainen <timo.sirainen@movial.fi> |
---|---|
date | Sun, 11 Jun 2006 20:39:04 +0300 |
parents | 85efed60baef |
children | 1a35d53c18fc |
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 |
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
|
16 struct dirsize_quota_root { |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 struct quota_root root; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 uint64_t storage_limit; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 }; |
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 |
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
|
24 static struct quota_root * |
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
|
25 dirsize_quota_init(struct quota_setup *setup, const char *name) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 { |
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
|
27 struct dirsize_quota_root *root; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 const char *const *args; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
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
|
30 root = i_new(struct dirsize_quota_root, 1); |
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
|
31 root->root.name = i_strdup(name); |
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
|
32 root->root.v = quota_backend_dirsize.v; |
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
|
33 |
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
|
34 t_push(); |
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
|
35 args = t_strsplit(setup->data, ":"); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
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
|
37 for (; *args != '\0'; args++) { |
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
|
38 if (strncmp(*args, "storage=", 8) == 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
|
39 root->storage_limit = strtoull(*args + 8, NULL, 10); |
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
|
40 } |
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
|
41 t_pop(); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
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
|
43 if (getenv("DEBUG") != NULL) { |
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
|
44 i_info("dirsize quota limit = %llukB", |
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
|
45 (unsigned long long)root->storage_limit); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
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
|
48 return &root->root; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 |
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
|
51 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
|
52 { |
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
|
53 struct dirsize_quota_root *root = (struct dirsize_quota_root *)_root; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
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
|
55 i_free(root->root.name); |
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
|
56 i_free(root); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 |
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
|
59 static bool |
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
|
60 dirsize_quota_add_storage(struct quota_root *root __attr_unused__, |
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
|
61 struct mail_storage *storage __attr_unused__) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 { |
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
|
63 return TRUE; |
3738
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 |
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
|
66 static void |
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
|
67 dirsize_quota_remove_storage(struct quota_root *root __attr_unused__, |
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
|
68 struct mail_storage *storage __attr_unused__) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 static const char *const * |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 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
|
74 { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 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
|
76 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 return resources; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 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
|
81 { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 DIR *dirp; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 string_t *path; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 struct dirent *d; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 struct stat st; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 unsigned int path_pos; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 int ret; |
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 dirp = opendir(dir); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 if (dirp == NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 if (errno == ENOENT) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 return 0; |
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 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
|
95 return -1; |
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 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 path = t_str_new(128); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 str_append(path, dir); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 str_append_c(path, '/'); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 path_pos = str_len(path); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 ret = 0; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 while ((d = readdir(dirp)) != NULL) { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 if (d->d_name[0] == '.' && |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 (d->d_name[1] == '\0' || |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 (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
|
108 /* skip . and .. */ |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 continue; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 str_truncate(path, path_pos); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 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
|
114 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 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
|
116 if (errno == ENOENT) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 continue; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
119 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
|
120 ret = -1; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 break; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 } 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
|
123 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
|
124 ret = -1; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 break; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 } else { |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 *value += st.st_size; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 (void)closedir(dirp); |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 return ret; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 |
4181
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
136 static int get_usage(struct dirsize_quota_root *root, |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
137 const char *path, bool is_file, uint64_t *value_r) |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
138 { |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
139 struct stat st; |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
140 |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
141 if (is_file) { |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
142 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
|
143 if (errno == ENOENT) |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
144 return 0; |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
145 |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
146 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
|
147 return -1; |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
148 } |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
149 *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
|
150 } else { |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
151 if (get_dir_usage(path, value_r) < 0) { |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
152 quota_set_error(root->root.setup->quota, |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
153 "Internal quota calculation error"); |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
154 return -1; |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
155 } |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
156 } |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
157 return 0; |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
158 } |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
159 |
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
|
160 struct quota_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
|
161 const char *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
|
162 bool 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
|
163 }; |
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 |
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 static void quota_count_path_add(array_t *paths, const char *path, bool 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 { |
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 ARRAY_SET_TYPE(paths, struct quota_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
|
168 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
|
169 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
|
170 |
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 count_path = array_get_modifyable(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
|
172 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
|
173 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
|
174 strlen(count_path[i].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
|
175 /* this path is already being counted */ |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
176 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
|
177 } |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
178 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
|
179 /* 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
|
180 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
|
181 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
|
182 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
|
183 } |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
184 } |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
185 |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 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
|
190 } |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
191 |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 static int |
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
|
193 get_quota_root_usage(struct dirsize_quota_root *root, uint64_t *value_r) |
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
|
194 { |
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
|
195 struct mail_storage *const *storages; |
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
|
196 array_t ARRAY_DEFINE(paths, struct quota_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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 |
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
|
202 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
|
203 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
|
204 struct quota_count_path, 8); |
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
|
205 storages = array_get(&root->root.storages, &count); |
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
|
206 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
|
207 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
|
208 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
|
209 |
b58eedd18662
Count INBOX also if it's outside the default mail directory.
Timo Sirainen <tss@iki.fi>
parents:
4087
diff
changeset
|
210 /* 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
|
211 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
|
212 &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
|
213 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
|
214 } |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
215 |
85efed60baef
When using multiple namespaces, don't count each of them if they're using
Timo Sirainen <tss@iki.fi>
parents:
4181
diff
changeset
|
216 /* 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
|
217 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
|
218 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
|
219 if (get_usage(root, count_paths[i].path, count_paths[i].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
|
220 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
|
221 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
|
222 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
|
223 } |
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
|
224 } |
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
|
225 |
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
|
226 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
|
227 |
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
|
228 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
|
229 } |
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
|
230 |
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
|
231 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
|
232 dirsize_quota_get_resource(struct quota_root *_root, const char *name, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 uint64_t *value_r, uint64_t *limit_r) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 { |
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
|
235 struct dirsize_quota_root *root = (struct dirsize_quota_root *)_root; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 *value_r = 0; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 *limit_r = 0; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 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
|
241 return 0; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 |
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
|
243 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
|
244 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
|
245 |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 *value_r /= 1024; |
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
|
247 *limit_r = root->storage_limit; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 return 1; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 static int |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 dirsize_quota_set_resource(struct quota_root *root, |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 const char *name __attr_unused__, |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 uint64_t value __attr_unused__) |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 { |
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
|
256 quota_set_error(root->setup->quota, MAIL_STORAGE_ERR_NO_PERMISSION); |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 return -1; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 |
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
|
260 static struct quota_root_transaction_context * |
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
|
261 dirsize_quota_transaction_begin(struct quota_root *_root, |
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
|
262 struct quota_transaction_context *_ctx) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 { |
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
|
264 struct dirsize_quota_root *root = (struct dirsize_quota_root *)_root; |
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
|
265 struct quota_root_transaction_context *ctx; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 |
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
|
267 ctx = i_new(struct quota_root_transaction_context, 1); |
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
|
268 ctx->root = _root; |
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
|
269 ctx->ctx = _ctx; |
3767
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
270 |
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
271 /* Get dir usage only once at the beginning of transaction. |
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
272 When copying/appending lots of mails we don't want to re-read the |
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
273 entire directory structure after each mail. */ |
4086
07c3a801c3dc
Maildir++ quota support.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4084
diff
changeset
|
274 if (get_quota_root_usage(root, &ctx->bytes_current) < 0 || |
07c3a801c3dc
Maildir++ quota support.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4084
diff
changeset
|
275 ctx->bytes_current == (uint64_t)-1) { |
07c3a801c3dc
Maildir++ quota support.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4084
diff
changeset
|
276 ctx->bytes_current = (uint64_t)-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
|
277 quota_set_error(_root->setup->quota, |
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
|
278 "Internal quota calculation error"); |
3767
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
279 } |
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
280 |
4086
07c3a801c3dc
Maildir++ quota support.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4084
diff
changeset
|
281 ctx->bytes_limit = root->storage_limit * 1024; |
4087 | 282 ctx->count_limit = (uint64_t)-1; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 return ctx; |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 static int |
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
|
287 dirsize_quota_transaction_commit(struct quota_root_transaction_context *ctx) |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 { |
4086
07c3a801c3dc
Maildir++ quota support.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4084
diff
changeset
|
289 int ret = ctx->bytes_current == (uint64_t)-1 ? -1 : 0; |
3767
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
290 |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 i_free(ctx); |
3767
c96f2e532b9d
Make dirsize backend read the directory only once at the beginning of
Timo Sirainen <tss@iki.fi>
parents:
3738
diff
changeset
|
292 return ret; |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 } |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 |
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
|
295 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
|
296 "dirsize", |
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 |
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
|
298 { |
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
|
299 dirsize_quota_init, |
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
|
300 dirsize_quota_deinit, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 |
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
|
302 dirsize_quota_add_storage, |
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
|
303 dirsize_quota_remove_storage, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 |
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
|
305 dirsize_quota_root_get_resources, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 |
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
|
307 dirsize_quota_get_resource, |
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
|
308 dirsize_quota_set_resource, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 |
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
|
310 dirsize_quota_transaction_begin, |
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
|
311 dirsize_quota_transaction_commit, |
4087 | 312 quota_default_transaction_rollback, |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 |
4087 | 314 quota_default_try_alloc, |
315 quota_default_try_alloc_bytes, | |
4330
823648215520
If size of the mail was known before saving started, we allocated
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4182
diff
changeset
|
316 quota_default_test_alloc_bytes, |
4087 | 317 quota_default_alloc, |
318 quota_default_free | |
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
|
319 } |
3738
732b62dc1976
Added beginnings of plugin infrastructure. TODO: These could be optionally
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 }; |