[lib] abstract a little more devmapper internals
authorChristophe Varoqui <christophe.varoqui@free.fr>
Sat, 19 Jul 2008 16:26:54 +0000 (18:26 +0200)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Sat, 19 Jul 2008 16:26:54 +0000 (18:26 +0200)
o move DEFAULT_TARGET define from defaults.h to devmapper.h
o rename DEFAULT_TARGET into TGT_MPATH (multipath)
o introduce TGT_PART (linear)
o remove the type param from functions used only with TGT_MPATH
o abstract dm_addmap() with to wrappers dm_addmap_create() and
  dm_addmap_reload(). Wrappers don't require the type and task
  params.
o move the dm_addmap(DM_DEVICE_CREATE, ...) cleanup on failure
  from configure.c into devmapper.c::dm_addmap_create()

libmultipath/configure.c
libmultipath/defaults.h
libmultipath/devmapper.c
libmultipath/devmapper.h
libmultipath/print.c
libmultipath/propsel.c
libmultipath/structs_vec.c
multipath/main.c
multipathd/main.c

index 13897e2..5a40222 100644 (file)
@@ -154,7 +154,7 @@ select_action (struct multipath * mpp, vector curmp, int force_reload)
 
        if (!find_mp_by_wwid(curmp, mpp->wwid)) {
                condlog(2, "%s: remove (wwid changed)", cmpp->alias);
-               dm_flush_map(mpp->alias, DEFAULT_TARGET);
+               dm_flush_map(mpp->alias);
                strncat(cmpp->wwid, mpp->wwid, WWID_SIZE);
                drop_multipath(curmp, cmpp->wwid, KEEP_PATHS);
                mpp->action = ACT_CREATE;
@@ -336,28 +336,15 @@ domap (struct multipath * mpp)
                        break;
                }
 
-               r = dm_addmap(DM_DEVICE_CREATE, mpp->alias, DEFAULT_TARGET,
-                             mpp->params, mpp->size, mpp->wwid);
-
-               /*
-                * DM_DEVICE_CREATE is actually DM_DEV_CREATE plus
-                * DM_TABLE_LOAD. Failing the second part leaves an
-                * empty map. Clean it up.
-                */
-               if (!r && dm_map_present(mpp->alias)) {
-                       condlog(3, "%s: failed to load map "
-                                  "(a path might be in use)",
-                                  mpp->alias);
-                       dm_flush_map(mpp->alias, DEFAULT_TARGET);
-               }
+               r = dm_addmap_create(mpp->alias, mpp->params, mpp->size,
+                                    mpp->wwid);
 
                lock_multipath(mpp, 0);
                break;
 
        case ACT_RELOAD:
-               r = (dm_addmap(DM_DEVICE_RELOAD, mpp->alias, DEFAULT_TARGET,
-                             mpp->params, mpp->size, NULL) &&
-                    dm_simplecmd(DM_DEVICE_RESUME, mpp->alias));
+               r = (dm_addmap_reload(mpp->alias, mpp->params, mpp->size, NULL)
+                    && dm_simplecmd(DM_DEVICE_RESUME, mpp->alias));
                break;
 
        case ACT_RENAME:
@@ -382,7 +369,7 @@ domap (struct multipath * mpp)
                        /* multipath daemon mode */
                        mpp->stat_map_loads++;
                        condlog(2, "%s: load table [0 %llu %s %s]", mpp->alias,
-                               mpp->size, DEFAULT_TARGET, mpp->params);
+                               mpp->size, TGT_MPATH, mpp->params);
                        /*
                         * Required action is over, reset for the stateful daemon
                         */
@@ -558,7 +545,7 @@ coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, int force_r
 
                        remove_map(mpp, vecs, 0);
 
-                       if (dm_flush_map(mpp->alias, DEFAULT_TARGET))
+                       if (dm_flush_map(mpp->alias))
                                condlog(2, "%s: remove failed (dead)",
                                        mpp->alias);
                        else
index e8060a2..826f360 100644 (file)
@@ -15,7 +15,6 @@
 #define DEFAULT_CHECKINT       5
 #define MAX_CHECKINT(a)                (a << 2)
 
