[multipathd] stop switch to best PG when no PG is active
authorChristophe Varoqui <root@xa-s05.(none)>
Fri, 4 Nov 2005 09:37:03 +0000 (10:37 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Fri, 4 Nov 2005 09:37:03 +0000 (10:37 +0100)
To do that I added struct multipath:bestpg to store
switchgroup:select_path_group() result.

struct multipath:nextpg now only store current DM setting.

So the test is now (bestpg != nextpg) to trigger a switchgroup.

libmultipath/structs.c
libmultipath/structs.h
libmultipath/switchgroup.c
libmultipath/switchgroup.h
multipath/main.c
multipathd/main.c

index b5db965..148d1ef 100644 (file)
@@ -108,7 +108,7 @@ alloc_multipath (void)
        mpp = (struct multipath *)MALLOC(sizeof(struct multipath));
 
        if (mpp)
-               mpp->nextpg = 1;
+               mpp->bestpg = 1;
 
        return mpp;
 }
index 2e35700..183e790 100644 (file)
@@ -112,6 +112,7 @@ struct multipath {
        char wwid[WWID_SIZE];
        int pgpolicy;
        int nextpg;
+       int bestpg;
        int queuedio;
        int action;
        int pgfailback;
index 857667c..8ebbae7 100644 (file)
@@ -3,16 +3,17 @@
 #include "switchgroup.h"
 #include "../libcheckers/path_state.h"
 
-extern void
+extern int
 select_path_group (struct multipath * mpp)
 {
        int i, j;
        int highest = 0;
+       int bestpg = 1;
        struct pathgroup * pgp;
        struct path * pp;
 
        if (!mpp->pg)
-               return;
+               return 1;
        
        vector_foreach_slot (mpp->pg, pgp, i) {
                if (!pgp->paths)
@@ -25,7 +26,8 @@ select_path_group (struct multipath * mpp)
 
                if (pgp->priority > highest) {
                        highest = pgp->priority;
-                       mpp->nextpg = i + 1;
+                       bestpg = i + 1;
                }
        }
+       return bestpg;
 }
index cc98210..edf6f24 100644 (file)
@@ -1 +1 @@
-void select_path_group (struct multipath * mpp);
+int select_path_group (struct multipath * mpp);
index 98bdda9..02a2279 100644 (file)
@@ -317,7 +317,7 @@ assemble_map (struct multipath * mp)
        
        shift = snprintf(p, freechar, "%s %s %i %i",
                         mp->features, mp->hwhandler,
-                        VECTOR_SIZE(mp->pg), mp->nextpg);
+                        VECTOR_SIZE(mp->pg), mp->bestpg);
 
        if (shift >= freechar) {
                fprintf(stderr, "mp->params too small\n");
@@ -418,7 +418,7 @@ setup_map (struct multipath * mpp)
         * ponders each path group and determine highest prio pg
         * to switch over (default to first)
         */
-       select_path_group(mpp);
+       mpp->bestpg = select_path_group(mpp);
 
        /*
         * transform the mp->pg vector of vectors of paths
@@ -548,7 +548,7 @@ select_action (struct multipath * mpp, vector curmp)
                condlog(3, "set ACT_RELOAD: path group topology change");
                return;
        }
-       if (cmpp->nextpg != mpp->nextpg) {
+       if (cmpp->nextpg != mpp->bestpg) {
                mpp->action = ACT_SWITCHPG;
                condlog(3, "set ACT_SWITCHPG: next path group change");
                return;
@@ -634,7 +634,7 @@ domap (struct multipath * mpp)
                return 2;
 
        case ACT_SWITCHPG:
-               dm_switchgroup(mpp->alias, mpp->nextpg);
+               dm_switchgroup(mpp->alias, mpp->bestpg);
                /*
                 * we may have avoided reinstating paths because there where in
                 * active or disabled PG. Now that the topology has changed,
@@ -686,7 +686,7 @@ domap (struct multipath * mpp)
                /*
                 * DM_DEVICE_CREATE or DM_DEVICE_RELOAD succeeded
                 */
-               dm_switchgroup(mpp->alias, mpp->nextpg);
+               dm_switchgroup(mpp->alias, mpp->bestpg);
                print_mp(mpp);
        }
 
@@ -936,7 +936,7 @@ get_dm_mpvec (vector curmp, vector pathvec, char * refwwid)
                        update_paths(mpp);
 
                if (conf->list > 1)
-                       select_path_group(mpp);
+                       mpp->bestpg = select_path_group(mpp);
 
                disassemble_status(mpp->status, mpp);
 
index 3c5701c..c290efa 100644 (file)
@@ -423,10 +423,9 @@ need_switch_pathgroup (struct multipath * mpp, int refresh)
                        vector_foreach_slot (pgp->paths, pp, j)
                                pathinfo(pp, conf->hwtable, DI_PRIO);
 
-       select_path_group(mpp); /* sets mpp->nextpg */
-       pgp = VECTOR_SLOT(mpp->pg, mpp->nextpg - 1);
+       mpp->bestpg = select_path_group(mpp);
 
-       if (pgp && pgp->status != PGSTATE_ACTIVE)
+       if (mpp->bestpg != mpp->nextpg)
                return 1;
 
        return 0;
@@ -435,15 +434,9 @@ need_switch_pathgroup (struct multipath * mpp, int refresh)
 static void
 switch_pathgroup (struct multipath * mpp)
 {
-       struct pathgroup * pgp;
-       
-       pgp = VECTOR_SLOT(mpp->pg, mpp->nextpg - 1);
-       
-       if (pgp && pgp->status != PGSTATE_ACTIVE) {
-               dm_switchgroup(mpp->alias, mpp->nextpg);
-               condlog(2, "%s: switch to path group #%i",
-                        mpp->alias, mpp->nextpg);
-       }
+       dm_switchgroup(mpp->alias, mpp->bestpg);
+       condlog(2, "%s: switch to path group #%i",
+                mpp->alias, mpp->bestpg);
 }
 
 static int