From patchwork Wed Apr 4 16:16:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10322847 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E9CD660390 for ; Wed, 4 Apr 2018 16:18:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBE9E28F49 for ; Wed, 4 Apr 2018 16:18:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA81928F19; Wed, 4 Apr 2018 16:18:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 21EF628F19 for ; Wed, 4 Apr 2018 16:18:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4D71E80485; Wed, 4 Apr 2018 16:18:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2757F16927; Wed, 4 Apr 2018 16:18:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D6E891800CAB; Wed, 4 Apr 2018 16:18:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w34GIO1b012503 for ; Wed, 4 Apr 2018 12:18:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D49E36FA; Wed, 4 Apr 2018 16:18:24 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03FE77D902; Wed, 4 Apr 2018 16:18:22 +0000 (UTC) Received: from prv3-mh.provo.novell.com (prv3-mh.provo.novell.com [137.65.250.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADB85C058ECC; Wed, 4 Apr 2018 16:18:20 +0000 (UTC) Received: from apollon.suse.de.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Wed, 04 Apr 2018 10:18:06 -0600 From: Martin Wilck To: Christophe Varoqui , Benjamin Marzinski Date: Wed, 4 Apr 2018 18:16:27 +0200 Message-Id: <20180404161627.6244-21-mwilck@suse.com> In-Reply-To: <20180404161627.6244-1-mwilck@suse.com> References: <20180404161627.6244-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 04 Apr 2018 16:18:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 04 Apr 2018 16:18:21 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'prv3-mh.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 prv3-mh.provo.novell.com 137.65.250.26 prv3-mh.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: dm-devel@redhat.com Cc: Julian Andres Klode , dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH v4 20/20] multipath.rules: find_multipaths "smart" logic X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 04 Apr 2018 16:18:28 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP When the first path to a device appears, we don't know if more paths are going to follow. find_multipath "smart" logic attempts to solve this dilemma by waiting for additional paths for a configurable time before giving up and releasing single paths to upper layers. These rules apply only if both find_multipaths is set to "smart" in multipath.conf. In this mode, multipath -u sets DM_MULTIPATH_DEVICE_PATH=2 if there's no clear evidence wheteher a given device should be a multipath member (not blacklisted, not listed as "failed", not in WWIDs file, not member of an existing map, only one path seen yet). In this case, "multipath -u" also sets the variable FIND_MULTIPATHS_WAIT_UNIL to a relative time stamp (we need to use relative "monotonic" time stamps because this may be triggered early during boot, before system "calendar" time is correctly initialized). In the DM_MULTIPATH_DEVICE_PATH=2 case, pretend that the path is multipath member, disallow further processing by systemd (allowing multipathd some time to grab the path), and set a systemd timer to check again after the given timeout. If the path is still not multipathed by then, pass it on to systemd for further processing. Signed-off-by: Martin Wilck Reviewed-by: Benjamin Marzinski --- multipath/multipath.rules | 64 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/multipath/multipath.rules b/multipath/multipath.rules index aab64dc..77b9f16 100644 --- a/multipath/multipath.rules +++ b/multipath/multipath.rules @@ -19,9 +19,65 @@ LABEL="test_dev" ENV{MPATH_SBIN_PATH}="/sbin" TEST!="$env{MPATH_SBIN_PATH}/multipath", ENV{MPATH_SBIN_PATH}="/usr/sbin" -# multipath -u sets DM_MULTIPATH_DEVICE_PATH -ENV{DM_MULTIPATH_DEVICE_PATH}!="1", IMPORT{program}="$env{MPATH_SBIN_PATH}/multipath -u %k" -ENV{DM_MULTIPATH_DEVICE_PATH}=="1", ENV{ID_FS_TYPE}="mpath_member", \ - ENV{SYSTEMD_READY}="0" +# FIND_MULTIPATHS_WAIT_UNTIL is the timeout (in seconds after the +# epoch). +IMPORT{db}="FIND_MULTIPATHS_WAIT_UNTIL" +ENV{.SAVED_FM_WAIT_UNTIL}="$env{FIND_MULTIPATHS_WAIT_UNTIL}" + +# multipath -u sets DM_MULTIPATH_DEVICE_PATH and, +# if "find_multipaths smart", also FIND_MULTIPATHS_WAIT_UNTIL. +ENV{DM_MULTIPATH_DEVICE_PATH}!="1", \ + IMPORT{program}="$env{MPATH_SBIN_PATH}/multipath -u %k" + +# case 1: this is definitely multipath +ENV{DM_MULTIPATH_DEVICE_PATH}=="1", \ + ENV{ID_FS_TYPE}="mpath_member", ENV{SYSTEMD_READY}="0", \ + GOTO="stop_wait" + +# case 2: this is definitely not multipath, or timeout has expired +ENV{DM_MULTIPATH_DEVICE_PATH}!="2", \ + GOTO="stop_wait" + +# Code below here is only run in "smart" mode. +# multipath -u has indicated this is "maybe" multipath. + +# This shouldn't happen, just in case. +ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="?*", GOTO="end_mpath" + +# Be careful not to start the timer twice. +ACTION!="add", GOTO="pretend_mpath" +ENV{.SAVED_FM_WAIT_UNTIL}=="?*", GOTO="pretend_mpath" + +# At this point, we are seeing this path for the first time, and it's "maybe" multipath. + +# The actual start command for the timer. +# +# The purpose of this command is only to make sure we will receive another +# uevent eventually. *Any* uevent may cause waiting to finish if it either ends +# in case 1-3 above, or if it arrives after FIND_MULTIPATHS_WAIT_UNTIL. +# +# Note that this will try to activate multipathd if it isn't running yet. +# If that fails, the unit starts and expires nonetheless. If multipathd +# startup needs to wait for other services, this wait time will add up with +# the --on-active timeout. +# +# We must trigger an "add" event because LVM2 will only act on those. + +RUN+="/usr/bin/systemd-run --unit=cancel-multipath-wait-$kernel --description 'cancel waiting for multipath siblings of $kernel' --no-block --timer-property DefaultDependencies=no --timer-property Conflicts=shutdown.target --timer-property Before=shutdown.target --timer-property AccuracySec=500ms --property DefaultDependencies=no --property Conflicts=shutdown.target --property Before=shutdown.target --property Wants=multipathd.service --property After=multipathd.service --on-active=$env{FIND_MULTIPATHS_WAIT_UNTIL} /usr/bin/udevadm trigger --action=add $sys$devpath" + +LABEL="pretend_mpath" +ENV{DM_MULTIPATH_DEVICE_PATH}="1" +ENV{SYSTEMD_READY}="0" +GOTO="end_mpath" + +LABEL="stop_wait" +# If timeout hasn't expired but we're not in "maybe" state any more, stop timer +# Do this only once, and only if the timer has been started before +IMPORT{db}="FIND_MULTIPATHS_WAIT_CANCELLED" +ENV{FIND_MULTIPATHS_WAIT_CANCELLED}!="?*", \ + ENV{FIND_MULTIPATHS_WAIT_UNTIL}=="?*", \ + ENV{FIND_MULTIPATHS_WAIT_UNTIL}!="0", \ + ENV{FIND_MULTIPATHS_WAIT_CANCELLED}="1", \ + RUN+="/usr/bin/systemctl stop cancel-multipath-wait-$kernel.timer" LABEL="end_mpath"