multipathd: fix reservation_key check
[multipath-tools/.git] / libmultipath / structs_vec.c
index c8d08ea..38f0438 100644 (file)
@@ -10,7 +10,6 @@
 #include "structs.h"
 #include "structs_vec.h"
 #include "sysfs.h"
-#include "waiter.h"
 #include "devmapper.h"
 #include "dmparser.h"
 #include "propsel.h"
@@ -18,6 +17,7 @@
 #include "prio.h"
 #include "configure.h"
 #include "libdevmapper.h"
+#include "io_err_stat.h"
 
 /*
  * creates or updates mpp->paths reading mpp->pg
@@ -71,9 +71,10 @@ int adopt_paths(vector pathvec, struct multipath *mpp)
                            store_path(mpp->paths, pp))
                                        return 1;
                        conf = get_multipath_config();
+                       pthread_cleanup_push(put_multipath_config, conf);
                        ret = pathinfo(pp, conf,
                                       DI_PRIO | DI_CHECKER);
-                       put_multipath_config(conf);
+                       pthread_cleanup_pop(1);
                        if (ret)
                                return 1;
                }
@@ -107,33 +108,13 @@ void orphan_paths(vector pathvec, struct multipath *mpp)
        }
 }
 
-static void
-set_multipath_wwid (struct multipath * mpp)
-{
-       if (strlen(mpp->wwid))
-               return;
-
-       dm_get_uuid(mpp->alias, mpp->wwid);
-}
-
-#define KEEP_WAITER 0
-#define STOP_WAITER 1
-#define PURGE_VEC 1
-
-static void
-_remove_map (struct multipath * mpp, struct vectors * vecs,
-           int stop_waiter, int purge_vec)
+void
+remove_map(struct multipath * mpp, struct vectors * vecs, int purge_vec)
 {
        int i;
 
        condlog(4, "%s: remove multipath map", mpp->alias);
 
-       /*
-        * stop the DM event waiter thread
-        */
-       if (stop_waiter)
-               stop_waiter_thread(mpp, vecs);
-
        /*
         * clear references to this map
         */
@@ -149,19 +130,16 @@ _remove_map (struct multipath * mpp, struct vectors * vecs,
        free_multipath(mpp, KEEP_PATHS);
 }
 
-void remove_map(struct multipath *mpp, struct vectors *vecs, int purge_vec)
-{
-       _remove_map(mpp, vecs, KEEP_WAITER, purge_vec);
-}
-
-void remove_map_and_stop_waiter(struct multipath *mpp, struct vectors *vecs,
-                               int purge_vec)
+void
+remove_map_by_alias(const char *alias, struct vectors * vecs, int purge_vec)
 {
-       _remove_map(mpp, vecs, STOP_WAITER, purge_vec);
+       struct multipath * mpp = find_mp_by_alias(vecs->mpvec, alias);
+       if (mpp)
+               remove_map(mpp, vecs, purge_vec);
 }
 
-static void
-_remove_maps (struct vectors * vecs, int stop_waiter)
+void
+remove_maps(struct vectors * vecs)
 {
        int i;
        struct multipath * mpp;
@@ -170,7 +148,7 @@ _remove_maps (struct vectors * vecs, int stop_waiter)
                return;
 
        vector_foreach_slot (vecs->mpvec, mpp, i) {
-               _remove_map(mpp, vecs, stop_waiter, 1);
+               remove_map(mpp, vecs, 1);
                i--;
        }
 
@@ -178,16 +156,6 @@ _remove_maps (struct vectors * vecs, int stop_waiter)
        vecs->mpvec = NULL;
 }
 
