Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-cache.c @ 6857:41911abe6fa7 HEAD
NFS cache flushing updates.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 25 Nov 2007 15:47:36 +0200 |
parents | 0c970b3493ac |
children | 414c9d631a81 |
rev | line source |
---|---|
6429
65c69a53a7be
Replaced my Copyright notices. The year range always ends with 2007 now.
Timo Sirainen <tss@iki.fi>
parents:
6428
diff
changeset
|
1 /* Copyright (c) 2003-2007 Dovecot authors, see the included COPYING file */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3380
diff
changeset
|
4 #include "array.h" |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
5 #include "buffer.h" |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
6 #include "hash.h" |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
7 #include "nfs-workarounds.h" |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
8 #include "file-cache.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mmap-util.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "write-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "mail-cache-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <unistd.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 void mail_cache_set_syscall_error(struct mail_cache *cache, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 const char *function) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 i_assert(function != NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 if (ENOSPACE(errno)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 cache->index->nodiskspace = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 mail_index_set_error(cache->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 "%s failed with index cache file %s: %m", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 function, cache->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
34 (void)unlink(cache->filepath); |
3103
f2f03044b6b2
When we detect cache corruption, just mark the cache as unusable instead of
Timo Sirainen <tss@iki.fi>
parents:
2941
diff
changeset
|
35 |
f2f03044b6b2
When we detect cache corruption, just mark the cache as unusable instead of
Timo Sirainen <tss@iki.fi>
parents:
2941
diff
changeset
|
36 /* mark the cache as unusable */ |
f2f03044b6b2
When we detect cache corruption, just mark the cache as unusable instead of
Timo Sirainen <tss@iki.fi>
parents:
2941
diff
changeset
|
37 cache->hdr = NULL; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 mail_index_set_error(cache->index, "Corrupted index cache file %s: %s", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 cache->filepath, t_strdup_vprintf(fmt, va)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 va_end(va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 |
2247
2d51bb58a070
Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
2220
diff
changeset
|
47 void mail_cache_file_close(struct mail_cache *cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 if (cache->mmap_base != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 if (munmap(cache->mmap_base, cache->mmap_length) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 mail_cache_set_syscall_error(cache, "munmap()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
54 if (cache->file_cache != NULL) |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
55 file_cache_set_fd(cache->file_cache, -1); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
56 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 cache->mmap_base = NULL; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
58 cache->data = NULL; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 cache->hdr = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 cache->mmap_length = 0; |
6705
68bb5bec043e
When reading the latest fields, begin finding the fields from the last known
Timo Sirainen <tss@iki.fi>
parents:
6703
diff
changeset
|
61 cache->last_field_header_offset = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
63 if (cache->file_lock != NULL) |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
64 file_lock_free(&cache->file_lock); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
65 cache->locked = FALSE; |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
66 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 if (cache->fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 if (close(cache->fd) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 mail_cache_set_syscall_error(cache, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 cache->fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
5145
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
74 static void mail_cache_init_file_cache(struct mail_cache *cache) |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
75 { |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
76 struct stat st; |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
77 |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
78 if (cache->file_cache == NULL) |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
79 return; |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
80 |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
81 file_cache_set_fd(cache->file_cache, cache->fd); |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
82 |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
83 if (fstat(cache->fd, &st) == 0) |
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
84 file_cache_set_size(cache->file_cache, st.st_size); |
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
85 else if (errno != ESTALE) |
5145
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
86 mail_cache_set_syscall_error(cache, "fstat()"); |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
87 |
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
88 cache->st_ino = st.st_ino; |
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
89 cache->st_dev = st.st_dev; |
5145
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
90 } |
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
91 |
6701
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
92 static bool mail_cache_need_reopen(struct mail_cache *cache) |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
93 { |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
94 struct stat st; |
6701
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
95 |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
96 if (MAIL_CACHE_IS_UNUSABLE(cache)) { |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
97 if (cache->need_compress_file_seq != 0) { |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
98 /* we're waiting for compression */ |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
99 return FALSE; |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
100 } |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
101 if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) { |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
102 /* disabled */ |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
103 return FALSE; |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
104 } |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
105 } |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
106 |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
107 if (cache->fd == -1) |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
108 return TRUE; |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
109 |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
110 /* see if the file has changed */ |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
111 if (cache->index->nfs_flush) { |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
112 i_assert(!cache->locked); |
6857 | 113 nfs_flush_file_handle_cache(cache->filepath); |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
114 } |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
115 if (nfs_safe_stat(cache->filepath, &st) < 0) { |
6701
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
116 mail_cache_set_syscall_error(cache, "stat()"); |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
117 return TRUE; |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
118 } |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
119 |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
120 if (st.st_ino != cache->st_ino || |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
121 !CMP_DEV_T(st.st_dev, cache->st_dev)) { |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
122 /* file changed */ |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
123 return TRUE; |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
124 } |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
125 |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
126 if (cache->index->nfs_flush) { |
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
127 /* if the old file has been deleted, the new file may have |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
128 the same inode as the old one. we'll catch this here by |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
129 checking if fstat() fails with ESTALE */ |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
130 if (fstat(cache->fd, &st) < 0) { |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
131 if (errno == ESTALE) |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
132 return TRUE; |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
133 mail_cache_set_syscall_error(cache, "fstat()"); |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
134 return FALSE; |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
135 } |
6815
c991d1b132d8
Fixed cache file's NFS attribute cache flushing.
Timo Sirainen <tss@iki.fi>
parents:
6772
diff
changeset
|
136 } |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
137 return FALSE; |
6701
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
138 } |
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
139 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
140 int mail_cache_reopen(struct mail_cache *cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 { |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
142 struct mail_index_view *view; |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
143 const struct mail_index_ext *ext; |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
144 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
145 i_assert(!cache->locked); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
146 |
6701
c601e8cd0ffc
mail_cache_reopen(): Don't bother reopening if file is still the same.
Timo Sirainen <tss@iki.fi>
parents:
6700
diff
changeset
|
147 if (!mail_cache_need_reopen(cache)) { |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
148 /* reopening does no good */ |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
149 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 mail_cache_file_close(cache); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
153 |
6686
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
154 cache->fd = nfs_safe_open(cache->filepath, |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
155 cache->index->readonly ? O_RDONLY : O_RDWR); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
156 if (cache->fd == -1) { |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
157 if (errno == ENOENT) |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
158 cache->need_compress_file_seq = 0; |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
159 else |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
160 mail_cache_set_syscall_error(cache, "open()"); |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
161 return -1; |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
162 } |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
163 |
5145
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
164 mail_cache_init_file_cache(cache); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
165 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
166 if (mail_cache_map(cache, 0, 0) < 0) |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
167 return -1; |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
168 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
169 if (mail_cache_header_fields_read(cache) < 0) |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
170 return -1; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
171 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
172 view = mail_index_view_open(cache->index); |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
173 ext = mail_index_view_get_ext(view, cache->ext_id); |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
174 if (ext == NULL || cache->hdr->file_seq != ext->reset_id) { |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
175 /* still different - maybe a race condition or maybe the |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
176 file_seq really is corrupted. either way, this shouldn't |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
177 happen often so we'll just mark cache to be compressed |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
178 later which fixes this. */ |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
179 cache->need_compress_file_seq = cache->hdr->file_seq; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
180 mail_index_view_close(&view); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
181 return 0; |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
182 } |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
183 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
184 mail_index_view_close(&view); |
5736
b3ed52bbeca7
Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents:
5734
diff
changeset
|
185 i_assert(!MAIL_CACHE_IS_UNUSABLE(cache)); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
186 return 1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3833
diff
changeset
|
189 static bool mail_cache_verify_header(struct mail_cache *cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 { |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
191 const struct mail_cache_header *hdr = cache->data; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 /* check that the header is still ok */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 if (cache->mmap_length < sizeof(struct mail_cache_header)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
195 mail_cache_set_corrupted(cache, "File too small"); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
196 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
199 if (hdr->version != MAIL_CACHE_VERSION) { |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
200 /* version changed - upgrade silently */ |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
201 return FALSE; |
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
202 } |
4657
a2a9b6a92831
Don't use time_t anymore in cache file. uint32_t is large enough and makes
Timo Sirainen <tss@iki.fi>
parents:
4655
diff
changeset
|
203 if (hdr->compat_sizeof_uoff_t != sizeof(uoff_t)) { |
a2a9b6a92831
Don't use time_t anymore in cache file. uint32_t is large enough and makes
Timo Sirainen <tss@iki.fi>
parents:
4655
diff
changeset
|
204 /* architecture change - handle silently(?) */ |
a2a9b6a92831
Don't use time_t anymore in cache file. uint32_t is large enough and makes
Timo Sirainen <tss@iki.fi>
parents:
4655
diff
changeset
|
205 return FALSE; |
3819
61f0e1fe9b55
Moved uoff_t and time_t compatibility checks to cache file, since they're
Timo Sirainen <tss@iki.fi>
parents:
3627
diff
changeset
|
206 } |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
207 |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
208 if (hdr->indexid != cache->index->indexid) { |
6407
1deb160e5fbb
Don't bother complaining about indexid changes. The real reason for the
Timo Sirainen <tss@iki.fi>
parents:
6360
diff
changeset
|
209 /* index id changed - handle silently */ |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
210 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 } |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
212 if (hdr->file_seq == 0) { |
5014
59b04ed146a9
Make sure file_seq isn't zero in cache file header.
Timo Sirainen <tss@iki.fi>
parents:
4968
diff
changeset
|
213 mail_cache_set_corrupted(cache, "file_seq is 0"); |
59b04ed146a9
Make sure file_seq isn't zero in cache file header.
Timo Sirainen <tss@iki.fi>
parents:
4968
diff
changeset
|
214 return FALSE; |
59b04ed146a9
Make sure file_seq isn't zero in cache file header.
Timo Sirainen <tss@iki.fi>
parents:
4968
diff
changeset
|
215 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 /* only check the header if we're locked */ |
2828 | 218 if (!cache->locked) |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
219 return TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
221 if (hdr->used_file_size < sizeof(struct mail_cache_header)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 mail_cache_set_corrupted(cache, "used_file_size too small"); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
223 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 } |
2276
5f374049abdb
Caching fixes and optimizations. Removed all network byte ordering code -
Timo Sirainen <tss@iki.fi>
parents:
2275
diff
changeset
|
225 if ((hdr->used_file_size % sizeof(uint32_t)) != 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 mail_cache_set_corrupted(cache, "used_file_size not aligned"); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
227 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
230 if (cache->mmap_base != NULL && |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
231 hdr->used_file_size > cache->mmap_length) { |
2201
7bdef5ea4591
Several fixes and cleanups to cache file code, still badly broken
Timo Sirainen <tss@iki.fi>
parents:
2200
diff
changeset
|
232 mail_cache_set_corrupted(cache, "used_file_size too large"); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
233 return FALSE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 } |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
235 return TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
238 int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 { |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
240 ssize_t ret; |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
241 |
5736
b3ed52bbeca7
Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents:
5734
diff
changeset
|
242 cache->remap_counter++; |
b3ed52bbeca7
Changed mail_cache_foreach() to be an iterator: mail_cache_lookup_iter_*()
Timo Sirainen <tss@iki.fi>
parents:
5734
diff
changeset
|
243 |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
244 if (size == 0) |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
245 size = sizeof(struct mail_cache_header); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
247 if (cache->file_cache != NULL) { |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
248 cache->data = NULL; |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
249 cache->hdr = NULL; |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
250 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
251 ret = file_cache_read(cache->file_cache, offset, size); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
252 if (ret < 0) { |
4023
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
253 /* In case of ESTALE we'll simply fail without error |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
254 messages. The caller will then just have to |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
255 fallback to generating the value itself. |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
256 |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
257 We can't simply reopen the cache flie, because |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
258 using it requires also having updated file |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
259 offsets. */ |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
260 if (errno != ESTALE) |
b19ccbaa3802
Try to handle ESTALE NFS errors the best way we can.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3981
diff
changeset
|
261 mail_cache_set_syscall_error(cache, "read()"); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
262 return -1; |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
263 } |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
264 |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
265 cache->data = file_cache_get_map(cache->file_cache, |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
266 &cache->mmap_length); |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
267 |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
268 if (offset == 0) { |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
269 if (!mail_cache_verify_header(cache)) { |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
270 cache->need_compress_file_seq = |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
271 !MAIL_CACHE_IS_UNUSABLE(cache) && |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
272 cache->hdr->file_seq != 0 ? |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
273 cache->hdr->file_seq : 0; |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
274 return -1; |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
275 } |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
276 memcpy(&cache->hdr_ro_copy, cache->data, |
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
277 sizeof(cache->hdr_ro_copy)); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
278 } |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
279 cache->hdr = &cache->hdr_ro_copy; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
280 return 0; |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
281 } |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
282 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 if (offset < cache->mmap_length && |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
284 size <= cache->mmap_length - offset) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 /* already mapped */ |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
286 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 if (cache->mmap_base != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 if (munmap(cache->mmap_base, cache->mmap_length) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 mail_cache_set_syscall_error(cache, "munmap()"); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
292 } else { |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
293 if (cache->fd == -1) { |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
294 /* unusable, waiting for compression or |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
295 index is in memory */ |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
296 i_assert(cache->need_compress_file_seq != 0 || |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
297 MAIL_INDEX_IS_IN_MEMORY(cache->index)); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
298 return -1; |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
299 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 /* map the whole file */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 cache->hdr = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
304 cache->mmap_length = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
306 cache->mmap_base = mmap_ro_file(cache->fd, &cache->mmap_length); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 if (cache->mmap_base == MAP_FAILED) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 cache->mmap_base = NULL; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
309 cache->data = NULL; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 mail_cache_set_syscall_error(cache, "mmap()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 } |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
313 cache->data = cache->mmap_base; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
315 if (!mail_cache_verify_header(cache)) { |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
316 cache->need_compress_file_seq = |
4325 | 317 !MAIL_CACHE_IS_UNUSABLE(cache) && |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
318 cache->hdr->file_seq != 0 ? |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
319 cache->hdr->file_seq : 0; |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
320 return -1; |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
321 } |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
322 |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
323 cache->hdr = cache->data; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
327 static int mail_cache_try_open(struct mail_cache *cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 { |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
329 cache->opened = TRUE; |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
330 |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
331 if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
332 return 0; |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
333 |
6686
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
334 cache->fd = nfs_safe_open(cache->filepath, |
610f3d9813b5
Added MAIL_INDEX_OPEN_FLAG_READONLY.
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
335 cache->index->readonly ? O_RDONLY : O_RDWR); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 if (cache->fd == -1) { |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
337 if (errno == ENOENT) { |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
338 cache->need_compress_file_seq = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 return 0; |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
340 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 mail_cache_set_syscall_error(cache, "open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
345 |
5145
3eecde9cbea4
Allocate cache file's size amount of memory for the file cache so it doesn't
Timo Sirainen <tss@iki.fi>
parents:
5014
diff
changeset
|
346 mail_cache_init_file_cache(cache); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
347 |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
348 if (mail_cache_map(cache, 0, sizeof(struct mail_cache_header)) < 0) |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
349 return -1; |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
350 |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
351 return 1; |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
352 } |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
353 |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
354 int mail_cache_open_and_verify(struct mail_cache *cache) |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
355 { |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
356 int ret; |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
357 |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
358 ret = mail_cache_try_open(cache); |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
359 if (ret > 0) |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
360 ret = mail_cache_header_fields_read(cache); |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
361 if (ret < 0) { |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
362 /* failed for some reason - doesn't really matter, |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
363 it's disabled for now. */ |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
364 mail_cache_file_close(cache); |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
365 } |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
366 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
369 static struct mail_cache *mail_cache_alloc(struct mail_index *index) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 struct mail_cache *cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 cache = i_new(struct mail_cache, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 cache->index = index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 cache->fd = -1; |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
376 cache->filepath = |
3316
62d31be5ae60
s/PREFIX/SUFFIX/ for .cache and .log filename suffixes..
Timo Sirainen <tss@iki.fi>
parents:
3271
diff
changeset
|
377 i_strconcat(index->filepath, MAIL_CACHE_FILE_SUFFIX, NULL); |
3106 | 378 cache->field_pool = pool_alloconly_create("Cache fields", 1024); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
379 cache->field_name_hash = |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
380 hash_create(default_pool, cache->field_pool, 0, |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
381 strcase_hash, (hash_cmp_callback_t *)strcasecmp); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 |
4968
1baf9dd3fc40
Added dotlock_use_excl setting.
Timo Sirainen <tss@iki.fi>
parents:
4928
diff
changeset
|
383 cache->dotlock_settings.use_excl_lock = index->use_excl_dotlocks; |
6592
b6631550cf84
dotlocks: Flush NFS attribute cache only if nfs_flush setting is TRUE.
Timo Sirainen <tss@iki.fi>
parents:
6455
diff
changeset
|
384 cache->dotlock_settings.nfs_flush = index->nfs_flush; |
3106 | 385 cache->dotlock_settings.timeout = MAIL_CACHE_LOCK_TIMEOUT; |
386 cache->dotlock_settings.stale_timeout = MAIL_CACHE_LOCK_CHANGE_TIMEOUT; | |
387 | |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
388 if (!MAIL_INDEX_IS_IN_MEMORY(index)) { |
5626
d1de7c486763
Removed mmap_no_write setting. The only OS requiring it is OpenBSD, so we're
Timo Sirainen <tss@iki.fi>
parents:
5319
diff
changeset
|
389 if (index->mmap_disable) |
3243
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
390 cache->file_cache = file_cache_new(-1); |
40b4ba3c55b8
In-memory indexes work again. Just pass dir as NULL to mail_index_alloc().
Timo Sirainen <tss@iki.fi>
parents:
3224
diff
changeset
|
391 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
393 cache->ext_id = |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
394 mail_index_ext_register(index, "cache", 0, |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
395 sizeof(uint32_t), sizeof(uint32_t)); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
396 mail_index_register_expunge_handler(index, cache->ext_id, FALSE, |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
397 mail_cache_expunge_handler, cache); |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
398 mail_index_register_sync_handler(index, cache->ext_id, |
2869
d2daf90c79f1
Cache invalidating needed to hook into view syncing as well.
Timo Sirainen <tss@iki.fi>
parents:
2867
diff
changeset
|
399 mail_cache_sync_handler, |
4283
22b54c007b91
We were updating index->map also when syncing views.
Timo Sirainen <tss@iki.fi>
parents:
4247
diff
changeset
|
400 MAIL_INDEX_SYNC_HANDLER_FILE | |
22b54c007b91
We were updating index->map also when syncing views.
Timo Sirainen <tss@iki.fi>
parents:
4247
diff
changeset
|
401 MAIL_INDEX_SYNC_HANDLER_HEAD | |
2908
ef0b296ad4dd
Cache sync handler wasn't registered correctly so it broke with
Timo Sirainen <tss@iki.fi>
parents:
2869
diff
changeset
|
402 (cache->file_cache == NULL ? 0 : |
ef0b296ad4dd
Cache sync handler wasn't registered correctly so it broke with
Timo Sirainen <tss@iki.fi>
parents:
2869
diff
changeset
|
403 MAIL_INDEX_SYNC_HANDLER_VIEW)); |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
404 |
2934
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2929
diff
changeset
|
405 if (cache->file_cache != NULL) { |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2929
diff
changeset
|
406 mail_index_register_sync_lost_handler(index, |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2929
diff
changeset
|
407 mail_cache_sync_lost_handler); |
c3ae75597952
Added "sync lost" handlers which are called with mmap_disable=yes when index
Timo Sirainen <tss@iki.fi>
parents:
2929
diff
changeset
|
408 } |
2200
97bb7b127617
Beginnings of getting cache file working again. Easy to break currently, but
Timo Sirainen <tss@iki.fi>
parents:
1956
diff
changeset
|
409 return cache; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
412 struct mail_cache *mail_cache_open_or_create(struct mail_index *index) |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
413 { |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
414 struct mail_cache *cache; |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
415 |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
416 cache = mail_cache_alloc(index); |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
417 return cache; |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
418 } |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
419 |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
420 struct mail_cache *mail_cache_create(struct mail_index *index) |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
421 { |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
422 struct mail_cache *cache; |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
423 |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
424 cache = mail_cache_alloc(index); |
6158
6e9b6468398f
If index is in memory, don't try to unlink() cache file.
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
425 if (!MAIL_INDEX_IS_IN_MEMORY(index)) { |
6e9b6468398f
If index is in memory, don't try to unlink() cache file.
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
426 if (unlink(cache->filepath) < 0 && errno != ENOENT) |
6e9b6468398f
If index is in memory, don't try to unlink() cache file.
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
427 mail_cache_set_syscall_error(cache, "unlink()"); |
6e9b6468398f
If index is in memory, don't try to unlink() cache file.
Timo Sirainen <tss@iki.fi>
parents:
5972
diff
changeset
|
428 } |
3129
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
429 return cache; |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
430 } |
1ea614abead3
Don't complain about cache indexid changing when recreating index.
Timo Sirainen <tss@iki.fi>
parents:
3106
diff
changeset
|
431 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
432 void mail_cache_free(struct mail_cache **_cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
434 struct mail_cache *cache = *_cache; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
435 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
436 *_cache = NULL; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
437 if (cache->file_cache != NULL) { |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
438 mail_index_unregister_sync_lost_handler(cache->index, |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
439 mail_cache_sync_lost_handler); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
440 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
441 file_cache_free(&cache->file_cache); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
442 } |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
443 |
3224
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
444 mail_index_unregister_expunge_handler(cache->index, cache->ext_id); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
445 mail_index_unregister_sync_handler(cache->index, cache->ext_id); |
f6e0d1826645
Added sync/sync_lost/expunge handler unregistering, and also do that. Fixes
Timo Sirainen <tss@iki.fi>
parents:
3191
diff
changeset
|
446 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 mail_cache_file_close(cache); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 |
6417
047d0d8bbf0a
hash_destroy() and hash_iterate_deinit() now take ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6414
diff
changeset
|
449 hash_destroy(&cache->field_name_hash); |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
450 pool_unref(&cache->field_pool); |
2362
f2acbe281ac1
Allocate cache->fields and cache->fields_file_map with malloc rather than
Timo Sirainen <tss@iki.fi>
parents:
2343
diff
changeset
|
451 i_free(cache->field_file_map); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
452 i_free(cache->file_field_map); |
2362
f2acbe281ac1
Allocate cache->fields and cache->fields_file_map with malloc rather than
Timo Sirainen <tss@iki.fi>
parents:
2343
diff
changeset
|
453 i_free(cache->fields); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 i_free(cache->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 i_free(cache); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
458 static int mail_cache_lock_file(struct mail_cache *cache) |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
459 { |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
460 int ret; |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
461 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
462 if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) { |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
463 i_assert(cache->file_lock == NULL); |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
464 ret = mail_index_lock_fd(cache->index, cache->filepath, |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
465 cache->fd, F_WRLCK, |
6360
461ae76c84da
Replaced MAIL_INDEX_LOCK_SECS usage with cache/index/log specific defines
Timo Sirainen <tss@iki.fi>
parents:
6165
diff
changeset
|
466 MAIL_CACHE_LOCK_TIMEOUT, |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
467 &cache->file_lock); |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
468 } else { |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
469 i_assert(cache->dotlock == NULL); |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
470 ret = file_dotlock_create(&cache->dotlock_settings, |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
471 cache->filepath, 0, &cache->dotlock); |
6772
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6708
diff
changeset
|
472 if (ret < 0) { |
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6708
diff
changeset
|
473 mail_cache_set_syscall_error(cache, |
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6708
diff
changeset
|
474 "file_dotlock_create()"); |
b78cfc60f6a1
Added missing error logging for file_dotlock_create/open calls.
Timo Sirainen <tss@iki.fi>
parents:
6708
diff
changeset
|
475 } |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
476 } |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
477 |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
478 if (ret <= 0) |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
479 return ret; |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
480 |
6829
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
481 mail_index_flush_read_cache(cache->index, cache->filepath, cache->fd, |
dbab5e592577
NFS cache flushing APIs changed and backend implements it a bit differently.
Timo Sirainen <tss@iki.fi>
parents:
6827
diff
changeset
|
482 TRUE); |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
483 return 1; |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
484 } |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
485 |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
486 static void mail_cache_unlock_file(struct mail_cache *cache) |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
487 { |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
488 if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
489 file_unlock(&cache->file_lock); |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
490 else |
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
491 (void)file_dotlock_delete(&cache->dotlock); |
2941
89ab5c72430d
lock_method=dotlock doesn't crash anymore while trying to modify cache file.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
492 } |
89ab5c72430d
lock_method=dotlock doesn't crash anymore while trying to modify cache file.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
493 |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
494 int mail_cache_lock(struct mail_cache *cache, bool require_same_reset_id) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
495 { |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
496 const struct mail_index_ext *ext; |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
497 struct mail_index_view *iview; |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
498 uint32_t reset_id; |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
499 int i, ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
501 i_assert(!cache->locked); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 |
4655
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
503 if (!cache->opened) |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
504 (void)mail_cache_open_and_verify(cache); |
df8de2e47fb5
Delay opening the cache file until it's actually needed.
Timo Sirainen <tss@iki.fi>
parents:
4653
diff
changeset
|
505 |
3833
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
506 if (MAIL_CACHE_IS_UNUSABLE(cache) || |
318c70c1d4ec
Beginnings of fallbacking to in-memory indexes when write fails with "out of
Timo Sirainen <tss@iki.fi>
parents:
3819
diff
changeset
|
507 MAIL_INDEX_IS_IN_MEMORY(cache->index)) |
2220
357bc14b6d05
Disable cache with mmap_disabled=yes, for now.
Timo Sirainen <tss@iki.fi>
parents:
2204
diff
changeset
|
508 return 0; |
357bc14b6d05
Disable cache with mmap_disabled=yes, for now.
Timo Sirainen <tss@iki.fi>
parents:
2204
diff
changeset
|
509 |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
510 iview = mail_index_view_open(cache->index); |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
511 ext = mail_index_view_get_ext(iview, cache->ext_id); |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
512 reset_id = ext == NULL ? 0 : ext->reset_id; |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
513 mail_index_view_close(&iview); |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
514 |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
515 if (ext == NULL && require_same_reset_id) { |
2853
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
516 /* cache not used */ |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
517 return 0; |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
518 } |
512dd7d76cdc
Removed cache_offset from mail_index_record and changed it to use extension
Timo Sirainen <tss@iki.fi>
parents:
2828
diff
changeset
|
519 |
6706 | 520 for (i = 0; i < 3; i++) { |
521 if (cache->hdr->file_seq != reset_id && | |
522 (require_same_reset_id || i == 0)) { | |
523 /* we want the latest cache file */ | |
6830
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
524 if (reset_id < cache->hdr->file_seq) { |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
525 /* either we're still waiting for index to |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
526 catch up with a cache compression, or |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
527 that catching up is never going to happen */ |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
528 ret = 0; |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
529 break; |
3a41003bb1ae
If cache file's file_seq appears to be broken, handle it by compressing the
Timo Sirainen <tss@iki.fi>
parents:
6829
diff
changeset
|
530 } |
6706 | 531 ret = mail_cache_reopen(cache); |
6708 | 532 if (ret < 0 || (ret == 0 && require_same_reset_id)) |
6706 | 533 break; |
534 } | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
536 ret = mail_cache_lock_file(cache); |
2941
89ab5c72430d
lock_method=dotlock doesn't crash anymore while trying to modify cache file.
Timo Sirainen <tss@iki.fi>
parents:
2936
diff
changeset
|
537 if (ret <= 0) |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
538 break; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
539 cache->locked = TRUE; |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
540 |
5947
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
541 if (cache->hdr->file_seq == reset_id || |
7ebe0593f488
Don't create cache file until something is actually being added to it.
Timo Sirainen <tss@iki.fi>
parents:
5736
diff
changeset
|
542 !require_same_reset_id) { |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
543 /* got it */ |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
544 break; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
545 } |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
546 |
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
547 /* okay, so it was just compressed. try again. */ |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
548 (void)mail_cache_unlock(cache); |
2275
c68a3c9f6d73
Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents:
2251
diff
changeset
|
549 ret = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
550 } |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
551 |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
552 if (ret > 0) { |
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
553 /* make sure our header is up to date */ |
2867
d416b6d0a7ee
More correct file cache invalidating.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
554 if (cache->file_cache != NULL) { |
d416b6d0a7ee
More correct file cache invalidating.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
555 file_cache_invalidate(cache->file_cache, 0, |
d416b6d0a7ee
More correct file cache invalidating.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
556 sizeof(struct mail_cache_header)); |
d416b6d0a7ee
More correct file cache invalidating.
Timo Sirainen <tss@iki.fi>
parents:
2866
diff
changeset
|
557 } |
3271
55bc96b23bc1
Don't crash at mail_cache_lock() if mail_cache_map() fails.
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
558 if (mail_cache_map(cache, 0, 0) == 0) |
55bc96b23bc1
Don't crash at mail_cache_lock() if mail_cache_map() fails.
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
559 cache->hdr_copy = *cache->hdr; |
55bc96b23bc1
Don't crash at mail_cache_lock() if mail_cache_map() fails.
Timo Sirainen <tss@iki.fi>
parents:
3243
diff
changeset
|
560 else { |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
561 (void)mail_cache_unlock(cache); |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
562 ret = -1; |
2929 | 563 } |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
564 } |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
565 |
2929 | 566 i_assert((ret <= 0 && !cache->locked) || (ret > 0 && cache->locked)); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
569 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
570 static void mail_cache_update_need_compress(struct mail_cache *cache) |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
571 { |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
572 const struct mail_cache_header *hdr = cache->hdr; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
573 unsigned int cont_percentage; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
574 uoff_t max_del_space; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
575 |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
576 cont_percentage = hdr->continued_record_count * 100 / |
6165
6418139447fa
Created a new struct mail_index_record_map which can be shared by multiple
Timo Sirainen <tss@iki.fi>
parents:
6158
diff
changeset
|
577 (cache->index->map->rec_map->records_count == 0 ? 1 : |
6418139447fa
Created a new struct mail_index_record_map which can be shared by multiple
Timo Sirainen <tss@iki.fi>
parents:
6158
diff
changeset
|
578 cache->index->map->rec_map->records_count); |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
579 if (cont_percentage >= MAIL_CACHE_COMPRESS_CONTINUED_PERCENTAGE && |
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
580 hdr->used_file_size >= MAIL_CACHE_COMPRESS_MIN_SIZE) { |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
581 /* too many continued rows, compress */ |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
582 cache->need_compress_file_seq = hdr->file_seq; |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
583 } |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
584 |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
585 /* see if we've reached the max. deleted space in file */ |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
586 max_del_space = hdr->used_file_size / 100 * |
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
587 MAIL_CACHE_COMPRESS_PERCENTAGE; |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
588 if (hdr->deleted_space >= max_del_space && |
4928
bb4ec18672fe
Prefix COMPRESS_* defines with MAIL_CACHE_.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
589 hdr->used_file_size >= MAIL_CACHE_COMPRESS_MIN_SIZE) |
4247
9c3f19110538
Don't compress cache file if it was just compressed by another process.
Timo Sirainen <tss@iki.fi>
parents:
4023
diff
changeset
|
590 cache->need_compress_file_seq = hdr->file_seq; |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
591 } |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
592 |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
593 int mail_cache_unlock(struct mail_cache *cache) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 { |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
595 int ret = 0; |
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
596 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
597 i_assert(cache->locked); |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
598 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
599 if (cache->field_header_write_pending) |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
600 ret = mail_cache_header_fields_update(cache); |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
601 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
602 cache->locked = FALSE; |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
603 |
2920
9b772db4503d
Don't write to closed cache file
Timo Sirainen <tss@iki.fi>
parents:
2908
diff
changeset
|
604 if (MAIL_CACHE_IS_UNUSABLE(cache)) { |
9b772db4503d
Don't write to closed cache file
Timo Sirainen <tss@iki.fi>
parents:
2908
diff
changeset
|
605 /* we found it to be broken during the lock. just clean up. */ |
9b772db4503d
Don't write to closed cache file
Timo Sirainen <tss@iki.fi>
parents:
2908
diff
changeset
|
606 cache->hdr_modified = FALSE; |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
607 return -1; |
2920
9b772db4503d
Don't write to closed cache file
Timo Sirainen <tss@iki.fi>
parents:
2908
diff
changeset
|
608 } |
9b772db4503d
Don't write to closed cache file
Timo Sirainen <tss@iki.fi>
parents:
2908
diff
changeset
|
609 |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
610 if (cache->hdr_modified) { |
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
611 cache->hdr_modified = FALSE; |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
612 if (mail_cache_write(cache, &cache->hdr_copy, |
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
613 sizeof(cache->hdr_copy), 0) < 0) |
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
614 ret = -1; |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
615 cache->hdr_ro_copy = cache->hdr_copy; |
2866
bf1e718e7370
Cache file works now with mmap_disable=yes. Still needs a few optimizations.
Timo Sirainen <tss@iki.fi>
parents:
2853
diff
changeset
|
616 mail_cache_update_need_compress(cache); |
2277
41e56f28d085
Cache updating is done now by first reserving space where to write, and then
Timo Sirainen <tss@iki.fi>
parents:
2276
diff
changeset
|
617 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
618 |
5972
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
619 if (cache->index->nfs_flush) { |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
620 if (fdatasync(cache->fd) < 0) |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
621 mail_cache_set_syscall_error(cache, "fdatasync()"); |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
622 } |
9fb9dc4d8df8
Flush NFS caches when needed if MAIL_INDEX_OPEN_FLAG_NFS_FLUSH is enabled.
Timo Sirainen <tss@iki.fi>
parents:
5947
diff
changeset
|
623 |
4876
f1d77064884c
Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents:
4657
diff
changeset
|
624 mail_cache_unlock_file(cache); |
3627
c0e35566dd14
Unlocking cache file can also corrupt it since it modifies it. Added a
Timo Sirainen <tss@iki.fi>
parents:
3553
diff
changeset
|
625 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
626 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
627 |
3375
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
628 int mail_cache_write(struct mail_cache *cache, const void *data, size_t size, |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
629 uoff_t offset) |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
630 { |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
631 if (pwrite_full(cache->fd, data, size, offset) < 0) { |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
632 mail_cache_set_syscall_error(cache, "pwrite_full()"); |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
633 return -1; |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
634 } |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
635 |
3380
bf654e4789a1
Pointers into file cache may change as a result of file_cache_write().
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
636 if (cache->file_cache != NULL) { |
3375
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
637 file_cache_write(cache->file_cache, data, size, offset); |
3380
bf654e4789a1
Pointers into file cache may change as a result of file_cache_write().
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
638 |
6703
75c48f171ad3
Keep a separate copy of mail_cache_header when mmap_disable=yes, otherwise
Timo Sirainen <tss@iki.fi>
parents:
6702
diff
changeset
|
639 /* data pointer may change if file cache was grown */ |
3380
bf654e4789a1
Pointers into file cache may change as a result of file_cache_write().
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
640 cache->data = file_cache_get_map(cache->file_cache, |
bf654e4789a1
Pointers into file cache may change as a result of file_cache_write().
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
641 &cache->mmap_length); |
bf654e4789a1
Pointers into file cache may change as a result of file_cache_write().
Timo Sirainen <tss@iki.fi>
parents:
3375
diff
changeset
|
642 } |
3375
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
643 return 0; |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
644 } |
9e2abc4c341c
Whenever writing to cache file, also updated file_cache. Fixes problems with
Timo Sirainen <tss@iki.fi>
parents:
3316
diff
changeset
|
645 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 struct mail_cache_view * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
647 mail_cache_view_open(struct mail_cache *cache, struct mail_index_view *iview) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
648 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
649 struct mail_cache_view *view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
650 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
651 view = i_new(struct mail_cache_view, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
652 view->cache = cache; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 view->view = iview; |
5734 | 654 i_array_init(&view->looping_offsets, 32); |
2327
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
655 view->cached_exists_buf = |
7d02e2a7672d
Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents:
2307
diff
changeset
|
656 buffer_create_dynamic(default_pool, |
2708
f1e9f3ec8135
Buffer API change: we no longer support limited sized buffers where
Timo Sirainen <tss@iki.fi>
parents:
2632
diff
changeset
|
657 cache->file_fields_count + 10); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
658 return view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
659 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
660 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 void mail_cache_view_close(struct mail_cache_view *view) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
662 { |
6455
5ad7a36ca8c3
mail_cache_transaction_commit()/rollback() API is now public and takes a **
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
663 i_assert(view->trans_view == NULL); |
5ad7a36ca8c3
mail_cache_transaction_commit()/rollback() API is now public and takes a **
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
664 |
2339
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
665 if (view->cache->field_header_write_pending) |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
666 (void)mail_cache_header_fields_update(view->cache); |
406692edc12d
Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents:
2327
diff
changeset
|
667 |
5734 | 668 array_free(&view->looping_offsets); |
6414
a6a49d5efc59
Changed buffer_free() and buffer_free_without_data() APIs to take ** pointer
Timo Sirainen <tss@iki.fi>
parents:
6407
diff
changeset
|
669 buffer_free(&view->cached_exists_buf); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
670 i_free(view); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
671 } |
6841
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
672 |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
673 uint32_t mail_cache_get_first_new_seq(struct mail_index_view *view) |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
674 { |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
675 const struct mail_index_header *idx_hdr; |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
676 uint32_t first_new_seq, message_count; |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
677 |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
678 idx_hdr = mail_index_get_header(view); |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
679 if (idx_hdr->day_first_uid[7] == 0) |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
680 return 1; |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
681 |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
682 if (!mail_index_lookup_seq_range(view, idx_hdr->day_first_uid[7], |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
683 (uint32_t)-1, &first_new_seq, |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
684 &message_count)) { |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
685 /* all messages are too old */ |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
686 return message_count+1; |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
687 } |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
688 return first_new_seq; |
0c970b3493ac
mail_cache_field_want_add(): Return TRUE for temp fields only if we're
Timo Sirainen <tss@iki.fi>
parents:
6830
diff
changeset
|
689 } |