From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christophe Varoqui Subject: [RFC] [PATCH] add serial keyword to the weightedpath prioritizer Date: Sun, 31 Jul 2016 21:26:53 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2115362649058437645==" Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Benjamin Marzinski , Hannes Reinecke Cc: device-mapper development List-Id: dm-devel.ids --===============2115362649058437645== Content-Type: multipart/alternative; boundary=001a114109ce58d7fb0538f377ca --001a114109ce58d7fb0538f377ca Content-Type: text/plain; charset=UTF-8 Ben, Hannes, Can you review this patch, adding a new 'serial' keyword to the weightedpath prioritizer. I compile-tested it only, as I have no testing environment at hand at the moment. I commited it in a separate 'weightedpath-serial' branch for now. http://git.opensvc.com/?p=multipath-tools/.git;a=commitdiff;h=4dd16d99281104fc3504ad73626894a5c3702fb3 Thanks, Christophe Varoqui OpenSVC --- commit 4dd16d99281104fc3504ad73626894a5c3702fb3 Author: Christophe Varoqui Date: Sun Jul 31 21:08:14 2016 +0200 multipath: add serial keyword to the weightedpath prioritizer Allow the weightedpath prioritizer to set priority to paths to specific serial numbers, expressed as regular expressions. Example: prio weightedpath prio_args "serial .*101 30 .*102 10" This feature is most synthetic for cross-site + all-paths-active topologies, where servers on a site want to prefer paths to the local storage heads. diff --git a/libmultipath/print.c b/libmultipath/print.c index 7c556b3..94d6384 100644 --- a/libmultipath/print.c +++ b/libmultipath/print.c @@ -503,7 +503,7 @@ snprint_path_size (char * buff, size_t len, struct path * pp) return snprint_size(buff, len, pp->size); } -static int +int snprint_path_serial (char * buff, size_t len, struct path * pp) { return snprint_str(buff, len, pp->serial); diff --git a/libmultipath/print.h b/libmultipath/print.h index 9306e50..6839fc7 100644 --- a/libmultipath/print.h +++ b/libmultipath/print.h @@ -112,6 +112,7 @@ int snprint_devices (struct config *, char *, int, struct vectors *); int snprint_hwtable (struct config *, char *, int, vector); int snprint_mptable (struct config *, char *, int, vector); int snprint_overrides (struct config *, char *, int, struct hwentry *); +int snprint_path_serial (char *, size_t, struct path *); int snprint_host_wwnn (char *, size_t, struct path *); int snprint_host_wwpn (char *, size_t, struct path *); int snprint_tgt_wwnn (char *, size_t, struct path *); diff --git a/libmultipath/prioritizers/weightedpath.c b/libmultipath/prioritizers/weightedpath.c index e8168fe..e53ab48 100644 --- a/libmultipath/prioritizers/weightedpath.c +++ b/libmultipath/prioritizers/weightedpath.c @@ -53,6 +53,16 @@ do { \ } while(0) static int +build_serial_path(struct path *pp, char *str, int len) +{ + char *p = str; + + p += snprint_path_serial(p, str + len - p, pp); + CHECK_LEN; + return 0; +} + +static int build_wwn_path(struct path *pp, char *str, int len) { char *p = str; @@ -103,8 +113,13 @@ int prio_path_weight(struct path *pp, char *prio_args) pp->sg_id.channel, pp->sg_id.scsi_id, pp->sg_id.lun); } else if (!strcmp(regex, DEV_NAME)) { strcpy(path, pp->dev); + } else if (!strcmp(regex, SERIAL)) { + if (build_serial_path(pp, path, FILE_NAME_SIZE) != 0) { + FREE(arg); + return priority; + } } else if (!strcmp(regex, WWN)) { - if (build_wwn_path(pp, path, FILE_NAME_SIZE) != 0) { + if (build_serial_path(pp, path, FILE_NAME_SIZE) != 0) { FREE(arg); return priority; } diff --git a/libmultipath/prioritizers/weightedpath.h b/libmultipath/prioritizers/weightedpath.h index 93d8c43..a1b268f 100644 --- a/libmultipath/prioritizers/weightedpath.h +++ b/libmultipath/prioritizers/weightedpath.h @@ -4,6 +4,7 @@ #define PRIO_WEIGHTED_PATH "weightedpath" #define HBTL "hbtl" #define DEV_NAME "devname" +#define SERIAL "serial" #define WWN "wwn" #define DEFAULT_PRIORITY 0 diff --git a/multipath/multipath.conf.5 b/multipath/multipath.conf.5 index ecaef1f..e73e917 100644 --- a/multipath/multipath.conf.5 +++ b/multipath/multipath.conf.5 @@ -243,17 +243,25 @@ prioritizers: .TP 12 .I weighted Needs a value of the form -.I " ..." +.I " ..." +.RS +.TP 8 .I hbtl regex can be of SCSI H:B:T:L format Ex: 1:0:.:. , *:0:0:. +.TP .I devname regex can be of device name format Ex: sda , sd.e +.TP +.I serial +regex can be of serial number format Ex: .*J1FR.*324 The serial can be looked up through sysfs or by running multipathd show paths format "%z" Ex: 0395J1FR904324 +.TP .I wwn regex can be of the form .I "host_wwnn:host_wwpn:target_wwnn:target_wwpn" these values can be looked up through sysfs or by running -.I mulitpathd show paths format "%N:%R:%n:%r" Ex: 0x200100e08ba0aea0:0x210100e08ba0aea0:.*:.* , .*:.*:iqn.2009-10.com.redhat.msp.lab.ask-06:.* -.TP +.I multipathd show paths format "%N:%R:%n:%r" Ex: 0x200100e08ba0aea0:0x210100e08ba0aea0:.*:.* , .*:.*:iqn.2009-10.com.redhat.msp.lab.ask-06:.* +.RE +.TP 12 .I alua If .I exclusive_pref_bit --001a114109ce58d7fb0538f377ca Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Ben, Hannes,

