From c70575799b2878d11235ce09a36a5221be23f69e Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 4 May 2011 11:38:53 +0200 Subject: [PATCH] Static Load balancing prioritizer '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 ... 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 Signed-off-by: Hannes Reinecke --- libmultipath/prio.h | 1 + libmultipath/prioritizers/Makefile | 3 +- libmultipath/prioritizers/weightedpath.c | 99 ++++++++++++++++++++++++++++++++ libmultipath/prioritizers/weightedpath.h | 11 ++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 libmultipath/prioritizers/weightedpath.c create mode 100644 libmultipath/prioritizers/weightedpath.h diff --git a/libmultipath/prio.h b/libmultipath/prio.h index d9ed7f3..c948783 100644 --- a/libmultipath/prio.h +++ b/libmultipath/prio.h @@ -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 diff --git a/libmultipath/prioritizers/Makefile b/libmultipath/prioritizers/Makefile index bb7d536..ece6347 100644 --- a/libmultipath/prioritizers/Makefile +++ b/libmultipath/prioritizers/Makefile @@ -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 index 0000000..d6c81f0 --- /dev/null +++ b/libmultipath/prioritizers/weightedpath.c @@ -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 +#include + +#include +#include "weightedpath.h" +#include +#include +#include +#include +#include + +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 index 0000000..509f215 --- /dev/null +++ b/libmultipath/prioritizers/weightedpath.h @@ -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 -- 2.7.4