From: Andrew Deason Date: Thu, 22 Mar 2012 22:54:12 +0000 (-0500) Subject: salvager: Trust inode-based special data over OGM X-Git-Tag: openafs-stable-1_8_0pre1~2539 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=df522b588396aaac3ec662b516ef7287f3b7c47b salvager: Trust inode-based special data over OGM Currently the salvaging code looks for special inodes, and infers the volume id and inode type from the OGM data in each special inode file. However, we can already derive this information from the inode number itself for the special inode, so if they disagree, use the values based off of the inode number and correct the OGM data. The inode number should be more likely to be correct, since that is how we look up the special inode from the header when attaching the volume. It is also impossible to get special inode files with the same name, so this ensures we don't get duplicates. And for people that go snooping around /vicepX/AFSIDat even though we tell them not to, it seems more likely that they go around 'chmod'ing or 'chown'ing rather than 'mv'ing. This change avoids an abort in the salvaging code when the OGM data is wrong. If we trust the OGM data when it is incorrect, we assume the special inode file is for a different volume. So when we go to recreate one of the special files for the volume we're actually working with, the IH_CREATE fails (from EEXIST) and so we abort. Change-Id: Ibfaa1bfb27d190c5fec6fc673d88df366268e302 Reviewed-on: http://gerrit.openafs.org/6946 Tested-by: Derrick Brashear Reviewed-by: Derrick Brashear --- diff --git a/src/vol/namei_ops.c b/src/vol/namei_ops.c index a02600d..a2e4ad5 100644 --- a/src/vol/namei_ops.c +++ b/src/vol/namei_ops.c @@ -663,6 +663,31 @@ CheckOGM(FdHandle_t *fdP, int p1) return 0; } + +static int +FixSpecialOGM(FdHandle_t *fdP, int check) +{ + Inode ino = fdP->fd_ih->ih_ino; + VnodeId vno = NAMEI_VNODESPECIAL, ogm_vno; + int ogm_volid; + + if (GetWinOGM(fdP->fd_fd, &ogm_volid, &ogm_vno)) { + return -1; + } + + /* the only thing we can check is the vnode number; for the volid we have + * nothing else to compare against */ + if (vno != ogm_vno) { + if (check) { + return -1; + } + if (SetWinOGM(fdP->fd_fd, ogm_volid, vno)) { + return -1; + } + } + return 0; +} + #else /* AFS_NT40_ENV */ /* SetOGM - set owner group and mode bits from parm and tag */ static int @@ -718,8 +743,68 @@ CheckOGM(FdHandle_t *fdP, int p1) return 0; } + +static int +FixSpecialOGM(FdHandle_t *fdP, int check) +{ + int inode_volid, ogm_volid; + int inode_type, ogm_type; + Inode ino = fdP->fd_ih->ih_ino; + + inode_volid = ((ino >> NAMEI_UNIQSHIFT) & NAMEI_UNIQMASK); + inode_type = (int)((ino >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK); + + if (GetOGM(fdP, &ogm_volid, &ogm_type) < 0) { + Log("Error retrieving OGM info\n"); + return -1; + } + + if (inode_volid != ogm_volid || inode_type != ogm_type) { + Log("%sIncorrect OGM data (ino: vol %u type %d) (ogm: vol %u type %d)\n", + check?"":"Fixing ", inode_volid, inode_type, ogm_volid, ogm_type); + + if (check) { + return -1; + } + + if (SetOGM(fdP->fd_fd, inode_volid, inode_type) < 0) { + Log("Error setting OGM data\n"); + return -1; + } + } + return 0; +} + #endif /* !AFS_NT40_ENV */ +/** + * Check/fix the OGM data for an inode + * + * @param[in] fdP Open file handle for the inode to check + * @param[in] check 1 to just check the OGM data, and return an error if it + * is incorrect. 0 to fix the OGM data if it is incorrect. + * + * @pre fdP must be for a special inode + * + * @return status + * @retval 0 success + * @retval -1 error + */ +int +namei_FixSpecialOGM(FdHandle_t *fdP, int check) +{ + int vnode; + Inode ino = fdP->fd_ih->ih_ino; + + vnode = (int)(ino & NAMEI_VNODEMASK); + if (vnode != NAMEI_VNODESPECIAL) { + Log("FixSpecialOGM: non-special vnode %u\n", vnode); + return -1; + } + + return FixSpecialOGM(fdP, check); +} + int big_vno = 0; /* Just in case we ever do 64 bit vnodes. */ /* Derive the name and create it O_EXCL. If that fails we have an error. @@ -1845,30 +1930,21 @@ _namei_examine_special(char * path1, { int ret = 0; struct ViceInodeInfo info; - afs_uint32 inode_vgid; if (DecodeInode(path1, dname, &info, myIH->ih_vid) < 0) { ret = 0; goto error; } -#ifdef AFS_NT40_ENV - inode_vgid = myIH->ih_vid; -#else - inode_vgid = (info.inodeNumber >> NAMEI_UNIQSHIFT) & NAMEI_UNIQMASK; -#endif - if (info.u.param[2] != VI_LINKTABLE) { info.linkCount = 1; - } else if ((info.u.param[0] != myIH->ih_vid) || - (inode_vgid != myIH->ih_vid)) { + } else if (info.u.param[0] != myIH->ih_vid) { /* VGID encoded in linktable filename and/or OGM data isn't * consistent with VGID encoded in namei path */ Log("namei_ListAFSSubDirs: warning: inconsistent linktable " "filename \"%s" OS_DIRSEP "%s\"; salvager will delete it " - "(dir_vgid=%u, inode_vgid=%u, ogm_vgid=%u)\n", + "(dir_vgid=%u, inode_vgid=%u)\n", path1, dname, myIH->ih_vid, - (unsigned int)inode_vgid, info.u.param[0]); } else { char path2[512]; @@ -2696,14 +2772,17 @@ DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info, if (strcmp(name, check)) return -1; - GetOGMFromStat(&status, &parm, &tag); if ((info->inodeNumber & NAMEI_INODESPECIAL) == NAMEI_INODESPECIAL) { + parm = ((info->inodeNumber >> NAMEI_UNIQSHIFT) & NAMEI_UNIQMASK); + tag = (int)((info->inodeNumber >> NAMEI_TAGSHIFT) & NAMEI_TAGMASK); + /* p1 - vid, p2 - -1, p3 - type, p4 - rwvid */ info->u.param[0] = parm; info->u.param[1] = -1; info->u.param[2] = tag; info->u.param[3] = volid; } else { + GetOGMFromStat(&status, &parm, &tag); /* p1 - vid, p2 - vno, p3 - uniq, p4 - dv */ info->u.param[0] = volid; info->u.param[1] = (int)(info->inodeNumber & NAMEI_VNODEMASK); diff --git a/src/vol/namei_ops.h b/src/vol/namei_ops.h index a950e78..9b80535 100644 --- a/src/vol/namei_ops.h +++ b/src/vol/namei_ops.h @@ -33,6 +33,7 @@ extern int namei_inc(IHandle_t * h, Inode ino, int p1); extern int namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit, int fixup, int nowrite); extern int namei_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked); extern int namei_ViceREADME(char *partition); +extern int namei_FixSpecialOGM(FdHandle_t *h, int check); #include "nfs.h" #include "viceinode.h" int namei_ListAFSFiles(char *dev, diff --git a/src/vol/vol-salvage.c b/src/vol/vol-salvage.c index 0b1fa26..5a4dbfa 100644 --- a/src/vol/vol-salvage.c +++ b/src/vol/vol-salvage.c @@ -2474,6 +2474,14 @@ SalvageHeader(struct SalvInfo *salvinfo, struct afs_inode_info *sp, * it below */ memset(&header, 0, sizeof(header)); } +#ifdef AFS_NAMEI_ENV + if (namei_FixSpecialOGM(fdP, check)) { + Log("Error with namei header OGM data (%s)\n", sp->description); + FDH_REALLYCLOSE(fdP); + IH_RELEASE(specH); + return -1; + } +#endif if (sp->inodeType == VI_VOLINFO && header.volumeInfo.destroyMe == DESTROY_ME) { if (deleteMe)