From patchwork Fri Nov 15 10:29:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 3187591 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EDB52C045B for ; Fri, 15 Nov 2013 10:33:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 32D6E207DE for ; Fri, 15 Nov 2013 10:33:47 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id E8DF9207CF for ; Fri, 15 Nov 2013 10:33:45 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rAFAUUwr023732; Fri, 15 Nov 2013 05:30:31 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rAFAUTxS018709 for ; Fri, 15 Nov 2013 05:30:29 -0500 Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.17]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAFAUTPo000891 for ; Fri, 15 Nov 2013 05:30:29 -0500 Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAFAURwU029955 for ; Fri, 15 Nov 2013 05:30:28 -0500 Received: from relay1.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 88D72A79B4; Fri, 15 Nov 2013 11:30:27 +0100 (CET) From: Hannes Reinecke To: Christophe Varoqui Date: Fri, 15 Nov 2013 11:29:44 +0100 Message-Id: <1384511384-27642-14-git-send-email-hare@suse.de> In-Reply-To: <1384511384-27642-1-git-send-email-hare@suse.de> References: <1384511384-27642-1-git-send-email-hare@suse.de> X-RedHat-Spam-Score: -7.3 (BAYES_00, DCC_REPUT_00_12, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, URIBL_BLOCKED) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.17 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 13/13] multipathd: no_map_shutdown option X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patchs implements the 'no_map_shutdown' configuration option. Idea is that the daemon will exit if no maps are found, as then there's nothing to be done for the daemon anyway. The daemon will be restarted via socket activation for any CLI command. This this option the multipathd.socket unit can be activated always and won't add to the overall system load. Signed-off-by: Hannes Reinecke --- libmultipath/config.h | 1 + libmultipath/dict.c | 32 ++++++++++++++++++++++++++++++++ multipath.conf.annotated | 9 +++++++++ multipath/multipath.conf.5 | 7 +++++++ multipathd/main.c | 20 +++++++++++++++----- multipathd/multipathd.8 | 4 ++++ multipathd/multipathd.service | 2 +- 7 files changed, 69 insertions(+), 6 deletions(-) diff --git a/libmultipath/config.h b/libmultipath/config.h index 9c467e8..590fb32 100644 --- a/libmultipath/config.h +++ b/libmultipath/config.h @@ -103,6 +103,7 @@ struct config { int fast_io_fail; unsigned int dev_loss; int log_checker_err; + int no_map_shutdown; int allow_queueing; uid_t uid; gid_t gid; diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 0bf9587..da706f7 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -545,6 +545,25 @@ def_log_checker_err_handler(vector strvec) } static int +def_no_map_shutdown_handler(vector strvec) +{ + char * buff; + + buff = set_value(strvec); + if (!buff) + return 1; + + if (!strncmp(buff, "on", 2) || !strncmp(buff, "yes", 3) || + !strncmp(buff, "1", 1)) + conf->no_map_shutdown = 1; + else + conf->no_map_shutdown = 0; + + free(buff); + return 0; +} + +static int def_reservation_key_handler(vector strvec) { char *buff; @@ -2714,6 +2733,18 @@ snprint_def_log_checker_err (char * buff, int len, void * data) } static int +snprint_def_no_map_shutdown (char * buff, int len, void * data) +{ + switch (conf->no_map_shutdown) { + case 0: + return snprintf(buff, len, "\"no\""); + case 1: + return snprintf(buff, len, "\"yes\""); + } + return 0; +} + +static int snprint_def_user_friendly_names (char * buff, int len, void * data) { if (conf->user_friendly_names == USER_FRIENDLY_NAMES_ON) @@ -2850,6 +2881,7 @@ init_keywords(void) install_keyword("reservation_key", &def_reservation_key_handler, &snprint_def_reservation_key); install_keyword("retain_attached_hw_handler", &def_retain_hwhandler_handler, &snprint_def_retain_hwhandler_handler); install_keyword("detect_prio", &def_detect_prio_handler, &snprint_def_detect_prio); + install_keyword("no_map_shutdown", &def_no_map_shutdown_handler, &snprint_def_no_map_shutdown); __deprecated install_keyword("default_selector", &def_selector_handler, NULL); __deprecated install_keyword("default_path_grouping_policy", &def_pgpolicy_handler, NULL); __deprecated install_keyword("default_uid_attribute", &def_uid_attribute_handler, NULL); diff --git a/multipath.conf.annotated b/multipath.conf.annotated index a20302c..4b56bc8 100644 --- a/multipath.conf.annotated +++ b/multipath.conf.annotated @@ -215,6 +215,15 @@ # user_friendly_names no # # # +# # name : no_map_shutdown +# # scope : multipathd +# # desc : If set to "yes" the multipath daemon will terminate +# # if no multipath devices have been found. +# # values : yes|no +# # default : no +# no_map_shutdown no +# +# # # # name : mode # # scope : multipath & multipathd # # desc : The mode to use for the multipath device nodes, in octal. diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index cf5bec0..dba0027 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -409,6 +409,13 @@ will automatically use the .I alua prioritizer. If not, the prioritizer will be selected as usual. Default is .I no +.TP +.B no_map_shutdown +If set to +.I yes +, the multipath daemon will terminate if no multipath devices are found. +Default is +.I no . .SH "blacklist section" The diff --git a/multipathd/main.c b/multipathd/main.c index d386e0a..d4a5809 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -1026,11 +1026,11 @@ followover_should_failback(struct path * pp) return 1; } -static void +static int defered_failback_tick (vector mpvec) { struct multipath * mpp; - unsigned int i; + unsigned int i, mpp_count = 0; vector_foreach_slot (mpvec, mpp, i) { /* @@ -1042,7 +1042,9 @@ defered_failback_tick (vector mpvec) if (!mpp->failback_tick && need_switch_pathgroup(mpp, 1)) switch_pathgroup(mpp); } + mpp_count++; } + return mpp_count; } static void @@ -1284,7 +1286,7 @@ checkerloop (void *ap) while (1) { struct timeval diff_time, start_time, end_time; - int num_paths = 0; + int num_paths = 0, num_maps = 0; if (gettimeofday(&start_time, NULL) != 0) start_time.tv_sec = 0; @@ -1300,7 +1302,7 @@ checkerloop (void *ap) } } if (vecs->mpvec) { - defered_failback_tick(vecs->mpvec); + num_maps = defered_failback_tick(vecs->mpvec); retry_count_tick(vecs->mpvec); } if (count) @@ -1320,6 +1322,11 @@ checkerloop (void *ap) num_paths, num_paths > 1 ? "s" : "", diff_time.tv_sec, diff_time.tv_usec); } + if (!num_maps && conf->no_map_shutdown) { + condlog(3, "terminating, no multipath devices"); + exit_daemon(); + break; + } sleep(1); } return NULL; @@ -1891,7 +1898,7 @@ main (int argc, char *argv[]) if (!conf) exit(1); - while ((arg = getopt(argc, argv, ":dsv:k::")) != EOF ) { + while ((arg = getopt(argc, argv, ":dnsv:k::")) != EOF ) { switch(arg) { case 'd': logsink = 0; @@ -1904,6 +1911,9 @@ main (int argc, char *argv[]) conf->verbosity = atoi(optarg); break; + case 'n': + conf->no_map_shutdown = 1; + break; case 's': logsink = -1; break; diff --git a/multipathd/multipathd.8 b/multipathd/multipathd.8 index 2aea150..eb39c9c 100644 --- a/multipathd/multipathd.8 +++ b/multipathd/multipathd.8 @@ -22,6 +22,10 @@ devmap reconfiguration, so that it can refresh its failed path list. .B \-d Foreground Mode. Don't daemonize, and print all messages to stdout and stderr. .TP +.B \-n +Oneshot Mode; daemon will terminate if no multipath devices are found. +Equivalent to set 'no_map_shutdown' to '1' in the configuration file. +.TP .B \-s Suppress timestamps. Do not prefix logging messages with a timestamp. .TP diff --git a/multipathd/multipathd.service b/multipathd/multipathd.service index 6472dd5..b34667d 100644 --- a/multipathd/multipathd.service +++ b/multipathd/multipathd.service @@ -8,7 +8,7 @@ Conflicts=shutdown.target [Service] Type=notify NotifyAccess=main -ExecStart=/sbin/multipathd -d -s +ExecStart=/sbin/multipathd -d -s -n ExecReload=/sbin/multipathd reconfigure WatchdogSec=5s LimitCORE=infinity