vice & vol: Cast FDH_SYNC results to void
[openafs.git] / src / vol / clone.c
index e2e5909..9d62c97 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
 
-#include <sys/types.h>
-#include <stdio.h>
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else /* AFS_PTHREAD_ENV */
-#include <afs/assert.h>
-#endif /* AFS_PTHREAD_ENV */
 #ifdef AFS_NT40_ENV
-#include <fcntl.h>
 #include <windows.h>
 #include <winbase.h>
-#include <io.h>
-#include <time.h>
-#else
-#include <sys/file.h>
-#include <sys/time.h>
-#include <unistd.h>
 #endif
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
 
 #include <rx/xdr.h>
 #include <afs/afsint.h>
+#include <afs/afssyscalls.h>
+
 #include "nfs.h"
 #include "lwp.h"
 #include "lock.h"
-#include <afs/afssyscalls.h>
 #include "ihandle.h"
 #include "vnode.h"
 #include "volume.h"
 
 int (*vol_PollProc) (void) = 0;        /* someone must init this */
 
-#define ERROR_EXIT(code) {error = code; goto error_exit;}
+#define ERROR_EXIT(code) do { \
+    error = code; \
+    goto error_exit; \
+} while (0)
 
 /* parameters for idec call - this could just be an IHandle_t, but leaving
  * open the possibility of decrementing the special files as well.
@@ -91,7 +79,7 @@ ci_AddItem(struct clone_head *ah, Inode aino)
        ti = (struct clone_items *)malloc(sizeof(struct clone_items));
        if (!ti) {
            Log("ci_AddItem: malloc failed\n");
-           assert(0);
+           osi_Panic("ci_AddItem: malloc failed\n");
        }
        ti->nitems = 0;
        ti->next = (struct clone_items *)0;
@@ -171,13 +159,18 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
     Inode clinode;
     struct clone_head decHead;
     struct clone_rock decRock;
-    afs_int32 offset = 0;
+    afs_foff_t offset = 0;
     afs_int32 dircloned, inodeinced;
     afs_int32 filecount = 0, diskused = 0;
     afs_ino_str_t stmp;
 
     struct VnodeClassInfo *vcp = &VnodeClassInfo[class];
-    int ReadWriteOriginal = VolumeWriteable(rwvp);
+    /*
+     * The fileserver's -readonly switch should make this false, but we
+     * have no useful way to know in the volserver.
+     * This doesn't make client data mutable.
+     */
+    int ReadWriteOriginal = 1;
 
     /* Correct number of files in volume: this assumes indexes are always
        cloned starting with vLarge */
@@ -186,6 +179,13 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
        diskused = V_diskused(rwvp);
     }
 
+    /* Initialize list of inodes to nuke - must do this before any calls
+     * to ERROR_EXIT, as the error handler requires an initialised list
+     */
+    ci_InitHead(&decHead);
+    decRock.h = V_linkHandle(rwvp);
+    decRock.vol = V_parentId(rwvp);
+
     /* Open the RW volume's index file and seek to beginning */
     IH_COPY(rwH, rwvp->vnodeIndex[class].handle);
     rwFd = IH_OPEN(rwH);
@@ -194,7 +194,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
     rwfile = FDH_FDOPEN(rwFd, ReadWriteOriginal ? "r+" : "r");
     if (!rwfile)
        ERROR_EXIT(EIO);
-    STREAM_SEEK(rwfile, vcp->diskSize, 0);     /* Will fail if no vnodes */
+    STREAM_ASEEK(rwfile, vcp->diskSize);       /* Will fail if no vnodes */
 
     /* Open the clone volume's index file and seek to beginning */
     IH_COPY(clHout, clvp->vnodeIndex[class].handle);
@@ -204,7 +204,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
     clfileout = FDH_FDOPEN(clFdOut, "a");
     if (!clfileout)
        ERROR_EXIT(EIO);
-    code = STREAM_SEEK(clfileout, vcp->diskSize, 0);
+    code = STREAM_ASEEK(clfileout, vcp->diskSize);
     if (code)
        ERROR_EXIT(EIO);
 
@@ -220,14 +220,9 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
        clfilein = FDH_FDOPEN(clFdIn, "r");
        if (!clfilein)
            ERROR_EXIT(EIO);
-       STREAM_SEEK(clfilein, vcp->diskSize, 0);        /* Will fail if no vnodes */
+       STREAM_ASEEK(clfilein, vcp->diskSize);  /* Will fail if no vnodes */
     }
 
-    /* Initialize list of inodes to nuke */
-    ci_InitHead(&decHead);
-    decRock.h = V_linkHandle(rwvp);
-    decRock.vol = V_parentId(rwvp);
-
     /* Read each vnode in the old volume's index file */
     for (offset = vcp->diskSize;
         STREAM_READ(rwvnode, vcp->diskSize, 1, rwfile) == 1;
@@ -287,14 +282,14 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
                rwvnode->dataVersion++;
 #endif /* DVINC */
                rwvnode->cloned = 1;
-               code = STREAM_SEEK(rwfile, offset, 0);
+               code = STREAM_ASEEK(rwfile, offset);
                if (code == -1)
                    goto clonefailed;
                code = STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile);
                if (code != 1)
                    goto clonefailed;
                dircloned = 1;
-               code = STREAM_SEEK(rwfile, offset + vcp->diskSize, 0);
+               code = STREAM_ASEEK(rwfile, offset + vcp->diskSize);
                if (code == -1)
                    goto clonefailed;
 #ifdef DVINC
@@ -323,7 +318,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
            /* And if the directory was marked clone, unmark it */
            if (dircloned) {
                rwvnode->cloned = 0;
-               if (STREAM_SEEK(rwfile, offset, 0) != -1)
+               if (STREAM_ASEEK(rwfile, offset) != -1)
                    (void)STREAM_WRITE(rwvnode, vcp->diskSize, 1, rwfile);
            }
            ERROR_EXIT(EIO);
@@ -341,7 +336,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
 
     /* Clean out any junk at end of clone file */
     if (reclone) {
-       STREAM_SEEK(clfilein, offset, 0);
+       STREAM_ASEEK(clfilein, offset);
        while (STREAM_READ(clvnode, vcp->diskSize, 1, clfilein) == 1) {
            if (clvnode->type != vNull && VNDISK_GET_INO(clvnode) != 0) {
                ci_AddItem(&decHead, VNDISK_GET_INO(clvnode));
@@ -392,7 +387,7 @@ DoCloneIndex(Volume * rwvp, Volume * clvp, VnodeClass class, int reclone)
                error = FDH_TRUNC(rwFd, offset);
            }
        }
-       FDH_SYNC(rwFd);
+       (void)FDH_SYNC(rwFd);
        FDH_CLOSE(rwFd);
     }