DEVEL15-salvage-zlc-20060903
authorChaskiel M Grundman <cg2v@andrew.cmu.edu>
Sun, 3 Sep 2006 06:53:14 +0000 (06:53 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 3 Sep 2006 06:53:14 +0000 (06:53 +0000)
make salvager deal with zero link count files

(cherry picked from commit 96c22fdc0d399bb2749bc47316d866120bc02dcf)

src/viced/viced.c
src/vol/listinodes.c
src/vol/namei_ops.c
src/vol/namei_ops.h
src/vol/vol-salvage.c
src/volser/volmain.c

index 0b8cbb1..f103826 100644 (file)
@@ -155,8 +155,6 @@ struct afsconf_dir *confDir;        /* Configuration dir object */
 
 int restartMode = RESTART_ORDINARY;
 
-int Testing = 0;               /* for ListViceInodes */
-
 /*
  * Home for the performance statistics.
  */
index 979cbea..8342b19 100644 (file)
@@ -135,7 +135,7 @@ extern off_t afs_lseek(int FD, off_t O, int F);
 
 #define        ROOTINODE       2
 static char *partition;
-extern int Testing;
+int Testing=0;
 int pfd;
 
 #ifdef AFS_AIX32_ENV
index 8cda06e..f600555 100644 (file)
@@ -70,6 +70,8 @@ extern off_t afs_lseek(int FD, off_t O, int F);
 /*@printflike@*/ extern void Log(const char *format, ...);
 
 extern char *volutil_PartitionName_r(int volid, char *buf, int buflen);
+int Testing=0;
+
 
 afs_sfsize_t
 namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
@@ -150,6 +152,8 @@ typedef struct {
 } namei_ogm_t;
 
 int namei_SetLinkCount(FdHandle_t * h, Inode ino, int count, int locked);
+static int namei_GetLinkCount2(FdHandle_t * h, Inode ino, int lockit, int fixup);
+
 static int GetFreeTag(IHandle_t * ih, int vno);
 
 /* namei_HandleToInodeDir
@@ -860,13 +864,17 @@ namei_GetLCOffsetAndIndexFromIno(Inode ino, afs_foff_t * offset, int *index)
  * If lockit is set, lock the file and leave it locked upon a successful
  * return.
  */
-int
-namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit)
+static int
+namei_GetLinkCount2(FdHandle_t * h, Inode ino, int lockit, int fixup)
 {
     unsigned short row = 0;
     afs_foff_t offset;
+    ssize_t rc;
     int index;
 
+    /* there's no linktable yet. the salvager will create one later */
+    if (h->fd_fd == -1 && fixup)
+       return 1;
     namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
 
     if (lockit) {
@@ -881,10 +889,25 @@ namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit)
     if (afs_lseek(h->fd_fd, offset, SEEK_SET) == -1)
        goto bad_getLinkByte;
 
-    if (read(h->fd_fd, (char *)&row, sizeof(row)) != sizeof(row)) {
+    rc = read(h->fd_fd, (char *)&row, sizeof(row));
+    if (rc == 0 && fixup) {
+        struct stat st;
+        if (fstat(h->fd_fd, &st) || st.st_size >= offset+sizeof(row))
+          goto bad_getLinkByte;
+        FDH_TRUNC(h, offset+sizeof(row));
+        row = 1 << index;
+rewrite:
+        rc = write(h->fd_fd, (char *)&row, sizeof(row));
+    }
+    if (rc != sizeof(row)) {
        goto bad_getLinkByte;
     }
 
+    if (fixup && !((row >> index) & NAMEI_TAGMASK)) {
+        row |= 1<<index;
+        goto rewrite;
+    }
     return (int)((row >> index) & NAMEI_TAGMASK);
 
   bad_getLinkByte:
@@ -897,6 +920,18 @@ namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit)
     return -1;
 }
 
