From e77d5cea4a11677fea03abb2eb88717a1b686a94 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 2 Nov 2011 16:55:49 -0500 Subject: [PATCH] afs: Do not use separate array for srvAddrs The array of srvAddr structs we use in afs_LoopServers have indices unrelated to the indices of conns, rxconns, etc. Several places were assuming that addr[i] corresponded to conn[i], which is not necessarily true. So instead, do not use the separate addr array (except when populating the conn and rxconn arrays), and just get the srvAddr structure by going through the relevant conn[i]. Reviewed-on: http://gerrit.openafs.org/5790 Reviewed-by: Marc Dionne Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit f199ac666195771a02e3ebb040c6e5fe47c58c58) Change-Id: I70be3c518d2b1ccd51e050532d966a27cf22090f Reviewed-on: http://gerrit.openafs.org/9434 Reviewed-by: Andrew Deason Reviewed-by: Derrick Brashear Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- src/afs/afs_prototypes.h | 12 +++------ src/afs/afs_server.c | 57 +++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 54ce2fd02..1d6d72f36 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -855,14 +855,10 @@ extern afs_int32 afs_ServerDown(struct srvAddr *sa, int code); extern void afs_CountServers(void); extern void afs_CheckServers(int adown, struct cell *acellp); extern void afs_LoopServers(int adown, struct cell *acellp, int vlalso, - void (*func1) (struct rx_connection **rxconns, - int nconns, int nservers, - struct afs_conn **conns, - struct srvAddr **addrs), - void (*func2) (struct rx_connection **rxconns, - int nconns, int nservers, - struct afs_conn **conns, - struct srvAddr **addrs)); + void (*func1) (int nconns, struct rx_connection **rxconns, + struct afs_conn **conns), + void (*func2) (int nconns, struct rx_connection **rxconns, + struct afs_conn **conns)); extern unsigned int afs_random(void); extern int afs_randomMod15(void); extern int afs_randomMod127(void); diff --git a/src/afs/afs_server.c b/src/afs/afs_server.c index 8470ca6a2..396c15638 100644 --- a/src/afs/afs_server.c +++ b/src/afs/afs_server.c @@ -562,8 +562,8 @@ CkSrv_MarkUpDown(struct afs_conn **conns, int nconns, afs_int32 *results) } void -CkSrv_SetTime(struct rx_connection **rxconns, int nconns, int nservers, - struct afs_conn **conns, struct srvAddr **addrs) +CkSrv_SetTime(int nconns, struct rx_connection **rxconns, + struct afs_conn **conns) { struct afs_conn *tc; afs_int32 start, end = 0, delta; @@ -573,11 +573,11 @@ CkSrv_SetTime(struct rx_connection **rxconns, int nconns, int nservers, afs_int32 i = 0; char tbuffer[CVBS]; - conntimer = afs_osi_Alloc(nservers * sizeof (afs_int32)); + conntimer = afs_osi_Alloc(nconns * sizeof (afs_int32)); osi_Assert(conntimer != NULL); - results = afs_osi_Alloc(nservers * sizeof (afs_int32)); + results = afs_osi_Alloc(nconns * sizeof (afs_int32)); osi_Assert(results != NULL); - deltas = afs_osi_Alloc(nservers * sizeof (afs_int32)); + deltas = afs_osi_Alloc(nconns * sizeof (afs_int32)); osi_Assert(deltas != NULL); /* make sure we're starting from zero */ @@ -601,7 +601,7 @@ CkSrv_SetTime(struct rx_connection **rxconns, int nconns, int nservers, deltas[multi_i] = end - tv.tv_sec; } multi_End; } else { /* find and query setTimeHost only */ - for ( i = 0 ; i < nservers ; i++ ) { + for ( i = 0 ; i < nconns ; i++ ) { if ( conns[i] == NULL || conns[i]->srvr == NULL ) continue; if ( conns[i]->srvr->server == afs_setTimeHost ) { @@ -688,25 +688,25 @@ CkSrv_SetTime(struct rx_connection **rxconns, int nconns, int nservers, } } } - afs_osi_Free(conntimer, nservers * sizeof(afs_int32)); - afs_osi_Free(deltas, nservers * sizeof(afs_int32)); - afs_osi_Free(results, nservers * sizeof(afs_int32)); + afs_osi_Free(conntimer, nconns * sizeof(afs_int32)); + afs_osi_Free(deltas, nconns * sizeof(afs_int32)); + afs_osi_Free(results, nconns * sizeof(afs_int32)); } void -CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers, - struct afs_conn **conns, struct srvAddr **addrs) +CkSrv_GetCaps(int nconns, struct rx_connection **rxconns, + struct afs_conn **conns) { Capabilities *caps; afs_int32 *results; afs_int32 i; struct server *ts; - caps = afs_osi_Alloc(nservers * sizeof (Capabilities)); + caps = afs_osi_Alloc(nconns * sizeof (Capabilities)); osi_Assert(caps != NULL); - memset(caps, 0, nservers * sizeof(Capabilities)); + memset(caps, 0, nconns * sizeof(Capabilities)); - results = afs_osi_Alloc(nservers * sizeof (afs_int32)); + results = afs_osi_Alloc(nconns * sizeof (afs_int32)); osi_Assert(results != NULL); AFS_GUNLOCK(); @@ -718,7 +718,7 @@ CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers, AFS_GLOCK(); for ( i = 0 ; i < nconns ; i++ ) { - ts = addrs[i]->server; + ts = conns[i]->srvr->server; if ( !ts ) continue; ts->capabilities = 0; @@ -739,8 +739,8 @@ CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers, } CkSrv_MarkUpDown(conns, nconns, results); - afs_osi_Free(caps, nservers * sizeof(Capabilities)); - afs_osi_Free(results, nservers * sizeof(afs_int32)); + afs_osi_Free(caps, nconns * sizeof(Capabilities)); + afs_osi_Free(results, nconns * sizeof(afs_int32)); } /* check down servers (if adown), or running servers (if !adown) */ @@ -756,12 +756,10 @@ afs_CheckServers(int adown, struct cell *acellp) * AFS_LS_ALL - check all */ void afs_LoopServers(int adown, struct cell *acellp, int vlalso, - void (*func1) (struct rx_connection **rxconns, int nconns, - int nservers, struct afs_conn **conns, - struct srvAddr **addrs), - void (*func2) (struct rx_connection **rxconns, int nconns, - int nservers, struct afs_conn **conns, - struct srvAddr **addrs)) + void (*func1) (int nservers, struct rx_connection **rxconns, + struct afs_conn **conns), + void (*func2) (int nservers, struct rx_connection **rxconns, + struct afs_conn **conns)) { struct vrequest treq; struct server *ts; @@ -775,7 +773,7 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso, struct afs_conn **conns; int nconns; struct rx_connection **rxconns; - afs_int32 *conntimer, *results; + afs_int32 *conntimer; AFS_STATCNT(afs_CheckServers); @@ -823,8 +821,6 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso, osi_Assert(rxconns != NULL); conntimer = afs_osi_Alloc(j * sizeof (afs_int32)); osi_Assert(conntimer != NULL); - results = afs_osi_Alloc(j * sizeof (afs_int32)); - osi_Assert(results != NULL); for (i = 0; i < j; i++) { struct rx_connection *rxconn; @@ -878,10 +874,13 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso, afs_PutConn(tc, rxconn, SHARED_LOCK); } /* Outer loop over addrs */ - (*func1)(rxconns, nconns, j, conns, addrs); + afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs)); + addrs = NULL; + + (*func1)(nconns, rxconns, conns); if (func2) { - (*func2)(rxconns, nconns, j, conns, addrs); + (*func2)(nconns, rxconns, conns); } for (i = 0; i < nconns; i++) { @@ -890,11 +889,9 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso, afs_PutConn(conns[i], rxconns[i], SHARED_LOCK); /* done with it now */ } - afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs)); afs_osi_Free(conns, j * sizeof(struct afs_conn *)); afs_osi_Free(rxconns, j * sizeof(struct rx_connection *)); afs_osi_Free(conntimer, j * sizeof(afs_int32)); - afs_osi_Free(results, j * sizeof(afs_int32)); } /*afs_CheckServers*/ -- 2.39.5