]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Added -T parameter to specify the I/O stall timeout.
authorTimo Sirainen <tss@iki.fi>
Wed, 26 Aug 2015 13:19:27 +0000 (15:19 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 26 Aug 2015 13:19:27 +0000 (15:19 +0200)
src/doveadm/doveadm-dsync.c
src/doveadm/dsync/dsync-ibc-stream.c
src/doveadm/dsync/dsync-ibc.h

index d79da21d0a671042fc014964e743da9bf6c0ed78..7979b40a5011cf45aed139a7f800bd5846f46f99 100644 (file)
@@ -38,7 +38,7 @@
 #include <ctype.h>
 #include <sys/wait.h>
 
-#define DSYNC_COMMON_GETOPT_ARGS "+1a:dEfg:l:m:n:NO:Pr:Rs:t:Ux:"
+#define DSYNC_COMMON_GETOPT_ARGS "+1a:dEfg:l:m:n:NO:Pr:Rs:t:T:Ux:"
 #define DSYNC_REMOTE_CMD_EXIT_WAIT_SECS 30
 /* The broken_char is mainly set to get a proper error message when trying to
    convert a mailbox with a name that can't be used properly translated between
@@ -47,6 +47,8 @@
    none of them are allowed to be created in regular mailbox names. */
 #define DSYNC_LIST_BROKEN_CHAR '\003'
 
+#define DSYNC_DEFAULT_IO_STREAM_TIMEOUT_SECS (60*10)
+
 enum dsync_run_type {
        DSYNC_RUN_TYPE_LOCAL,
        DSYNC_RUN_TYPE_STREAM,
@@ -64,6 +66,7 @@ struct dsync_cmd_context {
        ARRAY_TYPE(const_string) exclude_mailboxes;
        ARRAY_TYPE(const_string) namespace_prefixes;
        time_t sync_since_timestamp;
+       unsigned int io_timeout_secs;
 
        const char *remote_name;
        const char *local_location;
@@ -485,7 +488,7 @@ cmd_dsync_icb_stream_init(struct dsync_cmd_context *ctx,
        i_stream_ref(ctx->input);
        o_stream_ref(ctx->output);
        return dsync_ibc_init_stream(ctx->input, ctx->output,
-                                    name, temp_prefix);
+                                    name, temp_prefix, ctx->io_timeout_secs);
 }
 
 static void
@@ -1001,6 +1004,10 @@ cmd_mailbox_dsync_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
                if (mail_parse_human_timestamp(optarg, &ctx->sync_since_timestamp) < 0)
                        i_fatal("Invalid -t parameter: %s", optarg);
                break;
+       case 'T':
+               if (str_to_uint(optarg, &ctx->io_timeout_secs) < 0)
+                       i_fatal("Invalid -T parameter: %s", optarg);
+               break;
        case 'U':
                ctx->replicator_notify = TRUE;
                break;
@@ -1015,6 +1022,7 @@ static struct doveadm_mail_cmd_context *cmd_dsync_alloc(void)
        struct dsync_cmd_context *ctx;
 
        ctx = doveadm_mail_cmd_alloc(struct dsync_cmd_context);
+       ctx->io_timeout_secs = DSYNC_DEFAULT_IO_STREAM_TIMEOUT_SECS;
        ctx->ctx.getopt_args = DSYNC_COMMON_GETOPT_ARGS;
        ctx->ctx.v.parse_arg = cmd_mailbox_dsync_parse_arg;
        ctx->ctx.v.preinit = cmd_dsync_preinit;
@@ -1036,7 +1044,6 @@ static struct doveadm_mail_cmd_context *cmd_dsync_backup_alloc(void)
        struct dsync_cmd_context *ctx;
 
        _ctx = cmd_dsync_alloc();
-       _ctx->getopt_args = DSYNC_COMMON_GETOPT_ARGS;
        ctx = (struct dsync_cmd_context *)_ctx;
        ctx->backup = TRUE;
        return _ctx;
@@ -1120,6 +1127,10 @@ cmd_mailbox_dsync_server_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c)
        case 'r':
                ctx->rawlog_path = optarg;
                break;
+       case 'T':
+               if (str_to_uint(optarg, &ctx->io_timeout_secs) < 0)
+                       i_fatal("Invalid -T parameter: %s", optarg);
+               break;
        case 'U':
                ctx->replicator_notify = TRUE;
                break;
@@ -1134,7 +1145,8 @@ static struct doveadm_mail_cmd_context *cmd_dsync_server_alloc(void)
        struct dsync_cmd_context *ctx;
 
        ctx = doveadm_mail_cmd_alloc(struct dsync_cmd_context);
-       ctx->ctx.getopt_args = "Er:U";
+       ctx->io_timeout_secs = DSYNC_DEFAULT_IO_STREAM_TIMEOUT_SECS;
+       ctx->ctx.getopt_args = "Er:T:U";
        ctx->ctx.v.parse_arg = cmd_mailbox_dsync_server_parse_arg;
        ctx->ctx.v.run = cmd_dsync_server_run;
        ctx->sync_type = DSYNC_BRAIN_SYNC_TYPE_CHANGED;
index b303664ae05f23fa9cd2099ae382a25623b24113..656a06feb9812afbcc546bbd35170f392ae5c7c7 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <stdlib.h>
 
-#define DSYNC_IBC_STREAM_TIMEOUT_MSECS (60*10*1000)
 #define DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE (1024*128)
 
 #define DSYNC_PROTOCOL_VERSION_MAJOR 3
@@ -142,6 +141,7 @@ struct dsync_ibc_stream {
        struct dsync_ibc ibc;
 
        char *name, *temp_path_prefix;
+       unsigned int timeout_secs;
        struct istream *input;
        struct ostream *output;
        struct io *io;
@@ -291,7 +291,7 @@ static int dsync_ibc_stream_output(struct dsync_ibc_stream *ibc)
 static void dsync_ibc_stream_timeout(struct dsync_ibc_stream *ibc)
 {
        i_error("dsync(%s): I/O has stalled, no activity for %u seconds",
-               ibc->name, DSYNC_IBC_STREAM_TIMEOUT_MSECS/1000);
+               ibc->name, ibc->timeout_secs);
        ibc->ibc.timeout = TRUE;
        dsync_ibc_stream_stop(ibc);
 }
@@ -303,7 +303,7 @@ static void dsync_ibc_stream_init(struct dsync_ibc_stream *ibc)
        ibc->io = io_add_istream(ibc->input, dsync_ibc_stream_input, ibc);
        o_stream_set_no_error_handling(ibc->output, TRUE);
        o_stream_set_flush_callback(ibc->output, dsync_ibc_stream_output, ibc);
-       ibc->to = timeout_add(DSYNC_IBC_STREAM_TIMEOUT_MSECS,
+       ibc->to = timeout_add(ibc->timeout_secs * 1000,
                              dsync_ibc_stream_timeout, ibc);
        o_stream_cork(ibc->output);
        o_stream_nsend_str(ibc->output, DSYNC_HANDSHAKE_VERSION);
@@ -1943,7 +1943,8 @@ static const struct dsync_ibc_vfuncs dsync_ibc_stream_vfuncs = {
 
 struct dsync_ibc *
 dsync_ibc_init_stream(struct istream *input, struct ostream *output,
-                     const char *name, const char *temp_path_prefix)
+                     const char *name, const char *temp_path_prefix,
+                     unsigned int timeout_secs)
 {
        struct dsync_ibc_stream *ibc;
 
@@ -1953,6 +1954,7 @@ dsync_ibc_init_stream(struct istream *input, struct ostream *output,
        ibc->output = output;
        ibc->name = i_strdup(name);
        ibc->temp_path_prefix = i_strdup(temp_path_prefix);
+       ibc->timeout_secs = timeout_secs;
        ibc->ret_pool = pool_alloconly_create("ibc stream data", 2048);
        dsync_ibc_stream_init(ibc);
        return &ibc->ibc;
index 8a0863dcf1facf9960a4a57a040c85df063e1d2e..18a577457a5e3086bf1a707e986e5962ea8deedc 100644 (file)
@@ -70,7 +70,8 @@ void dsync_ibc_init_pipe(struct dsync_ibc **ibc1_r,
                         struct dsync_ibc **ibc2_r);
 struct dsync_ibc *
 dsync_ibc_init_stream(struct istream *input, struct ostream *output,
-                     const char *name, const char *temp_path_prefix);
+                     const char *name, const char *temp_path_prefix,
+                     unsigned int timeout_secs);
 void dsync_ibc_deinit(struct dsync_ibc **ibc);
 
 /* I/O callback is called whenever new data is available. It's also called on