-#define DEFAULT_TARGET         "multipath"
 #define DEFAULT_PIDFILE                "/var/run/multipathd.pid"
 #define DEFAULT_SOCKET         "/var/run/multipathd.sock"
 #define DEFAULT_CONFIGFILE     "/etc/multipath.conf"
index cc01486..3e79d97 100644 (file)
@@ -142,11 +142,11 @@ out:
 }
 
 extern int
-dm_prereq (char * str)
+dm_prereq (void)
 {
        if (dm_libprereq())
                return 1;
-       return dm_drvprereq(str);
+       return dm_drvprereq(TGT_MPATH);
 }
 
 extern int
@@ -211,11 +211,37 @@ dm_addmap (int task, const char *name, const char *target,
 
        addout:
        dm_task_destroy (dmt);
+
+       return r;
+}
+
+extern int
+dm_addmap_create (const char *name, const char *params,
+                 unsigned long long size, const char *uuid) {
+       int r;
+       r = dm_addmap(DM_DEVICE_CREATE, name, TGT_MPATH, params, size, uuid);
+       /*
+        * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD.
+        * Failing the second part leaves an empty map. Clean it up.
+        */
+       if (!r && dm_map_present(name)) {
+               condlog(3, "%s: failed to load map (a path might be in use)",
+                       name);
+               dm_flush_map(name);
+       }
+       return r;
+}
+
+extern int
+dm_addmap_reload (const char *name, const char *params,
+                 unsigned long long size, const char *uuid) {
+       int r;
+       r = dm_addmap(DM_DEVICE_RELOAD, name, TGT_MPATH, params, size, uuid);
        return r;
 }
 
 extern int
