diff mbox

multipath-tools/libmultipath pgpolicies.c

Message ID 20091216053151.31526.qmail@sourceware.org (mailing list archive)
State New, archived
Headers show

Commit Message

bmarzins@sourceware.org Dec. 16, 2009, 5:31 a.m. UTC
None
diff mbox

Patch

--- multipath-tools/libmultipath/pgpolicies.c	2009/04/03 15:09:02	1.7.2.1
+++ multipath-tools/libmultipath/pgpolicies.c	2009/12/16 05:31:50	1.7.2.2
@@ -206,7 +206,8 @@ 
 extern int
 one_path_per_group (struct multipath * mp)
 {
-	int i;
+	int i, j;
+	unsigned int prio;
 	struct path * pp;
 	struct pathgroup * pgp;
 
@@ -218,16 +219,30 @@ 
 
 	for (i = 0; i < VECTOR_SIZE(mp->paths); i++) {
 		pp = VECTOR_SLOT(mp->paths, i);
+		prio = pp->priority;
+
+		vector_foreach_slot(mp->pg, pgp, j) {
+			pp = VECTOR_SLOT(pgp->paths, 0);
+
+			if (prio > pp->priority)
+				break;
+		}
+
 		pgp = alloc_pathgroup();
 
 		if (!pgp)
 			goto out;
 
-		if (store_pathgroup(mp->pg, pgp))
-			goto out;
-		
-		if (store_path(pgp->paths, pp))
+		if (store_path(pgp->paths, VECTOR_SLOT(mp->paths, i)))
 			goto out;
+
+		if (j < VECTOR_SIZE(mp->pg)) {
+			if (!vector_insert_slot(mp->pg, j, pgp))
+				goto out;
+		} else {
+			if (store_pathgroup(mp->pg, pgp))
+				goto out;
+		}
 	}
 	free_pathvec(mp->paths, KEEP_PATHS);
 	mp->paths = NULL;