-void remove_maps(struct vectors *vecs)
-{
-       _remove_maps(vecs, KEEP_WAITER);
-}
-
-void remove_maps_and_stop_waiters(struct vectors *vecs)
-{
-       _remove_maps(vecs, STOP_WAITER);
-}
-
 void
 extract_hwe_from_path(struct multipath * mpp)
 {
@@ -309,7 +277,10 @@ update_multipath_strings(struct multipath *mpp, vector pathvec, int is_daemon)
 
 void enter_recovery_mode(struct multipath *mpp)
 {
+       int checkint;
        struct config *conf = get_multipath_config();
+       checkint = conf->checkint;
+       put_multipath_config(conf);
 
        /*
         * Enter retry mode.
@@ -317,65 +288,9 @@ void enter_recovery_mode(struct multipath *mpp)
         * starting retry.
         */
        mpp->stat_queueing_timeouts++;
-       mpp->retry_tick = mpp->no_path_retry * conf->checkint + 1;
+       mpp->retry_tick = mpp->no_path_retry * checkint + 1;
        condlog(1, "%s: Entering recovery mode: max_retries=%d",
                mpp->alias, mpp->no_path_retry);
-       put_multipath_config(conf);
-}
-
-static void set_no_path_retry(struct multipath *mpp)
-{
-       char is_queueing = 0;
-
-       mpp->nr_active = pathcount(mpp, PATH_UP) + pathcount(mpp, PATH_GHOST);
-       if (mpp->features && strstr(mpp->features, "queue_if_no_path"))
-               is_queueing = 1;
-
-       switch (mpp->no_path_retry) {
-       case NO_PATH_RETRY_UNDEF:
-               break;
-       case NO_PATH_RETRY_FAIL:
-               if (is_queueing)
-                       dm_queue_if_no_path(mpp->alias, 0);
-               break;
-       case NO_PATH_RETRY_QUEUE:
-               if (!is_queueing)
-                       dm_queue_if_no_path(mpp->alias, 1);
-               break;
-       default:
-               if (mpp->nr_active > 0) {
-                       mpp->retry_tick = 0;
-                       dm_queue_if_no_path(mpp->alias, 1);
-               } else if (is_queueing && mpp->retry_tick == 0)
-                       enter_recovery_mode(mpp);
-               break;
-       }
-}
-
-int __setup_multipath(struct vectors *vecs, struct multipath *mpp,
-                     int reset)
-{
-       if (dm_get_info(mpp->alias, &mpp->dmi)) {
-               /* Error accessing table */
-               condlog(3, "%s: cannot access table", mpp->alias);
-               goto out;
-       }
-
-       if (update_multipath_strings(mpp, vecs->pathvec, 1)) {
-               condlog(0, "%s: failed to setup multipath", mpp->alias);
-               goto out;
-       }
-
-       if (reset) {
-               set_no_path_retry(mpp);
-               if (VECTOR_SIZE(mpp->paths) != 0)
-                       dm_cancel_deferred_remove(mpp);
-       }
-
-       return 0;
-out:
-       remove_map(mpp, vecs, PURGE_VEC);
-       return 1;
 }
 
 void
@@ -409,92 +324,6 @@ sync_map_state(struct multipath *mpp)
        }
 }
 
-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->action = ACT_RELOAD;
-
-       extract_hwe_from_path(mpp);
-       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, const char *alias)
-{
-       struct multipath * mpp = alloc_multipath();
-       struct config *conf;
-
-       if (!mpp)
-               return NULL;
-       if (!alias) {
-               FREE(mpp);
-               return NULL;
-       }
-
-       mpp->alias = STRDUP(alias);
-
-       if (dm_get_info(mpp->alias, &mpp->dmi)) {
-               condlog(3, "%s: cannot access table", mpp->alias);
-               goto out;
-       }
-       set_multipath_wwid(mpp);
-       conf = get_multipath_config();
-       mpp->mpe = find_mpe(conf->mptable, mpp->wwid);
-       put_multipath_config(conf);
-
-       if (update_multipath_table(mpp, vecs->pathvec, 1))
-               goto out;
-       if (update_multipath_status(mpp))
-               goto out;
-
-       if (!vector_alloc_slot(vecs->mpvec))
-               goto out;
-
-       vector_set_slot(vecs->mpvec, mpp);
-
-       if (update_map(mpp, vecs) != 0) /* map removed */
-               return NULL;
-
-       if (start_waiter_thread(mpp, vecs))
-               goto out;
-
-       return mpp;
-out:
-       remove_map(mpp, vecs, PURGE_VEC);
-       return NULL;
-}
-
 static void
 find_existing_alias (struct multipath * mpp,
                     struct vectors *vecs)
@@ -587,54 +416,6 @@ int verify_paths(struct multipath *mpp, struct vectors *vecs)
        return count;
 }
 
-int update_multipath (struct vectors *vecs, char *mapname, int reset)
-{
-       struct multipath *mpp;
-       struct pathgroup  *pgp;
-       struct path *pp;
-       int i, j;
-
-       mpp = find_mp_by_alias(vecs->mpvec, mapname);
-
-       if (!mpp) {
-               condlog(3, "%s: multipath map not found", mapname);
-               return 2;
-       }
-
-       if (__setup_multipath(vecs, mpp, reset))
-               return 1; /* mpp freed in setup_multipath */
-
-       /*
-        * compare checkers states with DM states
-        */
-       vector_foreach_slot (mpp->pg, pgp, i) {
-               vector_foreach_slot (pgp->paths, pp, j) {
-                       if (pp->dmstate != PSTATE_FAILED)
-                               continue;
-
-                       if (pp->state != PATH_DOWN) {
-                               struct config *conf = get_multipath_config();
-                               int oldstate = pp->state;
-                               condlog(2, "%s: mark as failed", pp->dev);
-                               mpp->stat_path_failures++;
-                               pp->state = PATH_DOWN;
-                               if (oldstate == PATH_UP ||
-                                   oldstate == PATH_GHOST)
-                                       update_queue_mode_del_path(mpp);
-
-                               /*
-                                * if opportune,
-                                * schedule the next check earlier
-                                */
-                               if (pp->tick > conf->checkint)
-                                       pp->tick = conf->checkint;
-                               put_multipath_config(conf);
-                       }
-               }
-       }
-       return 0;
-}
-
 /*
  * mpp->no_path_retry:
  *   -2 (QUEUE) : queue_if_no_path enabled, never turned off