Can you review this patch,= adding a new 'serial' keyword to the weightedpath prioritizer.

I compile-tested it only, as I have no testing enviro= nment at hand at the moment.

I commited it in a se= parate 'weightedpath-serial' branch for now.

http://git.opensvc.com/?p= =3Dmultipath-tools/.git;a=3Dcommitdiff;h=3D4dd16d99281104fc3504ad73626894a5= c3702fb3

Thanks,
Christophe Varo= qui
OpenSVC

---

commit 4dd16d99281104fc3504ad73626894a5c3702fb3
Author: Chr= istophe Varoqui <chris= tophe.varoqui@opensvc.com>
Date: =C2=A0 Sun Jul 31 21:08:1= 4 2016 +0200

=C2=A0 =C2=A0 multipath: add serial k= eyword to the weightedpath prioritizer
=C2=A0 =C2=A0=C2=A0
<= div>=C2=A0 =C2=A0 Allow the weightedpath prioritizer to set priority to pat= hs to
=C2=A0 =C2=A0 specific serial numbers, expressed as regular= expressions.
=C2=A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 Example= :
=C2=A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 prio weightedpath
=
=C2=A0 =C2=A0 prio_args "serial .*101 30 .*102 10"
=C2= =A0 =C2=A0=C2=A0
=C2=A0 =C2=A0 This feature is most synthetic for= cross-site + all-paths-active
=C2=A0 =C2=A0 topologies, where se= rvers on a site want to prefer paths to the
=C2=A0 =C2=A0 local s= torage heads.

