dsync-brain.c revision a8c5a86d183db25a57bf193c06b41e092ec2e151
/* Copyright (c) 2013-2014 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "hostpid.h"
#include "str.h"
#include "process-title.h"
#include "settings-parser.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "mail-namespace.h"
#include "dsync-mailbox-tree.h"
#include "dsync-ibc.h"
#include "dsync-brain-private.h"
#include "dsync-mailbox-import.h"
#include "dsync-mailbox-export.h"
static const char *dsync_state_names[] = {
"master_recv_handshake",
"slave_recv_handshake",
"master_send_last_common",
"slave_recv_last_common",
"send_mailbox_tree",
"send_mailbox_tree_deletes",
"recv_mailbox_tree",
"recv_mailbox_tree_deletes",
"master_send_mailbox",
"slave_recv_mailbox",
"sync_mails",
"done"
};
{
const char *import_title, *export_title;
} else {
} else {
if (import_title[0] != '\0') {
}
if (export_title[0] != '\0') {
}
}
}
}
static void dsync_brain_run_io(void *context)
{
bool changed, try_pending;
return;
}
try_pending = TRUE;
do {
break;
}
if (changed)
try_pending = TRUE;
else if (try_pending) {
try_pending = FALSE;
}
} while (changed);
}
static struct dsync_brain *
{
struct dsync_brain *brain;
const struct master_service_settings *service_set;
return brain;
}
static void
{
(flags & DSYNC_BRAIN_FLAG_SEND_MAIL_REQUESTS) != 0;
(flags & DSYNC_BRAIN_FLAG_NO_BACKUP_OVERWRITE) != 0;
}
struct dsync_brain *
enum dsync_brain_flags flags,
const struct dsync_brain_settings *set)
{
struct dsync_ibc_settings ibc_set;
struct dsync_brain *brain;
const char *error;
sizeof(brain->sync_box_guid));
if (sync_type == DSYNC_BRAIN_SYNC_TYPE_STATE &&
i_error("Saved sync state is invalid, "
"falling back to full sync: %s", error);
}
sizeof(ibc_set.sync_box_guid));
/* reverse the backup direction for the slave */
if ((flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0)
else if ((flags & DSYNC_BRAIN_FLAG_BACKUP_RECV) != 0)
return brain;
}
struct dsync_brain *
bool local)
{
struct dsync_ibc_settings ibc_set;
struct dsync_brain *brain;
if (local) {
/* both master and slave are running within the same process,
update the proctitle only for master. */
}
return brain;
}
{
struct mail_namespace *ns;
struct mail_storage *storage;
continue;
if (mail_storage_purge(storage) < 0) {
}
}
}
{
int ret;
i_error("Timeout during state=%s%s",
t_strdup_printf(" (send=%s recv=%s)",
}
/* unlink the lock file before it gets unlocked */
}
return ret;
}
static int
{
const char *home;
int ret;
/* locking done by remote */
return 0;
}
/* running dsync within the same server.
locking done by master brain. */
return 0;
}
i_error("Couldn't look up user's home dir");
return -1;
}
if (ret == 0) {
i_error("User has no home directory");
return -1;
}
for (;;) {
i_error("Couldn't create lock %s: %m",
return -1;
}
i_error("Couldn't lock %s: Timed out after %u seconds",
} else {
}
break;
}
break;
}
break;
}
/* success */
return 0;
}
/* file was recreated, try again */
}
return -1;
}
{
const struct dsync_ibc_settings *ibc_set;
return FALSE;
if (brain->lock_timeout > 0) {
return FALSE;
}
}
return TRUE;
}
{
const struct dsync_ibc_settings *ibc_set;
return FALSE;
if (ibc_set->lock_timeout > 0) {
return FALSE;
}
}
}
sizeof(brain->sync_box_guid));
/* this flag is only set on the remote slave brain */
else
return TRUE;
}
{
struct dsync_mailbox_state *state;
}
for (;;) {
if (ret == DSYNC_IBC_SEND_RET_FULL)
return;
break;
}
}
const struct dsync_mailbox_state *state)
{
struct dsync_mailbox_state *dupstate;
}
{
struct dsync_mailbox_state state;
enum dsync_ibc_recv_ret ret;
}
if (ret == DSYNC_IBC_RECV_RET_FINISHED) {
}
return changed;
}
{
return FALSE;
}
break;
break;
break;
break;
break;
break;
break;
break;
break;
break;
case DSYNC_STATE_SYNC_MAILS:
break;
case DSYNC_STATE_DONE:
break;
}
i_debug("brain %c: out state=%s changed=%d",
}
if (brain->verbose_proctitle) {
}
}
{
bool ret;
return FALSE;
}
T_BEGIN {
} T_END;
return ret;
}
{
struct hash_iterate_context *iter;
struct dsync_mailbox_node *node;
const struct dsync_mailbox_state *new_state;
struct dsync_mailbox_state *state;
/* update mailbox states */
else
}
/* remove nonexistent mailboxes */
guid);
}
}
{
}
{
}
{
return brain->changes_during_sync;
}
struct mail_namespace *ns)
{
/* always skip aliases */
return FALSE;
}
if (brain->sync_visible_namespaces) {
return TRUE;
NAMESPACE_FLAG_LIST_CHILDREN)) != 0)
return TRUE;
return FALSE;
} else {
SETTING_STRVAR_UNEXPANDED) == 0;
}
}