Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-index/mail-transaction-log.c @ 1940:876bd2849a00 HEAD
fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 01 May 2004 17:30:25 +0300 |
parents | f56d502b248b |
children | ced8e41c137a |
rev | line source |
---|---|
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1 /* Copyright (C) 2003-2004 Timo Sirainen */ |
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" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "buffer.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "file-lock.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "file-dotlock.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "read-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "write-full.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "mmap-util.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "mail-index-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "mail-index-view-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include "mail-transaction-log-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include "mail-transaction-util.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "mail-index-transaction-private.h" |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <stddef.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <sys/stat.h> |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 |
1920
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
19 /* this lock should never exist for a long time.. */ |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
20 #define LOG_DOTLOCK_TIMEOUT 30 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
21 #define LOG_DOTLOCK_STALE_TIMEOUT 0 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
22 #define LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT 120 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
23 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 struct mail_transaction_add_ctx { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 struct mail_transaction_log *log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct mail_index_view *view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 buffer_t *appends, *expunges; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 buffer_t *flag_updates, *cache_updates; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 }; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
31 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 static struct mail_transaction_log_file * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 mail_transaction_log_file_open_or_create(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 const char *path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 static int mail_transaction_log_rotate(struct mail_transaction_log *log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 static int |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 mail_transaction_log_file_lock(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 int lock_type); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 static int mail_transaction_log_lock_head(struct mail_transaction_log *log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
41 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
44 const char *fmt, ...) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 va_list va; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 file->hdr.indexid = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 if (pwrite_full(file->fd, &file->hdr.indexid, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 sizeof(file->hdr.indexid), 0) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 mail_index_file_set_syscall_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 file->filepath, "pwrite()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
54 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 va_start(va, fmt); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 t_push(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 mail_index_set_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 "Corrupted transaction log file %s: %s", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 file->filepath, t_strdup_vprintf(fmt, va)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 t_pop(); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 va_end(va); |
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 |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
64 #define INDEX_HAS_MISSING_LOGS(index, file) \ |
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
65 ((file)->hdr.file_seq != (index)->hdr->log_file_seq && \ |
1940 | 66 ((file)->hdr.prev_file_seq != (index)->hdr->log_file_seq || \ |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
67 (file)->hdr.prev_file_offset != (index)->hdr->log_file_offset)) |
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
68 |
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
69 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 static int mail_transaction_log_check_file_seq(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 struct mail_index *index = log->index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 unsigned int lock_id; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 if (mail_transaction_log_lock_head(log) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
79 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 file = log->head; |
1940 | 81 file->refcount++; |
82 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
83 ret = mail_index_lock_shared(index, TRUE, &lock_id); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
84 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 ret = mail_index_map(index, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 ret = -1; |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
88 else if (INDEX_HAS_MISSING_LOGS(index, file)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 /* broken - fix it by creating a new log file */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
90 ret = mail_transaction_log_rotate(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
91 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
92 } |
1940 | 93 |
94 if (--file->refcount == 0) | |
95 mail_transaction_logs_clean(log); | |
96 else | |
97 (void)mail_transaction_log_file_lock(file, F_UNLCK); | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 struct mail_transaction_log * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 mail_transaction_log_open_or_create(struct mail_index *index) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 struct mail_transaction_log *log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
106 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
107 log = i_new(struct mail_transaction_log, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
108 log->index = index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
109 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
110 path = t_strconcat(log->index->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
111 MAIL_TRANSACTION_LOG_PREFIX, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
112 log->head = mail_transaction_log_file_open_or_create(log, path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
113 if (log->head == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
114 i_free(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
115 return NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
116 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
117 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
118 if (index->fd != -1 && |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
119 INDEX_HAS_MISSING_LOGS(index, log->head)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
120 /* head log file isn't same as head index file - |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 shouldn't happen except in race conditions. lock them and |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
122 check again - FIXME: missing error handling. */ |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 (void)mail_transaction_log_check_file_seq(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 return log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
126 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 void mail_transaction_log_close(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 i_assert(log->views == NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
132 i_free(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
135 static int |
1920
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
136 mail_transaction_log_file_dotlock(struct mail_transaction_log_file *file, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
137 int lock_type) |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
138 { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
139 int ret; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
140 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
141 if (lock_type == F_UNLCK) { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
142 ret = file_unlock_dotlock(file->filepath, &file->dotlock); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
143 if (ret < 0) { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
144 mail_index_file_set_syscall_error(file->log->index, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
145 file->filepath, "file_unlock_dotlock()"); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
146 return -1; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
147 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
148 file->lock_type = F_UNLCK; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
149 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
150 if (ret == 0) { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
151 mail_index_set_error(file->log->index, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
152 "Dotlock was lost for transaction log file %s", |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
153 file->filepath); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
154 return -1; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
155 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
156 return 0; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
157 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
158 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
159 ret = file_lock_dotlock(file->filepath, NULL, FALSE, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
160 LOG_DOTLOCK_TIMEOUT, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
161 LOG_DOTLOCK_STALE_TIMEOUT, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
162 LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
163 NULL, NULL, &file->dotlock); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
164 if (ret > 0) { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
165 file->lock_type = F_WRLCK; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
166 return 0; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
167 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
168 if (ret < 0) { |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
169 mail_index_file_set_syscall_error(file->log->index, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
170 file->filepath, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
171 "file_lock_dotlock()"); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
172 return -1; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
173 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
174 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
175 mail_index_set_error(file->log->index, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
176 "Timeout while waiting for release of " |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
177 "dotlock for transaction log file %s", |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
178 file->filepath); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
179 file->log->index->index_lock_timeout = TRUE; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
180 return -1; |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
181 } |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
182 |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
183 static int |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
184 mail_transaction_log_file_lock(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
185 int lock_type) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
186 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
187 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
188 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
189 if (lock_type == F_UNLCK) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 i_assert(file->lock_type != F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
192 i_assert(file->lock_type == F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
193 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
194 |
1920
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
195 if (file->log->index->fcntl_locks_disable) |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
196 return mail_transaction_log_file_dotlock(file, lock_type); |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
197 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 ret = file_wait_lock_full(file->fd, lock_type, DEFAULT_LOCK_TIMEOUT, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 NULL, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 if (ret > 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 file->lock_type = lock_type; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 if (ret < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 mail_index_file_set_syscall_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 file->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 "file_wait_lock()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 mail_index_set_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 "Timeout while waiting for release of " |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 "%s fcntl() lock for transaction log file %s", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 lock_type == F_WRLCK ? "exclusive" : "shared", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 file->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 file->log->index->index_lock_timeout = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 static void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 mail_transaction_log_file_close(struct mail_transaction_log_file *file) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 if (close(file->fd) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 mail_index_file_set_syscall_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 file->filepath, "close()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 i_free(file->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 i_free(file); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
231 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 static int |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 mail_transaction_log_file_read_hdr(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 struct stat *st) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
235 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
236 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 uint32_t old_size = file->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
239 if (file->lock_type != F_UNLCK) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
240 ret = pread_full(file->fd, &file->hdr, sizeof(file->hdr), 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
241 else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
242 if (mail_transaction_log_file_lock(file, F_RDLCK) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 ret = pread_full(file->fd, &file->hdr, sizeof(file->hdr), 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
245 (void)mail_transaction_log_file_lock(file, F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
246 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
247 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
248 if (ret < 0) { |
1919
4aeb7357951a
locking fixes, mmap_disable=yes fixes
Timo Sirainen <tss@iki.fi>
parents:
1917
diff
changeset
|
249 // FIXME: handle ESTALE |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
250 mail_index_file_set_syscall_error(file->log->index, |
1933 | 251 file->filepath, |
252 "pread_full()"); | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
253 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
255 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 mail_transaction_log_file_set_corrupted(file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 "unexpected end of file while reading header"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
259 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
260 if (file->hdr.indexid == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 /* corrupted */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 mail_index_set_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 "Transaction log file %s: marked corrupted", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 file->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 if (file->hdr.indexid != file->log->index->indexid && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 file->log->index->indexid != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 /* either index was just recreated, or transaction has wrong |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 indexid. we don't know here which one is the case, so we'll |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 just fail. If index->indexid == 0, we're rebuilding it and |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 we just want to lock the transaction log. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 mail_index_set_error(file->log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 "Transaction log file %s: invalid indexid", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 file->filepath); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 if (file->hdr.used_size > st->st_size) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 mail_transaction_log_file_set_corrupted(file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 "used_size (%u) > file size (%"PRIuUOFF_T")", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 file->hdr.used_size, (uoff_t)st->st_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 if (file->hdr.used_size < old_size) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 mail_transaction_log_file_set_corrupted(file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 "used_size (%u) < old_size (%u)", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 file->hdr.used_size, old_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
294 static int |
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
295 mail_transaction_log_file_create(struct mail_transaction_log *log, |
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
296 const char *path, dev_t dev, ino_t ino) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 struct mail_index *index = log->index; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 struct mail_transaction_log_header hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
300 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 int fd, fd2, ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 |
1920
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
303 fd = file_dotlock_open(path, NULL, LOG_DOTLOCK_TIMEOUT, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
304 LOG_DOTLOCK_STALE_TIMEOUT, |
d11efbf1d341
Added fcntl_lock_disable setting to allow indexes to work with NFS. Some
Timo Sirainen <tss@iki.fi>
parents:
1919
diff
changeset
|
305 LOG_DOTLOCK_IMMEDIATE_STALE_TIMEOUT, NULL, NULL); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 if (fd == -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 mail_index_file_set_syscall_error(index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 "file_dotlock_open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 /* log creation is locked now - see if someone already created it */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 fd2 = open(path, O_RDWR); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
314 if (fd2 != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 if ((ret = fstat(fd2, &st)) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
316 mail_index_file_set_syscall_error(index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 "fstat()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 } else if (st.st_dev == dev && st.st_ino == ino) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 /* same file, still broken */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 (void)file_dotlock_delete(path, fd2); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 return fd2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 (void)close(fd2); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 fd2 = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
329 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
330 } else if (errno != ENOENT) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
331 mail_index_file_set_syscall_error(index, path, "open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
332 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
333 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 memset(&hdr, 0, sizeof(hdr)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 hdr.indexid = index->indexid; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
337 hdr.used_size = sizeof(hdr); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 |
1940 | 339 if (index->fd != -1) { |
340 hdr.prev_file_seq = index->hdr->log_file_seq; | |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
341 hdr.prev_file_offset = index->hdr->log_file_offset; |
1940 | 342 } |
1935
ec4d5ff99f6e
Don't modify index file when creating new transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1933
diff
changeset
|
343 hdr.file_seq = index->hdr->log_file_seq+1; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
344 |
1940 | 345 if (log->head != NULL && hdr.file_seq <= log->head->hdr.file_seq) { |
346 /* make sure the sequence grows */ | |
347 hdr.file_seq = log->head->hdr.file_seq+1; | |
348 } | |
1936 | 349 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 if (write_full(fd, &hdr, sizeof(hdr)) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 mail_index_file_set_syscall_error(index, path, "write_full()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 (void)file_dotlock_delete(path, fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
353 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
354 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 fd2 = dup(fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 if (fd2 < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 mail_index_file_set_syscall_error(index, path, "dup()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 (void)file_dotlock_delete(path, fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
362 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 if (file_dotlock_replace(path, fd, FALSE) <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
365 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
366 /* success */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 return fd2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
369 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
370 static struct mail_transaction_log_file * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
371 mail_transaction_log_file_fd_open(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
372 const char *path, int fd) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
373 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 struct mail_transaction_log_file **p; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
377 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
379 if (fstat(fd, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 mail_index_file_set_syscall_error(log->index, path, "stat()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
381 return NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
382 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
383 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
384 file = i_new(struct mail_transaction_log_file, 1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 file->refcount = 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 file->log = log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
387 file->filepath = i_strdup(path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
388 file->fd = fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
389 file->lock_type = F_UNLCK; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 file->st_dev = st.st_dev; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
391 file->st_ino = st.st_ino; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
393 ret = mail_transaction_log_file_read_hdr(file, &st); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
395 /* corrupted header */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
396 fd = mail_transaction_log_file_create(log, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
397 st.st_dev, st.st_ino); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
398 if (fstat(fd, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 mail_index_file_set_syscall_error(log->index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
400 "stat()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
401 (void)close(fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 fd = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
403 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
404 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
405 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
406 if (fd != -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 (void)close(file->fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
408 file->fd = fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
409 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
410 file->st_dev = st.st_dev; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
411 file->st_ino = st.st_ino; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
413 memset(&file->hdr, 0, sizeof(file->hdr)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
414 ret = mail_transaction_log_file_read_hdr(file, &st); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
415 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 if (ret <= 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
418 mail_transaction_log_file_close(file); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
419 return NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
420 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
421 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
422 for (p = &log->tail; *p != NULL; p = &(*p)->next) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
423 ; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
424 *p = file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
425 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
426 return file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
427 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
428 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
429 static struct mail_transaction_log_file * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 mail_transaction_log_file_open_or_create(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 const char *path) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
433 int fd; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
435 fd = open(path, O_RDWR); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
436 if (fd == -1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
437 if (errno != ENOENT) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
438 mail_index_file_set_syscall_error(log->index, path, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
439 "open()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
440 return NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
441 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
442 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
443 fd = mail_transaction_log_file_create(log, path, 0, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
444 if (fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 return NULL; |
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 return mail_transaction_log_file_fd_open(log, path, fd); |
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 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 void mail_transaction_logs_clean(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
452 { |
1940 | 453 struct mail_transaction_log_file **p, *next; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
454 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 for (p = &log->tail; *p != NULL; ) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 if ((*p)->refcount != 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 p = &(*p)->next; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
458 else { |
1940 | 459 next = (*p)->next; |
460 mail_transaction_log_file_close(*p); | |
461 *p = next; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
466 static int mail_transaction_log_rotate(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
468 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 struct stat st; |
1940 | 470 int fd, lock_type; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
471 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 if (fstat(log->head->fd, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
473 mail_index_file_set_syscall_error(log->index, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
474 log->head->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 "fstat()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 fd = mail_transaction_log_file_create(log, log->head->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 st.st_dev, st.st_ino); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 if (fd == -1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
483 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 file = mail_transaction_log_file_fd_open(log, log->head->filepath, fd); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 if (file == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 |
1940 | 488 lock_type = log->head->lock_type; |
489 if (lock_type != F_UNLCK) { | |
490 if (mail_transaction_log_file_lock(file, lock_type) < 0) | |
491 return -1; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 |
1940 | 494 if (--log->head->refcount == 0) |
495 mail_transaction_logs_clean(log); | |
496 else | |
497 (void)mail_transaction_log_file_lock(log->head, F_UNLCK); | |
498 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 log->head = file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
502 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 static int mail_transaction_log_refresh(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
505 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
506 struct stat st; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 const char *path; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
509 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
510 path = t_strconcat(log->index->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
511 MAIL_TRANSACTION_LOG_PREFIX, NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
512 if (stat(path, &st) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
513 mail_index_file_set_syscall_error(log->index, path, "stat()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
515 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
516 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
517 if (log->head != NULL && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
518 log->head->st_ino == st.st_ino && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
519 log->head->st_dev == st.st_dev) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
520 /* same file */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
521 ret = mail_transaction_log_file_read_hdr(log->head, &st); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 return ret <= 0 ? -1 : 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
524 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
525 file = mail_transaction_log_file_open_or_create(log, path); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
526 if (file == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
527 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
528 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
529 if (log->head != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
530 if (--log->head->refcount == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
531 mail_transaction_logs_clean(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
532 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
533 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
534 log->head = file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
535 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
536 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
537 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
538 int mail_transaction_log_file_find(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
539 uint32_t file_seq, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
540 struct mail_transaction_log_file **file_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
541 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
542 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
543 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
544 if (file_seq > log->head->hdr.file_seq) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
545 if (mail_transaction_log_refresh(log) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
546 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
547 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
548 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
549 for (file = log->tail; file != NULL; file = file->next) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
550 if (file->hdr.file_seq == file_seq) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
551 *file_r = file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
552 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
553 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
554 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
555 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
556 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
557 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
558 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 static int |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
560 mail_transaction_log_file_read(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
561 uoff_t offset) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
562 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 void *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 size_t size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
565 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 i_assert(file->mmap_base == NULL); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
568 i_assert(offset <= file->hdr.used_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
569 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
570 if (file->buffer != NULL && file->buffer_offset > offset) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
571 /* we have to insert missing data to beginning of buffer */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
572 size = file->buffer_offset - offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
573 buffer_copy(file->buffer, size, file->buffer, 0, (size_t)-1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
574 file->buffer_offset = offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 |
1932 | 576 data = buffer_get_space_unsafe(file->buffer, 0, size); |
1933 | 577 ret = pread_full(file->fd, data, size, offset); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
578 if (ret < 0 && errno == ESTALE) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
579 /* log file was deleted in NFS server, fail silently */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 if (ret <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
585 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 if (file->buffer == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 size = file->hdr.used_size - offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
588 file->buffer = buffer_create_dynamic(default_pool, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
589 size, (size_t)-1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
590 file->buffer_offset = offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 size = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 size = buffer_get_used_size(file->buffer); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 if (file->buffer_offset + size >= file->hdr.used_size) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
595 /* caller should have checked this.. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
596 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 } |
1933 | 599 offset = file->buffer_offset + size; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
601 size = file->hdr.used_size - file->buffer_offset - size; |
1919
4aeb7357951a
locking fixes, mmap_disable=yes fixes
Timo Sirainen <tss@iki.fi>
parents:
1917
diff
changeset
|
602 if (size == 0) |
4aeb7357951a
locking fixes, mmap_disable=yes fixes
Timo Sirainen <tss@iki.fi>
parents:
1917
diff
changeset
|
603 return 1; |
4aeb7357951a
locking fixes, mmap_disable=yes fixes
Timo Sirainen <tss@iki.fi>
parents:
1917
diff
changeset
|
604 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
605 data = buffer_append_space_unsafe(file->buffer, size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
606 |
1933 | 607 ret = pread_full(file->fd, data, size, offset); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
608 if (ret < 0 && errno == ESTALE) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
609 /* log file was deleted in NFS server, fail silently */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
610 ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
611 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
612 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
613 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
614 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
615 int mail_transaction_log_file_map(struct mail_transaction_log_file *file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
616 uoff_t start_offset, uoff_t end_offset) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
617 { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
618 struct mail_index *index = file->log->index; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
619 size_t size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
620 struct stat st; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
621 int ret, use_mmap; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
622 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
623 i_assert(start_offset <= end_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
624 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
625 if (file->hdr.indexid == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
626 /* corrupted */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
627 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
628 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
629 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
630 /* with mmap_no_write we could alternatively just write to log with |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
631 msync() rather than pwrite(). that'd cause slightly more disk I/O, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
632 so rather use more memory. */ |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
633 use_mmap = !index->mmap_disable && !index->mmap_no_write; |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
634 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
635 if (file->buffer != NULL && file->buffer_offset <= start_offset) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
636 /* see if we already have it */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
637 size = buffer_get_used_size(file->buffer); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
638 if (file->buffer_offset + size >= end_offset) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
639 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
640 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
641 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
642 if (fstat(file->fd, &st) < 0) { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
643 mail_index_file_set_syscall_error(index, file->filepath, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
644 "fstat()"); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
645 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
646 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
647 |
1933 | 648 if (st.st_size == file->hdr.used_size && |
649 file->buffer_offset <= start_offset && end_offset == (uoff_t)-1) { | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
650 /* we've seen the whole file.. do we have all of it mapped? */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
651 size = buffer_get_used_size(file->buffer); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
652 if (file->buffer_offset + size == file->hdr.used_size) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
653 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
654 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
655 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
656 if (file->buffer != NULL && |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
657 (file->mmap_base != NULL || use_mmap)) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
658 buffer_free(file->buffer); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
659 file->buffer = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
660 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
661 if (file->mmap_base != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
662 if (munmap(file->mmap_base, file->mmap_size) < 0) { |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
663 mail_index_file_set_syscall_error(index, file->filepath, |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
664 "munmap()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
665 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
666 file->mmap_base = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
667 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
668 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
669 if (mail_transaction_log_file_read_hdr(file, &st) <= 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
670 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
671 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
672 if (end_offset == (uoff_t)-1) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
673 end_offset = file->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
674 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
675 if (start_offset < sizeof(file->hdr)) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 mail_transaction_log_file_set_corrupted(file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
677 "offset (%"PRIuUOFF_T"u) < header size (%"PRIuSIZE_T")", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
678 start_offset, sizeof(file->hdr)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
679 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
681 if (end_offset > file->hdr.used_size) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
682 mail_transaction_log_file_set_corrupted(file, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 "offset (%"PRIuUOFF_T"u) > used_size (%u)", |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
684 end_offset, file->hdr.used_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
686 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
687 |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
688 if (!use_mmap) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
689 ret = mail_transaction_log_file_read(file, start_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 if (ret <= 0) { |
1933 | 691 if (ret < 0) { |
692 mail_index_file_set_syscall_error(index, | |
693 file->filepath, "pread_full()"); | |
694 } else { | |
695 mail_transaction_log_file_set_corrupted(file, | |
696 "Unexpected EOF"); | |
697 } | |
698 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 /* make sure we don't leave ourself in |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
700 inconsistent state */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
701 if (file->buffer != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 buffer_free(file->buffer); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 file->buffer = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
706 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 file->mmap_size = file->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
710 file->mmap_base = mmap(NULL, file->mmap_size, PROT_READ, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
711 MAP_SHARED, file->fd, 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
712 if (file->mmap_base == MAP_FAILED) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
713 file->mmap_base = NULL; |
1917
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
714 mail_index_file_set_syscall_error(index, file->filepath, |
68938dccbc45
Forced locking to be right with mprotect()ing index file. Support for
Timo Sirainen <tss@iki.fi>
parents:
1915
diff
changeset
|
715 "mmap()"); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 file->buffer = buffer_create_const_data(default_pool, file->mmap_base, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
719 file->mmap_size); |
1933 | 720 file->buffer_offset = 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
721 return 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
722 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
723 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
724 static int mail_transaction_log_lock_head(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
725 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
726 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
727 int ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
728 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
729 /* we want to get the head file locked. this is a bit racy, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
730 since by the time we have it locked a new log file may have been |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
731 created. |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
732 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
733 creating new log file requires locking the head file, so if we |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
734 can lock it and don't see another file, we can be sure no-one is |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
735 creating a new log at the moment */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
736 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
737 for (;;) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 file = log->head; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 if (mail_transaction_log_file_lock(file, F_WRLCK) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
740 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
741 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
742 file->refcount++; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 ret = mail_transaction_log_refresh(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 if (--file->refcount == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
745 mail_transaction_logs_clean(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 file = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
747 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
748 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
749 if (ret == 0 && log->head == file) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 /* success */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
751 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
753 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
754 if (file != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 if (mail_transaction_log_file_lock(file, F_UNLCK) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
756 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
757 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
758 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
759 if (ret < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
760 break; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
761 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
762 /* try again */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
763 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
764 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
765 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
766 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
767 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
768 static int get_expunge_buf(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
769 struct mail_index_view *view, buffer_t *expunges) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
770 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
771 struct mail_transaction_log_view *sync_view; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
772 const struct mail_transaction_header *hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
773 const void *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
774 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
775 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
776 sync_view = mail_transaction_log_view_open(log); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
777 ret = mail_transaction_log_view_set(sync_view, view->log_file_seq, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
778 view->log_file_offset, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
779 log->head->hdr.file_seq, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
780 log->head->hdr.used_size, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
781 MAIL_TRANSACTION_TYPE_MASK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
782 while ((ret = mail_transaction_log_view_next(sync_view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
783 &hdr, &data, NULL)) == 1) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
784 if ((hdr->type & MAIL_TRANSACTION_TYPE_MASK) == |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
785 MAIL_TRANSACTION_EXPUNGE) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
786 mail_transaction_log_sort_expunges(expunges, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
787 data, hdr->size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
788 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
789 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
790 mail_transaction_log_view_close(sync_view); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
791 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
792 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
793 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
794 static void |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
795 log_view_fix_sequences(struct mail_index_view *view, buffer_t *view_expunges, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
796 buffer_t *buf, size_t record_size, int two, int uids) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
797 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
798 // FIXME: make sure this function works correctly |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
799 const struct mail_transaction_expunge *exp, *exp_end, *exp2; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
800 unsigned char *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
801 uint32_t *seq, expunges_before, count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
802 size_t src_idx, dest_idx, size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
803 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
804 if (buf == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
805 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
806 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
807 exp = buffer_get_data(view_expunges, &size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
808 exp_end = exp + (size / sizeof(*exp)); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
809 if (exp == exp_end) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
810 return; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
811 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
812 data = buffer_get_modifyable_data(buf, &size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
813 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
814 expunges_before = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
815 for (src_idx = dest_idx = 0; src_idx < size; src_idx += record_size) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
816 seq = (uint32_t *)&data[src_idx]; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
817 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
818 while (exp != exp_end && exp->seq1 < seq[0]) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
819 expunges_before += exp->seq2 - exp->seq1 + 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
820 exp++; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
821 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
822 if (exp != exp_end && exp->seq1 == seq[0]) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
823 /* this sequence was expunged */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
824 if (!two) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
825 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
826 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
827 /* we point to next non-expunged message */ |
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 (expunges_before != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
830 if (uids) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
831 (void)mail_index_lookup_uid(view, seq[0], |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
832 &seq[2]); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
833 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
834 seq[0] -= expunges_before; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
835 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
836 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
837 if (two) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
838 exp2 = exp; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
839 count = expunges_before; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
840 while (exp2 != exp_end && exp2->seq1 <= seq[1]) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
841 count += exp->seq2 - exp->seq1 + 1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
842 exp2++; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
843 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
844 if (seq[1] < count || seq[1]-count < seq[0]) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
845 /* whole range is expunged */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
846 continue; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
847 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
848 if (count != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
849 if (uids) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
850 (void)mail_index_lookup_uid(view, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
851 seq[1], |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
852 &seq[3]); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
853 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
854 seq[1] -= count; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
855 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
856 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
857 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
858 if (src_idx != dest_idx) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
859 memcpy(&data[dest_idx], &data[src_idx], record_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
860 dest_idx += record_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
861 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
862 buffer_set_used_size(buf, dest_idx); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
863 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
864 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
865 static int |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
866 mail_transaction_log_fix_sequences(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
867 struct mail_index_transaction *t) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
868 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
869 buffer_t *view_expunges; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
870 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
871 if (t->updates == NULL && t->cache_updates == NULL && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
872 t->expunges == NULL) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
873 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
874 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
875 /* all sequences are currently relative to given view. we have to |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
876 find out all the expunges since then, even the ones that aren't |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
877 yet synchronized to index file. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
878 view_expunges = buffer_create_dynamic(default_pool, 1024, (size_t)-1); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
879 if (get_expunge_buf(log, t->view, view_expunges) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
880 buffer_free(view_expunges); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
881 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
882 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
883 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
884 log_view_fix_sequences(t->view, view_expunges, t->updates, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
885 sizeof(struct mail_transaction_flag_update), |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
886 TRUE, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
887 log_view_fix_sequences(t->view, view_expunges, t->cache_updates, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
888 sizeof(struct mail_transaction_cache_update), |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
889 FALSE, FALSE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
890 log_view_fix_sequences(t->view, view_expunges, t->expunges, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
891 sizeof(struct mail_transaction_expunge), |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
892 TRUE, TRUE); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
893 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
894 buffer_free(view_expunges); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
895 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
896 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
897 |
1937
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
898 static int mail_transaction_log_fix_appends(struct mail_transaction_log *log, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
899 struct mail_index_transaction *t) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
900 { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
901 struct mail_transaction_log_view *sync_view; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
902 const struct mail_index_record *old, *old_end; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
903 struct mail_index_record *appends, *end, *rec, *dest; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
904 const struct mail_transaction_header *hdr; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
905 const void *data; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
906 size_t size; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
907 int ret, deleted = FALSE; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
908 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
909 if (t->appends == NULL) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
910 return 0; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
911 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
912 appends = buffer_get_modifyable_data(t->appends, &size); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
913 end = PTR_OFFSET(appends, size); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
914 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
915 if (appends == end) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
916 return 0; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
917 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
918 /* we'll just check that none of the appends are already in |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
919 transaction log. this could happen if we crashed before we had |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
920 a chance to update index file */ |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
921 sync_view = mail_transaction_log_view_open(log); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
922 ret = mail_transaction_log_view_set(sync_view, t->view->log_file_seq, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
923 t->view->log_file_offset, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
924 log->head->hdr.file_seq, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
925 log->head->hdr.used_size, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
926 MAIL_TRANSACTION_TYPE_MASK); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
927 while ((ret = mail_transaction_log_view_next(sync_view, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
928 &hdr, &data, NULL)) == 1) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
929 if ((hdr->type & MAIL_TRANSACTION_TYPE_MASK) != |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
930 MAIL_TRANSACTION_APPEND) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
931 continue; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
932 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
933 old = data; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
934 old_end = CONST_PTR_OFFSET(old, hdr->size); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
935 for (; old != old_end; old++) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
936 /* appends are sorted */ |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
937 for (rec = appends; rec != end; rec++) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
938 if (rec->uid >= old->uid) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
939 if (rec->uid == old->uid) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
940 rec->uid = 0; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
941 deleted = TRUE; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
942 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
943 break; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
944 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
945 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
946 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
947 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
948 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
949 if (deleted) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
950 /* compress deleted appends away */ |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
951 for (rec = dest = appends; rec != end; rec++) { |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
952 if (rec->uid != 0) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
953 dest++; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
954 else if (rec != dest) |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
955 *rec = *dest; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
956 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
957 buffer_set_used_size(t->appends, |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
958 (char *)dest - (char *)appends); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
959 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
960 |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
961 mail_transaction_log_view_close(sync_view); |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
962 return ret; |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
963 } |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
964 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
965 static int |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
966 log_append_buffer(struct mail_transaction_log_file *file, const buffer_t *buf, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
967 enum mail_transaction_type type, int external) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
968 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
969 struct mail_transaction_header hdr; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
970 const void *data; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
971 size_t size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
972 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
973 i_assert((type & MAIL_TRANSACTION_TYPE_MASK) != 0); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
974 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
975 if (buf != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
976 data = buffer_get_data(buf, &size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
977 if (size == 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
978 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
979 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
980 /* write only the header */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
981 data = NULL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
982 size = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
983 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
984 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
985 hdr.type = type; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
986 if (type == MAIL_TRANSACTION_EXPUNGE) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
987 hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
988 if (external) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
989 hdr.type |= MAIL_TRANSACTION_EXTERNAL; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
990 hdr.size = size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
991 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
992 if (pwrite_full(file->fd, &hdr, sizeof(hdr), file->hdr.used_size) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
993 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
994 file->hdr.used_size += sizeof(hdr); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
995 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
996 if (size != 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
997 if (pwrite_full(file->fd, data, size, file->hdr.used_size) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
998 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
999 file->hdr.used_size += size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1000 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1001 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1002 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1003 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1004 int mail_transaction_log_append(struct mail_index_transaction *t, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1005 uint32_t *log_file_seq_r, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1006 uoff_t *log_file_offset_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1007 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1008 struct mail_index_view *view = t->view; |
1940 | 1009 struct mail_index *index; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1010 struct mail_transaction_log *log; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1011 struct mail_transaction_log_file *file; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1012 size_t offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1013 uoff_t append_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1014 int ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1015 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1016 if (t->updates == NULL && t->cache_updates == NULL && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1017 t->expunges == NULL && t->appends == NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1018 /* nothing to append */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1019 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1020 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1021 |
1940 | 1022 index = mail_index_view_get_index(view); |
1023 log = index->log; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1024 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1025 if (log->index->log_locked) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1026 i_assert(view->external); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1027 } else { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1028 if (mail_transaction_log_lock_head(log) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1029 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1030 } |
1940 | 1031 |
1032 if (log->head->hdr.file_seq == index->hdr->log_file_seq && | |
1033 log->head->hdr.used_size > MAIL_TRANSACTION_LOG_ROTATE_SIZE) { | |
1034 /* everything synced in index, we can rotate. */ | |
1035 if (mail_transaction_log_rotate(log) < 0) { | |
1036 if (!log->index->log_locked) { | |
1037 (void)mail_transaction_log_file_lock(log->head, | |
1038 F_UNLCK); | |
1039 } | |
1040 return -1; | |
1041 } | |
1042 } | |
1043 | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1044 file = log->head; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1045 append_offset = file->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1046 |
1937
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
1047 if (mail_transaction_log_fix_sequences(log, t) < 0 || |
f56d502b248b
Ignore new mail appends if they're already in transaction log.
Timo Sirainen <tss@iki.fi>
parents:
1936
diff
changeset
|
1048 mail_transaction_log_fix_appends(log, t) < 0) { |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1049 if (!log->index->log_locked) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1050 (void)mail_transaction_log_file_lock(file, F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1051 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1052 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1053 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1054 ret = 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1055 if (t->appends != NULL) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1056 ret = log_append_buffer(file, t->appends, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1057 MAIL_TRANSACTION_APPEND, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1058 view->external); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1059 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1060 if (t->updates != NULL && ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1061 ret = log_append_buffer(file, t->updates, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1062 MAIL_TRANSACTION_FLAG_UPDATE, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1063 view->external); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1064 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1065 if (t->cache_updates != NULL && ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1066 ret = log_append_buffer(file, t->cache_updates, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1067 MAIL_TRANSACTION_CACHE_UPDATE, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1068 view->external); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1069 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1070 if (t->expunges != NULL && ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1071 ret = log_append_buffer(file, t->expunges, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1072 MAIL_TRANSACTION_EXPUNGE, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1073 view->external); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1074 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1075 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1076 if (ret == 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1077 /* rewrite used_size */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1078 offset = offsetof(struct mail_transaction_log_header, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1079 used_size); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1080 ret = pwrite_full(file->fd, &file->hdr.used_size, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1081 sizeof(file->hdr.used_size), offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1082 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1083 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1084 if (ret == 0 && (t->updates != NULL || t->appends != NULL) && |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1085 t->hide_transaction) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1086 mail_index_view_add_synced_transaction(view, file->hdr.file_seq, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1087 append_offset); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1088 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1089 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1090 if (ret < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1091 file->hdr.used_size = append_offset; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1092 mail_index_file_set_syscall_error(log->index, file->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1093 "pwrite()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1094 } else if (fsync(file->fd) < 0) { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1095 /* we don't know how much of it got written, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1096 it may be corrupted now.. */ |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1097 mail_index_file_set_syscall_error(log->index, file->filepath, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1098 "fsync()"); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1099 ret = -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1100 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1101 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1102 *log_file_seq_r = file->hdr.file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1103 *log_file_offset_r = file->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1104 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1105 if (!log->index->log_locked) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1106 (void)mail_transaction_log_file_lock(file, F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1107 return ret; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1108 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1109 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1110 int mail_transaction_log_sync_lock(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1111 uint32_t *file_seq_r, uoff_t *file_offset_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1112 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1113 i_assert(!log->index->log_locked); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1114 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1115 if (mail_transaction_log_lock_head(log) < 0) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1116 return -1; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1117 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1118 log->index->log_locked = TRUE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1119 *file_seq_r = log->head->hdr.file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1120 *file_offset_r = log->head->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1121 return 0; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1122 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1123 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1124 void mail_transaction_log_sync_unlock(struct mail_transaction_log *log) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1125 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1126 i_assert(log->index->log_locked); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1127 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1128 log->index->log_locked = FALSE; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1129 (void)mail_transaction_log_file_lock(log->head, F_UNLCK); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1130 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1131 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1132 void mail_transaction_log_get_head(struct mail_transaction_log *log, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1133 uint32_t *file_seq_r, uoff_t *file_offset_r) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1134 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1135 i_assert(log->index->log_locked); |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1136 |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1137 *file_seq_r = log->head->hdr.file_seq; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1138 *file_offset_r = log->head->hdr.used_size; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
1139 } |