#include "vector.h"
#include "structs.h"
#include "pgpolicies.h"
+#include "switchgroup.h"
extern int
get_pgpolicy_id (char * str)
return snprintf(buff, POLICY_NAME_SIZE, "%s", s);
}
+
+void
+sort_pathgroups (struct multipath *mp) {
+ int i, j;
+ struct pathgroup * pgp1, * pgp2;
+
+ if (!mp->pg)
+ return;
+
+ vector_foreach_slot(mp->pg, pgp1, i) {
+ path_group_prio_update(pgp1);
+ for (j = i - 1; j >= 0; j--) {
+ pgp2 = VECTOR_SLOT(mp->pg, j);
+ if (!pgp2)
+ continue;
+ if (pgp2->priority > pgp1->priority ||
+ (pgp2->priority == pgp1->priority &&
+ pgp2->enabled_paths >= pgp1->enabled_paths)) {
+ vector_move_up(mp->pg, i, j + 1);
+ break;
+ }
+ }
+ if (j < 0 && i != 0)
+ vector_move_up(mp->pg, i, 0);
+ }
+}
+
+
/*
* One path group per unique tgt_node_name present in the path vector
*/
}
}
FREE(bitmap);
+ sort_pathgroups(mp);
free_pathvec(mp->paths, KEEP_PATHS);
mp->paths = NULL;
return 0;
}
}
FREE(bitmap);
+ sort_pathgroups(mp);
free_pathvec(mp->paths, KEEP_PATHS);
mp->paths = NULL;
return 0;
if (store_path(pgp->paths, pp))
goto out;
}
+ sort_pathgroups(mp);
free_pathvec(mp->paths, KEEP_PATHS);
mp->paths = NULL;
return 0;
static int
snprint_pg_pri (char * buff, size_t len, struct pathgroup * pgp)
{
- int avg_priority = 0;
/*
* 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);
- if (pgp->enabled_paths)
- avg_priority = pgp->priority / pgp->enabled_paths;
- return snprint_int(buff, len, avg_priority);
+ return snprint_int(buff, len, pgp->priority);
}
static int
pgp->enabled_paths++;
}
}
- pgp->priority = priority;
+ if (pgp->enabled_paths)
+ pgp->priority = priority / pgp->enabled_paths;
+ else
+ pgp->priority = 0;
}
extern int
select_path_group (struct multipath * mpp)
{
int i;
- int max_priority = 0, avg_priority;
+ int max_priority = 0;
int bestpg = 1;
int max_enabled_paths = 1;
struct pathgroup * pgp;
path_group_prio_update(pgp);
if (pgp->enabled_paths) {
- avg_priority = pgp->priority / pgp->enabled_paths;
- if (avg_priority > max_priority) {
- max_priority = avg_priority;
+ if (pgp->priority > max_priority) {
+ max_priority = pgp->priority;
max_enabled_paths = pgp->enabled_paths;
bestpg = i + 1;
- } else if (avg_priority == max_priority) {
+ } else if (pgp->priority == max_priority) {
if (pgp->enabled_paths > max_enabled_paths) {
max_enabled_paths = pgp->enabled_paths;
bestpg = i + 1;
return v->slot;
}
+int
+vector_move_up(vector v, int src, int dest)
+{
+ void *value;
+ int i;
+ if (dest == src)
+ return 0;
+ if (dest > src || src >= v->allocated)
+ return -1;
+ value = v->slot[src];
+ for (i = src - 1; i >= dest; i--)
+ v->slot[i + 1] = v->slot[i];
+ v->slot[dest] = value;
+ return 0;
+}
+
void *
vector_insert_slot(vector v, int slot, void *value)
{