-dm_map_present (char * str)
+dm_map_present (const char * str)
 {
        int r = 0;
        struct dm_task *dmt;
@@ -352,7 +378,7 @@ out:
  *   -1 : empty map
  */
 extern int
-dm_type(char * name, char * type)
+dm_type(const char * name, char * type)
 {
        int r = 0;
        struct dm_task *dmt;
@@ -387,7 +413,7 @@ out:
 }
 
 static int
-dm_dev_t (char * mapname, char * dev_t, int len)
+dm_dev_t (const char * mapname, char * dev_t, int len)
 {
        int r = 1;
        struct dm_task *dmt;
@@ -416,7 +442,7 @@ out:
 }
        
 int
-dm_get_opencount (char * mapname)
+dm_get_opencount (const char * mapname)
 {
        int r = -1;
        struct dm_task *dmt;
@@ -466,14 +492,14 @@ out:
 }
        
 extern int
-dm_flush_map (char * mapname, char * type)
+dm_flush_map (const char * mapname)
 {
        int r;
 
        if (!dm_map_present(mapname))
                return 0;
 
-       if (dm_type(mapname, type) <= 0)
+       if (dm_type(mapname, TGT_MPATH) <= 0)
                return 1;
 
        if (dm_remove_partmaps(mapname))
@@ -494,7 +520,7 @@ dm_flush_map (char * mapname, char * type)
 }
 
 extern int
-dm_flush_maps (char * type)
+dm_flush_maps (void)
 {
        int r = 0;
        struct dm_task *dmt;
@@ -516,7 +542,7 @@ dm_flush_maps (char * type)
                goto out;
 
        do {
-               r += dm_flush_map(names->name, type);
+               r += dm_flush_map(names->name);
                next = names->next;
                names = (void *) names + next;
        } while (next);
@@ -633,7 +659,7 @@ dm_disablegroup(char * mapname, int index)
 }
 
 int
-dm_get_maps (vector mp, char * type)
+dm_get_maps (vector mp)
 {
        struct multipath * mpp;
        int r = 1;
@@ -642,7 +668,7 @@ dm_get_maps (vector mp, char * type)
        struct dm_names *names;
        unsigned next = 0;
 
-       if (!type || !mp)
+       if (!mp)
                return 1;
 
        if (!(dmt = dm_task_create(DM_DEVICE_LIST)))
@@ -662,7 +688,7 @@ dm_get_maps (vector mp, char * type)
        }
 
        do {
-               info = dm_type(names->name, type);
+               info = dm_type(names->name, TGT_MPATH);
 
                if (info <= 0)
                        goto next;
@@ -708,7 +734,7 @@ out:
 }
 
 extern int
-dm_get_name(char *uuid, char *type, char *name)
+dm_get_name(char *uuid, char *name)
 {
        vector vec;
        struct multipath *mpp;
@@ -719,7 +745,7 @@ dm_get_name(char *uuid, char *type, char *name)
        if (!vec)
                return 0;
 
-       if (dm_get_maps(vec, type)) {
+       if (dm_get_maps(vec)) {
                vector_free(vec);
                return 0;
        }
@@ -818,7 +844,7 @@ bad:
 }
 
 int
-dm_remove_partmaps (char * mapname)
+dm_remove_partmaps (const char * mapname)
 {
        struct dm_task *dmt;
        struct dm_names *names;
@@ -852,7 +878,7 @@ dm_remove_partmaps (char * mapname)
                    /*
                     * if devmap target is "linear"
                     */
-                   (dm_type(names->name, "linear") > 0) &&
+                   (dm_type(names->name, TGT_PART) > 0) &&
 
                    /*
                     * and the multipath mapname and the part mapname start
@@ -975,7 +1001,7 @@ dm_rename_partmaps (char * old, char * new)
                    /*
                     * if devmap target is "linear"
                     */
-                   (dm_type(names->name, "linear") > 0) &&
+                   (dm_type(names->name, TGT_PART) > 0) &&
 
                    /*
                     * and the multipath mapname and the part mapname start
index 8438034..962df8a 100644 (file)
@@ -1,14 +1,19 @@
+#define TGT_MPATH      "multipath"
+#define TGT_PART       "linear"
+
 void dm_init(void);
-int dm_prereq (char *);
+int dm_prereq (void);
 int dm_simplecmd (int, const char *);
-int dm_addmap (int, const char *, const char *, const char *,
-              unsigned long long, const char *uuid);
-int dm_map_present (char *);
+int dm_addmap_create (const char *, const char *,
+                      unsigned long long size, const char *uuid);
+int dm_addmap_reload (const char *, const char *,
+                      unsigned long long size, const char *uuid);
+int dm_map_present (const char *);
 int dm_get_map(char *, unsigned long long *, char *);
 int dm_get_status(char *, char *);
-int dm_type(char *, char *);
-int dm_flush_map (char *, char *);
-int dm_flush_maps (char *);
+int dm_type(const char *, char *);
+int dm_flush_map (const char *);
+int dm_flush_maps (void);
 int dm_fail_path(char * mapname, char * path);
 int dm_reinstate_path(char * mapname, char * path);
 int dm_queue_if_no_path(char *mapname, int enable);
@@ -16,12 +21,12 @@ int dm_set_pg_timeout(char *mapname, int timeout_val);
 int dm_switchgroup(char * mapname, int index);
 int dm_enablegroup(char * mapname, int index);
 int dm_disablegroup(char * mapname, int index);
-int dm_get_maps (vector mp, char * type);
+int dm_get_maps (vector mp);
 int dm_geteventnr (char *name);
 int dm_get_minor (char *name);
 char * dm_mapname(int major, int minor);
-int dm_remove_partmaps (char * mapname);
+int dm_remove_partmaps (const char * mapname);
 int dm_get_uuid(char *name, char *uuid);
 int dm_get_info (char * mapname, struct dm_info ** dmi);
 int dm_rename (char * old, char * new);
-int dm_get_name(char * uuid, char * type, char * name);
+int dm_get_name(char * uuid, char * name);
index 9c509d5..3be1c9d 100644 (file)
@@ -21,6 +21,7 @@
 #include "parser.h"
 #include "blacklist.h"
 #include "switchgroup.h"
+#include "devmapper.h"
 
 #define MAX(x,y) (x > y) ? x : y
 #define TAIL     (line + len - 1 - c)
@@ -1235,7 +1236,7 @@ print_map (struct multipath * mpp)
 {
        if (mpp->size && mpp->params)
                printf("0 %llu %s %s\n",
-                        mpp->size, DEFAULT_TARGET, mpp->params);
+                        mpp->size, TGT_MPATH, mpp->params);
        return;
 }
 
index bd85cb9..43611ff 100644 (file)
@@ -168,8 +168,7 @@ select_alias (struct multipath * mp)
                if (mp->alias == NULL){
                        char *alias;
                        if ((alias = MALLOC(WWID_SIZE)) != NULL){
-                               if (dm_get_name(mp->wwid, DEFAULT_TARGET,
-                                               alias) == 1)
+                               if (dm_get_name(mp->wwid, alias) == 1)
                                        mp->alias = alias;
                                else
                                        FREE(alias);
index 3bb79cd..34b7669 100644 (file)
@@ -300,7 +300,7 @@ retry:
                /*
                 * detect an external rename of the multipath device
                 */
-               if (dm_get_name(mpp->wwid, DEFAULT_TARGET, new_alias)) {
+               if (dm_get_name(mpp->wwid, new_alias)) {
                        condlog(3, "%s multipath mapped device name has "
                                "changed from %s to %s", mpp->wwid,
                                mpp->alias, new_alias);
index b7334ec..4c65808 100644 (file)
@@ -157,7 +157,7 @@ get_dm_mpvec (vector curmp, vector pathvec, char * refwwid)
        int i;
        struct multipath * mpp;
 
-       if (dm_get_maps(curmp, DEFAULT_TARGET))
+       if (dm_get_maps(curmp))
                return 1;
 
        vector_foreach_slot (curmp, mpp, i) {
@@ -328,7 +328,7 @@ main (int argc, char *argv[])
                exit(1);
        }
 
-       if (dm_prereq(DEFAULT_TARGET))
+       if (dm_prereq())
                exit(1);
 
        if (load_config(DEFAULT_CONFIGFILE))
@@ -424,14 +424,14 @@ main (int argc, char *argv[])
 
        if (conf->remove == FLUSH_ONE) {
                if (conf->dev_type == DEV_DEVMAP)
-                       dm_flush_map(conf->dev, DEFAULT_TARGET);
+                       dm_flush_map(conf->dev);
                else
                        condlog(0, "must provide a map name to remove");
 
                goto out;
        }
        else if (conf->remove == FLUSH_ALL) {
-               dm_flush_maps(DEFAULT_TARGET);
+               dm_flush_maps();
                goto out;
        }
        while ((r = configure()) < 0)
index d406a4b..8d74cb9 100644 (file)
@@ -121,7 +121,7 @@ coalesce_maps(struct vectors *vecs, vector nmpv)
                         * remove all current maps not allowed by the
                         * current configuration
                         */
-                       if (dm_flush_map(ompp->alias, DEFAULT_TARGET)) {
+                       if (dm_flush_map(ompp->alias)) {
                                condlog(0, "%s: unable to flush devmap",
                                        ompp->alias);
                                /*
@@ -191,7 +191,7 @@ flush_map(struct multipath * mpp, struct vectors * vecs)
         * clear references to this map before flushing so we can ignore
         * the spurious uevent we may generate with the dm_flush_map call below
         */
-       if (dm_flush_map(mpp->alias, DEFAULT_TARGET)) {
+       if (dm_flush_map(mpp->alias)) {
                /*
                 * May not really be an error -- if the map was already flushed
                 * from the device mapper by dmsetup(8) for instance.
@@ -240,7 +240,7 @@ ev_add_map (struct sysfs_device * dev, struct vectors * vecs)
 
        map_present = dm_map_present(alias);
 
-       if (map_present && dm_type(alias, DEFAULT_TARGET) <= 0) {
+       if (map_present && dm_type(alias, TGT_MPATH) <= 0) {
                condlog(4, "%s: not a multipath map", alias);
                return 0;
        }
@@ -558,7 +558,7 @@ map_discovery (struct vectors * vecs)
        struct multipath * mpp;
        unsigned int i;
 
-       if (dm_get_maps(vecs->mpvec, "multipath"))
+       if (dm_get_maps(vecs->mpvec))
                return 1;
 
        vector_foreach_slot (vecs->mpvec, mpp, i)