Index: src/afs/afs_server.c =================================================================== RCS file: /cvs/openafs/src/afs/afs_server.c,v retrieving revision 1.43.4.11 diff -u -r1.43.4.11 afs_server.c --- src/afs/afs_server.c 18 Mar 2009 13:41:35 -0000 1.43.4.11 +++ src/afs/afs_server.c 13 Apr 2009 06:17:35 -0000 @@ -940,6 +940,55 @@ } } /*afs_SortServers */ +/* + * For Summer of Code Patch, should make the server rank random + */ +void +afs_SortServersRand(struct server *aservers[], int count) +{ + struct server *ts, *index; + int i, j, low, k, l; + + AFS_STATCNT(afs_SortServers); + + for (i = 0; i < count; i++) { + if (!aservers[i]) + break; + aservers[i]->addr->sa_iprank = afs_randomMod15(); + + for (low = i, j = i + 1; j <= count; j++) { + if ((!aservers[j]) || (!aservers[j]->addr)) + break; + if ((!aservers[low]) || (!aservers[low]->addr)) + break; + if (aservers[j]->addr->sa_iprank < aservers[low]->addr->sa_iprank) { + low = j; + } + } + if (low != i) { + ts = aservers[i]; + aservers[i] = aservers[low]; + aservers[low] = ts; + } + } + + for (k=1; k < count; k++) + { + /*index = aservers[k];*/ + memcpy(aservers[k], index, sizeof(index)); + l = k; + while ((l > 0) && (aservers[l-1]->addr->sa_iprank > index->addr->sa_iprank)) + { + /*aservers[l] = aservers[l-1];*/ + memcpy(aservers[l-1], aservers[l], sizeof(aservers[l])); + l = l - 1; + } + memcpy(index, aservers[l], sizeof(aservers[l])); + /*aservers[l] = index;*/ + } + +} /*afs_SortServers */ + /* afs_SetServerPrefs is rather system-dependent. It pokes around in kernel data structures to determine what the local IP addresses and subnet masks are in order to choose which server(s) are on the local subnet.