mirror of
https://git.openafs.org/openafs.git
synced 2025-01-22 17:00:15 +00:00
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 <adeason@sinenomine.net> Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Derrick Brashear <shadow@dementix.org>
This commit is contained in:
parent
b99ab0371a
commit
4aa72b4308
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user