From 1aa7d3c199e77e3ebdffe9cea4dee8ee82e81fcd Mon Sep 17 00:00:00 2001 From: Mark Vitale Date: Mon, 4 Mar 2019 01:37:53 -0500 Subject: [PATCH] afs: refactor directory checking in DRead Commit d566c1cf874d15ca02020894ff0af62c4e39e7bb 'dread-do-validation-20041012' modified directory checking (in the afs_buffer.c implementation of DRead()) to use size information passed to DRead, rather than obtained from the cache via afs_CFileOpen. Because this directory checking does not require any information from the cache buffers or the cache partition, we can make the check right away, before searching the cache buffers or calling afs_newslot. To clarify and simplify, move the directory sanity checking logic to the beginning of DRead. Remove the afs_newslot cleanup logic which is no longer needed. While here, add Doxygen comments for DRead. Change-Id: I8cea4e885ece64e760271c8194c126250f87104e Reviewed-on: https://gerrit.openafs.org/13803 Reviewed-by: Andrew Deason Reviewed-by: Benjamin Kaduk Tested-by: BuildBot --- src/afs/afs_buffer.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/afs/afs_buffer.c b/src/afs/afs_buffer.c index 1f2a470..99af18e 100644 --- a/src/afs/afs_buffer.c +++ b/src/afs/afs_buffer.c @@ -147,6 +147,16 @@ DInit(int abuffers) return; } +/*! + * Read and return the requested directory page. + * + * \param[in] adc pointer to directory dcache + * \param[in] page number of the desired directory page + * \param[out] entry buffer to return requested page + * + * \retval 0 success + * \retval non-zero invalid directory or internal IO error + */ int DRead(struct dcache *adc, int page, struct DirBuffer *entry) { @@ -159,6 +169,15 @@ DRead(struct dcache *adc, int page, struct DirBuffer *entry) memset(entry, 0, sizeof(struct DirBuffer)); + if (adc->f.chunk == 0 && adc->f.chunkBytes == 0) { + /* The directory blob is empty, apparently. This is not a valid dir + * blob, so throw an error. */ + return EIO; + } + if (page * AFS_BUFFER_PAGESIZE >= adc->f.chunkBytes) { + return ENOENT; /* past the end */ + } + ObtainWriteLock(&afs_bufferLock, 256); #define bufmatch(tb) (tb->page == page && tb->fid == adc->index) @@ -231,17 +250,6 @@ DRead(struct dcache *adc, int page, struct DirBuffer *entry) ObtainWriteLock(&tb->lock, 260); tb->lockers++; ReleaseWriteLock(&afs_bufferLock); - code = 0; - if (adc->f.chunk == 0 && adc->f.chunkBytes == 0) { - /* The directory blob is empty, apparently. This is not a valid dir - * blob, so throw an error. */ - code = EIO; - goto error; - } else if (page * AFS_BUFFER_PAGESIZE >= adc->f.chunkBytes) { - code = ENOENT; /* past the end */ - goto error; - } - tfile = afs_CFileOpen(&adc->f.inode); if (!tfile) { code = EIO; -- 1.9.4