File: switchgroup.c

package info (click to toggle)
multipath-tools 0.4.7-1.1etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,204 kB
  • ctags: 2,144
  • sloc: ansic: 18,261; makefile: 398; sh: 286
file content (42 lines) | stat: -rw-r--r-- 704 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (c) 2005 Christophe Varoqui
 * Copyright (c) 2005 Edward Goggin, EMC
 */
#include <checkers.h>

#include "vector.h"
#include "structs.h"
#include "switchgroup.h"

extern int
select_path_group (struct multipath * mpp)
{
	int i, j;
	int highest = 0;
	int bestpg = 1;
	struct pathgroup * pgp;
	struct path * pp;
	int priority;

	if (!mpp->pg)
		return 1;
	
	vector_foreach_slot (mpp->pg, pgp, i) {
		if (!pgp->paths)
			continue;

		priority = 0;

		vector_foreach_slot (pgp->paths, pp, j) {
			if (pp->state != PATH_DOWN)
				priority += pp->priority;
		}
		pgp->priority = priority;

		if (pgp->priority > highest) {
			highest = pgp->priority;
			bestpg = i + 1;
		}
	}
	return bestpg;
}