From patchwork Fri Jul 15 06:48:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 9231211 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 215E160865 for ; Fri, 15 Jul 2016 06:53:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F4A22819A for ; Fri, 15 Jul 2016 06:53:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 040BC28319; Fri, 15 Jul 2016 06:53:14 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (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 48F732819A for ; Fri, 15 Jul 2016 06:53:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6F6nW1h023551; Fri, 15 Jul 2016 02:49:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u6F6n2xn021301 for ; Fri, 15 Jul 2016 02:49:02 -0400 Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6F6n2xT030203 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 15 Jul 2016 02:49:02 -0400 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B62DDC05AA4C; Fri, 15 Jul 2016 06:49:00 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 54E37AC72; Fri, 15 Jul 2016 06:48:59 +0000 (UTC) From: Hannes Reinecke To: Christophe Varoqui Date: Fri, 15 Jul 2016 08:48:57 +0200 Message-Id: <1468565337-5178-4-git-send-email-hare@suse.de> In-Reply-To: <1468565337-5178-1-git-send-email-hare@suse.de> References: <1468565337-5178-1-git-send-email-hare@suse.de> X-Greylist: Sender IP whitelisted by DNSRBL, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 15 Jul 2016 06:49:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 15 Jul 2016 06:49:01 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx2.suse.de' FROM:'hare@suse.de' RCPT:'' X-RedHat-Spam-Score: -3.188 (BAYES_50, DCC_REPUT_00_12, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, SPF_PASS) 195.135.220.15 mx2.suse.de 195.135.220.15 mx2.suse.de X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com Subject: [dm-devel] [PATCH 3/3] multipathd: Add 'sysfs' prioritizer 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-Virus-Scanned: ClamAV using ClamSMTP Recent kernels have an 'access_state' attribute which allows us to read the asymmetric access state directly from sysfs. Signed-off-by: Hannes Reinecke --- libmultipath/discovery.c | 33 +++++++++++++++++++++ libmultipath/discovery.h | 2 ++ libmultipath/prio.h | 1 + libmultipath/prioritizers/Makefile | 3 +- libmultipath/prioritizers/sysfs.c | 61 ++++++++++++++++++++++++++++++++++++++ libmultipath/propsel.c | 6 +++- multipath/multipath.conf.5 | 19 ++++++++++-- 7 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 libmultipath/prioritizers/sysfs.c diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index e9e0313..07c60cf 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -209,6 +209,8 @@ declare_sysfs_get_str(devtype); declare_sysfs_get_str(vendor); declare_sysfs_get_str(model); declare_sysfs_get_str(rev); +declare_sysfs_get_str(access_state); +declare_sysfs_get_str(preferred_path); ssize_t sysfs_get_vpd (struct udev_device * udev, int pg, @@ -484,6 +486,37 @@ int sysfs_get_iscsi_ip_address(struct path *pp, char *ip_address) return 1; } +int +sysfs_get_asymmetric_access_state(struct path *pp, char *buff, int buflen) +{ + struct udev_device *parent = pp->udev; + char value[16], *eptr; + unsigned int preferred; + + while (parent) { + const char *subsys = udev_device_get_subsystem(parent); + if (subsys && !strncmp(subsys, "scsi", 4)) + break; + parent = udev_device_get_parent(parent); + } + + if (!parent) + return -1; + + if (sysfs_get_access_state(parent, buff, buflen) <= 0) + return -1; + + if (sysfs_get_preferred_path(parent, value, 16) <= 0) + return 0; + + preferred = strtoul(value, &eptr, 0); + if (value == eptr || preferred == ULONG_MAX) { + /* Parse error, ignore */ + return 0; + } + return preferred; +} + static void sysfs_set_rport_tmo(struct multipath *mpp, struct path *pp) { diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h index 321d930..0f5b1e6 100644 --- a/libmultipath/discovery.h +++ b/libmultipath/discovery.h @@ -47,6 +47,8 @@ int sysfs_get_host_pci_name(struct path *pp, char *pci_name); int sysfs_get_iscsi_ip_address(struct path *pp, char *ip_address); ssize_t sysfs_get_vpd (struct udev_device * udev, int pg, unsigned char * buff, size_t len); +int sysfs_get_asymmetric_access_state(struct path *pp, + char *buff, int buflen); /* * discovery bitmask diff --git a/libmultipath/prio.h b/libmultipath/prio.h index 7195986..032028e 100644 --- a/libmultipath/prio.h +++ b/libmultipath/prio.h @@ -30,6 +30,7 @@ struct path; #define PRIO_RANDOM "random" #define PRIO_RDAC "rdac" #define PRIO_WEIGHTED_PATH "weightedpath" +#define PRIO_SYSFS "sysfs" /* * Value used to mark the fact prio was not defined diff --git a/libmultipath/prioritizers/Makefile b/libmultipath/prioritizers/Makefile index 903a139..bb76700 100644 --- a/libmultipath/prioritizers/Makefile +++ b/libmultipath/prioritizers/Makefile @@ -15,7 +15,8 @@ LIBS = \ libprioontap.so \ libpriorandom.so \ libpriordac.so \ - libprioweightedpath.so + libprioweightedpath.so \ + libpriosysfs.so CFLAGS += -I.. diff --git a/libmultipath/prioritizers/sysfs.c b/libmultipath/prioritizers/sysfs.c new file mode 100644 index 0000000..ff567df --- /dev/null +++ b/libmultipath/prioritizers/sysfs.c @@ -0,0 +1,61 @@ +/* + * sysfs.c + * + * Copyright(c) 2016 Hannes Reinecke, SUSE Linux GmbH + */ + +#include + +#include "structs.h" +#include "discovery.h" +#include "prio.h" + +static const struct { + unsigned char value; + char *name; +} sysfs_access_state_map[] = { + { 50, "active/optimized" }, + { 10, "active/non-optimized" }, + { 5, "lba-dependent" }, + { 1, "standby" }, +}; + +int get_exclusive_pref_arg(char *args) +{ + char *ptr; + + if (args == NULL) + return 0; + ptr = strstr(args, "exclusive_pref_bit"); + if (!ptr) + return 0; + if (ptr[18] != '\0' && ptr[18] != ' ' && ptr[18] != '\t') + return 0; + if (ptr != args && ptr[-1] != ' ' && ptr[-1] != '\t') + return 0; + return 1; +} + +int getprio (struct path * pp, char * args, unsigned int timeout) +{ + int prio = 0, rc, i; + char buff[512]; + int exclusive_pref; + + exclusive_pref = get_exclusive_pref_arg(args); + rc = sysfs_get_asymmetric_access_state(pp, buff, 512); + if (rc < 0) + return PRIO_UNDEF; + prio = 0; + for (i = 0; i < 4; i++) { + if (!strncmp(buff, sysfs_access_state_map[i].name, + strlen(sysfs_access_state_map[i].name))) { + prio = sysfs_access_state_map[i].value; + break; + } + } + if (rc > 0 && (prio != 50 || exclusive_pref)) + prio += 80; + + return prio; +} diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c index beb0798..0caf269 100644 --- a/libmultipath/propsel.c +++ b/libmultipath/propsel.c @@ -375,6 +375,8 @@ detect_prio(struct config *conf, struct path * pp) struct prio *p = &pp->prio; int tpgs = 0; unsigned int timeout = conf->checker_timeout; + char buff[512]; + char *default_prio = PRIO_ALUA; if ((tpgs = get_target_port_group_support(pp->fd, timeout)) <= 0) return; @@ -384,7 +386,9 @@ detect_prio(struct config *conf, struct path * pp) return; if (get_asymmetric_access_state(pp->fd, ret, timeout) < 0) return; - prio_get(conf->multipath_dir, p, PRIO_ALUA, DEFAULT_PRIO_ARGS); + if (sysfs_get_asymmetric_access_state(pp, buff, 512) >= 0) + default_prio = PRIO_SYSFS; + prio_get(conf->multipath_dir, p, default_prio, DEFAULT_PRIO_ARGS); } #define set_prio(dir, src, msg) \ diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index 709ab3c..fc3877f 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -212,6 +212,11 @@ are implemented: .I const Return a constant priority of \fI1\fR. .TP +.I sysfs +Use the sysfs attributes \fIaccess_state\fR and \fIpreferred_path\fR to +generate the path priority. This prioritizer accepts the optional prio_arg +.I exclusive_pref_bit +.TP .I emc (Hardware-dependent) Generate the path priority for DGC class arrays as CLARiiON CX/AX and @@ -277,8 +282,8 @@ these values can be looked up through sysfs or by running .I alua If .I exclusive_pref_bit -is set, paths with the TPGS pref bit set will always be in their own path -group. +is set, paths with the \fIpreferred path\fR bit set will always +be in their own path group. .TP .I datacore .I preferredsds @@ -569,8 +574,16 @@ If set to .I yes , multipath will try to detect if the device supports SCSI-3 ALUA. If so, the device will automatically use the +.I sysfs +prioritizer if the required sysfs attributes +.I access_state +and +.I preferred_path +are supported, or the .I alua -prioritizer. If not, the prioritizer will be selected as usual. +prioritizer if not. If set to +.I no +, the prioritizer will be selected as usual. .RS .TP Default value is: \fBno\fR