From: Simon Wilkinson Date: Sun, 26 Dec 2010 14:00:42 +0000 (+0000) Subject: vos: Abstract out bulk list conversion X-Git-Tag: upstream/1.6.0.pre2^2~161 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=0c6ecb1274e15fac5aa106ca0bcf0e4969ea67c3;p=packages%2Fo%2Fopenafs.git vos: Abstract out bulk list conversion Pull the various segments of code that do bulk list conversion into their own functions. This is purely code reorganisation at this point, fixes for these functions will follow in subsequent patches. Reviewed-on: http://gerrit.openafs.org/3595 Reviewed-by: Derrick Brashear Tested-by: BuildBot (cherry picked from commit 3503f32848ab3fcb0df5a0b40518106bf19cee6e) Change-Id: Ib6b32fe942f5083e18f32404156a42cd82bf5c5a Reviewed-on: http://gerrit.openafs.org/3634 Tested-by: BuildBot Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- diff --git a/src/volser/vsutils.c b/src/volser/vsutils.c index 6bccda037..6782d6e80 100644 --- a/src/volser/vsutils.c +++ b/src/volser/vsutils.c @@ -416,6 +416,42 @@ VLDB_ReplaceEntryU(afs_uint32 volid, afs_int32 voltype, struct uvldbentry *entry return code; } +static void +convertBulkToNBulk(bulkentries *bulk, nbulkentries *nbulk, int *entriesp) { + int i; + + nbulk->nbulkentries_val = + (nvldbentry *) xdr_alloc(*entriesp * sizeof(struct nvldbentry)); + + for (i = 0; i < *entriesp; i++) { /* process each entry */ + ovlentry_to_nvlentry(&bulk->bulkentries_val[i], + &nbulk->nbulkentries_val[i]); + } +} + +static void +convertBulkToUBulk(bulkentries *bulk, ubulkentries *ubulk, int *entriesp) { + int i; + + ubulk->ubulkentries_val = + (uvldbentry *) xdr_alloc(*entriesp * sizeof(struct uvldbentry)); + for (i = 0; i < *entriesp; i++) { /* process each entry */ + ovlentry_to_uvlentry(&bulk->bulkentries_val[i], + &ubulk->ubulkentries_val[i]); + } +} + +static void +convertNBulkToUBulk(nbulkentries *nbulk, ubulkentries *ubulk, int *entriesp) { + int i; + + ubulk->ubulkentries_val = + (uvldbentry *) xdr_alloc(*entriesp * sizeof(struct uvldbentry)); + for (i = 0; i < *entriesp; i++) { /* process each entry */ + nvlentry_to_uvlentry(&nbulk->nbulkentries_val[i], + &ubulk->ubulkentries_val[i]); + } +} int VLDB_ListAttributes(VldbListByAttributes *attrp, @@ -425,21 +461,16 @@ VLDB_ListAttributes(VldbListByAttributes *attrp, int code; if (newvlserver == vltype_old) { - int i; bulkentries arrayEntries; tryold: memset(&arrayEntries, 0, sizeof(arrayEntries)); /*initialize to hint the stub to alloc space */ code = ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp, &arrayEntries); - if (!code) { - blkentriesp->nbulkentries_val = - (nvldbentry *) xdr_alloc(*entriesp * sizeof(struct nvldbentry)); - for (i = 0; i < *entriesp; i++) { /* process each entry */ - ovlentry_to_nvlentry(&arrayEntries.bulkentries_val[i], - &blkentriesp->nbulkentries_val[i]); - } - } + + if (!code) + convertBulkToNBulk(&arrayEntries, blkentriesp, entriesp); + if (arrayEntries.bulkentries_val) xdr_free((xdrproc_t) xdr_bulkentries, &arrayEntries); return code; @@ -460,7 +491,7 @@ VLDB_ListAttributesU(VldbListByAttributes *attrp, ubulkentries *blkentriesp) { nbulkentries narrayEntries; - int code, i; + int code; if (newvlserver == vltype_old) { bulkentries arrayEntries; @@ -469,14 +500,9 @@ VLDB_ListAttributesU(VldbListByAttributes *attrp, code = ubik_VL_ListAttributes(cstruct, 0, attrp, entriesp, &arrayEntries); - if (!code) { - blkentriesp->ubulkentries_val = - (uvldbentry *) xdr_alloc(*entriesp * sizeof(struct uvldbentry)); - for (i = 0; i < *entriesp; i++) { /* process each entry */ - ovlentry_to_uvlentry(&arrayEntries.bulkentries_val[i], - &blkentriesp->ubulkentries_val[i]); - } - } + if (!code) + convertBulkToUBulk(&arrayEntries, blkentriesp, entriesp); + if (arrayEntries.bulkentries_val) xdr_free((xdrproc_t) xdr_bulkentries, &arrayEntries); return code; @@ -490,12 +516,8 @@ VLDB_ListAttributesU(VldbListByAttributes *attrp, goto tryold; } if (!code) { - blkentriesp->ubulkentries_val = - (uvldbentry *) xdr_alloc(*entriesp * sizeof(struct uvldbentry)); - for (i = 0; i < *entriesp; i++) { /* process each entry */ - nvlentry_to_uvlentry(&narrayEntries.nbulkentries_val[i], - &blkentriesp->ubulkentries_val[i]); - } + convertNBulkToUBulk(&narrayEntries, blkentriesp, entriesp); + } if (narrayEntries.nbulkentries_val) xdr_free((xdrproc_t) xdr_bulkentries, &narrayEntries); @@ -529,7 +551,6 @@ VLDB_ListAttributesN2U(VldbListByAttributes *attrp, afs_int32 *nextindexp) { afs_int32 code = RXGEN_OPCODE; - int i; if (newvlserver != vltype_old) { nbulkentries narrayEntries; @@ -538,14 +559,9 @@ VLDB_ListAttributesN2U(VldbListByAttributes *attrp, code = ubik_VL_ListAttributesN2(cstruct, 0, attrp, (name ? name : ""), thisindex, nentriesp, &narrayEntries, nextindexp); - if (!code) { - blkentriesp->ubulkentries_val = - (uvldbentry *) xdr_alloc(*nentriesp * sizeof(struct uvldbentry)); - for (i = 0; i < *nentriesp; i++) { /* process each entry */ - nvlentry_to_uvlentry(&narrayEntries.nbulkentries_val[i], - &blkentriesp->ubulkentries_val[i]); - } - } + if (!code) + convertNBulkToUBulk(&narrayEntries, blkentriesp, nentriesp); + if (narrayEntries.nbulkentries_val) xdr_free((xdrproc_t) xdr_bulkentries, &narrayEntries); return code;