Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-index-alloc-cache.c @ 22576:707ae9de3812
lib: istream-multiplex - Minor code cleanup
Avoid propagating the error twice, and avoid any confusion about what "got"
actually contains.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 05 Oct 2017 20:24:11 +0300 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21389
diff
changeset
|
1 /* Copyright (c) 2010-2017 Dovecot authors, see the included COPYING file */ |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "ioloop.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "module-context.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "eacces-error.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mail-index-private.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "mail-index-alloc-cache.h" |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #define MAIL_INDEX_ALLOC_CACHE_CONTEXT(obj) \ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 MODULE_CONTEXT(obj, mail_index_alloc_cache_index_module) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 /* How many seconds to keep index opened for reuse after it's been closed */ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #define INDEX_CACHE_TIMEOUT 10 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 /* How many closed indexes to keep */ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #define INDEX_CACHE_MAX 3 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 struct mail_index_alloc_cache_list { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 union mail_index_module_context module_ctx; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 struct mail_index_alloc_cache_list *next; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 struct mail_index *index; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 char *mailbox_path; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 int refcount; |
15560
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
25 bool referenced; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 dev_t index_dir_dev; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 ino_t index_dir_ino; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 time_t destroy_time; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 }; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 static MODULE_CONTEXT_DEFINE_INIT(mail_index_alloc_cache_index_module, |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 &mail_index_module_register); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 static struct mail_index_alloc_cache_list *indexes = NULL; |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
36 static unsigned int indexes_cache_references_count = 0; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 static struct timeout *to_index = NULL; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 static struct mail_index_alloc_cache_list * |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 mail_index_alloc_cache_add(struct mail_index *index, |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 const char *mailbox_path, struct stat *st) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 struct mail_index_alloc_cache_list *list; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 list = i_new(struct mail_index_alloc_cache_list, 1); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 list->refcount = 1; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 list->index = index; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 list->mailbox_path = i_strdup(mailbox_path); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 list->index_dir_dev = st->st_dev; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 list->index_dir_ino = st->st_ino; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 list->next = indexes; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 indexes = list; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 MODULE_CONTEXT_SET(index, mail_index_alloc_cache_index_module, list); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 return list; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 static void |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
61 mail_index_alloc_cache_list_unref(struct mail_index_alloc_cache_list *list) |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
62 { |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
63 i_assert(list->referenced); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
64 i_assert(indexes_cache_references_count > 0); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
65 |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
66 indexes_cache_references_count--; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
67 mail_index_close(list->index); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
68 list->referenced = FALSE; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
69 } |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
70 |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
71 static void |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 mail_index_alloc_cache_list_free(struct mail_index_alloc_cache_list *list) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 { |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
74 i_assert(list->refcount == 0); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
75 |
15560
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
76 if (list->referenced) |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
77 mail_index_alloc_cache_list_unref(list); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 mail_index_free(&list->index); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 i_free(list->mailbox_path); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 i_free(list); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
81 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 |
11059
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
83 static struct mail_index_alloc_cache_list * |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
84 mail_index_alloc_cache_find(const char *mailbox_path, const char *index_dir, |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
85 const struct stat *index_st) |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
86 { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
87 struct mail_index_alloc_cache_list **indexp, *rec, *match; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
88 unsigned int destroy_count; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
89 struct stat st; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
90 |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
91 destroy_count = 0; match = NULL; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
92 for (indexp = &indexes; *indexp != NULL;) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
93 rec = *indexp; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
94 |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
95 if (match != NULL) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
96 /* already found the index. we're just going through |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
97 the rest of them to drop 0 refcounts */ |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
98 } else if (rec->refcount == 0 && rec->index->open_count == 0) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
99 /* index is already closed. don't even try to |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
100 reuse it. */ |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
101 } else if (index_dir != NULL && rec->index_dir_ino != 0) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
102 if (index_st->st_ino == rec->index_dir_ino && |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
103 CMP_DEV_T(index_st->st_dev, rec->index_dir_dev)) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
104 /* make sure the directory still exists. |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
105 it might have been renamed and we're trying |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
106 to access it via its new path now. */ |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
107 if (stat(rec->index->dir, &st) < 0 || |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
108 st.st_ino != index_st->st_ino || |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
109 !CMP_DEV_T(st.st_dev, index_st->st_dev)) |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
110 rec->destroy_time = 0; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
111 else |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
112 match = rec; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
113 } |
16894
2b3948fa4a09
lib-index: Don't mix index struct caching for in-memory vs. disk indexes.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
114 } else if (mailbox_path != NULL && rec->mailbox_path != NULL && |
2b3948fa4a09
lib-index: Don't mix index struct caching for in-memory vs. disk indexes.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
115 index_dir == NULL && rec->index_dir_ino == 0) { |
11059
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
116 if (strcmp(mailbox_path, rec->mailbox_path) == 0) |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
117 match = rec; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
118 } |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
119 |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
120 if (rec->refcount == 0 && rec != match) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
121 if (rec->destroy_time <= ioloop_time || |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
122 destroy_count >= INDEX_CACHE_MAX) { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
123 *indexp = rec->next; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
124 mail_index_alloc_cache_list_free(rec); |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
125 continue; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
126 } else { |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
127 destroy_count++; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
128 } |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
129 } |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
130 |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
131 indexp = &(*indexp)->next; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
132 } |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
133 return match; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
134 } |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
135 |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
136 struct mail_index * |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 mail_index_alloc_cache_get(const char *mailbox_path, |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 const char *index_dir, const char *prefix) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
139 { |
11059
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
140 struct mail_index_alloc_cache_list *match; |
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
141 struct stat st; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
143 /* compare index_dir inodes so we don't break even with symlinks. |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
144 if index_dir doesn't exist yet or if using in-memory indexes, just |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
145 compare mailbox paths */ |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
146 i_zero(&st); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 if (index_dir == NULL) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 /* in-memory indexes */ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 } else if (stat(index_dir, &st) < 0) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 if (errno == ENOENT) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 /* it'll be created later */ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 } else if (errno == EACCES) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 i_error("%s", eacces_error_get("stat", index_dir)); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
154 } else { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
155 i_error("stat(%s) failed: %m", index_dir); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
156 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
157 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
158 |
11059
6a65c0e043e2
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Timo Sirainen <tss@iki.fi>
parents:
10878
diff
changeset
|
159 match = mail_index_alloc_cache_find(mailbox_path, index_dir, &st); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 if (match == NULL) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
161 struct mail_index *index = mail_index_alloc(index_dir, prefix); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 match = mail_index_alloc_cache_add(index, mailbox_path, &st); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
163 } else { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
164 match->refcount++; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 i_assert(match->index != NULL); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 return match->index; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
170 static bool destroy_unrefed(unsigned int min_destroy_count) |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
171 { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 struct mail_index_alloc_cache_list **list, *rec; |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
173 bool destroyed = FALSE; |
10878
131436a6b8b3
lib-index: Index alloc cache fixes. It wasn't really working.
Timo Sirainen <tss@iki.fi>
parents:
10784
diff
changeset
|
174 bool seen_ref0 = FALSE; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 for (list = &indexes; *list != NULL;) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 rec = *list; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 if (rec->refcount == 0 && |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
180 (min_destroy_count > 0 || rec->destroy_time <= ioloop_time)) { |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
181 *list = rec->next; |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
182 destroyed = TRUE; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
183 mail_index_alloc_cache_list_free(rec); |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
184 if (min_destroy_count > 0) |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
185 min_destroy_count--; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 } else { |
10878
131436a6b8b3
lib-index: Index alloc cache fixes. It wasn't really working.
Timo Sirainen <tss@iki.fi>
parents:
10784
diff
changeset
|
187 if (rec->refcount == 0) |
131436a6b8b3
lib-index: Index alloc cache fixes. It wasn't really working.
Timo Sirainen <tss@iki.fi>
parents:
10784
diff
changeset
|
188 seen_ref0 = TRUE; |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
189 if (min_destroy_count > 0 && |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
190 rec->index->open_count == 1 && |
15560
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
191 rec->referenced) { |
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
192 /* we're the only one keeping this index open. |
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
193 we might be here, because the caller is |
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
194 deleting this mailbox and wants its indexes |
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
195 to be closed. so close it. */ |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
196 destroyed = TRUE; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
197 mail_index_alloc_cache_list_unref(rec); |
15560
b53ab1c11843
lib-index: If sure mail_index_alloc_cache_destroy_unrefed() closes indexes it alone keeps open.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
198 } |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 list = &(*list)->next; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 |
10878
131436a6b8b3
lib-index: Index alloc cache fixes. It wasn't really working.
Timo Sirainen <tss@iki.fi>
parents:
10784
diff
changeset
|
203 if (!seen_ref0 && to_index != NULL) |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 timeout_remove(&to_index); |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
205 return destroyed; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
208 static void ATTR_NULL(1) |
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
209 index_removal_timeout(void *context ATTR_UNUSED) |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 { |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
211 destroy_unrefed(0); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
214 void mail_index_alloc_cache_unref(struct mail_index **_index) |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 { |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
216 struct mail_index *index = *_index; |
10783
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
217 struct mail_index_alloc_cache_list *list, **listp; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
219 *_index = NULL; |
10783
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
220 list = NULL; |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
221 for (listp = &indexes; *listp != NULL; listp = &(*listp)->next) { |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
222 if ((*listp)->index == index) { |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
223 list = *listp; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 break; |
10783
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
225 } |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 i_assert(list != NULL); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 i_assert(list->refcount > 0); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 list->refcount--; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 list->destroy_time = ioloop_time + INDEX_CACHE_TIMEOUT; |
10783
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
233 |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
234 if (list->refcount == 0 && index->open_count == 0) { |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
235 /* index was already closed. don't even try to cache it. */ |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
236 *listp = list->next; |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
237 mail_index_alloc_cache_list_free(list); |
3c0d86e79040
lib-index: When a closed index's refcount drops to 0, free it immediately.
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
238 } else if (to_index == NULL) { |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 to_index = timeout_add(INDEX_CACHE_TIMEOUT*1000/2, |
15079
925d4a890a9b
Fixed compiling with OSes where NULL isn't defined as void pointer (e.g. Solaris).
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
240 index_removal_timeout, (void *)NULL); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 void mail_index_alloc_cache_destroy_unrefed(void) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 { |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
246 destroy_unrefed(UINT_MAX); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 } |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
249 void mail_index_alloc_cache_index_opened(struct mail_index *index) |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
251 struct mail_index_alloc_cache_list *list = |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
252 MAIL_INDEX_ALLOC_CACHE_CONTEXT(index); |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 struct stat st; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 if (list != NULL && list->index_dir_ino == 0 && |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 !MAIL_INDEX_IS_IN_MEMORY(index)) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 /* newly created index directory. update its stat. */ |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 if (stat(index->dir, &st) == 0) { |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 list->index_dir_ino = st.st_ino; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 list->index_dir_dev = st.st_dev; |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 } |
10878
131436a6b8b3
lib-index: Index alloc cache fixes. It wasn't really working.
Timo Sirainen <tss@iki.fi>
parents:
10784
diff
changeset
|
262 } |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
263 } |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
264 |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
265 void mail_index_alloc_cache_index_closing(struct mail_index *index) |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
266 { |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
267 struct mail_index_alloc_cache_list *list = |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
268 MAIL_INDEX_ALLOC_CACHE_CONTEXT(index); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
269 |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
270 i_assert(index->open_count > 0); |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
271 if (index->open_count > 1 || list == NULL) |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
272 return; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
273 |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
274 if (list->referenced) { |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
275 /* we're closing our referenced index */ |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
276 return; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 } |
17578
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
278 while (indexes_cache_references_count > INDEX_CACHE_MAX) { |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
279 if (!destroy_unrefed(1)) { |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
280 /* our cache is full already, don't keep more */ |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
281 return; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
282 } |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
283 } |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
284 /* keep the index referenced for caching */ |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
285 indexes_cache_references_count++; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
286 list->referenced = TRUE; |
8944983786cc
lib-index: Index cache could have kept too many indexes open.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
287 index->open_count++; |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 } |