]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Added mail_get_stream_because() and mail_get_hdr_stream_because()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 25 Jul 2016 18:16:39 +0000 (14:16 -0400)
committerGitLab <gitlab@git.dovecot.net>
Wed, 3 Aug 2016 08:52:57 +0000 (11:52 +0300)
With mail_debug=yes each mail access is now logged with a reason. This can
be helpful when figuring out why something isn't in dovecot.index.cache.

src/lib-storage/index/index-mail.c
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.h
src/lib-storage/mail.c

index 9270947eb4a3bc440c7e84e0d849f2af17759c88..ffb6e324965e684f1af740d1c26f9ee0ee97d32d 100644 (file)
@@ -1077,9 +1077,11 @@ void index_mail_stream_log_failure_for(struct index_mail *mail,
                        return;
        }
        mail_storage_set_critical(_mail->box->storage,
-               "read(%s) failed: %s (uid=%u, box=%s)",
+               "read(%s) failed: %s (uid=%u, box=%s, read reason=%s)",
                i_stream_get_name(input), i_stream_get_error(input),
-               _mail->uid, mailbox_get_vname(_mail->box));
+               _mail->uid, mailbox_get_vname(_mail->box),
+               mail->mail.get_stream_reason == NULL ? "" :
+               mail->mail.get_stream_reason);
 }
 
 static int index_mail_parse_body(struct index_mail *mail,
@@ -1142,6 +1144,14 @@ int index_mail_init_stream(struct index_mail *mail,
        bool has_nuls;
        int ret;
 
+       if (_mail->box->storage->user->mail_debug &&
+           mail->mail.get_stream_reason != NULL &&
+           mail->mail.get_stream_reason[0] != '\0') {
+               i_debug("Mailbox %s: Opened mail UID=%u because: %s",
+                       _mail->box->vname, _mail->uid,
+                       mail->mail.get_stream_reason);
+       }
+
        if (!data->initialized_wrapper_stream &&
            _mail->transaction->stats_track) {
                input = i_stream_create_mail(_mail, data->stream,
index f330798db671fdd1234299444067d07e7d95c35f..072f2022b90ba67e5882963b15bea7d616cdcd3b 100644 (file)
@@ -503,6 +503,8 @@ struct mail_private {
 
        pool_t pool, data_pool;
        ARRAY(union mail_module_context *) module_contexts;
+
+       const char *get_stream_reason;
 };
 
 struct mailbox_list_context {
index b4b8cd43bc79b17c803118f8527821aeb1728629..300604aa983ba58d51bbb52712e05c839bc8fd07 100644 (file)
@@ -857,10 +857,21 @@ int mail_get_header_stream(struct mail *mail,
 int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
                    struct message_size *body_size, struct istream **stream_r)
        ATTR_NULL(2, 3);
+/* Same as mail_get_stream(), but specify a reason why the mail is being read.
+   This can be useful for debugging purposes. */
+int mail_get_stream_because(struct mail *mail, struct message_size *hdr_size,
+                           struct message_size *body_size,
+                           const char *reason, struct istream **stream_r)
+       ATTR_NULL(2, 3);
 /* Similar to mail_get_stream(), but the stream may or may not contain the
    message body. */
 int mail_get_hdr_stream(struct mail *mail, struct message_size *hdr_size,
                        struct istream **stream_r) ATTR_NULL(2);
+/* Same as mail_get_hdr_stream(), but specify a reason why the header is being
+   read. This can be useful for debugging purposes. */
+int mail_get_hdr_stream_because(struct mail *mail,
+                               struct message_size *hdr_size,
+                               const char *reason, struct istream **stream_r);
 /* Returns the message part's body decoded to 8bit binary. If the
    Content-Transfer-Encoding isn't supported, returns -1 and sets error to
    MAIL_ERROR_CONVERSION. If the part refers to a multipart, all of its
index 4be8f73c1a62ddba234b6f9ad497efa7a6f3f714..47b6b232b0c0f1fe7c67421e08384ee8dde92902 100644 (file)
@@ -246,6 +246,14 @@ void mail_set_aborted(struct mail *mail)
 
 int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
                    struct message_size *body_size, struct istream **stream_r)
+{
+       return mail_get_stream_because(mail, hdr_size, body_size,
+                                      "mail stream", stream_r);
+}
+
+int mail_get_stream_because(struct mail *mail, struct message_size *hdr_size,
+                           struct message_size *body_size,
+                           const char *reason, struct istream **stream_r)
 {
        struct mail_private *p = (struct mail_private *)mail;
        int ret;
@@ -255,13 +263,22 @@ int mail_get_stream(struct mail *mail, struct message_size *hdr_size,
                return -1;
        }
        T_BEGIN {
+               p->get_stream_reason = reason;
                ret = p->v.get_stream(mail, TRUE, hdr_size, body_size, stream_r);
+               p->get_stream_reason = "";
        } T_END;
        return ret;
 }
 
 int mail_get_hdr_stream(struct mail *mail, struct message_size *hdr_size,
                        struct istream **stream_r)
+{
+       return mail_get_hdr_stream_because(mail, hdr_size, "header stream", stream_r);
+}
+
+int mail_get_hdr_stream_because(struct mail *mail,
+                               struct message_size *hdr_size,
+                               const char *reason, struct istream **stream_r)
 {
        struct mail_private *p = (struct mail_private *)mail;
        int ret;
@@ -271,7 +288,9 @@ int mail_get_hdr_stream(struct mail *mail, struct message_size *hdr_size,
                return -1;
        }
        T_BEGIN {
+               p->get_stream_reason = reason;
                ret = p->v.get_stream(mail, FALSE, hdr_size, NULL, stream_r);
+               p->get_stream_reason = "";
        } T_END;
        return ret;
 }