From: Jeffrey Altman Date: Sat, 8 Jan 2011 17:21:23 +0000 (-0500) Subject: Windows: refactor buf_Get() to improve readability X-Git-Tag: upstream/1.6.0.pre2^2~88 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=fd022f97b7341a40efd8e3db5f3091d3a3e77b31;p=packages%2Fo%2Fopenafs.git Windows: refactor buf_Get() to improve readability Refactor buf_Get() by using a switch() instead of a jumble of if() conditionals. Improve comments to make it clear that given the current use and implementation of cm_BufRead() from cm_dcache.c that created buffer pages will never be populated with actual data. Reviewed-on: http://gerrit.openafs.org/3630 Tested-by: BuildBot Reviewed-by: Jeffrey Altman Tested-by: Jeffrey Altman (cherry picked from commit 9f584e811486da7129a61da554fae09029b0de67) Change-Id: I32ff33df359fb7794e9cf47c2027eb48363c80eb Reviewed-on: http://gerrit.openafs.org/3816 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/WINNT/afsd/cm_buf.c b/src/WINNT/afsd/cm_buf.c index af6aaa5eb..15305b6a4 100644 --- a/src/WINNT/afsd/cm_buf.c +++ b/src/WINNT/afsd/cm_buf.c @@ -1151,7 +1151,7 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf created = 0; pageOffset.HighPart = offsetp->HighPart; pageOffset.LowPart = offsetp->LowPart & ~(cm_data.buf_blockSize-1); - while (1) { + while (!created) { lcount++; #ifdef TESTING buf_ValidateBufQueues(); @@ -1171,25 +1171,28 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf /* otherwise, we have to create a page */ code = buf_GetNewLocked(scp, &pageOffset, reqp, &bp); - /* bp->mx is now held */ - - /* check if the buffer was created in a race condition branch. - * If so, go around so we can hold a reference to it. - */ - if (code == CM_BUF_EXISTS) - continue; - - /* something else went wrong */ - if (code != 0) { + switch (code) { + case 0: + /* the requested buffer was created */ + created = 1; + break; + case CM_BUF_EXISTS: + /* + * the requested buffer existed by the time the + * scp->bufCreateLock and buf_globalLock could be obtained. + * loop again and permit buf_Find() to obtain a reference. + */ + break; + default: + /* + * the requested buffer could not be created. + * return the error to the caller. + */ #ifdef TESTING buf_ValidateBufQueues(); #endif /* TESTING */ return code; } - - /* otherwise, we have a locked buffer that we just created */ - created = 1; - break; } /* big while loop */ /* if we get here, we have a locked buffer that may have just been @@ -1199,7 +1202,11 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf /* load the page; freshly created pages should be idle */ osi_assertx(!(bp->flags & (CM_BUF_READING | CM_BUF_WRITING)), "incorrect cm_buf_t flags"); - /* start the I/O; may drop lock */ + /* + * start the I/O; may drop lock. as of this writing, the only + * implementation of Readp is cm_BufRead() which simply sets + * tcount to 0 and returns success. + */ bp->flags |= CM_BUF_READING; code = (*cm_buf_opsp->Readp)(bp, cm_data.buf_blockSize, &tcount, NULL); @@ -1226,7 +1233,8 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf return code; } } else { - /* otherwise, I/O completed instantly and we're done, except + /* + * otherwise, I/O completed instantly and we're done, except * for padding the xfr out with 0s and checking for EOF */ if (tcount < (unsigned long) cm_data.buf_blockSize) { @@ -1240,7 +1248,6 @@ long buf_Get(struct cm_scache *scp, osi_hyper_t *offsetp, cm_req_t *reqp, cm_buf osi_Wakeup((LONG_PTR) bp); } } - } /* if created */ /* wait for reads, either that which we started above, or that someone