From 6bd94fe29d1aa6ce61ba02e681defea79770ccdd Mon Sep 17 00:00:00 2001 From: Mark Vitale Date: Wed, 5 Feb 2020 17:49:03 -0500 Subject: [PATCH] dir: check DNew return code Commit 0284e65f97861e888d95576f22a93cd681813c39 'dir: Explicitly state buffer locations for data' changed DNew and DRead to return a return code. However, the callers of DNew were not modified to check the new return code. (This commit applied only to the implementations dealing with AFS directories, in afs/afs_buffer.c and dir/dir.c. The ubik implmentations of DNew and DRead, dealing with ubik databases, were not modified.) Modify all (non-ubik) callers of DNew to check the return code. In addition, modify code as needed so return codes are properly propagated to the callers. While here, add Doxygen comments for AddPage and FindBlobs. Change-Id: Iabde6499745dd351f3fcda73c9f52c440a36490e Reviewed-on: https://gerrit.openafs.org/13801 Tested-by: BuildBot Reviewed-by: Benjamin Kaduk --- src/dir/dir.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/dir/dir.c b/src/dir/dir.c index 0fb6bff..00e7ea6 100644 --- a/src/dir/dir.c +++ b/src/dir/dir.c @@ -72,7 +72,7 @@ extern int DNew(struct dcache *adc, int page, struct DirBuffer *); /* Local static prototypes */ static int FindBlobs(dir_file_t, int); -static void AddPage(dir_file_t, int); +static int AddPage(dir_file_t, int); static void FreeBlobs(dir_file_t, int, int); static int FindItem(dir_file_t, char *, struct DirBuffer *, struct DirBuffer *); @@ -199,7 +199,15 @@ afs_dir_Delete(dir_file_t dir, char *entry) return 0; } -/* Find a bunch of contiguous entries; at least nblobs in a row. */ +/*! + * Find a bunch of contiguous entries; at least nblobs in a row. + * + * \param dir pointer to the directory object + * \param nblobs number of contiguous entries we need + * + * \return element number (directory entry) of the requested space + * \retval -1 failed to find 'nblobs' contiguous entries + */ static int FindBlobs(dir_file_t dir, int nblobs) { @@ -209,6 +217,7 @@ FindBlobs(dir_file_t dir, int nblobs) struct DirHeader *dhp; struct PageHeader *pp; int pgcount; + int code; /* read the dir header in first. */ if (DRead(dir, 0, &headerbuf) != 0) @@ -228,12 +237,16 @@ FindBlobs(dir_file_t dir, int nblobs) } if (i > pgcount - 1) { /* this page is bigger than last allocated page */ - AddPage(dir, i); + code = AddPage(dir, i); + if (code) + break; dhp->header.pgcount = htons(i + 1); } } else if (dhp->alloMap[i] == EPP) { /* Add the page to the directory. */ - AddPage(dir, i); + code = AddPage(dir, i); + if (code) + break; dhp->alloMap[i] = EPP - 1; dhp->header.pgcount = htons(i + 1); } @@ -268,20 +281,32 @@ FindBlobs(dir_file_t dir, int nblobs) DRelease(&pagebuf, 0); /* This dir page is unchanged. */ } } - /* If we make it here, the directory is full. */ + /* If we make it here, the directory is full, or we encountered an I/O error. */ DRelease(&headerbuf, 1); return -1; } -static void +/*! + * Add a page to a directory object. + * + * \param dir pointer to the directory object + * \param pageno page number to add + * + * \retval 0 succcess + * \retval non-zero return error from DNew + */ +static int AddPage(dir_file_t dir, int pageno) { /* Add a page to a directory. */ int i; struct PageHeader *pp; struct DirBuffer pagebuf; + int code; /* Get a new buffer labelled dir,pageno */ - DNew(dir, pageno, &pagebuf); + code = DNew(dir, pageno, &pagebuf); + if (code) + return code; pp = (struct PageHeader *)pagebuf.data; pp->tag = htons(1234); @@ -292,6 +317,7 @@ AddPage(dir_file_t dir, int pageno) for (i = 1; i < EPP / 8; i++) /* It's a constant */ pp->freebitmap[i] = 0; DRelease(&pagebuf, 1); + return 0; } /* Free a whole bunch of directory entries. */ @@ -346,7 +372,9 @@ afs_dir_MakeDir(dir_file_t dir, afs_int32 * me, afs_int32 * parent) struct DirHeader *dhp; int code; - DNew(dir, 0, &buffer); + code = DNew(dir, 0, &buffer); + if (code) + return code; dhp = (struct DirHeader *)buffer.data; dhp->header.pgcount = htons(1); -- 1.9.4