+int
+namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit) 
+{
+    return namei_GetLinkCount2(h, ino, lockit, 0);
+}
+
+void
+namei_SetNonZLC(FdHandle_t * h, Inode ino) 
+{
+    (void)namei_GetLinkCount2(h, ino, 0, 1);
+}
+
 /* Return a free column index for this vnode. */
 static int
 GetFreeTag(IHandle_t * ih, int vno)
@@ -1291,9 +1326,9 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
                /* Open this handle */
                (void)afs_snprintf(path2, sizeof path2, "%s/%s", path1,
                                   dp1->d_name);
-               linkHandle.fd_fd = afs_open(path2, O_RDONLY, 0666);
+               linkHandle.fd_fd = afs_open(path2, Testing ? O_RDONLY : O_RDWR, 0666);
                info.linkCount =
-                   namei_GetLinkCount(&linkHandle, (Inode) 0, 0);
+                   namei_GetLinkCount2(&linkHandle, (Inode) 0, 1, !Testing);
            }
            if (judgeFun && !(*judgeFun) (&info, singleVolumeNumber, rock))
                continue;
@@ -1344,8 +1379,8 @@ namei_ListAFSSubDirs(IHandle_t * dirIH,
                                (path3, dp3->d_name, &info, myIH.ih_vid) < 0)
                                continue;
                            info.linkCount =
-                               namei_GetLinkCount(&linkHandle,
-                                                  info.inodeNumber, 0);
+                               namei_GetLinkCount2(&linkHandle,
+                                                  info.inodeNumber, 1, !Testing);
                            if (info.linkCount == 0) {
 #ifdef DELETE_ZLC
                                Log("Found 0 link count file %s/%s, deleting it.\n", path3, dp3->d_name);
index 9f0df4a..8f615a2 100644 (file)
@@ -42,6 +42,7 @@ afs_sfsize_t namei_iwrite(IHandle_t * h, afs_foff_t offset, char *buf,
 extern int namei_dec(IHandle_t * h, Inode ino, int p1);
 extern int namei_inc(IHandle_t * h, Inode ino, int p1);
 extern int namei_GetLinkCount(FdHandle_t * h, Inode ino, int lockit);
+extern void namei_SetNonZLC(FdHandle_t * h, Inode ino);
 extern int namei_ViceREADME(char *partition);
 #include "nfs.h"
 #include "viceinode.h"
index fa7d9b0..0661582 100644 (file)
@@ -222,7 +222,7 @@ static char *TimeStamp(time_t clock, int precision);
 
 
 int debug;                     /* -d flag */
-int Testing = 0;               /* -n flag */
+extern int Testing;            /* -n flag */
 int ListInodeOption;           /* -i flag */
 int ShowRootFiles;             /* -r flag */
 int RebuildDirs;               /* -sal flag */
@@ -1452,7 +1452,19 @@ DoSalvageVolumeGroup(register struct InodeSummary *isp, int nVols)
        if (Testing) {
            IH_INIT(VGLinkH, fileSysDevice, -1, -1);
        } else {
+            int i, j;
+            struct ViceInodeInfo *ip;
            CreateLinkTable(isp, ino);
+           fdP = IH_OPEN(VGLinkH);
+            /* Sync fake 1 link counts to the link table, now that it exists */
+            if (fdP) {
+               namei_SetNonZLC(fdP, ino);
+               for (i = 0; i < nVols; i++) {
+                       ip = allInodes + isp[i].index;
+                       for (j = isp[i].nSpecialInodes; j < isp[i].nInodes; j++)
+                               namei_SetNonZLC(fdP, ip[j].inodeNumber);
+               }
+           }
        }
     }
     if (fdP)
index 215a90d..f30ae9c 100644 (file)
@@ -95,7 +95,6 @@ int DoLogging = 0;
 int lwps = 9;
 int udpBufSize = 0;            /* UDP buffer size for receive */
 
-int Testing = 0;               /* for ListViceInodes */
 int rxBind = 0;
 
 #define ADDRSPERSITE 16         /* Same global is in rx/rx_user.c */