Mercurial > dovecot > core-2.2
annotate src/lib-index/mail-transaction-log-view.c @ 22691:dca05b22217b
director: Fix crash when handling expired USER timestamps.
The fix in 154f91726624265fce15097eb4bbbf6e55f8c477 wasn't complete.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 28 Nov 2017 13:10:35 +0200 |
parents | 2553f62ea247 |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21184
diff
changeset
|
1 /* Copyright (c) 2003-2017 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" |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
4 #include "array.h" |
21087
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
5 #include "str.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "mail-index-private.h" |
9251
08cf5c1814ef
Transaction log view code cleanups.
Timo Sirainen <tss@iki.fi>
parents:
9250
diff
changeset
|
7 #include "mail-transaction-log-view-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 struct mail_transaction_log_view * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 mail_transaction_log_view_open(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 struct mail_transaction_log_view *view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 view = i_new(struct mail_transaction_log_view, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 view->log = log; |
1941
ced8e41c137a
automatically fix broken/missing transaction log files on the fly
Timo Sirainen <tss@iki.fi>
parents:
1940
diff
changeset
|
16 view->broken = TRUE; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
21184
e87c575aaa1c
lib-index: Do not crash if log is missing
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21171
diff
changeset
|
18 i_assert(view->log->head != NULL); |
e87c575aaa1c
lib-index: Do not crash if log is missing
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
21171
diff
changeset
|
19 |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
20 view->head = view->tail = view->log->head; |
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
21 view->head->refcount++; |
4842 | 22 i_array_init(&view->file_refs, 8); |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
23 array_append(&view->file_refs, &view->head, 1); |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
24 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 view->next = log->views; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 log->views = view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 return view; |
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 |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
30 static void |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
31 mail_transaction_log_view_unref_all(struct mail_transaction_log_view *view) |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
32 { |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
33 struct mail_transaction_log_file *const *files; |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
34 unsigned int i, count; |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
35 |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
36 files = array_get(&view->file_refs, &count); |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
37 for (i = 0; i < count; i++) |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
38 files[i]->refcount--; |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
39 |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
40 array_clear(&view->file_refs); |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
41 } |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
42 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
43 void mail_transaction_log_view_close(struct mail_transaction_log_view **_view) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
45 struct mail_transaction_log_view *view = *_view; |
1942 | 46 struct mail_transaction_log_view **p; |
47 | |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
48 *_view = NULL; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
49 |
1942 | 50 for (p = &view->log->views; *p != NULL; p = &(*p)->next) { |
51 if (*p == view) { | |
52 *p = view->next; | |
53 break; | |
54 } | |
55 } | |
56 | |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
57 mail_transaction_log_view_unref_all(view); |
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
58 mail_transaction_logs_clean(view->log); |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
59 |
4828
7cc1b8fec8ab
Reference counting fixes. Fixes an assert crash when closing the index.
Timo Sirainen <tss@iki.fi>
parents:
4785
diff
changeset
|
60 array_free(&view->file_refs); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 i_free(view); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
63 |
21087
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
64 static const char * |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
65 mail_transaction_log_get_file_seqs(struct mail_transaction_log *log) |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
66 { |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
67 struct mail_transaction_log_file *file; |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
68 string_t *str = t_str_new(32); |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
69 |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
70 if (log->files == NULL) |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
71 return ""; |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
72 |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
73 for (file = log->files; file != NULL; file = file->next) |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
74 str_printfa(str, ",%u", file->hdr.file_seq); |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
75 return str_c(str) + 1; |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
76 } |
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
77 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
78 int mail_transaction_log_view_set(struct mail_transaction_log_view *view, |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
79 uint32_t min_file_seq, uoff_t min_file_offset, |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
80 uint32_t max_file_seq, uoff_t max_file_offset, |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
81 bool *reset_r, const char **reason_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 { |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
83 struct mail_transaction_log_file *file, *const *files; |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
84 uoff_t start_offset, end_offset; |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
85 unsigned int i; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 uint32_t seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
89 *reset_r = FALSE; |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
90 *reason_r = NULL; |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
91 |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
92 if (view->log == NULL) { |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
93 /* transaction log is closed already. this log view shouldn't |
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
94 be used anymore. */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
95 *reason_r = "Log already closed"; |
1942 | 96 return -1; |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
97 } |
1942 | 98 |
2507
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
99 if (min_file_seq == 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
100 /* index file doesn't exist yet. this transaction log should |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
101 start from the beginning */ |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
102 if (view->log->files->hdr.prev_file_seq != 0) { |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
103 /* but it doesn't */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
104 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
105 "Wanted log beginning, but found prev_file_seq=%u", |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
106 view->log->files->hdr.prev_file_seq); |
5689
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
107 return 0; |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
108 } |
c2362f144f15
Initial commit for major index file code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
5656
diff
changeset
|
109 |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
110 min_file_seq = view->log->files->hdr.file_seq; |
3173
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
111 min_file_offset = 0; |
2507
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
112 |
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
113 if (max_file_seq == 0) { |
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
114 max_file_seq = min_file_seq; |
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
115 max_file_offset = min_file_offset; |
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
116 } |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
117 } |
2507
5ad6ccb8000b
Handle correctly the case when index hasn't yet been synced with transaction
Timo Sirainen <tss@iki.fi>
parents:
2418
diff
changeset
|
118 |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
119 for (file = view->log->files; file != NULL; file = file->next) { |
16342
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
120 if (file->hdr.prev_file_seq == min_file_seq) |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
121 break; |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
122 } |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
123 |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
124 if (file != NULL && min_file_offset == file->hdr.prev_file_offset) { |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
125 /* we can (and sometimes must) skip to the next file */ |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
126 min_file_seq = file->hdr.file_seq; |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
127 min_file_offset = file->hdr.hdr_size; |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
128 } |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
129 |
62874b472dc6
lib-index: Previous commit sometimes broke scanning transaction log view.
Timo Sirainen <tss@iki.fi>
parents:
16331
diff
changeset
|
130 for (file = view->log->files; file != NULL; file = file->next) { |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
131 if (file->hdr.prev_file_seq == max_file_seq) |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
132 break; |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
133 } |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
134 if (file != NULL && max_file_offset == file->hdr.prev_file_offset) { |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
135 /* we can skip to the next file. we've delayed checking for |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
136 min_file_seq <= max_file_seq until now, because it's not |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
137 really an error to specify the same position twice (even if |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
138 in "wrong" order) */ |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
139 i_assert(min_file_seq <= max_file_seq || |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
140 min_file_seq <= file->hdr.file_seq); |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
141 max_file_seq = file->hdr.file_seq; |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
142 max_file_offset = file->hdr.hdr_size; |
16265
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
143 } else { |
286fa7f9538c
lib-index: Assert-crashfix on some rare situations.
Timo Sirainen <tss@iki.fi>
parents:
16023
diff
changeset
|
144 i_assert(min_file_seq <= max_file_seq); |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
145 } |
1952
05f76fe32f0d
Don't crash in assert() with corrupted index file.
Timo Sirainen <tss@iki.fi>
parents:
1942
diff
changeset
|
146 |
5017 | 147 if (min_file_seq == max_file_seq && min_file_offset > max_file_offset) { |
148 /* log file offset is probably corrupted in the index file. */ | |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
149 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
150 "Invalid offset: file_seq=%u, min_file_offset (%"PRIuUOFF_T |
5017 | 151 ") > max_file_offset (%"PRIuUOFF_T")", |
152 min_file_seq, min_file_offset, max_file_offset); | |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
153 mail_transaction_log_view_set_corrupted(view, "%s", *reason_r); |
5017 | 154 return -1; |
155 } | |
2087 | 156 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
157 view->tail = view->head = file = NULL; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
158 for (seq = min_file_seq; seq <= max_file_seq; seq++) { |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
159 const char *reason = NULL; |
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
160 |
3320
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
161 if (file == NULL || file->hdr.file_seq != seq) { |
6802
ba58eaf06763
Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents:
6458
diff
changeset
|
162 /* see if we could find the missing file. if we know |
21120
aca58a1e6717
lib-index: Fix flushing NFS if minimum wanted transaction log file is lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21087
diff
changeset
|
163 the max. file sequence or we don't have the the min. |
aca58a1e6717
lib-index: Fix flushing NFS if minimum wanted transaction log file is lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21087
diff
changeset
|
164 file, make sure NFS attribute cache gets flushed if |
aca58a1e6717
lib-index: Fix flushing NFS if minimum wanted transaction log file is lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21087
diff
changeset
|
165 necessary. */ |
aca58a1e6717
lib-index: Fix flushing NFS if minimum wanted transaction log file is lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21087
diff
changeset
|
166 bool nfs_flush = seq == min_file_seq || |
aca58a1e6717
lib-index: Fix flushing NFS if minimum wanted transaction log file is lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21087
diff
changeset
|
167 max_file_seq != (uint32_t)-1; |
6802
ba58eaf06763
Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents:
6458
diff
changeset
|
168 |
ba58eaf06763
Keep better track of when we need to flush NFS attribute caches.
Timo Sirainen <tss@iki.fi>
parents:
6458
diff
changeset
|
169 ret = mail_transaction_log_find_file(view->log, seq, |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
170 nfs_flush, &file, &reason); |
3320
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
171 if (ret <= 0) { |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
172 if (ret < 0) { |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
173 *reason_r = t_strdup_printf( |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
174 "Failed to find file seq=%u: %s", |
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
175 seq, reason); |
3320
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
176 return -1; |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
177 } |
3320
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
178 |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
179 /* not found / corrupted */ |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
180 file = NULL; |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
181 } |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
182 } |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
183 |
0403596c93fd
index.log file is now rotated to .index.log.2 file. When log file is
Timo Sirainen <tss@iki.fi>
parents:
3304
diff
changeset
|
184 if (file == NULL || file->hdr.file_seq != seq) { |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
185 i_assert(reason != NULL); |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
186 if (file == NULL && max_file_seq == (uint32_t)-1 && |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
187 view->head == view->log->head) { |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2882
diff
changeset
|
188 /* we just wanted to sync everything */ |
5089 | 189 i_assert(max_file_offset == (uoff_t)-1); |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2882
diff
changeset
|
190 max_file_seq = seq-1; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2882
diff
changeset
|
191 break; |
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2882
diff
changeset
|
192 } |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
193 /* if any of the found files reset the index, |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
194 ignore any missing files up to it */ |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
195 file = view->tail != NULL ? view->tail : |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
196 view->log->files; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
197 for (;; file = file->next) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
198 if (file == NULL || |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
199 file->hdr.file_seq > max_file_seq) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
200 /* missing files in the middle */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
201 *reason_r = t_strdup_printf( |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
202 "Missing middle file seq=%u (between %u..%u, we have seqs %s): %s", |
21087
3b909cd1264b
lib-index: Improve error messages when transaction log is unexpectedly lost
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
203 seq, min_file_seq, max_file_seq, |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
204 mail_transaction_log_get_file_seqs(view->log), reason); |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
205 return 0; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
206 } |
2885
1880f191278a
Avoid re-reading index file with mmap_disabled=yes. Instead sync it by
Timo Sirainen <tss@iki.fi>
parents:
2882
diff
changeset
|
207 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
208 if (file->hdr.file_seq >= seq && |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
209 file->hdr.prev_file_seq == 0) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
210 /* we can ignore the missing file */ |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
211 break; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
212 } |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
213 } |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
214 seq = file->hdr.file_seq; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
215 view->tail = NULL; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
216 } |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
217 |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
218 if (view->tail == NULL) |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
219 view->tail = file; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
220 view->head = file; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
221 file = file->next; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
222 } |
11074
c32f55615055
Small code changes to make static analyzer happier.
Timo Sirainen <tss@iki.fi>
parents:
11068
diff
changeset
|
223 i_assert(view->tail != NULL); |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
224 |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
225 if (min_file_offset == 0) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
226 /* beginning of the file */ |
8290
4402563ad86e
index files: Another try at fixing handling log files with different header sizes.
Timo Sirainen <tss@iki.fi>
parents:
8289
diff
changeset
|
227 min_file_offset = view->tail->hdr.hdr_size; |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
228 if (min_file_offset > max_file_offset && |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
229 min_file_seq == max_file_seq) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
230 /* we don't actually want to show anything */ |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
231 max_file_offset = min_file_offset; |
2091
2450b4ff4894
show error messages when log files are missing
Timo Sirainen <tss@iki.fi>
parents:
2087
diff
changeset
|
232 } |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
233 } |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
234 |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
235 if (min_file_offset < view->tail->hdr.hdr_size) { |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
236 /* log file offset is probably corrupted in the index file. */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
237 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
238 "Invalid min_file_offset: file_seq=%u, min_file_offset (%"PRIuUOFF_T |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
239 ") < hdr_size (%u)", |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
240 min_file_seq, min_file_offset, view->tail->hdr.hdr_size); |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
241 mail_transaction_log_view_set_corrupted(view, "%s", *reason_r); |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
242 return -1; |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
243 } |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
244 if (max_file_offset < view->head->hdr.hdr_size) { |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
245 /* log file offset is probably corrupted in the index file. */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
246 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
247 "Invalid max_file_offset: file_seq=%u, min_file_offset (%"PRIuUOFF_T |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
248 ") < hdr_size (%u)", |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
249 max_file_seq, max_file_offset, view->head->hdr.hdr_size); |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
250 mail_transaction_log_view_set_corrupted(view, "%s", *reason_r); |
16331
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
251 return -1; |
664ec741de8c
lib-index: The previous assert-crashfix didn't actually fix the problem.
Timo Sirainen <tss@iki.fi>
parents:
16265
diff
changeset
|
252 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
254 /* we have all of them. update refcounts. */ |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
255 mail_transaction_log_view_unref_all(view); |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
256 |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
257 /* Reference all used files. */ |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
258 for (file = view->tail;; file = file->next) { |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
259 array_append(&view->file_refs, &file, 1); |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
260 file->refcount++; |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
261 |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
262 if (file == view->head) |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
263 break; |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
264 } |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
265 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
266 view->cur = view->tail; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
267 view->cur_offset = view->cur->hdr.file_seq == min_file_seq ? |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
268 min_file_offset : view->cur->hdr.hdr_size; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
269 |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
270 /* Map the files only after we've found them all. Otherwise if we map |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
271 one file and then another file just happens to get rotated, we could |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
272 include both files in the view but skip the last transactions from |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
273 the first file. |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
274 |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
275 We're mapping the files in reverse order so that _log_file_map() |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
276 can verify that prev_file_offset matches how far it actually managed |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
277 to sync the file. */ |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
278 files = array_idx(&view->file_refs, 0); |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
279 for (i = array_count(&view->file_refs); i > 0; i--) { |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
280 file = files[i-1]; |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
281 start_offset = file->hdr.file_seq == min_file_seq ? |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
282 min_file_offset : file->hdr.hdr_size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 end_offset = file->hdr.file_seq == max_file_seq ? |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 max_file_offset : (uoff_t)-1; |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
285 ret = mail_transaction_log_file_map(file, start_offset, |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
286 end_offset, reason_r); |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
287 if (ret <= 0) { |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
288 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
289 "Failed to map file seq=%u " |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
290 "offset=%"PRIuUOFF_T"..%"PRIuUOFF_T" (ret=%d): %s", |
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
291 file->hdr.file_seq, start_offset, end_offset, ret, *reason_r); |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
292 return ret; |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
293 } |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
294 |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
295 if (file->hdr.prev_file_seq == 0) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
296 /* this file resets the index. |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
297 don't bother reading the others. */ |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
298 if (view->cur != file || |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
299 view->cur_offset == file->hdr.hdr_size) { |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
300 view->cur = file; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
301 view->cur_offset = file->hdr.hdr_size; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
302 *reset_r = TRUE; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
303 break; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
304 } |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
305 i_assert(i == 1); |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
306 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 |
11368
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
309 if (min_file_seq == view->head->hdr.file_seq && |
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
310 min_file_offset > view->head->sync_offset) { |
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
311 /* log file offset is probably corrupted in the index file. */ |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
312 *reason_r = t_strdup_printf( |
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
313 "Invalid offset: file_seq=%u, min_file_offset (%"PRIuUOFF_T |
11368
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
314 ") > sync_offset (%"PRIuUOFF_T")", min_file_seq, |
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
315 min_file_offset, view->head->sync_offset); |
18398
8146fdc0de34
lib-index: Added reason_r parameter to mail_transaction_log_view_set()
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
316 mail_transaction_log_view_set_corrupted(view, "%s", *reason_r); |
11368
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
317 return -1; |
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
318 } |
fb1cc2f5d681
lib-index: Fix to recent error handling change.
Timo Sirainen <tss@iki.fi>
parents:
11364
diff
changeset
|
319 |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
320 i_assert(max_file_seq == (uint32_t)-1 || |
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
321 max_file_seq == view->head->hdr.file_seq); |
2418 | 322 i_assert(max_file_offset == (uoff_t)-1 || |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
323 max_file_offset <= view->head->sync_offset); |
9098 | 324 i_assert(min_file_seq != max_file_seq || |
325 max_file_seq != view->head->hdr.file_seq || | |
326 max_file_offset != (uoff_t)-1 || | |
327 min_file_offset <= view->head->sync_offset); | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
329 view->prev_file_seq = view->cur->hdr.file_seq; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
330 view->prev_file_offset = view->cur_offset; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 view->min_file_seq = min_file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 view->min_file_offset = min_file_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 view->max_file_seq = max_file_seq; |
5793
512f8982ae8b
Map the log files only after they've all been found. Otherwise we could have
Timo Sirainen <tss@iki.fi>
parents:
5728
diff
changeset
|
335 view->max_file_offset = I_MIN(max_file_offset, view->head->sync_offset); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 view->broken = FALSE; |
3173
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
337 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
338 if (mail_transaction_log_file_get_highest_modseq_at(view->cur, |
22062
7d4ec76b7d94
lib-index: mail_transaction_log_file_get_highest_modseq_at() - return error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22060
diff
changeset
|
339 view->cur_offset, &view->prev_modseq, reason_r) < 0) |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
340 return -1; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
341 |
3180
ef16bb8091aa
Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
342 i_assert(view->cur_offset <= view->cur->sync_offset); |
3832
76f4be7ae499
Handle missing/broken transaction logs better. Handle broken sync position
Timo Sirainen <tss@iki.fi>
parents:
3649
diff
changeset
|
343 return 1; |
1915
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 |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
346 int mail_transaction_log_view_set_all(struct mail_transaction_log_view *view) |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
347 { |
15660
22a1f4cfe9fb
lib-index: mail_transaction_log_view_set_all() didn't necessarily scan .log.2 file.
Timo Sirainen <tss@iki.fi>
parents:
15034
diff
changeset
|
348 struct mail_transaction_log_file *file, *first; |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
349 const char *reason = NULL; |
22059
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
350 int ret; |
14675 | 351 |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
352 /* make sure .log.2 file is opened */ |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
353 (void)mail_transaction_log_find_file(view->log, 1, FALSE, &file, &reason); |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
354 |
15660
22a1f4cfe9fb
lib-index: mail_transaction_log_view_set_all() didn't necessarily scan .log.2 file.
Timo Sirainen <tss@iki.fi>
parents:
15034
diff
changeset
|
355 first = view->log->files; |
22a1f4cfe9fb
lib-index: mail_transaction_log_view_set_all() didn't necessarily scan .log.2 file.
Timo Sirainen <tss@iki.fi>
parents:
15034
diff
changeset
|
356 i_assert(first != NULL); |
22a1f4cfe9fb
lib-index: mail_transaction_log_view_set_all() didn't necessarily scan .log.2 file.
Timo Sirainen <tss@iki.fi>
parents:
15034
diff
changeset
|
357 |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
358 for (file = view->log->files; file != NULL; file = file->next) { |
22059
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
359 ret = mail_transaction_log_file_map(file, file->hdr.hdr_size, |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
360 (uoff_t)-1, &reason); |
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
361 if (ret < 0) { |
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
362 first = NULL; |
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
363 break; |
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
364 } |
22059
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
365 if (ret == 0) { |
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
366 /* corrupted */ |
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
367 first = NULL; |
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
368 } else if (file->hdr.prev_file_seq == 0) { |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
369 /* this file resets the index. skip the old ones. */ |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
370 first = file; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
371 } |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
372 } |
22059
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
373 if (first == NULL) { |
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
374 /* index wasn't reset after corruption was found */ |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
375 i_assert(reason != NULL); |
22074
2553f62ea247
lib-index: Fix crash in mail_transaction_log_view_set_all() error handling
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22062
diff
changeset
|
376 mail_index_set_error(view->log->index, |
22060
dc04a912eb35
lib-index: mail_transaction_log_file_map() - return reason/error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22059
diff
changeset
|
377 "Failed to map transaction log %s for all-view: %s", |
22074
2553f62ea247
lib-index: Fix crash in mail_transaction_log_view_set_all() error handling
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22062
diff
changeset
|
378 view->log->filepath, reason); |
22059
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
379 return -1; |
b6ec79a3d312
lib-index: mail_transaction_log_view_set_all() - don't entirely ignore corrupted logs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21876
diff
changeset
|
380 } |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
381 |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
382 mail_transaction_log_view_unref_all(view); |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
383 for (file = first; file != NULL; file = file->next) { |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
384 array_append(&view->file_refs, &file, 1); |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
385 file->refcount++; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
386 } |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
387 |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
388 view->tail = first; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
389 view->cur = view->tail; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
390 view->cur_offset = view->tail->hdr.hdr_size; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
391 |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
392 view->prev_file_seq = view->cur->hdr.file_seq; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
393 view->prev_file_offset = view->cur_offset; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
394 |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
395 view->min_file_seq = view->cur->hdr.file_seq; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
396 view->min_file_offset = view->cur_offset; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
397 view->max_file_seq = view->head->hdr.file_seq; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
398 view->max_file_offset = view->head->sync_offset; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
399 view->broken = FALSE; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
400 |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
401 if (mail_transaction_log_file_get_highest_modseq_at(view->cur, |
22062
7d4ec76b7d94
lib-index: mail_transaction_log_file_get_highest_modseq_at() - return error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22060
diff
changeset
|
402 view->cur_offset, &view->prev_modseq, &reason) < 0) { |
22074
2553f62ea247
lib-index: Fix crash in mail_transaction_log_view_set_all() error handling
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22062
diff
changeset
|
403 mail_index_set_error(view->log->index, |
22062
7d4ec76b7d94
lib-index: mail_transaction_log_file_get_highest_modseq_at() - return error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22060
diff
changeset
|
404 "Failed to get modseq in %s for all-view: %s", |
22074
2553f62ea247
lib-index: Fix crash in mail_transaction_log_view_set_all() error handling
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22062
diff
changeset
|
405 view->log->filepath, reason); |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
406 return -1; |
22062
7d4ec76b7d94
lib-index: mail_transaction_log_file_get_highest_modseq_at() - return error string
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22060
diff
changeset
|
407 } |
14579
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
408 return 0; |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
409 } |
fead3400c379
lib-index: Added mail_transaction_log_view_set_all()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
410 |
6458
cca479cb3ef0
Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
411 void mail_transaction_log_view_clear(struct mail_transaction_log_view *view, |
cca479cb3ef0
Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
412 uint32_t oldest_file_seq) |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
413 { |
6458
cca479cb3ef0
Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
414 struct mail_transaction_log_file *file; |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
415 const char *reason; |
6458
cca479cb3ef0
Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
416 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
417 mail_transaction_log_view_unref_all(view); |
14884
7aece00b8538
lib-index: Support clearing the whole log view with mail_transaction_log_view_clear(0)
Timo Sirainen <tss@iki.fi>
parents:
14882
diff
changeset
|
418 if (oldest_file_seq != 0 && |
7aece00b8538
lib-index: Support clearing the whole log view with mail_transaction_log_view_clear(0)
Timo Sirainen <tss@iki.fi>
parents:
14882
diff
changeset
|
419 mail_transaction_log_find_file(view->log, oldest_file_seq, FALSE, |
21171
d3022316712b
lib-index: Add more information to "Missing middle file" error.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21120
diff
changeset
|
420 &file, &reason) > 0) { |
9250
4d6f33fa08ee
mail_transaction_log_view_clear() should keep oldest_file_seq and newer referenced.
Timo Sirainen <tss@iki.fi>
parents:
9249
diff
changeset
|
421 for (; file != NULL; file = file->next) { |
4d6f33fa08ee
mail_transaction_log_view_clear() should keep oldest_file_seq and newer referenced.
Timo Sirainen <tss@iki.fi>
parents:
9249
diff
changeset
|
422 array_append(&view->file_refs, &file, 1); |
4d6f33fa08ee
mail_transaction_log_view_clear() should keep oldest_file_seq and newer referenced.
Timo Sirainen <tss@iki.fi>
parents:
9249
diff
changeset
|
423 file->refcount++; |
4d6f33fa08ee
mail_transaction_log_view_clear() should keep oldest_file_seq and newer referenced.
Timo Sirainen <tss@iki.fi>
parents:
9249
diff
changeset
|
424 } |
6458
cca479cb3ef0
Keep transaction logs referenced while we know we need them. This fixes
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
425 } |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
426 |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
427 view->cur = view->head = view->tail = NULL; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
428 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
429 view->mark_file = NULL; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
430 view->mark_offset = 0; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
431 view->mark_modseq = 0; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
432 |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
433 view->min_file_seq = view->max_file_seq = 0; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
434 view->min_file_offset = view->max_file_offset = 0; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
435 view->cur_offset = 0; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
436 |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
437 view->prev_file_seq = 0; |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
438 view->prev_file_offset = 0; |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
439 view->prev_modseq = 0; |
5849
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
440 } |
a9df50952600
Added support for resetting index.
Timo Sirainen <tss@iki.fi>
parents:
5793
diff
changeset
|
441 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 mail_transaction_log_view_get_prev_pos(struct mail_transaction_log_view *view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 uint32_t *file_seq_r, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 uoff_t *file_offset_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
446 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
447 *file_seq_r = view->prev_file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 *file_offset_r = view->prev_file_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
450 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
451 uint64_t |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
452 mail_transaction_log_view_get_prev_modseq(struct mail_transaction_log_view *view) |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
453 { |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
454 return view->prev_modseq; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
455 } |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
456 |
5656
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
457 static bool |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
458 mail_transaction_log_view_get_last(struct mail_transaction_log_view *view, |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
459 struct mail_transaction_log_file **last_r, |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
460 uoff_t *last_offset_r) |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
461 { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
462 struct mail_transaction_log_file *cur = view->cur; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
463 uoff_t cur_offset = view->cur_offset; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
464 bool last = FALSE; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
465 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
466 if (cur == NULL) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
467 *last_r = NULL; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
468 return TRUE; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
469 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
470 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
471 for (;;) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
472 if (cur->hdr.file_seq == view->max_file_seq) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
473 /* last file */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
474 if (cur_offset == view->max_file_offset || |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
475 cur_offset == cur->sync_offset) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
476 /* we're all finished */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
477 last = TRUE; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
478 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
479 } else if (cur_offset == cur->sync_offset) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
480 /* end of file, go to next one */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
481 if (cur->next == NULL) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
482 last = TRUE; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
483 } else { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
484 cur = cur->next; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
485 cur_offset = cur->hdr.hdr_size; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
486 continue; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
487 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
488 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
489 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
490 /* not EOF */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
491 break; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
492 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
493 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
494 *last_r = cur; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
495 *last_offset_r = cur_offset; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
496 return last; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
497 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
498 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
499 bool mail_transaction_log_view_is_last(struct mail_transaction_log_view *view) |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
500 { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
501 struct mail_transaction_log_file *cur; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
502 uoff_t cur_offset; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
503 |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
504 return mail_transaction_log_view_get_last(view, &cur, &cur_offset); |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
505 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
506 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 mail_transaction_log_view_set_corrupted(struct mail_transaction_log_view *view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 const char *fmt, ...) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 view->broken = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 va_start(va, fmt); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
516 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
517 mail_transaction_log_file_set_corrupted(view->log->head, "%s", |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
518 t_strdup_vprintf(fmt, va)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
519 } T_END; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 va_end(va); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3832
diff
changeset
|
523 bool |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 mail_transaction_log_view_is_corrupted(struct mail_transaction_log_view *view) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 return view->broken; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
529 static bool |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
530 log_view_is_uid_range_valid(struct mail_transaction_log_file *file, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
531 enum mail_transaction_type rec_type, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
532 const ARRAY_TYPE(seq_range) *uids) |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
533 { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
534 const struct seq_range *rec, *prev = NULL; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
535 unsigned int i, count = array_count(uids); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
536 |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
537 if ((uids->arr.buffer->used % uids->arr.element_size) != 0) { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
538 mail_transaction_log_file_set_corrupted(file, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
539 "Invalid record size (type=0x%x)", rec_type); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
540 return FALSE; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
541 } else if (count == 0) { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
542 mail_transaction_log_file_set_corrupted(file, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
543 "No UID ranges (type=0x%x)", rec_type); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
544 return FALSE; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
545 } |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
546 |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
547 for (i = 0; i < count; i++, prev = rec) { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
548 rec = array_idx(uids, i); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
549 if (rec->seq1 > rec->seq2 || rec->seq1 == 0) { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
550 mail_transaction_log_file_set_corrupted(file, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
551 "Invalid UID range (%u .. %u, type=0x%x)", |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
552 rec->seq1, rec->seq2, rec_type); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
553 return FALSE; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
554 } |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
555 if (prev != NULL && rec->seq1 <= prev->seq2) { |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
556 mail_transaction_log_file_set_corrupted(file, |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
557 "Non-sorted UID ranges (type=0x%x)", rec_type); |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
558 return FALSE; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
559 } |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
560 } |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
561 return TRUE; |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
562 } |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
563 |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
564 static bool |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
565 log_view_is_record_valid(struct mail_transaction_log_file *file, |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
566 const struct mail_transaction_header *hdr, |
5723
ad695be143ff
Don't assume that transaction record type is a bitmask in the transaction
Timo Sirainen <tss@iki.fi>
parents:
5721
diff
changeset
|
567 const void *data) |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
568 { |
5720 | 569 enum mail_transaction_type rec_type; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
570 ARRAY_TYPE(seq_range) uids = ARRAY_INIT; |
9623
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
571 buffer_t uid_buf; |
5719 | 572 uint32_t rec_size; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
573 |
5720 | 574 rec_type = hdr->type & MAIL_TRANSACTION_TYPE_MASK; |
5719 | 575 rec_size = mail_index_offset_to_uint32(hdr->size) - sizeof(*hdr); |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
576 |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
577 /* we want to be extra careful with expunges */ |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
578 if ((hdr->type & MAIL_TRANSACTION_EXPUNGE) != 0) { |
5720 | 579 if (rec_type != (MAIL_TRANSACTION_EXPUNGE | |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
580 MAIL_TRANSACTION_EXPUNGE_PROT)) { |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
581 mail_transaction_log_file_set_corrupted(file, |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
582 "expunge record missing protection mask"); |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
583 return FALSE; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
584 } |
8612
3ee12ca9e2c4
index: Expunge records' UIDs weren't verified to be valid before using them.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
585 rec_type &= ~MAIL_TRANSACTION_EXPUNGE_PROT; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
586 } |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
587 if ((hdr->type & MAIL_TRANSACTION_EXPUNGE_GUID) != 0) { |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
588 if (rec_type != (MAIL_TRANSACTION_EXPUNGE_GUID | |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
589 MAIL_TRANSACTION_EXPUNGE_PROT)) { |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
590 mail_transaction_log_file_set_corrupted(file, |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
591 "expunge guid record missing protection mask"); |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
592 return FALSE; |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
593 } |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
594 rec_type &= ~MAIL_TRANSACTION_EXPUNGE_PROT; |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
595 } |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
596 |
5721
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
597 if (rec_size == 0) { |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
598 mail_transaction_log_file_set_corrupted(file, |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
599 "Empty record contents (type=0x%x)", rec_type); |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
600 return FALSE; |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
601 } |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
602 |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
603 /* records that are exported by syncing and view syncing will be |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
604 checked here so that we don't have to implement the same validation |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
605 multiple times. other records are checked internally by |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
606 mail_index_sync_record(). */ |
5720 | 607 switch (rec_type) { |
5721
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
608 case MAIL_TRANSACTION_APPEND: |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
609 if ((rec_size % sizeof(struct mail_index_record)) != 0) { |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
610 mail_transaction_log_file_set_corrupted(file, |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
611 "Invalid append record size"); |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
612 return FALSE; |
5721
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
613 } |
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
614 break; |
5720 | 615 case MAIL_TRANSACTION_EXPUNGE: |
15034
7efef678bca8
Renamed buffer_create_*data() to buffer_create_from_*data() for consistency.
Timo Sirainen <tss@iki.fi>
parents:
14884
diff
changeset
|
616 buffer_create_from_const_data(&uid_buf, data, rec_size); |
9623
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
617 array_create_from_buffer(&uids, &uid_buf, |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
618 sizeof(struct mail_transaction_expunge)); |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
619 break; |
12747
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
620 case MAIL_TRANSACTION_EXPUNGE_GUID: { |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
621 const struct mail_transaction_expunge_guid *recs = data; |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
622 unsigned int i, count; |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
623 |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
624 if ((rec_size % sizeof(*recs)) != 0) { |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
625 mail_transaction_log_file_set_corrupted(file, |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
626 "Invalid expunge guid record size"); |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
627 return FALSE; |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
628 } |
12747
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
629 count = rec_size / sizeof(*recs); |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
630 for (i = 0; i < count; i++) { |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
631 if (recs[i].uid == 0) { |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
632 mail_transaction_log_file_set_corrupted(file, |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
633 "Expunge guid record with uid=0"); |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
634 return FALSE; |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
635 } |
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
636 } |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
637 break; |
12747
9a4c198597d8
lib-index: Verify that expunge-guid records have valid UID.
Timo Sirainen <tss@iki.fi>
parents:
11368
diff
changeset
|
638 } |
5720 | 639 case MAIL_TRANSACTION_FLAG_UPDATE: |
15034
7efef678bca8
Renamed buffer_create_*data() to buffer_create_from_*data() for consistency.
Timo Sirainen <tss@iki.fi>
parents:
14884
diff
changeset
|
640 buffer_create_from_const_data(&uid_buf, data, rec_size); |
9623
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
641 array_create_from_buffer(&uids, &uid_buf, |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
642 sizeof(struct mail_transaction_flag_update)); |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
643 break; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
644 case MAIL_TRANSACTION_KEYWORD_UPDATE: { |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
645 const struct mail_transaction_keyword_update *rec = data; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
646 unsigned int seqset_offset; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
647 |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
648 seqset_offset = sizeof(*rec) + rec->name_size; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
649 if ((seqset_offset % 4) != 0) |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
650 seqset_offset += 4 - (seqset_offset % 4); |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
651 |
13889
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
652 if (rec->name_size == 0) { |
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
653 mail_transaction_log_file_set_corrupted(file, |
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
654 "Trying to use empty keyword"); |
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
655 return FALSE; |
931436c5f2cc
lib-index: Avoid assert-crashing on keyword-update record with empty keyword.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
656 } |
5721
18d7a680ffae
Added more corruption detection code.
Timo Sirainen <tss@iki.fi>
parents:
5720
diff
changeset
|
657 if (seqset_offset > rec_size) { |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
658 mail_transaction_log_file_set_corrupted(file, |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
659 "Invalid keyword update record size"); |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
660 return FALSE; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
661 } |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
662 |
15034
7efef678bca8
Renamed buffer_create_*data() to buffer_create_from_*data() for consistency.
Timo Sirainen <tss@iki.fi>
parents:
14884
diff
changeset
|
663 buffer_create_from_const_data(&uid_buf, |
9623
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
664 CONST_PTR_OFFSET(data, seqset_offset), |
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
665 rec_size - seqset_offset); |
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
666 array_create_from_buffer(&uids, &uid_buf, |
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
667 sizeof(uint32_t)*2); |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
668 break; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
669 } |
5720 | 670 case MAIL_TRANSACTION_KEYWORD_RESET: |
15034
7efef678bca8
Renamed buffer_create_*data() to buffer_create_from_*data() for consistency.
Timo Sirainen <tss@iki.fi>
parents:
14884
diff
changeset
|
671 buffer_create_from_const_data(&uid_buf, data, rec_size); |
9623
3da42dafa798
buffer_create_[const_]data() API change: Take buffer_t as parameter instead of allocating it.
Timo Sirainen <tss@iki.fi>
parents:
9251
diff
changeset
|
672 array_create_from_buffer(&uids, &uid_buf, |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
673 sizeof(struct mail_transaction_keyword_reset)); |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
674 break; |
14882
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
675 case MAIL_TRANSACTION_EXT_INTRO: { |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
676 const struct mail_transaction_ext_intro *rec; |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
677 unsigned int i; |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
678 |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
679 for (i = 0; i < rec_size; ) { |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
680 if (i + sizeof(*rec) > rec_size) { |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
681 /* should be just extra padding */ |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
682 break; |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
683 } |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
684 |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
685 rec = CONST_PTR_OFFSET(data, i); |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
686 if (i + sizeof(*rec) + rec->name_size > rec_size) { |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
687 mail_transaction_log_file_set_corrupted(file, |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
688 "ext intro: name_size too large"); |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
689 return FALSE; |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
690 } |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
691 i += sizeof(*rec) + rec->name_size; |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
692 if ((i % 4) != 0) |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
693 i += 4 - (i % 4); |
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
694 } |
16023
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
695 break; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
696 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
697 case MAIL_TRANSACTION_ATTRIBUTE_UPDATE: { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
698 const char *attr_changes = data; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
699 unsigned int i; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
700 |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
701 for (i = 0; i+2 < rec_size && attr_changes[i] != '\0'; ) { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
702 if (attr_changes[i] != '+' && attr_changes[i] != '-') { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
703 mail_transaction_log_file_set_corrupted(file, |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
704 "attribute update: Invalid prefix 0x%02x", |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
705 attr_changes[i]); |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
706 return FALSE; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
707 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
708 i++; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
709 if (attr_changes[i] != 'p' && attr_changes[i] != 's') { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
710 mail_transaction_log_file_set_corrupted(file, |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
711 "attribute update: Invalid type 0x%02x", |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
712 attr_changes[i]); |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
713 return FALSE; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
714 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
715 i++; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
716 if (attr_changes[i] == '\0') { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
717 mail_transaction_log_file_set_corrupted(file, |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
718 "attribute update: Empty key"); |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
719 return FALSE; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
720 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
721 i += strlen(attr_changes+i) + 1; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
722 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
723 if (i == 0 || (i < rec_size && attr_changes[i] != '\0')) { |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
724 mail_transaction_log_file_set_corrupted(file, |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
725 "attribute update doesn't end with NUL"); |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
726 return FALSE; |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
727 } |
db0136374bb0
lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
728 break; |
14882
ba6b92cf7d49
lib-index: Verify validity of ext-intro records in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
14675
diff
changeset
|
729 } |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
730 default: |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
731 break; |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
732 } |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
733 |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
734 if (array_is_created(&uids)) { |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
735 if (!log_view_is_uid_range_valid(file, rec_type, &uids)) |
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
736 return FALSE; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
737 } |
11068
a65dbdedb202
lib-index: Small code cleanup.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
738 return TRUE; |
5718
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
739 } |
8b481177965a
Moved duplicated log record validation code to a single place.
Timo Sirainen <tss@iki.fi>
parents:
5689
diff
changeset
|
740 |
2616
13930bda8b69
Don't check extra updates data_id validity if we're just skipping over them.
Timo Sirainen <tss@iki.fi>
parents:
2585
diff
changeset
|
741 static int |
13930bda8b69
Don't check extra updates data_id validity if we're just skipping over them.
Timo Sirainen <tss@iki.fi>
parents:
2585
diff
changeset
|
742 log_view_get_next(struct mail_transaction_log_view *view, |
13930bda8b69
Don't check extra updates data_id validity if we're just skipping over them.
Timo Sirainen <tss@iki.fi>
parents:
2585
diff
changeset
|
743 const struct mail_transaction_header **hdr_r, |
2702
d6f25d0e104a
Don't complain about corruption when there is none.
Timo Sirainen <tss@iki.fi>
parents:
2701
diff
changeset
|
744 const void **data_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
745 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 const struct mail_transaction_header *hdr; |
1940 | 747 struct mail_transaction_log_file *file; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
748 const void *data; |
5720 | 749 enum mail_transaction_type rec_type; |
5719 | 750 uint32_t full_size; |
1933 | 751 size_t file_size; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
752 int ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
753 |
3173
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
754 if (view->cur == NULL) |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
755 return 0; |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
756 |
3180
ef16bb8091aa
Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
757 /* prev_file_offset should point to beginning of previous log record. |
ef16bb8091aa
Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
758 when we reach EOF, it should be left there, not to beginning of the |
5656
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
759 next file that's not included inside the view. */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
760 if (mail_transaction_log_view_get_last(view, &view->cur, |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
761 &view->cur_offset)) { |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
762 /* if the last file was the beginning of a file, we want to |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
763 move prev pointers there */ |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
764 view->prev_file_seq = view->cur->hdr.file_seq; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
765 view->prev_file_offset = view->cur_offset; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
766 view->cur = NULL; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
767 return 0; |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
768 } |
1273ce0585b3
Added mail_transaction_log_view_is_last()
Timo Sirainen <tss@iki.fi>
parents:
5278
diff
changeset
|
769 |
3173
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
770 view->prev_file_seq = view->cur->hdr.file_seq; |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
771 view->prev_file_offset = view->cur_offset; |
d137899ea853
We could have gone past the transaction log view's boundaries if log was
Timo Sirainen <tss@iki.fi>
parents:
2885
diff
changeset
|
772 |
3180
ef16bb8091aa
Several transaction log cleanups and fixes.
Timo Sirainen <tss@iki.fi>
parents:
3173
diff
changeset
|
773 file = view->cur; |
2392
dad26f6995ff
mail_transaction_log_view_next() didn't actually stop at the end of view
Timo Sirainen <tss@iki.fi>
parents:
2331
diff
changeset
|
774 |
1933 | 775 data = buffer_get_data(file->buffer, &file_size); |
776 file_size += file->buffer_offset; | |
777 | |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
778 if (view->cur_offset + sizeof(*hdr) > file_size) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
779 mail_transaction_log_file_set_corrupted(file, |
1933 | 780 "offset points outside file " |
781 "(%"PRIuUOFF_T" + %"PRIuSIZE_T" > %"PRIuSIZE_T")", | |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
782 view->cur_offset, sizeof(*hdr), file_size); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
783 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
784 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
785 |
3342 | 786 i_assert(view->cur_offset >= file->buffer_offset); |
2074
cb5269c052e0
Keep the transaction log view open all the time for index views (not just
Timo Sirainen <tss@iki.fi>
parents:
2050
diff
changeset
|
787 hdr = CONST_PTR_OFFSET(data, view->cur_offset - file->buffer_offset); |
2115
f720b3f15333
Modifying extra_records should work now.
Timo Sirainen <tss@iki.fi>
parents:
2095
diff
changeset
|
788 data = CONST_PTR_OFFSET(hdr, sizeof(*hdr)); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
789 |
5720 | 790 rec_type = hdr->type & MAIL_TRANSACTION_TYPE_MASK; |
5719 | 791 full_size = mail_index_offset_to_uint32(hdr->size); |
792 if (full_size < sizeof(*hdr)) { | |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2392
diff
changeset
|
793 mail_transaction_log_file_set_corrupted(file, |
3351
63fc076992bf
Added offsets to log file corruption error messages
Timo Sirainen <tss@iki.fi>
parents:
3342
diff
changeset
|
794 "record size too small (type=0x%x, " |
63fc076992bf
Added offsets to log file corruption error messages
Timo Sirainen <tss@iki.fi>
parents:
3342
diff
changeset
|
795 "offset=%"PRIuUOFF_T", size=%u)", |
5720 | 796 rec_type, view->cur_offset, full_size); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
797 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
798 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
799 |
5719 | 800 if (file_size - view->cur_offset < full_size) { |
3342 | 801 mail_transaction_log_file_set_corrupted(file, |
3351
63fc076992bf
Added offsets to log file corruption error messages
Timo Sirainen <tss@iki.fi>
parents:
3342
diff
changeset
|
802 "record size too large (type=0x%x, " |
63fc076992bf
Added offsets to log file corruption error messages
Timo Sirainen <tss@iki.fi>
parents:
3342
diff
changeset
|
803 "offset=%"PRIuUOFF_T", size=%u, end=%"PRIuSIZE_T")", |
5720 | 804 rec_type, view->cur_offset, full_size, file_size); |
3342 | 805 return -1; |
806 } | |
807 | |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
808 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
809 ret = log_view_is_record_valid(file, hdr, data) ? 1 : -1; |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
810 } T_END; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
811 if (ret > 0) { |
21876
ccbdafa83dbc
lib-index: Don't increase modseq for backend/dirty flag changes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
812 mail_transaction_update_modseq(hdr, data, &view->prev_modseq, |
ccbdafa83dbc
lib-index: Don't increase modseq for backend/dirty flag changes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
813 MAIL_TRANSACTION_LOG_HDR_VERSION(&file->hdr)); |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
814 *hdr_r = hdr; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
815 *data_r = data; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
816 view->cur_offset += full_size; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
817 } |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6802
diff
changeset
|
818 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
820 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
821 int mail_transaction_log_view_next(struct mail_transaction_log_view *view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
822 const struct mail_transaction_header **hdr_r, |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
823 const void **data_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
824 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
825 const struct mail_transaction_header *hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
826 const void *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
827 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
828 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
829 if (view->broken) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
830 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
831 |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
832 ret = log_view_get_next(view, &hdr, &data); |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
833 if (ret <= 0) { |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
834 if (ret < 0) |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
835 view->cur_offset = view->cur->sync_offset; |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
836 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
837 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
838 |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
839 /* drop expunge protection */ |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
840 if ((hdr->type & MAIL_TRANSACTION_TYPE_MASK) == |
9624
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
841 (MAIL_TRANSACTION_EXPUNGE | MAIL_TRANSACTION_EXPUNGE_PROT) || |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
842 (hdr->type & MAIL_TRANSACTION_TYPE_MASK) == |
2558ba736207
Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents:
9623
diff
changeset
|
843 (MAIL_TRANSACTION_EXPUNGE_GUID | MAIL_TRANSACTION_EXPUNGE_PROT)) |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
844 view->tmp_hdr.type = hdr->type & ~MAIL_TRANSACTION_EXPUNGE_PROT; |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
845 else |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
846 view->tmp_hdr.type = hdr->type; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
847 |
5723
ad695be143ff
Don't assume that transaction record type is a bitmask in the transaction
Timo Sirainen <tss@iki.fi>
parents:
5721
diff
changeset
|
848 /* return record's size */ |
5728
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
849 view->tmp_hdr.size = mail_index_offset_to_uint32(hdr->size); |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
850 i_assert(view->tmp_hdr.size > sizeof(*hdr)); |
7aab5d99fb45
Removed sync_mask parameter from mail_transaction_log_view_set(). The user
Timo Sirainen <tss@iki.fi>
parents:
5727
diff
changeset
|
851 view->tmp_hdr.size -= sizeof(*hdr); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
852 |
2407
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2392
diff
changeset
|
853 *hdr_r = &view->tmp_hdr; |
fed6d07bd8ee
Transaction log file is now read-lockless.
Timo Sirainen <tss@iki.fi>
parents:
2392
diff
changeset
|
854 *data_r = data; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
855 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
856 } |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
857 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
858 void mail_transaction_log_view_mark(struct mail_transaction_log_view *view) |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
859 { |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
860 i_assert(view->cur->hdr.file_seq == view->prev_file_seq); |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
861 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
862 view->mark_file = view->cur; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
863 view->mark_offset = view->prev_file_offset; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
864 view->mark_next_offset = view->cur_offset; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
865 view->mark_modseq = view->prev_modseq; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
866 } |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
867 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
868 void mail_transaction_log_view_rewind(struct mail_transaction_log_view *view) |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
869 { |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
870 i_assert(view->mark_file != NULL); |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
871 |
7812
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
872 view->cur = view->mark_file; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
873 view->cur_offset = view->mark_next_offset; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
874 view->prev_file_seq = view->cur->hdr.file_seq; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
875 view->prev_file_offset = view->mark_offset; |
d10cb44ab446
Modseqs are no longer calculated from transaction log sequence + offset.
Timo Sirainen <tss@iki.fi>
parents:
7549
diff
changeset
|
876 view->prev_modseq = view->mark_modseq; |
5278
d569caa88a66
If we run out of disk space, move to in-memory indexes.
Timo Sirainen <tss@iki.fi>
parents:
5256
diff
changeset
|
877 } |