From e9def7311e36284b83e1a9a015cfb841fa0b2511 Mon Sep 17 00:00:00 2001 From: Michael Meffie Date: Mon, 21 Nov 2011 19:12:56 -0500 Subject: [PATCH] vol: log error reason on header read failure Log the error reason instead of just VSALVAGE when ReadHeader() fails. Reviewed-on: http://gerrit.openafs.org/6108 Tested-by: BuildBot Reviewed-by: Andrew Deason Reviewed-by: Derrick Brashear (cherry picked from commit 0d0a8288c1cdd05bbf5717ac45638cf6760ee7a8) Change-Id: Ie49c9ee3ea23873f8d71c80fda45b763bcd8e466 Reviewed-on: http://gerrit.openafs.org/6328 Reviewed-by: Michael Meffie Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/vol/volume.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/vol/volume.c b/src/vol/volume.c index d44c701bf9..9e0194973e 100644 --- a/src/vol/volume.c +++ b/src/vol/volume.c @@ -1881,6 +1881,22 @@ VShutdownVolume_r(Volume * vp) /* Header I/O routines */ /***************************************************/ +static const char * +HeaderName(bit32 magic) +{ + switch (magic) { + case VOLUMEINFOMAGIC: + return "volume info"; + case SMALLINDEXMAGIC: + return "small index"; + case LARGEINDEXMAGIC: + return "large index"; + case LINKTABLEMAGIC: + return "link table"; + } + return "unknown"; +} + /* open a descriptor for the inode (h), * read in an on-disk structure into buffer (to) of size (size), * verify versionstamp in structure has magic (magic) and @@ -1892,29 +1908,63 @@ ReadHeader(Error * ec, IHandle_t * h, char *to, int size, bit32 magic, { struct versionStamp *vsn; FdHandle_t *fdP; + afs_sfsize_t nbytes; + afs_ino_str_t stmp; *ec = 0; if (h == NULL) { + Log("ReadHeader: Null inode handle argument for %s header file.\n", + HeaderName(magic)); *ec = VSALVAGE; return; } fdP = IH_OPEN(h); if (fdP == NULL) { + Log("ReadHeader: Failed to open %s header file " + "(volume=%u, inode=%s); errno=%d\n", HeaderName(magic), h->ih_vid, + PrintInode(stmp, h->ih_ino), errno); *ec = VSALVAGE; return; } vsn = (struct versionStamp *)to; - if (FDH_PREAD(fdP, to, size, 0) != size || vsn->magic != magic) { + nbytes = FDH_PREAD(fdP, to, size, 0); + if (nbytes < 0) { + Log("ReadHeader: Failed to read %s header file " + "(volume=%u, inode=%s); errno=%d\n", HeaderName(magic), h->ih_vid, + PrintInode(stmp, h->ih_ino), errno); *ec = VSALVAGE; FDH_REALLYCLOSE(fdP); return; } + if (nbytes != size) { + Log("ReadHeader: Incorrect number of bytes read from %s header file " + "(volume=%u, inode=%s); expected=%d, read=%d\n", + HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino), size, + (int)nbytes); + *ec = VSALVAGE; + FDH_REALLYCLOSE(fdP); + return; + } + if (vsn->magic != magic) { + Log("ReadHeader: Incorrect magic for %s header file " + "(volume=%u, inode=%s); expected=0x%x, read=0x%x\n", + HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino), magic, + vsn->magic); + *ec = VSALVAGE; + FDH_REALLYCLOSE(fdP); + return; + } + FDH_CLOSE(fdP); /* Check is conditional, in case caller wants to inspect version himself */ if (version && vsn->version != version) { + Log("ReadHeader: Incorrect version for %s header file " + "(volume=%u, inode=%s); expected=%x, read=%x\n", + HeaderName(magic), h->ih_vid, PrintInode(stmp, h->ih_ino), + version, vsn->version); *ec = VSALVAGE; } }