From 4aa72b4308bae8e1d789682e7ead83bcadded862 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Sat, 23 Jul 2011 14:55:57 -0400 Subject: [PATCH] volinfo: release volume header ihandles when done After scanning the volume, release the header ihandles for the volume. Change-Id: I689a33b321fc68d0dc480369e6cbdfd41c1dbfc9 Reviewed-on: http://gerrit.openafs.org/5099 Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/vol/vol-info.c | 57 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/vol/vol-info.c b/src/vol/vol-info.c index a1f96444b9..64ced429c1 100644 --- a/src/vol/vol-info.c +++ b/src/vol/vol-info.c @@ -319,6 +319,10 @@ AttachVolume(struct DiskPartition64 * dp, char *volname, afs_int32 ec = 0; vp = (Volume *) calloc(1, sizeof(Volume)); + if (!vp) { + fprintf(stderr, "%s: Failed to allocate volume object.\n", progname); + return NULL; + } vp->specialStatus = 0; vp->device = dp->device; vp->partition = dp; @@ -334,6 +338,11 @@ AttachVolume(struct DiskPartition64 * dp, char *volname, vp->goingOffline = 0; vp->nUsers = 1; vp->header = (struct volHeader *)calloc(1, sizeof(*vp->header)); + if (!vp->header) { + fprintf(stderr, "%s: Failed to allocate volume header.\n", progname); + free(vp); + return NULL; + } ec = ReadHdr1(V_diskDataHandle(vp), (char *)&V_disk(vp), sizeof(V_disk(vp)), VOLUMEINFOMAGIC, VOLUMEINFOVERSION); if (!ec) { @@ -358,6 +367,24 @@ AttachVolume(struct DiskPartition64 * dp, char *volname, return vp; } +/** + * Simplified detach volume + * + * param[in] vp volume object from AttachVolume + * + * @return none + */ +static void +DetachVolume(Volume * vp) +{ + IH_RELEASE(vp->vnodeIndex[vLarge].handle); + IH_RELEASE(vp->vnodeIndex[vSmall].handle); + IH_RELEASE(vp->diskDataHandle); + IH_RELEASE(V_linkHandle(vp)); + free(vp->header); + free(vp); +} + /** * Convert the partition device number into a partition name. * @@ -783,7 +810,7 @@ HandleVolume(struct DiskPartition64 *dp, char *name) struct VolumeHeader header; struct VolumeDiskHeader diskHeader; FD_t fd = INVALID_FD; - Volume *vp; + Volume *vp = NULL; char headerName[1024]; afs_sfsize_t n; @@ -791,39 +818,38 @@ HandleVolume(struct DiskPartition64 *dp, char *name) VPartitionPath(dp), name); if ((fd = OS_OPEN(headerName, O_RDONLY, 0666)) == INVALID_FD) { fprintf(stderr, "%s: Cannot open volume header %s\n", progname, name); - return; + goto cleanup; } if (OS_SIZE(fd) < 0) { fprintf(stderr, "%s: Cannot read volume header %s\n", progname, name); - OS_CLOSE(fd); - return; + goto cleanup; } n = OS_READ(fd, &diskHeader, sizeof(diskHeader)); if (n != sizeof(diskHeader) || diskHeader.stamp.magic != VOLUMEHEADERMAGIC) { fprintf(stderr, "%s: Error reading volume header %s\n", progname, name); - OS_CLOSE(fd); - return; + goto cleanup; } if (diskHeader.stamp.version != VOLUMEHEADERVERSION) { fprintf(stderr, "%s: Volume %s, version number is incorrect; volume needs to be salvaged\n", progname, name); - OS_CLOSE(fd); - return; + goto cleanup; } + DiskToVolumeHeader(&header, &diskHeader); if (DumpHeader || ShowSizes) { HandleHeaderFiles(dp, fd, &header); } - OS_CLOSE(fd); + vp = AttachVolume(dp, name, &header); if (!vp) { fprintf(stderr, "%s: Error attaching volume header %s\n", progname, name); - return; + goto cleanup; } + if (DumpInfo) { PrintHeader(vp); } @@ -839,10 +865,15 @@ HandleVolume(struct DiskPartition64 *dp, char *name) volumeTotals.auxsize_k + volumeTotals.vnodesize_k; PrintVolumeSizes(vp); } - free(vp->header); - free(vp); -} + cleanup: + if (fd != INVALID_FD) { + OS_CLOSE(fd); + } + if (vp) { + DetachVolume(vp); + } +} /** * volinfo program entry