From 66a63e16473f178c69ba4ae6e495fbca5cd2a424 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 23 Mar 2011 17:25:03 -0500 Subject: [PATCH] salvager: Give back volumes when exiting early Sometimes the salvager exits a bit earlier than normal. For instance, when no applicable inodes are found for a volume group, or if the -inodes command line option was given. In these cases, we have already checked out singleVolumeNumber from the fileserver (if we're salvaging a single VG), so we need to give it back. So, give it back in those instances. Reviewed-on: http://gerrit.openafs.org/4297 Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit 637f5b642aaee3a6f4642fd0ba15e2a9eec6c496) Change-Id: Ib40ffb84fa6c40cfd692c561b913decb97268403 Reviewed-on: http://gerrit.openafs.org/5762 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/vol/vol-salvage.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 31ab2374a..20ef0aea1 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -318,6 +318,7 @@ char *tmpdir = NULL; static int IsVnodeOrphaned(struct SalvInfo *salvinfo, VnodeId vnode); static int AskVolumeSummary(struct SalvInfo *salvinfo, VolumeId singleVolumeNumber); +static void MaybeAskOnline(struct SalvInfo *salvinfo, VolumeId volumeId); #if defined(AFS_DEMAND_ATTACH_FS) || defined(AFS_DEMAND_ATTACH_UTIL) static int LockVolume(struct SalvInfo *salvinfo, VolumeId volumeId); @@ -869,6 +870,11 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) if (GetInodeSummary(salvinfo, inodeFile, singleVolumeNumber) < 0) { fclose(inodeFile); + if (singleVolumeNumber) { + /* the volume group -- let alone the volume -- does not exist, + * but we checked it out, so give it back to the fileserver */ + AskDelete(salvinfo, singleVolumeNumber); + } return; } salvinfo->inodeFd = fileno(inodeFile); @@ -877,6 +883,14 @@ SalvageFileSys1(struct DiskPartition64 *partP, VolumeId singleVolumeNumber) afs_lseek(salvinfo->inodeFd, 0L, SEEK_SET); if (ListInodeOption) { PrintInodeList(salvinfo); + if (singleVolumeNumber) { + /* We've checked out the volume from the fileserver, and we need + * to give it back. We don't know if the volume exists or not, + * so we don't know whether to AskOnline or not. Try to determine + * if the volume exists by trying to read the volume header, and + * AskOnline if it is readable. */ + MaybeAskOnline(salvinfo, singleVolumeNumber); + } return; } /* enumerate volumes in the partition. @@ -4461,6 +4475,19 @@ AskDAFS(void) return ret; } +static void +MaybeAskOnline(struct SalvInfo *salvinfo, VolumeId volumeId) +{ + struct VolumeDiskHeader diskHdr; + int code; + code = VReadVolumeDiskHeader(volumeId, salvinfo->fileSysPartition, &diskHdr); + if (code) { + /* volume probably does not exist; no need to bring back online */ + return; + } + AskOnline(salvinfo, volumeId); +} + void AskOnline(struct SalvInfo *salvinfo, VolumeId volumeId) { -- 2.39.5