]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: dsync - Replace i_<log>() with e_<log>()
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 30 Aug 2022 13:18:27 +0000 (13:18 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 6 Oct 2022 18:01:26 +0000 (18:01 +0000)
dsync-brain
dsync-brain-mailbox-tree-sync
dsync-brain-mailbox-tree
dsync-brain-mailbox
dsync-brain-mails
dsync-mailbox-tree-sync
dsync-mailbox

src/doveadm/dsync/dsync-brain-mailbox-tree-sync.c
src/doveadm/dsync/dsync-brain-mailbox-tree.c
src/doveadm/dsync/dsync-brain-mailbox.c
src/doveadm/dsync/dsync-brain-mails.c
src/doveadm/dsync/dsync-brain.c
src/doveadm/dsync/dsync-mailbox-tree-sync.c
src/doveadm/dsync/dsync-mailbox.c

index 2030e040d2424ea030d0edf845fc575f6eeb00dd..5d64daba3516f0225661749ed1bf3ae6135e8ad6 100644 (file)
@@ -24,7 +24,7 @@ sync_create_box(struct dsync_brain *brain, struct mailbox *box,
        if (mailbox_create(box, &update, FALSE) < 0) {
                errstr = mailbox_get_last_internal_error(box, &error);
                if (error != MAIL_ERROR_EXISTS) {
-                       i_error("Can't create mailbox %s: %s",
+                       e_error(brain->event, "Can't create mailbox %s: %s",
                                mailbox_get_vname(box), errstr);
                        *error_r = error;
                        return -1;
@@ -37,7 +37,7 @@ sync_create_box(struct dsync_brain *brain, struct mailbox *box,
        }
        /* sync the mailbox so we can look up its latest status */
        if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-               i_error("Can't sync mailbox %s: %s",
+               e_error(brain->event, "Can't sync mailbox %s: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, error_r));
                return -1;
@@ -50,7 +50,7 @@ sync_create_box(struct dsync_brain *brain, struct mailbox *box,
           mismatching UIDVALIDITY is handled later, because we choose it by
           checking which mailbox has more messages */
        if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, &metadata) < 0) {
-               i_error("Can't get mailbox GUID %s: %s",
+               e_error(brain->event, "Can't get mailbox GUID %s: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, error_r));
                return -1;
@@ -65,18 +65,15 @@ sync_create_box(struct dsync_brain *brain, struct mailbox *box,
 
        if ((ret > 0 && !brain->backup_recv &&
             !brain->backup_send) || (ret != 0 && brain->backup_recv)) {
-               if (brain->debug) {
-                       i_debug("brain %c: Changing mailbox %s GUID %s -> %s",
-                               brain->master_brain ? 'M' : 'S',
-                               mailbox_get_vname(box),
-                               guid_128_to_string(metadata.guid),
-                               guid_128_to_string(mailbox_guid));
-               }
+               e_debug(brain->event, "Changing mailbox %s GUID %s -> %s",
+                       mailbox_get_vname(box),
+                       guid_128_to_string(metadata.guid),
+                       guid_128_to_string(mailbox_guid));
                i_zero(&update);
                memcpy(update.mailbox_guid, mailbox_guid,
                       sizeof(update.mailbox_guid));
                if (mailbox_update(box, &update) < 0) {
-                       i_error("Can't update mailbox GUID %s: %s",
+                       e_error(brain->event, "Can't update mailbox GUID %s: %s",
                                mailbox_get_vname(box),
                                mailbox_get_last_internal_error(box, error_r));
                        return -1;
@@ -84,27 +81,25 @@ sync_create_box(struct dsync_brain *brain, struct mailbox *box,
                /* verify that the update worked */
                if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID,
                                         &metadata) < 0) {
-                       i_error("Can't get mailbox GUID %s: %s",
+                       e_error(brain->event, "Can't get mailbox GUID %s: %s",
                                mailbox_get_vname(box),
                                mailbox_get_last_internal_error(box, error_r));
                        return -1;
                }
                if (memcmp(mailbox_guid, metadata.guid,
                           sizeof(metadata.guid)) != 0) {
-                       i_error("Backend didn't update mailbox %s GUID",
+                       e_error(brain->event,
+                               "Backend didn't update mailbox %s GUID",
                                mailbox_get_vname(box));
                        *error_r = MAIL_ERROR_TEMP;
                        return -1;
                }
        } else if (ret < 0) {
-               if (brain->debug) {
-                       i_debug("brain %c: Other brain should change mailbox "
-                               "%s GUID %s -> %s",
-                               brain->master_brain ? 'M' : 'S',
-                               mailbox_get_vname(box),
-                               guid_128_to_string(mailbox_guid),
-                               guid_128_to_string(metadata.guid));
-               }
+               e_debug(brain->event,
+                       "Other brain should change mailbox %s GUID %s -> %s",
+                       mailbox_get_vname(box),
+                       guid_128_to_string(mailbox_guid),
+                       guid_128_to_string(metadata.guid));
        }
        return 0;
 }
@@ -129,7 +124,8 @@ int dsync_brain_mailbox_tree_sync_change(struct dsync_brain *brain,
                ret = dsync_brain_mailbox_alloc(brain, change->mailbox_guid,
                                                &box, &errstr, error_r);
                if (ret < 0) {
-                       i_error("Mailbox sync: Couldn't allocate mailbox %s GUID %s: %s",
+                       e_error(brain->event,
+                               "Mailbox sync: Couldn't allocate mailbox %s GUID %s: %s",
                                change->full_name,
                                guid_128_to_string(change->mailbox_guid), errstr);
                        return -1;
@@ -156,7 +152,8 @@ int dsync_brain_mailbox_tree_sync_change(struct dsync_brain *brain,
                                change->full_name, errstr));
                        return 0;
                } else {
-                       i_error("Mailbox sync: mailbox_list_delete_dir failed: %s",
+                       e_error(brain->event,
+                               "Mailbox sync: mailbox_list_delete_dir failed: %s",
                                errstr);
                        *error_r = error;
                        return -1;
@@ -219,7 +216,8 @@ int dsync_brain_mailbox_tree_sync_change(struct dsync_brain *brain,
                                mailbox_get_vname(box), func_name, errstr));
                        ret = 0;
                } else {
-                       i_error("Mailbox %s sync: %s failed: %s",
+                       e_error(brain->event,
+                               "Mailbox %s sync: %s failed: %s",
                                mailbox_get_vname(box), func_name, errstr);
                        *error_r = error;
                }
index 980a013cb9b1c01ceef8df52d3ec0eb86f5d66bb..ced073f983ea7f83363d26afe0bd7c13e83aede7 100644 (file)
@@ -66,10 +66,8 @@ void dsync_brain_mailbox_trees_init(struct dsync_brain *brain)
        for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) {
                if (!dsync_brain_want_namespace(brain, ns))
                        continue;
-               if (brain->debug)
-                       i_debug("brain %c: Namespace %s has location %s",
-                               brain->master_brain ? 'M' : 'S',
-                               ns->prefix, ns->set->location);
+               e_debug(brain->event, "Namespace %s has location %s",
+                       ns->prefix, ns->set->location);
                if (dsync_mailbox_tree_fill(brain->local_mailbox_tree, ns,
                                            brain->sync_box,
                                            brain->sync_box_guid,
@@ -119,11 +117,8 @@ void dsync_brain_send_mailbox_tree(struct dsync_brain *brain)
                T_BEGIN {
                        const char *const *parts;
 
-                       if (brain->debug) {
-                               i_debug("brain %c: Local mailbox tree: %s %s",
-                                       brain->master_brain ? 'M' : 'S', full_name,
-                                       dsync_mailbox_node_to_string(node));
-                       }
+                       e_debug(brain->event, "Local mailbox tree: %s %s",
+                               full_name, dsync_mailbox_node_to_string(node));
 
                        parts = dsync_brain_mailbox_to_parts(brain, full_name);
                        ret = dsync_ibc_send_mailbox_tree_node(brain->ibc,
@@ -434,12 +429,9 @@ dsync_brain_recv_mailbox_tree_add(struct dsync_brain *brain,
 
        if (dsync_get_mailbox_name(brain, parts, &name, &ns) < 0)
                return -1;
-       if (brain->debug) {
-               i_debug("brain %c: Remote mailbox tree: %s %s",
-                       brain->master_brain ? 'M' : 'S',
-                       t_strarray_join(parts, sep),
-                       dsync_mailbox_node_to_string(remote_node));
-       }
+       e_debug(brain->event, "Remote mailbox tree: %s %s",
+               t_strarray_join(parts, sep),
+               dsync_mailbox_node_to_string(remote_node));
        node = dsync_mailbox_tree_get(brain->remote_mailbox_tree, name);
        node->ns = ns;
        dsync_mailbox_node_copy_data(node, remote_node);
@@ -464,7 +456,8 @@ bool dsync_brain_recv_mailbox_tree(struct dsync_brain *brain)
                                        brain, parts, remote_node, sep);
                } T_END;
                if (ret2 < 0) {
-                       i_error("Couldn't find namespace for mailbox %s",
+                       e_error(brain->event,
+                               "Couldn't find namespace for mailbox %s",
                                t_strarray_join(parts, sep));
                        brain->failed = TRUE;
                        return TRUE;
@@ -475,7 +468,8 @@ bool dsync_brain_recv_mailbox_tree(struct dsync_brain *brain)
 
        if (dsync_mailbox_tree_build_guid_hash(brain->remote_mailbox_tree,
                                               &dup_node1, &dup_node2) < 0) {
-               i_error("Remote sent duplicate mailbox GUID %s for mailboxes %s and %s",
+               e_error(brain->event,
+                       "Remote sent duplicate mailbox GUID %s for mailboxes %s and %s",
                        guid_128_to_string(dup_node1->mailbox_guid),
                        dsync_mailbox_node_get_full_name(brain->remote_mailbox_tree,
                                                         dup_node1),
@@ -593,8 +587,9 @@ bool dsync_brain_recv_mailbox_tree_deletes(struct dsync_brain *brain)
                if (brain->debug) {
                        const char *node_name = node == NULL ? "" :
                                dsync_mailbox_node_get_full_name(brain->local_mailbox_tree, node);
-                       i_debug("brain %c: Remote mailbox tree deletion: guid=%s type=%s timestamp=%ld name=%s local update=%s",
-                               brain->master_brain ? 'M' : 'S',
+                       e_debug(brain->event,
+                               "Remote mailbox tree deletion: guid=%s type=%s "
+                               "timestamp=%ld name=%s local update=%s",
                                guid_128_to_string(deletes[i].guid),
                                dsync_mailbox_delete_type_to_string(deletes[i].type),
                                deletes[i].timestamp, node_name, status);
index 9c0d81b0334a42422771b1cdf453e40ba2f951f6..6a780b2a42b86905fb9223369321917b422d20ba 100644 (file)
@@ -270,7 +270,8 @@ int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
                                              last_common_pvt_modseq,
                                              &pvt_too_old);
        if (ret < 0) {
-               i_error("Failed to read transaction log for mailbox %s",
+               e_error(brain->event,
+                       "Failed to read transaction log for mailbox %s",
                        mailbox_get_vname(brain->box));
                brain->failed = TRUE;
                return -1;
@@ -318,7 +319,8 @@ int dsync_brain_sync_mailbox_open(struct dsync_brain *brain,
                }
        }
        if (ret == 0) {
-               i_warning("Failed to do incremental sync for mailbox %s, "
+               e_warning(brain->event,
+                         "Failed to do incremental sync for mailbox %s, "
                          "retry with a full sync (%s)",
                          mailbox_get_vname(brain->box), desync_reason);
                dsync_brain_set_changes_during_sync(brain, t_strdup_printf(
@@ -373,7 +375,7 @@ void dsync_brain_sync_mailbox_deinit(struct dsync_brain *brain)
                         brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_CHANGED);
                if (dsync_mailbox_export_deinit(&brain->box_exporter,
                                                &errstr, &error) < 0)
-                       i_error("Mailbox export failed: %s", errstr);
+                       e_error(brain->event, "Mailbox export failed: %s", errstr);
        }
        if (brain->box_importer != NULL) {
                uint32_t last_common_uid, last_messages_count;
@@ -428,7 +430,7 @@ static int dsync_box_get(struct mailbox *box, struct dsync_mailbox *dsync_box_r,
                           mainly for invalid mbox files. */
                        return 0;
                }
-               i_error("Failed to access mailbox %s: %s",
+               e_error(box->event, "Failed to access mailbox %s: %s",
                        mailbox_get_vname(box), errstr);
                *error_r = error;
                return -1;
@@ -549,7 +551,7 @@ dsync_brain_try_next_mailbox(struct dsync_brain *brain, struct mailbox **box_r,
                        return -1;
                }
                if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-                       i_error("Can't sync mailbox %s: %s",
+                       e_error(brain->event, "Can't sync mailbox %s: %s",
                                mailbox_get_vname(box),
                                mailbox_get_last_internal_error(box, &brain->mail_error));
                        brain->failed = TRUE;
@@ -771,7 +773,7 @@ bool dsync_brain_mailbox_update_pre(struct dsync_brain *brain,
        }
 
        if (mailbox_update(box, &update) < 0) {
-               i_error("Couldn't update mailbox %s metadata: %s",
+               e_error(brain->event, "Couldn't update mailbox %s metadata: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, &brain->mail_error));
                brain->failed = TRUE;
@@ -786,11 +788,8 @@ dsync_brain_slave_send_mailbox_lost(struct dsync_brain *brain,
 {
        struct dsync_mailbox delete_box;
 
-       if (brain->debug) {
-               i_debug("brain %c: We don't have mailbox %s",
-                       brain->master_brain ? 'M' : 'S',
-                       guid_128_to_string(dsync_box->mailbox_guid));
-       }
+       e_debug(brain->event, "We don't have mailbox %s",
+               guid_128_to_string(dsync_box->mailbox_guid));
        i_zero(&delete_box);
        memcpy(delete_box.mailbox_guid, dsync_box->mailbox_guid,
               sizeof(delete_box.mailbox_guid));
@@ -825,7 +824,7 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
 
        if (dsync_brain_mailbox_alloc(brain, dsync_box->mailbox_guid,
                                      &box, &errstr, &error) < 0) {
-               i_error("Couldn't allocate mailbox GUID %s: %s",
+               e_error(brain->event, "Couldn't allocate mailbox GUID %s: %s",
                        guid_128_to_string(dsync_box->mailbox_guid), errstr);
                brain->mail_error = error;
                brain->failed = TRUE;
@@ -834,12 +833,9 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
        if (box == NULL) {
                /* mailbox was probably deleted/renamed during sync */
                if (brain->backup_send && brain->no_backup_overwrite) {
-                       if (brain->debug) {
-                               i_debug("brain %c: Ignore nonexistent "
-                                       "mailbox GUID %s with -1 sync",
-                                       brain->master_brain ? 'M' : 'S',
+                               e_debug(brain->event,
+                                       "Ignore nonexistent mailbox GUID %s with -1 sync",
                                        guid_128_to_string(dsync_box->mailbox_guid));
-                       }
                        dsync_brain_slave_send_mailbox_lost(brain, dsync_box, TRUE);
                        return TRUE;
                }
@@ -857,7 +853,7 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
                return TRUE;
        }
        if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-               i_error("Can't sync mailbox %s: %s",
+               e_error(brain->event, "Can't sync mailbox %s: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, &brain->mail_error));
                file_lock_free(&lock);
@@ -875,11 +871,8 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
                        return TRUE;
                }
                /* another process just deleted this mailbox? */
-               if (brain->debug) {
-                       i_debug("brain %c: Skipping lost mailbox %s",
-                               brain->master_brain ? 'M' : 'S',
-                               guid_128_to_string(dsync_box->mailbox_guid));
-               }
+               e_debug(brain->event, "Skipping lost mailbox %s",
+                       guid_128_to_string(dsync_box->mailbox_guid));
                dsync_brain_slave_send_mailbox_lost(brain, dsync_box, FALSE);
                return TRUE;
        }
@@ -892,21 +885,15 @@ bool dsync_brain_slave_recv_mailbox(struct dsync_brain *brain)
 
        if (!dsync_boxes_need_sync(brain, &local_dsync_box, dsync_box, &reason)) {
                /* no fields appear to have changed, skip this mailbox */
-               if (brain->debug) {
-                       i_debug("brain %c: Skipping unchanged mailbox %s",
-                               brain->master_brain ? 'M' : 'S',
-                               guid_128_to_string(dsync_box->mailbox_guid));
-               }
+               e_debug(brain->event, "Skipping unchanged mailbox %s",
+                       guid_128_to_string(dsync_box->mailbox_guid));
                dsync_ibc_send_mailbox(brain->ibc, &local_dsync_box);
                file_lock_free(&lock);
                mailbox_free(&box);
                return TRUE;
        }
-       if (brain->debug) {
-               i_debug("brain %c: Syncing mailbox %s: %s",
-                       brain->master_brain ? 'M' : 'S',
-                       guid_128_to_string(dsync_box->mailbox_guid), reason);
-       }
+       e_debug(brain->event, "Syncing mailbox %s: %s",
+               guid_128_to_string(dsync_box->mailbox_guid), reason);
 
        /* start export/import */
        dsync_brain_sync_mailbox_init(brain, box, lock, &local_dsync_box, FALSE);
index 3feea20f5f78fef51e445c9f5b7ab7ea6fe5e7a8..7865148062930079be97307debea582857f9853c 100644 (file)
@@ -30,23 +30,21 @@ static bool dsync_brain_master_sync_recv_mailbox(struct dsync_brain *brain)
        if ((ret = dsync_ibc_recv_mailbox(brain->ibc, &dsync_box)) == 0)
                return FALSE;
        if (ret == DSYNC_IBC_RECV_RET_FINISHED) {
-               i_error("Remote sent end-of-list instead of a mailbox");
+               e_error(brain->event, "Remote sent end-of-list instead of a mailbox");
                brain->failed = TRUE;
                return TRUE;
        }
        if (memcmp(dsync_box->mailbox_guid, brain->local_dsync_box.mailbox_guid,
                   sizeof(dsync_box->mailbox_guid)) != 0) {
-               i_error("Remote sent mailbox with a wrong GUID");
+               e_error(brain->event, "Remote sent mailbox with a wrong GUID");
                brain->failed = TRUE;
                return TRUE;
        }
 
        if (dsync_box->mailbox_ignore) {
                /* ignore this box */
-               if (brain->debug)
-                       i_debug("brain %c: Ignoring missing remote box GUID %s",
-                               brain->master_brain ? 'M' : 'S',
-                               guid_128_to_string(dsync_box->mailbox_guid));
+               e_debug(brain->event, "Ignoring missing remote box GUID %s",
+                       guid_128_to_string(dsync_box->mailbox_guid));
                dsync_brain_sync_mailbox_deinit(brain);
                return TRUE;
        }
@@ -70,11 +68,8 @@ static bool dsync_brain_master_sync_recv_mailbox(struct dsync_brain *brain)
                dsync_brain_sync_mailbox_deinit(brain);
                return TRUE;
        }
-       if (brain->debug) {
-               i_debug("brain %c: Syncing mailbox %s: %s",
-                       brain->master_brain ? 'M' : 'S',
-                       guid_128_to_string(dsync_box->mailbox_guid), reason);
-       }
+       e_debug(brain->event, "Syncing mailbox %s: %s",
+               guid_128_to_string(dsync_box->mailbox_guid), reason);
        if ((ret = dsync_brain_sync_mailbox_open(brain, dsync_box)) < 0)
                return TRUE;
        if (resync)
@@ -122,7 +117,7 @@ static int dsync_brain_export_deinit(struct dsync_brain *brain)
 
        if (dsync_mailbox_export_deinit(&brain->box_exporter,
                                        &errstr, &error) < 0) {
-               i_error("Exporting mailbox %s failed: %s",
+               e_error(brain->event, "Exporting mailbox %s failed: %s",
                        mailbox_get_vname(brain->box), errstr);
                brain->mail_error = error;
                brain->failed = TRUE;
@@ -308,10 +303,8 @@ static bool dsync_brain_recv_mail(struct dsync_brain *brain)
                dsync_brain_sync_half_finished(brain);
                return TRUE;
        }
-       if (brain->debug) {
-               i_debug("brain %c: import mail uid %u guid %s",
-                       brain->master_brain ? 'M' : 'S', mail->uid, mail->guid);
-       }
+               e_debug(brain->event, "import mail uid %u guid %s",
+                       mail->uid, mail->guid);
        if (dsync_mailbox_import_mail(brain->box_importer, mail) < 0)
                brain->failed = TRUE;
        i_stream_unref(&mail->input);
@@ -354,7 +347,8 @@ static bool dsync_brain_recv_last_common(struct dsync_brain *brain)
        if ((ret = dsync_ibc_recv_mailbox_state(brain->ibc, &state)) == 0)
                return FALSE;
        if (ret == DSYNC_IBC_RECV_RET_FINISHED) {
-               i_error("Remote sent end-of-list instead of a mailbox state");
+               e_error(brain->event,
+                       "Remote sent end-of-list instead of a mailbox state");
                brain->failed = TRUE;
                return TRUE;
        }
index 1c6b413cbfee4179f3fe1f39f4d0e10f11534ef5..fcf208feb64eb40992086c34578e8d4dcc6e6776 100644 (file)
@@ -252,15 +252,13 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc,
        else if (dsync_mailbox_states_import(brain->mailbox_states, brain->pool,
                                             set->state, &error) < 0) {
                hash_table_clear(brain->mailbox_states, FALSE);
-               i_error("Saved sync state is invalid, "
+               e_error(brain->event,
+                       "Saved sync state is invalid, "
                        "falling back to full sync: %s", error);
                brain->sync_type = sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL;
        } else {
-               if (brain->debug) {
-                       i_debug("brain %c: Imported mailbox states:",
-                               brain->master_brain ? 'M' : 'S');
-                       dsync_brain_mailbox_states_dump(brain);
-               }
+               e_debug(brain->event, "Imported mailbox states:");
+               dsync_brain_mailbox_states_dump(brain);
        }
        dsync_brain_mailbox_trees_init(brain);
 
@@ -344,7 +342,8 @@ static void dsync_brain_purge(struct dsync_brain *brain)
 
                storage = mail_namespace_get_default_storage(ns);
                if (mail_storage_purge(storage) < 0) {
-                       i_error("Purging namespace '%s' failed: %s", ns->prefix,
+                       e_error(brain->event,
+                               "Purging namespace '%s' failed: %s", ns->prefix,
                                mail_storage_get_last_internal_error(storage, NULL));
                }
        }
@@ -358,7 +357,7 @@ int dsync_brain_deinit(struct dsync_brain **_brain, enum mail_error *error_r)
        *_brain = NULL;
 
        if (dsync_ibc_has_timed_out(brain->ibc)) {
-               i_error("Timeout during state=%s%s",
+               e_error(brain->event, "Timeout during state=%s%s",
                        dsync_state_names[brain->state],
                        brain->state != DSYNC_STATE_SYNC_MAILS ? "" :
                        t_strdup_printf(" (send=%s recv=%s)",
@@ -391,11 +390,7 @@ int dsync_brain_deinit(struct dsync_brain **_brain, enum mail_error *error_r)
        if (brain->lock_fd != -1) {
                /* unlink the lock file before it gets unlocked */
                i_unlink(brain->lock_path);
-               if (brain->debug) {
-                       i_debug("brain %c: Unlocked %s",
-                               brain->master_brain ? 'M' : 'S',
-                               brain->lock_path);
-               }
+               e_debug(brain->event, "Unlocked %s", brain->lock_path);
                file_lock_free(&brain->lock);
                i_close_fd(&brain->lock_fd);
        }
@@ -425,32 +420,26 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname)
 
        if ((ret = strcmp(remote_hostname, local_hostname)) < 0) {
                /* locking done by remote */
-               if (brain->debug) {
-                       i_debug("brain %c: Locking done by remote "
-                               "(local hostname=%s, remote hostname=%s)",
-                               brain->master_brain ? 'M' : 'S',
-                               local_hostname, remote_hostname);
-               }
+               e_debug(brain->event,
+                       "Locking done by remote (local hostname=%s, remote hostname=%s)",
+                       local_hostname, remote_hostname);
                return 0;
        }
        if (ret == 0 && !brain->master_brain) {
                /* running dsync within the same server.
                   locking done by master brain. */
-               if (brain->debug) {
-                       i_debug("brain %c: Locking done by local master-brain "
-                               "(local hostname=%s, remote hostname=%s)",
-                               brain->master_brain ? 'M' : 'S',
-                               local_hostname, remote_hostname);
-               }
+               e_debug(brain->event,
+                       "Locking done by local master-brain (local hostname=%s, remote hostname=%s)",
+                       local_hostname, remote_hostname);
                return 0;
        }
 
        if ((ret = mail_user_get_home(brain->user, &home)) < 0) {
-               i_error("Couldn't look up user's home dir");
+               e_error(brain->event, "Couldn't look up user's home dir");
                return -1;
        }
        if (ret == 0) {
-               i_error("User has no home directory");
+               e_error(brain->event, "User has no home directory");
                return -1;
        }
 
@@ -468,11 +457,10 @@ dsync_brain_lock(struct dsync_brain *brain, const char *remote_hostname)
                        &brain->lock, &created, &error);
        }
        if (brain->lock_fd == -1)
-               i_error("Couldn't lock %s: %s", brain->lock_path, error);
-       else if (brain->debug) {
-               i_debug("brain %c: Locking done locally in %s "
-                       "(local hostname=%s, remote hostname=%s)",
-                       brain->master_brain ? 'M' : 'S',
+               e_error(brain->event, "Couldn't lock %s: %s", brain->lock_path, error);
+       else {
+               e_debug(brain->event,
+                       "Locking done locally in %s (local hostname=%s, remote hostname=%s)",
                        brain->lock_path, local_hostname, remote_hostname);
        }
        if (brain->verbose_proctitle)
@@ -552,7 +540,7 @@ static bool dsync_brain_slave_recv_handshake(struct dsync_brain *brain)
                        ns = mail_namespace_find(brain->user->namespaces,
                                                 *prefixes);
                        if (ns == NULL) {
-                               i_error("Namespace not found: '%s'", *prefixes);
+                               e_error(brain->event, "Namespace not found: '%s'", *prefixes);
                                brain->failed = TRUE;
                                return FALSE;
                        }
@@ -670,7 +658,7 @@ static bool dsync_brain_finish(struct dsync_brain *brain)
        if (ret == DSYNC_IBC_RECV_RET_TRYAGAIN)
                return FALSE;
        if (error != NULL) {
-               i_error("Remote dsync failed: %s", error);
+               e_error(brain->event, "Remote dsync failed: %s", error);
                brain->failed = TRUE;
                if (mail_error != 0 &&
                    (brain->mail_error == 0 || brain->mail_error == MAIL_ERROR_TEMP))
@@ -772,10 +760,13 @@ static void dsync_brain_mailbox_states_dump(struct dsync_brain *brain)
        struct dsync_mailbox_state *state;
        uint8_t *guid;
 
+       if (!event_want_debug(brain->event)) return;
+
        iter = hash_table_iterate_init(brain->mailbox_states);
        while (hash_table_iterate(iter, brain->mailbox_states, &guid, &state)) {
-               i_debug("brain %c: Mailbox %s state: uidvalidity=%u uid=%u modseq=%"PRIu64" pvt_modseq=%"PRIu64" messages=%u changes_during_sync=%d",
-                       brain->master_brain ? 'M' : 'S',
+               e_debug(brain->event,
+                       "Mailbox %s state: uidvalidity=%u uid=%u modseq=%"PRIu64" "
+                       "pvt_modseq=%"PRIu64" messages=%u changes_during_sync=%d",
                        guid_128_to_string(guid),
                        state->last_uidvalidity,
                        state->last_common_uid,
@@ -816,21 +807,16 @@ void dsync_brain_get_state(struct dsync_brain *brain, string_t *output)
                                                      guid);
                if (node == NULL ||
                    node->existence != DSYNC_MAILBOX_NODE_EXISTS) {
-                       if (brain->debug) {
-                               i_debug("brain %c: Removed state for deleted mailbox %s",
-                                       brain->master_brain ? 'M' : 'S',
-                                       guid_128_to_string(guid));
-                       }
+                       e_debug(brain->event,
+                               "Removed state for deleted mailbox %s",
+                               guid_128_to_string(guid));
                        hash_table_remove(brain->mailbox_states, guid);
                }
        }
        hash_table_iterate_deinit(&iter);
 
-       if (brain->debug) {
-               i_debug("brain %c: Exported mailbox states:",
-                       brain->master_brain ? 'M' : 'S');
-               dsync_brain_mailbox_states_dump(brain);
-       }
+       e_debug(brain->event, "Exported mailbox states:");
+       dsync_brain_mailbox_states_dump(brain);
        dsync_mailbox_states_export(brain->mailbox_states, output);
 }
 
@@ -904,10 +890,7 @@ bool dsync_brain_want_namespace(struct dsync_brain *brain,
 void dsync_brain_set_changes_during_sync(struct dsync_brain *brain,
                                         const char *reason)
 {
-       if (brain->debug) {
-               i_debug("brain %c: Change during sync: %s",
-                       brain->master_brain ? 'M' : 'S', reason);
-       }
+       e_debug(brain->event, "Change during sync: %s", reason);
        if (brain->changes_during_sync == NULL)
                brain->changes_during_sync = p_strdup(brain->pool, reason);
 }
index 287fed1e6e5f7c0106a5b0e9d770bfbcf7243673..c515e45f18317b8d3d8a9c95cd3d034ad37482dc 100644 (file)
@@ -156,10 +156,8 @@ sync_delete_mailbox_node(struct dsync_mailbox_tree_sync_ctx *ctx,
        struct dsync_mailbox_tree_sync_change *change;
        const char *name;
 
-       if ((ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_DEBUG) != 0 &&
-           tree == ctx->local_tree) {
-               i_debug("brain %c: Deleting mailbox '%s' (GUID %s): %s",
-                       (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S',
+       if (tree == ctx->local_tree) {
+               e_debug(ctx->event, "Deleting mailbox '%s' (GUID %s): %s",
                        dsync_mailbox_node_get_full_name(tree, node),
                        guid_128_to_string(node->mailbox_guid), reason);
        }
@@ -907,11 +905,8 @@ static bool sync_rename_mailboxes(struct dsync_mailbox_tree_sync_ctx *ctx,
                                                       remote_node, &reason);
                }
                /* handle children, if there are any */
-               if (debug != NULL) {
-                       i_debug("brain %c: %s: %s",
-                               (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S',
-                               str_c(debug), reason);
-               }
+               if (debug != NULL)
+                       e_debug(ctx->event, "%s: %s", str_c(debug), reason);
 
                if (!changed) T_BEGIN {
                        changed = sync_rename_mailboxes(ctx, local_node,
@@ -1052,23 +1047,17 @@ sync_rename_temp_mailboxes(struct dsync_mailbox_tree_sync_ctx *ctx,
                            !node_has_existent_children(node, FALSE))) {
                        /* we can just delete this directory and
                           any child directories it may have */
-                       if ((ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_DEBUG) != 0) {
-                               i_debug("brain %c: %s mailbox %s: Delete directory-only tree",
-                                       (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S',
-                                       tree == ctx->local_tree ? "local" : "remote",
-                                       dsync_mailbox_node_get_full_name(tree, node));
-                       }
+                       e_debug(ctx->event, "%s mailbox %s: Delete directory-only tree",
+                               tree == ctx->local_tree ? "local" : "remote",
+                               dsync_mailbox_node_get_full_name(tree, node));
                        sync_rename_delete_node_dirs(ctx, tree, node);
                } else {
                        T_BEGIN {
                                *renames_r = TRUE;
                                sync_rename_temp_mailbox_node(tree, node, &reason);
-                               if ((ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_DEBUG) != 0) {
-                                       i_debug("brain %c: %s mailbox %s: %s",
-                                               (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S',
-                                               tree == ctx->local_tree ? "local" : "remote",
-                                               dsync_mailbox_node_get_full_name(tree, node), reason);
-                               }
+                               e_debug(ctx->event, "%s mailbox %s: %s",
+                                       tree == ctx->local_tree ? "local" : "remote",
+                                       dsync_mailbox_node_get_full_name(tree, node), reason);
                        } T_END;
                        return TRUE;
                }
@@ -1091,15 +1080,14 @@ dsync_mailbox_tree_handle_renames(struct dsync_mailbox_tree_sync_ctx *ctx,
                        changed = sync_rename_mailboxes(ctx, &ctx->local_tree->root,
                                                        &ctx->remote_tree->root);
                } T_END;
-               if ((ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_DEBUG) != 0 &&
-                   changed) {
-                       i_debug("brain %c: -- Mailbox renamed, restart sync --",
-                               (ctx->sync_flags & DSYNC_MAILBOX_TREES_SYNC_FLAG_MASTER_BRAIN) != 0 ? 'M' : 'S');
-               }
+               if (changed)
+                       e_debug(ctx->event, "-- Mailbox renamed, restart sync --");
+
        } while (changed && ++count <= max_renames);
 
        if (changed) {
-               i_error("BUG: Mailbox renaming algorithm got into a potentially infinite loop, aborting");
+               e_debug(ctx->event,
+                       "BUG: Mailbox renaming algorithm got into a potentially infinite loop, aborting");
                return -1;
        }
 
index d6d06fde39cbe33abff40ab8dd491d26ee10c668..3b10dab16c21a0aa6ca6c2f24c93a75e756dfc9b 100644 (file)
@@ -31,14 +31,16 @@ int dsync_mailbox_lock(struct dsync_brain *brain, struct mailbox *box,
 
        /* Make sure the mailbox is open - locking requires it */
        if (mailbox_open(box) < 0) {
-               i_error("Can't open mailbox %s: %s", mailbox_get_vname(box),
+               e_error(brain->event,
+                       "Can't open mailbox %s: %s", mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, &brain->mail_error));
                return -1;
        }
 
        ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, &path);
        if (ret < 0) {
-               i_error("Can't get mailbox %s path: %s", mailbox_get_vname(box),
+               e_error(brain->event,
+                       "Can't get mailbox %s path: %s", mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, &brain->mail_error));
                return -1;
        }
@@ -53,7 +55,8 @@ int dsync_mailbox_lock(struct dsync_brain *brain, struct mailbox *box,
        if (mailbox_lock_file_create(box, DSYNC_MAILBOX_LOCK_FILENAME,
                                     brain->mailbox_lock_timeout_secs,
                                     lock_r, &error) <= 0) {
-               i_error("Failed to lock mailbox %s for dsyncing: %s",
+               e_error(brain->event,
+                       "Failed to lock mailbox %s for dsyncing: %s",
                        box->vname, error);
                return -1;
        }