diff --git a/libmultipath/print.c b/= libmultipath/print.c
index 7c556b3..94d6384 100644
--- = a/libmultipath/print.c
+++ b/libmultipath/print.c
@@ -5= 03,7 +503,7 @@ snprint_path_size (char * buff, size_t len, struct path * pp= )
=C2=A0 return snprint_size(buff, len, pp->size);
=C2=A0= }
=C2=A0
-static int
+int
=C2=A0snp= rint_path_serial (char * buff, size_t len, struct path * pp)
=C2= =A0{
=C2=A0 return snprint_str(buff, len, pp->serial);
di= ff --git a/libmultipath/print.h b/libmultipath/print.h
index 9306= e50..6839fc7 100644
--- a/libmultipath/print.h
+++ b/li= bmultipath/print.h
@@ -112,6 +112,7 @@ int snprint_devices (struc= t config *, char *, int, struct vectors *);
=C2=A0int snprint_hwt= able (struct config *, char *, int, vector);
=C2=A0int snprint_mp= table (struct config *, char *, int, vector);
=C2=A0int snprint_o= verrides (struct config *, char *, int, struct hwentry *);
+int s= nprint_path_serial (char *, size_t, struct path *);
=C2=A0int snp= rint_host_wwnn (char *, size_t, struct path *);
=C2=A0int snprint= _host_wwpn (char *, size_t, struct path *);
=C2=A0int snprint_tgt= _wwnn (char *, size_t, struct path *);
diff --git a/libmultipath/= prioritizers/weightedpath.c b/libmultipath/prioritizers/weightedpath.c
index e8168fe..e53ab48 100644
--- a/libmultipath/prioritize= rs/weightedpath.c
+++ b/libmultipath/prioritizers/weightedpath.c<= /div>
@@ -53,6 +53,16 @@ do { \
=C2=A0} while(0)
= =C2=A0
=C2=A0static int
+build_serial_path(struct path = *pp, char *str, int len)
+{
+ char *p =3D str;
+
+ <= /span>p +=3D snprint_path_serial(p, str + len - p, pp);
+ CHECK_LEN;
+ <= /span>return 0;
+}
+
+static int
= =C2=A0build_wwn_path(struct path *pp, char *str, int len)
=C2=A0{=
=C2=A0 char *p =3D str;
@@ -103,8 +113,13 @@ int prio_path_= weight(struct path *pp, char *prio_args)
=C2=A0 pp->sg_id.channel= , pp->sg_id.scsi_id, pp->sg_id.lun);
=C2=A0 } else if (!strcmp(r= egex, DEV_NAME)) {
=C2=A0 strcpy(path, pp->dev);
+ } else if = (!strcmp(regex, SERIAL)) {
+ if (build_serial_path(pp, path, FILE_NAM= E_SIZE) !=3D 0) {
+ FREE(arg);
+ return priority;
+= }
=C2=A0 } else if (!strcmp(regex, WWN)) {
- if (build_wwn_path(pp,= path, FILE_NAME_SIZE) !=3D 0) {
+ if (build_serial_path(pp, path, FI= LE_NAME_SIZE) !=3D 0) {
=C2=A0 FREE(arg);
=C2=A0 return prior= ity;
=C2=A0 }
diff --git a/libmultipath/prioritizers/weight= edpath.h b/libmultipath/prioritizers/weightedpath.h
index 93d8c43= ..a1b268f 100644
--- a/libmultipath/prioritizers/weightedpath.h
+++ b/libmultipath/prioritizers/weightedpath.h
@@ -4,6 += 4,7 @@
=C2=A0#define PRIO_WEIGHTED_PATH "weightedpath"<= /div>
=C2=A0#define HBTL "hbtl"
=C2=A0#define DEV_N= AME "devname"
+#define SERIAL "serial"
<= div>=C2=A0#define WWN "wwn"
=C2=A0#define DEFAULT_PRIOR= ITY 0
=C2=A0
diff --git a/multipath/multipath.conf.5 b/= multipath/multipath.conf.5
index ecaef1f..e73e917 100644
--- a/multipath/multipath.conf.5
+++ b/multipath/multipath.conf= .5
@@ -243,17 +243,25 @@ prioritizers:
=C2=A0.TP 12
=C2=A0.I weighted
=C2=A0Needs a value of the form
-.I "<hbtl|devname|wwn> <regex1> <prio1> <regex= 2> <prio2> ..."
+.I "<hbtl|devname|serial|w= wn> <regex1> <prio1> <regex2> <prio2> ..."<= /div>
+.RS
+.TP 8
=C2=A0.I hbtl
=C2=A0reg= ex can be of SCSI H:B:T:L format =C2=A0Ex: 1:0:.:. , *:0:0:.
+.TP=
=C2=A0.I devname
=C2=A0regex can be of device name for= mat =C2=A0Ex: sda , sd.e
+.TP
+.I serial
+reg= ex can be of serial number format =C2=A0Ex: .*J1FR.*324 =C2=A0The serial ca= n be looked up through sysfs or by running multipathd show paths format &qu= ot;%z" Ex: 0395J1FR904324
+.TP
=C2=A0.I wwn
<= div>=C2=A0regex can be of the form
=C2=A0.I "host_wwnn:host_= wwpn:target_wwnn:target_wwpn"
=C2=A0these values can be look= ed up through sysfs or by running
-.I mulitpathd show paths forma= t "%N:%R:%n:%r" Ex: 0x200100e08ba0aea0:0x210100e08ba0aea0:.*:.* ,= .*:.*:iqn.2009-10.com.redhat.msp.lab.ask-06:.*
-.TP
+.= I multipathd show paths format "%N:%R:%n:%r" Ex: 0x200100e08ba0ae= a0:0x210100e08ba0aea0:.*:.* , .*:.*:iqn.2009-10.com.redhat.msp.lab.ask-06:.= *
+.RE
+.TP 12
=C2=A0.I alua
=C2=A0= If
=C2=A0.I exclusive_pref_bit

--001a114109ce58d7fb0538f377ca-- --===============2115362649058437645== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============2115362649058437645==--