multipathd: move helper functions to libmultipath
authorBenjamin Marzinski <bmarzins@redhat.com>
Thu, 7 Dec 2017 18:48:59 +0000 (12:48 -0600)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sat, 13 Jan 2018 09:13:51 +0000 (10:13 +0100)
This commit simply moves sync_map_state() and update_map() from
multipathd/main.c to libmultipath/structs_vec.c, to enable future
changes.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
libmultipath/structs_vec.c
libmultipath/structs_vec.h
multipathd/main.c
multipathd/main.h

index 22be8e0..eddeeaf 100644 (file)
@@ -16,6 +16,8 @@
 #include "propsel.h"
 #include "discovery.h"
 #include "prio.h"
+#include "configure.h"
+#include "libdevmapper.h"
 
 /*
  * creates or updates mpp->paths reading mpp->pg
@@ -415,6 +417,78 @@ out:
        return 1;
 }
 
+void
+sync_map_state(struct multipath *mpp)
+{
+       struct pathgroup *pgp;
+       struct path *pp;
+       unsigned int i, j;
+
+       if (!mpp->pg)
+               return;
+
+       vector_foreach_slot (mpp->pg, pgp, i){
+               vector_foreach_slot (pgp->paths, pp, j){
+                       if (pp->state == PATH_UNCHECKED ||
+                           pp->state == PATH_WILD ||
+                           pp->state == PATH_DELAYED)
+                               continue;
+                       if (mpp->ghost_delay_tick > 0)
+                               continue;
+                       if ((pp->dmstate == PSTATE_FAILED ||
+                            pp->dmstate == PSTATE_UNDEF) &&
+                           (pp->state == PATH_UP || pp->state == PATH_GHOST))
+                               dm_reinstate_path(mpp->alias, pp->dev_t);
+                       else if ((pp->dmstate == PSTATE_ACTIVE ||
+                                 pp->dmstate == PSTATE_UNDEF) &&
+                                (pp->state == PATH_DOWN ||
+                                 pp->state == PATH_SHAKY))
+                               dm_fail_path(mpp->alias, pp->dev_t);
+               }
+       }
+}
+
+int
+update_map (struct multipath *mpp, struct vectors *vecs)
+{
+       int retries = 3;
+       char params[PARAMS_SIZE] = {0};
+
+retry:
+       condlog(4, "%s: updating new map", mpp->alias);
+       if (adopt_paths(vecs->pathvec, mpp)) {
+               condlog(0, "%s: failed to adopt paths for new map update",
+                       mpp->alias);
+               retries = -1;
+               goto fail;
+       }
+       verify_paths(mpp, vecs);
+       mpp->flush_on_last_del = FLUSH_UNDEF;
+       mpp->action = ACT_RELOAD;
+
+       if (setup_map(mpp, params, PARAMS_SIZE)) {
+               condlog(0, "%s: failed to setup new map in update", mpp->alias);
+               retries = -1;
+               goto fail;
+       }
+       if (domap(mpp, params, 1) <= 0 && retries-- > 0) {
+               condlog(0, "%s: map_udate sleep", mpp->alias);
+               sleep(1);
+               goto retry;
+       }
+       dm_lib_release();
+
+fail:
+       if (setup_multipath(vecs, mpp))
+               return 1;
+
+       sync_map_state(mpp);
+
+       if (retries < 0)
+               condlog(0, "%s: failed reload in new map update", mpp->alias);
+       return 0;
+}
+
 struct multipath *add_map_without_path (struct vectors *vecs, char *alias)
 {
        struct multipath * mpp = alloc_multipath();
index 46f30af..54444e0 100644 (file)
@@ -30,6 +30,8 @@ void remove_map_and_stop_waiter (struct multipath * mpp, struct vectors * vecs,
 void remove_maps (struct vectors * vecs);
 void remove_maps_and_stop_waiters (struct vectors * vecs);
 
+void sync_map_state (struct multipath *);
+int update_map (struct multipath *mpp, struct vectors *vecs);
 struct multipath * add_map_without_path (struct vectors * vecs, char * alias);
 struct multipath * add_map_with_path (struct vectors * vecs,
                                struct path * pp, int add_vec);
index 20e9211..7c7eb2f 100644 (file)
@@ -337,37 +337,6 @@ coalesce_maps(struct vectors *vecs, vector nmpv)
        return 0;
 }
 
-void
-sync_map_state(struct multipath *mpp)
-{
-       struct pathgroup *pgp;
-       struct path *pp;
-       unsigned int i, j;
-
-       if (!mpp->pg)
-               return;
-
-       vector_foreach_slot (mpp->pg, pgp, i){
-               vector_foreach_slot (pgp->paths, pp, j){
-                       if (pp->state == PATH_UNCHECKED ||
-                           pp->state == PATH_WILD ||
-                           pp->state == PATH_DELAYED)
-                               continue;
-                       if (mpp->ghost_delay_tick > 0)
-                               continue;
-                       if ((pp->dmstate == PSTATE_FAILED ||
-                            pp->dmstate == PSTATE_UNDEF) &&
-                           (pp->state == PATH_UP || pp->state == PATH_GHOST))
-                               dm_reinstate_path(mpp->alias, pp->dev_t);
-                       else if ((pp->dmstate == PSTATE_ACTIVE ||
-                                 pp->dmstate == PSTATE_UNDEF) &&
-                                (pp->state == PATH_DOWN ||
-                                 pp->state == PATH_SHAKY))
-                               dm_fail_path(mpp->alias, pp->dev_t);
-               }
-       }
-}
-
 static void
 sync_maps_state(vector mpvec)
 {
@@ -415,47 +384,6 @@ flush_map(struct multipath * mpp, struct vectors * vecs, int nopaths)
        return 0;
 }
 
-int
-update_map (struct multipath *mpp, struct vectors *vecs)
-{
-       int retries = 3;
-       char params[PARAMS_SIZE] = {0};
-
-retry:
-       condlog(4, "%s: updating new map", mpp->alias);
-       if (adopt_paths(vecs->pathvec, mpp)) {
-               condlog(0, "%s: failed to adopt paths for new map update",
-                       mpp->alias);
-               retries = -1;
-               goto fail;
-       }
-       verify_paths(mpp, vecs);
-       mpp->flush_on_last_del = FLUSH_UNDEF;
-       mpp->action = ACT_RELOAD;
-
-       if (setup_map(mpp, params, PARAMS_SIZE)) {
-               condlog(0, "%s: failed to setup new map in update", mpp->alias);
-               retries = -1;
-               goto fail;
-       }
-       if (domap(mpp, params, 1) <= 0 && retries-- > 0) {
-               condlog(0, "%s: map_udate sleep", mpp->alias);
-               sleep(1);
-               goto retry;
-       }
-       dm_lib_release();
-
-fail:
-       if (setup_multipath(vecs, mpp))
-               return 1;
-
-       sync_map_state(mpp);
-
-       if (retries < 0)
-               condlog(0, "%s: failed reload in new map update", mpp->alias);
-       return 0;
-}
-
 static int
 uev_add_map (struct uevent * uev, struct vectors * vecs)
 {
index 094b04f..ededdab 100644 (file)
@@ -26,7 +26,6 @@ int ev_add_path (struct path *, struct vectors *, int);
 int ev_remove_path (struct path *, struct vectors *, int);
 int ev_add_map (char *, char *, struct vectors *);
 int ev_remove_map (char *, char *, int, struct vectors *);
-void sync_map_state (struct multipath *);
 int set_config_state(enum daemon_status);
 void * mpath_alloc_prin_response(int prin_sa);
 int prin_do_scsi_ioctl(char *, int rq_servact, struct prin_resp * resp,