[libmultipath] move get_refwwid() to libmultipath/configure.c
authorChristophe Varoqui <root@xa-s05.(none)>
Wed, 23 Nov 2005 13:47:50 +0000 (14:47 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Wed, 23 Nov 2005 13:47:50 +0000 (14:47 +0100)
And pass "dev" and "dev_type" as params
to make it usable from multipathd.

libmultipath/configure.c
libmultipath/configure.h
multipath/main.c

index 77b84f3..6ea2f7b 100644 (file)
@@ -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;
+}
+
index d58d0f9..16be8e3 100644 (file)
@@ -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);
+
index c40d916..4ef4797 100644 (file)
 
 #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");