[libmultipath] update path group prio on pg display
authorChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 18 Nov 2007 18:26:44 +0000 (19:26 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Sun, 18 Nov 2007 18:26:44 +0000 (19:26 +0100)
pg prio was previously only computed upon switching.
Updating upon display make sense too.

libmultipath/print.c
libmultipath/switchgroup.c
libmultipath/switchgroup.h

index 9ac5cc0..cd42ca3 100644 (file)
@@ -21,6 +21,7 @@
 #include "defaults.h"
 #include "parser.h"
 #include "blacklist.h"
+#include "switchgroup.h"
 
 #define MAX(x,y) (x > y) ? x : y
 #define TAIL     (line + len - 1 - c)
@@ -340,6 +341,13 @@ snprint_pg_selector (char * buff, size_t len, struct pathgroup * pgp)
 static int
 snprint_pg_pri (char * buff, size_t len, struct pathgroup * pgp)
 {
+       /*
+        * path group priority is not updated for every path prio change,
+        * but only on switch group code path.
+        *
+        * Printing is another reason to update.
+        */
+       path_group_prio_update(pgp);
        return snprint_int(buff, len, pgp->priority);
 }
 
index 757543f..e99a297 100644 (file)
@@ -8,15 +8,31 @@
 #include "structs.h"
 #include "switchgroup.h"
 
+extern void
+path_group_prio_update (struct pathgroup * pgp)
+{
+       int i;
+       int priority = 0;
+       struct path * pp;
+
+       if (!pgp->paths) {
+               pgp->priority = 0;
+               return;
+       }
+       vector_foreach_slot (pgp->paths, pp, i) {
+               if (pp->state != PATH_DOWN)
+                       priority += pp->priority;
+       }
+       pgp->priority = priority;
+}
+
 extern int
 select_path_group (struct multipath * mpp)
 {
-       int i, j;
+       int i;
        int highest = 0;
        int bestpg = 1;
        struct pathgroup * pgp;
-       struct path * pp;
-       int priority;
 
        if (!mpp->pg)
                return 1;
@@ -25,14 +41,7 @@ select_path_group (struct multipath * mpp)
                if (!pgp->paths)
                        continue;
 
-               priority = 0;
-
-               vector_foreach_slot (pgp->paths, pp, j) {
-                       if (pp->state != PATH_DOWN)
-                               priority += pp->priority;
-               }
-               pgp->priority = priority;
-
+               path_group_prio_update(pgp);
                if (pgp->priority > highest) {
                        highest = pgp->priority;
                        bestpg = i + 1;
index edf6f24..9365e2e 100644 (file)
@@ -1 +1,2 @@
+void path_group_prio_update (struct pathgroup * pgp);
 int select_path_group (struct multipath * mpp);