Static Load balancing prioritizer
authorHannes Reinecke <hare@suse.de>
Wed, 4 May 2011 09:38:53 +0000 (11:38 +0200)
committerHannes Reinecke <hare@suse.de>
Wed, 4 May 2011 09:56:22 +0000 (11:56 +0200)
'Weighted path' is a new path prioritizer for device mapper
multipath, where specific paths and the corresponding priority
values can be provided as arguments.
This prioritizer assigns the priority value provided in the
configuration file based on the comparison made between the
specified paths and the path instance for which this is called.
Paths can be specified as a regular expression of devname
of the path or as hbtl information of the path.

Syntax:
weightedpath  <hbtl|devname> <regex1> <prio1> <regex2> <prio2> ...

Examples:
prio  "weightedpath"
prio_args "hbtl 1:.:.:. 2 4:.:.:. 4"

prio  "weightedpath"
prio_args "devname sda$ 10 sde$ 20"

This prioritizer allows user to set static load balancing
for devices. Useful when user has prior knowledge of path
performance difference or unavailability of certain paths.

Signed-off-by: Vijayakumar Balasubramanian <vijaykumar@hp.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/prio.h
libmultipath/prioritizers/Makefile
libmultipath/prioritizers/weightedpath.c [new file with mode: 0644]
libmultipath/prioritizers/weightedpath.h [new file with mode: 0644]

index d9ed7f3..c948783 100644 (file)
@@ -25,6 +25,7 @@
 #define PRIO_RANDOM "random"
 #define PRIO_RDAC "rdac"
 #define PRIO_DATACORE "datacore"
+#define PRIO_WEIGHTED_PATH "weightedpath"
 
 /*
  * Value used to mark the fact prio was not defined
index bb7d536..ece6347 100644 (file)
@@ -13,7 +13,8 @@ LIBS = \
        libprioalua.so \
        libprioontap.so \
        libpriodatacore.so \
-       libpriohds.so
+       libpriohds.so \
+       libprioweightedpath.so
 
 CFLAGS += -I..
 
diff --git a/libmultipath/prioritizers/weightedpath.c b/libmultipath/prioritizers/weightedpath.c
new file mode 100644 (file)
index 0000000..d6c81f0
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ *
+ *  (C)  Copyright 2008 Hewlett-Packard Development Company, L.P
+ *
+ *  This file is released under the GPL
+ */
+
+/*
+ * Prioritizer for device mapper multipath, where specific paths and the
+ * corresponding priority values are provided as arguments.
+ *
+ * This prioritizer assigns the priority value provided in the configuration
+ * file based on the comparison made between the specified paths and the path
+ * instance for which this is called.
+ * Paths can be specified as a regular expression of devname of the path or
+ * as hbtl information of the path.
+ *
+ * Examples:
+ *     prio            "weightedpath hbtl 1:.:.:. 2 4:.:.:. 4"
+ *     prio            "weightedpath devname sda 10 sde 20"
+ *
+ * Returns zero as the default priority.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <prio.h>
+#include "weightedpath.h"
+#include <config.h>
+#include <structs.h>
+#include <memory.h>
+#include <debug.h>
+#include <regex.h>
+
+char *get_next_string(char **temp, char *split_char)
+{
+       char *token = NULL;
+       token = strsep(temp, split_char);
+       while (token != NULL && !strcmp(token, ""))
+               token = strsep(temp, split_char);
+       return token;
+}
+
+/* main priority routine */
+int prio_path_weight(struct path *pp, char *prio_args)
+{
+       char path[FILE_NAME_SIZE];
+       char *arg;
+       char *temp, *regex, *prio;
+       char split_char[] = " \t";
+       int priority = DEFAULT_PRIORITY, path_found = 0;
+       regex_t pathe;
+
+       /* Return default priority if there is no argument */
+       if (!prio_args)
+               return priority;
+
+       arg = temp = STRDUP(prio_args);
+
+       regex = get_next_string(&temp, split_char);
+
+       if (!strcmp(regex, HBTL)) {
+               sprintf(path, "%d:%d:%d:%d", pp->sg_id.host_no,
+                       pp->sg_id.channel, pp->sg_id.scsi_id, pp->sg_id.lun);
+       } else if (!strcmp(regex, DEV_NAME)) {
+               strcpy(path, pp->dev);
+       } else {
+               condlog(0, "%s: %s - Invalid arguments", pp->dev,
+                       pp->prio->name);
+               return priority;
+       }
+
+       while (!path_found) {
+               if (!temp)
+                       break;
+               if (!(regex = get_next_string(&temp, split_char)))
+                       break;
+               if (!(prio = get_next_string(&temp, split_char)))
+                       break;
+
+               if (!regcomp(&pathe, regex, REG_EXTENDED|REG_NOSUB)) {
+                       if (!regexec(&pathe, path, 0, NULL, 0)) {
+                               path_found = 1;
+                               priority = atoi(prio);
+                       }
+                       regfree(&pathe);
+               }
+       }
+
+       FREE(arg);
+       return priority;
+}
+
+int getprio(struct path *pp, char *args)
+{
+       return prio_path_weight(pp, args);
+}
+
diff --git a/libmultipath/prioritizers/weightedpath.h b/libmultipath/prioritizers/weightedpath.h
new file mode 100644 (file)
index 0000000..509f215
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _WEIGHTED_PATH_H
+#define _WEIGHTED_PATH_H
+
+#define PRIO_WEIGHTED_PATH "weightedpath"
+#define HBTL "hbtl"
+#define DEV_NAME "devname"
+#define DEFAULT_PRIORITY 0
+
+int prio_path_weight(struct path *pp, char *prio_args);
+
+#endif