From patchwork Thu Jun 22 14:59:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 9804591 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 B8E1260329 for ; Thu, 22 Jun 2017 15:00:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A71DA286D1 for ; Thu, 22 Jun 2017 15:00:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B89C286F2; Thu, 22 Jun 2017 15:00:25 +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 4DBAC26861 for ; Thu, 22 Jun 2017 15:00:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9C43B9ABF; Thu, 22 Jun 2017 15:00:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9C43B9ABF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A9C43B9ABF Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE63561280; Thu, 22 Jun 2017 15:00:20 +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 267154E984; Thu, 22 Jun 2017 15:00:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MF0GaD012278 for ; Thu, 22 Jun 2017 11:00:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4CDF75C7A9; Thu, 22 Jun 2017 15:00:16 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E8815C7A5; Thu, 22 Jun 2017 15:00:12 +0000 (UTC) Received: from prv3-mh.provo.novell.com (victor.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 7C00F41A32; Thu, 22 Jun 2017 15:00:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7C00F41A32 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mwilck@suse.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7C00F41A32 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); Thu, 22 Jun 2017 08:59:54 -0600 From: Martin Wilck To: Christophe Varoqui , Hannes Reinecke Date: Thu, 22 Jun 2017 16:59:12 +0200 Message-Id: <20170622145913.23714-11-mwilck@suse.com> In-Reply-To: <20170622145913.23714-1-mwilck@suse.com> References: <20170622145913.23714-1-mwilck@suse.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 22 Jun 2017 15:00:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 22 Jun 2017 15:00:06 +0000 (UTC) for IP:'137.65.250.26' DOMAIN:'victor.provo.novell.com' HELO:'prv3-mh.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -1.901 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.26 victor.provo.novell.com 137.65.250.26 victor.provo.novell.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Xose Vazquez Perez Subject: [dm-devel] [PATCH v4 10/11] libmultipath: don't try to set hwhandler if it is retained 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 22 Jun 2017 15:00:23 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Setting a device handler only works if retain_attached_hw_handler is 'no', or if the kernel didn't auto-assign a handler. If this is not the case, don't even attempt to set a different handler. This requires reading the sysfs "dh_state" path attribute. Signed-off-by: Martin Wilck --- libmultipath/configure.c | 8 +++++++- libmultipath/propsel.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 74b6f52a..03874f47 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -275,15 +275,21 @@ int setup_map(struct multipath *mpp, char *params, int params_size) /* * properties selectors + * + * Ordering matters for some properties: + * - features after no_path_retry and retain_hwhandler + * - hwhandler after retain_hwhandler + * No guarantee that this list is complete, check code in + * propsel.c if in doubt. */ conf = get_multipath_config(); select_pgfailback(conf, mpp); select_pgpolicy(conf, mpp); select_selector(conf, mpp); - select_hwhandler(conf, mpp); select_no_path_retry(conf, mpp); select_retain_hwhandler(conf, mpp); select_features(conf, mpp); + select_hwhandler(conf, mpp); select_rr_weight(conf, mpp); select_minio(conf, mpp); select_mode(conf, mpp); diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index d609394e..a86207a0 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -19,8 +19,10 @@ #include "discovery.h" #include "dict.h" #include "util.h" +#include "sysfs.h" #include "prioritizers/alua_rtpg.h" #include +#include pgpolicyfn *pgpolicies[] = { NULL, @@ -342,9 +344,42 @@ out: return 0; } +static int get_dh_state(struct path *pp, char *value, size_t value_len) +{ + struct udev_device *ud; + + if (pp->udev == NULL) + return -1; + + ud = udev_device_get_parent_with_subsystem_devtype( + pp->udev, "scsi", "scsi_device"); + if (ud == NULL) + return -1; + + return sysfs_attr_get_value(ud, "dh_state", value, value_len); +} + int select_hwhandler(struct config *conf, struct multipath *mp) { char *origin; + struct path *pp; + /* dh_state is no longer than "detached" */ + char handler[12]; + char *dh_state; + int i; + + dh_state = &handler[2]; + if (mp->retain_hwhandler != RETAIN_HWHANDLER_OFF) { + vector_foreach_slot(mp->paths, pp, i) { + if (get_dh_state(pp, dh_state, sizeof(handler) - 2) > 0 + && strcmp(dh_state, "detached")) { + memcpy(handler, "1 ", 2); + mp->hwhandler = handler; + origin = "(setting: retained by kernel driver)"; + goto out; + } + } + } mp_set_hwe(hwhandler); mp_set_conf(hwhandler);