]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_transaction_log_file_get_highest_modseq_at() - return error string
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 17 May 2017 13:28:58 +0000 (16:28 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 22 May 2017 12:12:35 +0000 (15:12 +0300)
This can help figuring out why some error happened when more context is
provided in the caller's error messages.

src/lib-index/mail-transaction-log-file.c
src/lib-index/mail-transaction-log-private.h
src/lib-index/mail-transaction-log-view.c
src/lib-index/test-mail-transaction-log-view.c

index f94b0683fd6515fefc154127510676871943265f..d0aaced25f2c4647ec4e6cf7f9753110df8c5e3c 100644 (file)
@@ -1171,7 +1171,8 @@ modseq_cache_get_modseq(struct mail_transaction_log_file *file, uint64_t modseq)
 
 static int
 log_get_synced_record(struct mail_transaction_log_file *file, uoff_t *offset,
-                     const struct mail_transaction_header **hdr_r)
+                     const struct mail_transaction_header **hdr_r,
+                     const char **error_r)
 {
        const struct mail_transaction_header *hdr;
        uint32_t trans_size;
@@ -1184,10 +1185,11 @@ log_get_synced_record(struct mail_transaction_log_file *file, uoff_t *offset,
        trans_size = mail_index_offset_to_uint32(hdr->size);
        if (trans_size < sizeof(*hdr) ||
            *offset - file->buffer_offset + trans_size > file->buffer->used) {
-               mail_transaction_log_file_set_corrupted(file,
+               *error_r = t_strdup_printf(
                        "Transaction log corrupted unexpectedly at "
                        "%"PRIuUOFF_T": Invalid size %u (type=%x)",
                        *offset, trans_size, hdr->type);
+               mail_transaction_log_file_set_corrupted(file, "%s", *error_r);
                return -1;
        }
        *offset += trans_size;
@@ -1197,7 +1199,8 @@ log_get_synced_record(struct mail_transaction_log_file *file, uoff_t *offset,
 
 int mail_transaction_log_file_get_highest_modseq_at(
                struct mail_transaction_log_file *file,
-               uoff_t offset, uint64_t *highest_modseq_r)
+               uoff_t offset, uint64_t *highest_modseq_r,
+               const char **error_r)
 {
        const struct mail_transaction_header *hdr;
        struct modseq_cache *cache;
@@ -1230,7 +1233,7 @@ int mail_transaction_log_file_get_highest_modseq_at(
 
        ret = mail_transaction_log_file_map(file, cur_offset, offset, &reason);
        if (ret <= 0) {
-               mail_index_set_error(file->log->index,
+               *error_r = t_strdup_printf(
                        "Failed to map transaction log %s for getting modseq "
                        "at offset=%"PRIuUOFF_T" with start_offset=%"PRIuUOFF_T": %s",
                        file->filepath, offset, cur_offset, reason);
@@ -1240,7 +1243,7 @@ int mail_transaction_log_file_get_highest_modseq_at(
        i_assert(cur_offset >= file->buffer_offset);
        i_assert(cur_offset + file->buffer->used >= offset);
        while (cur_offset < offset) {
-               if (log_get_synced_record(file, &cur_offset, &hdr) < 0)
+               if (log_get_synced_record(file, &cur_offset, &hdr, error_r) < 0)
                        return- 1;
                mail_transaction_update_modseq(hdr, hdr + 1, &cur_modseq,
                        MAIL_TRANSACTION_LOG_HDR_VERSION(&file->hdr));
@@ -1313,8 +1316,11 @@ int mail_transaction_log_file_get_modseq_next_offset(
 
        i_assert(cur_offset >= file->buffer_offset);
        while (cur_offset < file->sync_offset) {
-               if (log_get_synced_record(file, &cur_offset, &hdr) < 0)
+               if (log_get_synced_record(file, &cur_offset, &hdr, &reason) < 0) {
+                       mail_index_set_error(file->log->index,
+                               "%s: %s", file->filepath, reason);
                        return -1;
+               }
                mail_transaction_update_modseq(hdr, hdr + 1, &cur_modseq,
                        MAIL_TRANSACTION_LOG_HDR_VERSION(&file->hdr));
                if (cur_modseq >= modseq)
index 30edd662fdc0da15574ca0072bb0f316e5279f07..f56434b40155a005d7f1825a336786c363ea6980 100644 (file)
@@ -153,7 +153,8 @@ void mail_transaction_update_modseq(const struct mail_transaction_header *hdr,
                                    unsigned int version);
 int mail_transaction_log_file_get_highest_modseq_at(
                struct mail_transaction_log_file *file,
-               uoff_t offset, uint64_t *highest_modseq_r);
+               uoff_t offset, uint64_t *highest_modseq_r,
+               const char **error_r);
 int mail_transaction_log_file_get_modseq_next_offset(
                struct mail_transaction_log_file *file,
                uint64_t modseq, uoff_t *next_offset_r);
index cfd32ef3dfa5a96421c631c4e6ece1a8f67fb526..6fa4fcb9975d615767b9431ef2a8dd25e9f2c1cc 100644 (file)
@@ -336,10 +336,8 @@ int mail_transaction_log_view_set(struct mail_transaction_log_view *view,
        view->broken = FALSE;
 
        if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
-                               view->cur_offset, &view->prev_modseq) < 0) {
-               *reason_r = "Failed to get modseq";
+                               view->cur_offset, &view->prev_modseq, reason_r) < 0)
                return -1;
-       }
 
        i_assert(view->cur_offset <= view->cur->sync_offset);
        return 1;
@@ -401,8 +399,12 @@ int mail_transaction_log_view_set_all(struct mail_transaction_log_view *view)
        view->broken = FALSE;
 
        if (mail_transaction_log_file_get_highest_modseq_at(view->cur,
-                               view->cur_offset, &view->prev_modseq) < 0)
+                       view->cur_offset, &view->prev_modseq, &reason) < 0) {
+               mail_index_set_error(file->log->index,
+                       "Failed to get modseq in %s for all-view: %s",
+                       file->filepath, reason);
                return -1;
+       }
        return 0;
 }
 
index 4ea5c8baba44356c0622903725b9e20e335d3761..547677d7f3513c37f694f319f70dd5f05ee8515a 100644 (file)
@@ -49,7 +49,8 @@ int mail_transaction_log_file_map(struct mail_transaction_log_file *file ATTR_UN
 
 int mail_transaction_log_file_get_highest_modseq_at(
                struct mail_transaction_log_file *file ATTR_UNUSED,
-               uoff_t offset ATTR_UNUSED, uint64_t *highest_modseq_r)
+               uoff_t offset ATTR_UNUSED, uint64_t *highest_modseq_r,
+               const char **error_r ATTR_UNUSED)
 {
        *highest_modseq_r = 0;
        return 0;