]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm director flush: Added --max-parallel parameter.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 24 Oct 2016 19:42:43 +0000 (22:42 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 25 Oct 2016 18:01:23 +0000 (21:01 +0300)
src/doveadm/doveadm-director.c

index 25b0e399f9b361c71e78134f697b2f8ae6f936b6..4fce99d324bf7200189860cc64c2978f6506f2ed 100644 (file)
@@ -33,6 +33,7 @@ struct director_context {
        struct istream *input;
        bool explicit_socket_path;
        bool hash_map, user_map, force_flush;
+       int64_t max_parallel;
 };
 
 struct user_list {
@@ -128,6 +129,8 @@ cmd_director_init(struct doveadm_cmd_context *cctx)
                ctx->vhost_count = NULL;
        if (!doveadm_cmd_param_str(cctx, "passdb-field", &(ctx->passdb_field)))
                ctx->passdb_field = NULL;
+       if (!doveadm_cmd_param_int64(cctx, "max-parallel", &(ctx->max_parallel)))
+               ctx->max_parallel = 0;
        if (!ctx->user_map)
                director_connect(ctx);
        return ctx;
@@ -629,8 +632,15 @@ static void cmd_director_flush_all(struct director_context *ctx)
 {
        const char *line;
 
-       director_send(ctx, ctx->force_flush ?
-                     "HOST-FLUSH\n" : "HOST-RESET-USERS\n");
+       if (ctx->force_flush)
+               line = "HOST-FLUSH\n";
+       else if (ctx->max_parallel > 0) {
+               line = t_strdup_printf("HOST-RESET-USERS\t\t%lld\n",
+                                      (long long)ctx->max_parallel);
+       } else {
+               line = "HOST-RESET-USERS\n";
+       }
+       director_send(ctx, line);
 
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
@@ -651,6 +661,7 @@ static void cmd_director_flush(struct doveadm_cmd_context *cctx)
        unsigned int i, ips_count;
        struct ip_addr ip;
        const char *line;
+       string_t *cmd;
 
        ctx = cmd_director_init(cctx);
        if (ctx->host == NULL) {
@@ -669,10 +680,20 @@ static void cmd_director_flush(struct doveadm_cmd_context *cctx)
                if (director_get_host(ctx->host, &ips, &ips_count) != 0) return;
        }
 
+       cmd = t_str_new(64);
        for (i = 0; i < ips_count; i++) {
-               director_send(ctx, t_strdup_printf("%s\t%s\n",
-                       ctx->force_flush ? "HOST-FLUSH" : "HOST-RESET-USERS",
-                       net_ip2addr(&ip)));
+               str_truncate(cmd, 0);
+               if (ctx->force_flush)
+                       str_printfa(cmd, "HOST-FLUSH\t%s\n", net_ip2addr(&ip));
+               else {
+                       str_printfa(cmd, "HOST-RESET-USERS\t%s", net_ip2addr(&ip));
+                       if (ctx->max_parallel > 0) {
+                               str_printfa(cmd, "\t%lld",
+                                           (long long)ctx->max_parallel);
+                       }
+                       str_append_c(cmd, '\n');
+               }
+               director_send(ctx, str_c(cmd));
        }
        for (i = 0; i < ips_count; i++) {
                line = i_stream_read_next_line(ctx->input);
@@ -942,10 +963,11 @@ DOVEADM_CMD_PARAMS_END
 {
        .name = "director flush",
        .cmd = cmd_director_flush,
-       .usage = "[-a <director socket path>] [-F] <host>|all",
+       .usage = "[-a <director socket path>] [-F] [--max-parallel <n>] <host>|all",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_PARAM('a', "socket-path", CMD_PARAM_STR, 0)
 DOVEADM_CMD_PARAM('F', "force-flush", CMD_PARAM_BOOL, 0)
+DOVEADM_CMD_PARAM('\0', "max-parallel", CMD_PARAM_INT64, 0)
 DOVEADM_CMD_PARAM('\0', "host", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 },