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 <christophe.varoqui@opensvc.com>
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 "<hbtl|devname|wwn> <regex1> <prio1> <regex2> <prio2> ..."
+.I "<hbtl|devname|serial|wwn> <regex1> <prio1> <regex2> <prio2> ..."
+.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