From 6f51f9fcd62400715a92d7cf515e4a49569c59c0 Mon Sep 17 00:00:00 2001 From: Christophe Varoqui Date: Wed, 23 Nov 2005 14:47:50 +0100 Subject: [PATCH] [libmultipath] move get_refwwid() to libmultipath/configure.c And pass "dev" and "dev_type" as params to make it usable from multipathd. --- libmultipath/configure.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ libmultipath/configure.h | 2 ++ multipath/main.c | 89 +----------------------------------------------- 3 files changed, 92 insertions(+), 88 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 77b84f3..6ea2f7b 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -32,6 +32,7 @@ #include "configure.h" #include "pgpolicies.h" #include "dict.h" +#include "alias.h" extern int setup_map (struct multipath * mpp) @@ -521,3 +522,91 @@ coalesce_paths (struct vectors * vecs, vector newmp) } return 0; } + +extern char * +get_refwwid (char * dev, int dev_type, vector pathvec) +{ + struct path * pp; + char buff[FILE_NAME_SIZE]; + char * refwwid; + + if (dev_type == DEV_NONE) + return NULL; + + if (dev_type == DEV_DEVNODE) { + basename(dev, buff); + pp = find_path_by_dev(pathvec, buff); + + if (!pp) { + pp = alloc_path(); + + if (!pp) + return NULL; + + strncpy(pp->dev, buff, FILE_NAME_SIZE); + + if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID)) + return NULL; + + if (store_path(pathvec, pp)) { + free_path(pp); + return NULL; + } + } + refwwid = pp->wwid; + goto out; + } + + if (dev_type == DEV_DEVT) { + pp = find_path_by_devt(pathvec, dev); + + if (!pp) { + if (devt2devname(buff, dev)) + return NULL; + + pp = alloc_path(); + + if (!pp) + return NULL; + + strncpy(pp->dev, buff, FILE_NAME_SIZE); + + if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID)) + return NULL; + + if (store_path(pathvec, pp)) { + free_path(pp); + return NULL; + } + } + refwwid = pp->wwid; + goto out; + } + if (dev_type == DEV_DEVMAP) { + /* + * may be a binding + */ + refwwid = get_user_friendly_wwid(dev, + conf->bindings_file); + + if (refwwid) + return refwwid; + + /* + * or may be an alias + */ + refwwid = get_mpe_wwid(dev); + + /* + * or directly a wwid + */ + if (!refwwid) + refwwid = dev; + } +out: + if (refwwid && strlen(refwwid)) + return STRDUP(refwwid); + + return NULL; +} + diff --git a/libmultipath/configure.h b/libmultipath/configure.h index d58d0f9..16be8e3 100644 --- a/libmultipath/configure.h +++ b/libmultipath/configure.h @@ -25,3 +25,5 @@ int setup_map (struct multipath * mpp); int domap (struct multipath * mpp); int reinstate_paths (struct multipath *mpp); int coalesce_paths (struct vectors *vecs, vector curmp); +char * get_refwwid (char * dev, int dev_type, vector pathvec); + diff --git a/multipath/main.c b/multipath/main.c index c40d916..4ef4797 100644 --- a/multipath/main.c +++ b/multipath/main.c @@ -50,93 +50,6 @@ #include "main.h" -static char * -get_refwwid (vector pathvec) -{ - struct path * pp; - char buff[FILE_NAME_SIZE]; - char * refwwid; - - if (conf->dev_type == DEV_NONE) - return NULL; - - if (conf->dev_type == DEV_DEVNODE) { - basename(conf->dev, buff); - pp = find_path_by_dev(pathvec, buff); - - if (!pp) { - pp = alloc_path(); - - if (!pp) - return NULL; - - strncpy(pp->dev, buff, FILE_NAME_SIZE); - - if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID)) - return NULL; - - if (store_path(pathvec, pp)) { - free_path(pp); - return NULL; - } - } - refwwid = pp->wwid; - goto out; - } - - if (conf->dev_type == DEV_DEVT) { - pp = find_path_by_devt(pathvec, conf->dev); - - if (!pp) { - if (devt2devname(buff, conf->dev)) - return NULL; - - pp = alloc_path(); - - if (!pp) - return NULL; - - strncpy(pp->dev, buff, FILE_NAME_SIZE); - - if (pathinfo(pp, conf->hwtable, DI_SYSFS | DI_WWID)) - return NULL; - - if (store_path(pathvec, pp)) { - free_path(pp); - return NULL; - } - } - refwwid = pp->wwid; - goto out; - } - if (conf->dev_type == DEV_DEVMAP) { - /* - * may be a binding - */ - refwwid = get_user_friendly_wwid(conf->dev, - conf->bindings_file); - - if (refwwid) - return refwwid; - - /* - * or may be an alias - */ - refwwid = get_mpe_wwid(conf->dev); - - /* - * or directly a wwid - */ - if (!refwwid) - refwwid = conf->dev; - } -out: - if (refwwid && strlen(refwwid)) - return STRDUP(refwwid); - - return NULL; -} - static int filter_pathvec (vector pathvec, char * refwwid) { @@ -334,7 +247,7 @@ configure (void) * failing the translation is fatal (by policy) */ if (conf->dev) { - refwwid = get_refwwid(pathvec); + refwwid = get_refwwid(conf->dev, conf->dev_type, pathvec); if (!refwwid) { condlog(3, "scope is nul"); -- 2.7.4