From: Timo Sirainen Date: Fri, 2 Mar 2012 13:49:34 +0000 (+0200) Subject: dsync: Added -n parameter to dsync a specific namespace. X-Git-Tag: 2.1.2~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd611ca82b8b8a61736d21a8a0de58cfd53bc9b6;p=thirdparty%2Fdovecot%2Fcore.git dsync: Added -n parameter to dsync a specific namespace. --- diff --git a/src/doveadm/doveadm-settings.c b/src/doveadm/doveadm-settings.c index ba8da47627..8f94688ace 100644 --- a/src/doveadm/doveadm-settings.c +++ b/src/doveadm/doveadm-settings.c @@ -78,7 +78,7 @@ const struct doveadm_settings doveadm_default_settings = { .doveadm_password = "", .doveadm_allowed_commands = "", .dsync_alt_char = "_", - .dsync_remote_cmd = "ssh -l%{login} %{host} doveadm dsync-server -u%u -l%{lock_timeout}", + .dsync_remote_cmd = "ssh -l%{login} %{host} doveadm dsync-server -u%u -l%{lock_timeout} -n%{namespace}", .plugin_envs = ARRAY_INIT }; diff --git a/src/doveadm/dsync/doveadm-dsync.c b/src/doveadm/dsync/doveadm-dsync.c index c6d7f2f499..2a2d07bb87 100644 --- a/src/doveadm/dsync/doveadm-dsync.c +++ b/src/doveadm/dsync/doveadm-dsync.c @@ -28,7 +28,7 @@ struct dsync_cmd_context { struct doveadm_mail_cmd_context ctx; enum dsync_brain_flags brain_flags; - const char *mailbox; + const char *mailbox, *namespace_prefix; const char *local_location; @@ -139,6 +139,7 @@ get_ssh_cmd_args(struct dsync_cmd_context *ctx, { '\0', NULL, "login" }, { '\0', NULL, "host" }, { '\0', NULL, "lock_timeout" }, + { '\0', NULL, "namespace" }, { '\0', NULL, NULL } }; struct var_expand_table *tab; @@ -153,6 +154,7 @@ get_ssh_cmd_args(struct dsync_cmd_context *ctx, tab[1].value = login; tab[2].value = host; tab[3].value = dec2str(ctx->lock_timeout); + tab[4].value = ctx->namespace_prefix; t_array_init(&cmd_args, 8); str = t_str_new(128); @@ -265,7 +267,8 @@ cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user) "points to same directory: %s", path1); } - worker2 = dsync_worker_init_local(user2, *ctx->ctx.set->dsync_alt_char); + worker2 = dsync_worker_init_local(user2, ctx->namespace_prefix, + *ctx->ctx.set->dsync_alt_char); mail_user_unref(&user2); return worker2; } @@ -367,7 +370,8 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) user->admin = TRUE; /* create workers */ - worker1 = dsync_worker_init_local(user, *_ctx->set->dsync_alt_char); + worker1 = dsync_worker_init_local(user, ctx->namespace_prefix, + *_ctx->set->dsync_alt_char); if (!ctx->remote) worker2 = cmd_dsync_run_local(ctx, user); else @@ -507,6 +511,9 @@ cmd_mailbox_dsync_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c) case 'm': ctx->mailbox = optarg; break; + case 'n': + ctx->namespace_prefix = optarg; + break; case 'R': ctx->reverse_workers = TRUE; break; @@ -521,7 +528,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->ctx.getopt_args = "+dEfl:m:R"; + ctx->ctx.getopt_args = "+dEfl:m:n:R"; ctx->ctx.v.parse_arg = cmd_mailbox_dsync_parse_arg; ctx->ctx.v.preinit = cmd_dsync_preinit; ctx->ctx.v.init = cmd_dsync_init; @@ -556,7 +563,8 @@ cmd_dsync_server_run(struct doveadm_mail_cmd_context *_ctx, i_set_failure_prefix(t_strdup_printf("dsync-remote(%s): ", user->username)); - worker = dsync_worker_init_local(user, *_ctx->set->dsync_alt_char); + worker = dsync_worker_init_local(user, ctx->namespace_prefix, + *_ctx->set->dsync_alt_char); server = dsync_proxy_server_init(STDIN_FILENO, STDOUT_FILENO, worker); if (!ctx->lock) @@ -594,6 +602,9 @@ cmd_mailbox_dsync_server_parse_arg(struct doveadm_mail_cmd_context *_ctx, int c) if (str_to_uint(optarg, &ctx->lock_timeout) < 0) i_error("Invalid -l parameter: %s", optarg); break; + case 'n': + ctx->namespace_prefix = optarg; + break; default: return FALSE; } @@ -605,18 +616,19 @@ 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 = "El:"; + ctx->ctx.getopt_args = "El:n:"; ctx->ctx.v.parse_arg = cmd_mailbox_dsync_server_parse_arg; ctx->ctx.v.run = cmd_dsync_server_run; return &ctx->ctx; } struct doveadm_mail_cmd cmd_dsync_mirror = { - cmd_dsync_alloc, "sync", "[-dfR] [-l ] [-m ] " + cmd_dsync_alloc, "sync", + "[-dfR] [-l ] [-m ] [-n ] " }; struct doveadm_mail_cmd cmd_dsync_backup = { cmd_dsync_backup_alloc, "backup", - "[-dfR] [-l ] [-m ] " + "[-dfR] [-l ] [-m ] [-n ] " }; struct doveadm_mail_cmd cmd_dsync_server = { cmd_dsync_server_alloc, "dsync-server", &doveadm_mail_cmd_hide diff --git a/src/doveadm/dsync/dsync-worker-local.c b/src/doveadm/dsync/dsync-worker-local.c index 0191e361f4..5e81ff90ce 100644 --- a/src/doveadm/dsync/dsync-worker-local.c +++ b/src/doveadm/dsync/dsync-worker-local.c @@ -94,7 +94,7 @@ struct local_dsync_worker { struct hash_table *dir_changes_hash; char alt_char; - ARRAY_DEFINE(wanted_namespaces, struct mail_namespace *); + const char *namespace_prefix; mailbox_guid_t selected_box_guid; struct mailbox *selected_box; @@ -151,18 +151,33 @@ static unsigned int mailbox_guid_hash(const void *p) return h; } -static bool local_worker_want_namespace(struct mail_namespace *ns) +static bool local_worker_want_namespace(struct local_dsync_worker *worker, + struct mail_namespace *ns) { - return strcmp(ns->unexpanded_set->location, - SETTING_STRVAR_UNEXPANDED) == 0; + if (worker->namespace_prefix == NULL) { + return strcmp(ns->unexpanded_set->location, + SETTING_STRVAR_UNEXPANDED) == 0; + } else { + return strcmp(ns->prefix, worker->namespace_prefix) == 0; + } } static void dsync_check_namespaces(struct local_dsync_worker *worker) { struct mail_namespace *ns; + if (worker->namespace_prefix != NULL) { + ns = mail_namespace_find_prefix(worker->user->namespaces, + worker->namespace_prefix); + if (ns == NULL) { + i_fatal("Namespace prefix '%s' not found", + worker->namespace_prefix); + } + return; + } + for (ns = worker->user->namespaces; ns != NULL; ns = ns->next) { - if (local_worker_want_namespace(ns)) + if (local_worker_want_namespace(worker, ns)) return; } i_fatal("All your namespaces have a location setting. " @@ -171,7 +186,8 @@ static void dsync_check_namespaces(struct local_dsync_worker *worker) } struct dsync_worker * -dsync_worker_init_local(struct mail_user *user, char alt_char) +dsync_worker_init_local(struct mail_user *user, const char *namespace_prefix, + char alt_char) { struct local_dsync_worker *worker; pool_t pool; @@ -181,13 +197,13 @@ dsync_worker_init_local(struct mail_user *user, char alt_char) worker->worker.v = local_dsync_worker; worker->user = user; worker->pool = pool; + worker->namespace_prefix = p_strdup(pool, namespace_prefix); worker->alt_char = alt_char; worker->mailbox_hash = hash_table_create(default_pool, pool, 0, mailbox_guid_hash, mailbox_guid_cmp); i_array_init(&worker->saved_uids, 128); i_array_init(&worker->msg_get_queue, 32); - p_array_init(&worker->wanted_namespaces, pool, 8); dsync_check_namespaces(worker); mail_user_ref(worker->user); @@ -382,7 +398,8 @@ static int dsync_worker_get_mailbox_log(struct local_dsync_worker *worker) hash_table_create(default_pool, worker->pool, 0, dir_change_hash, dir_change_cmp); for (ns = worker->user->namespaces; ns != NULL; ns = ns->next) { - if (ns->alias_for != NULL || !local_worker_want_namespace(ns)) + if (ns->alias_for != NULL || + !local_worker_want_namespace(worker, ns)) continue; if (dsync_worker_get_list_mailbox_log(worker, ns->list) < 0) @@ -503,7 +520,7 @@ local_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *_iter, memset(dsync_box_r, 0, sizeof(*dsync_box_r)); while ((info = mailbox_list_iter_next(iter->list_iter)) != NULL) { - if (local_worker_want_namespace(info->ns)) + if (local_worker_want_namespace(worker, info->ns)) break; } if (info == NULL) @@ -646,7 +663,7 @@ local_worker_subs_iter_next(struct dsync_worker_subs_iter *_iter, memset(rec_r, 0, sizeof(*rec_r)); while ((info = mailbox_list_iter_next(iter->list_iter)) != NULL) { - if (local_worker_want_namespace(info->ns) || + if (local_worker_want_namespace(worker, info->ns) || (info->ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0) break; } diff --git a/src/doveadm/dsync/dsync-worker.h b/src/doveadm/dsync/dsync-worker.h index 3b858dc444..563796a9eb 100644 --- a/src/doveadm/dsync/dsync-worker.h +++ b/src/doveadm/dsync/dsync-worker.h @@ -30,7 +30,8 @@ typedef void dsync_worker_msg_callback_t(enum dsync_msg_get_result result, typedef void dsync_worker_finish_callback_t(bool success, void *context); struct dsync_worker * -dsync_worker_init_local(struct mail_user *user, char alt_char); +dsync_worker_init_local(struct mail_user *user, const char *namespace_prefix, + char alt_char); struct dsync_worker *dsync_worker_init_proxy_client(int fd_in, int fd_out); void dsync_worker_deinit(struct dsync_worker **worker);