afs: Create afs_SetDataVersion
[openafs.git] / src / afs / afs_disconnected.c
index 4c95707..957bf93 100644 (file)
@@ -6,17 +6,14 @@
 
 #include <afsconfig.h>
 #include "afs/param.h"
-RCSID("$Header$");
+
+
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
 #include "afs/afs_stats.h"     /* statistics */
 #include "afs/lock.h"
 #include "afs/afs_cbqueue.h"
 
-#ifdef AFS_DISCON_ENV
-
 #define dv_match(vc, fstat)                             \
        ((vc->f.m.DataVersion.low == fstat.DataVersion) && \
        (vc->f.m.DataVersion.high == fstat.dataVersionHigh))
@@ -51,8 +48,7 @@ enum {
 
 afs_int32 afs_ConflictPolicy = SERVER_WINS;
 
-static void afs_DisconResetVCache(struct vcache *, struct AFS_UCRED *);
-static void afs_DisconDiscardAllShadows(int, struct AFS_UCRED *);
+static void afs_DisconDiscardAllShadows(int, afs_ucred_t *);
 void afs_DbgListDirEntries(struct VenusFid *afid);
 
 
@@ -65,7 +61,8 @@ void afs_DbgListDirEntries(struct VenusFid *afid);
  *
  * \return The found dcache or NULL.
  */
-struct dcache *afs_FindDCacheByFid(struct VenusFid *afid)
+struct dcache *
+afs_FindDCacheByFid(struct VenusFid *afid)
 {
     afs_int32 i, index;
     struct dcache *tdc = NULL;
@@ -74,12 +71,14 @@ struct dcache *afs_FindDCacheByFid(struct VenusFid *afid)
     ObtainWriteLock(&afs_xdcache, 758);
     for (index = afs_dvhashTbl[i]; index != NULLIDX;) {
        if (afs_indexUnique[index] == afid->Fid.Unique) {
-           tdc = afs_GetDSlot(index, NULL);
-           ReleaseReadLock(&tdc->tlock);
-           if (!FidCmp(&tdc->f.fid, afid)) {
-               break;          /* leaving refCount high for caller */
+           tdc = afs_GetValidDSlot(index);
+           if (tdc) {
+               ReleaseReadLock(&tdc->tlock);
+               if (!FidCmp(&tdc->f.fid, afid)) {
+                   break;              /* leaving refCount high for caller */
+               }
+               afs_PutDCache(tdc);
            }
-           afs_PutDCache(tdc);
        }
        index = afs_dvnextTbl[index];
     }
@@ -101,7 +100,8 @@ struct dcache *afs_FindDCacheByFid(struct VenusFid *afid)
  *
  * \return Mask of operations.
  */
-int afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
+int
+afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
 {
     if (!avc || !astat || !avc->f.ddirty_flags)
        return 0;
@@ -131,10 +131,9 @@ int afs_GenStoreStatus(struct vcache *avc, struct AFSStoreStatus *astat)
  *
  * \param hdata The fid to be filled.
  */
-int get_parent_dir_fid_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+get_parent_dir_fid_hook(void *hdata, char *aname, afs_int32 vnode,
+                       afs_int32 unique)
 {
     struct VenusFid *tfid = (struct VenusFid *) hdata;
 
@@ -156,7 +155,8 @@ int get_parent_dir_fid_hook(void *hdata,
  *
  * \return 0 on success, -1 on failure
  */
-int afs_GetParentDirFid(struct vcache *avc, struct VenusFid *afid)
+int
+afs_GetParentDirFid(struct vcache *avc, struct VenusFid *afid)
 {
     struct dcache *tdc;
 
@@ -187,7 +187,6 @@ int afs_GetParentDirFid(struct vcache *avc, struct VenusFid *afid)
        break;
     default:
        return -1;
-       break;
     }
 
     return 0;
@@ -205,10 +204,9 @@ struct NameAndFid {
  * \param hdata NameAndFid structure containin a pointer to a fid
  * and an allocate name. The name will be filled when hit.
  */
-int get_vnode_name_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+get_vnode_name_hook(void *hdata, char *aname, afs_int32 vnode,
+                   afs_int32 unique)
 {
     struct NameAndFid *nf = (struct NameAndFid *) hdata;
 
@@ -234,10 +232,9 @@ int get_vnode_name_hook(void *hdata,
  * \param deleted Has this file been deleted? If yes, use the shadow
  * dir for looking up the name.
  */
-int afs_GetVnodeName(struct vcache *avc,
-                       struct VenusFid *afid,
-                       char *aname,
-                       int deleted)
+int
+afs_GetVnodeName(struct vcache *avc, struct VenusFid *afid, char *aname,
+                int deleted)
 {
     int code = 0;
     struct dcache *tdc;
@@ -267,7 +264,7 @@ int afs_GetVnodeName(struct vcache *avc,
        parent_vc = afs_FindVCache(&parent_fid, 0, 1);
        ReleaseSharedLock(&afs_xvcache);
        if (!parent_vc) {
-           return ENOENT;
+           return ENETDOWN;
        }
 
        shadow_fid.Cell = parent_vc->f.fid.Cell;
@@ -295,8 +292,8 @@ int afs_GetVnodeName(struct vcache *avc,
        if (tnf.name_len == -1)
            code = ENOENT;
     } else {
-       printf("Directory dcache not found!\n");
-        code = ENOENT;
+       /* printf("Directory dcache not found!\n"); */
+        code = ENETDOWN;
     }
 
     return code;
@@ -310,10 +307,9 @@ struct DirtyChildrenCount {
 /*!
  * Lookup dirty deleted vnodes in this dir.
  */
-int chk_del_children_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+chk_del_children_hook(void *hdata, char *aname, afs_int32 vnode,
+                     afs_int32 unique)
 {
     struct VenusFid tfid;
     struct DirtyChildrenCount *v = (struct DirtyChildrenCount *) hdata;
@@ -360,7 +356,8 @@ int chk_del_children_hook(void *hdata,
  *
  * \note afs_DDirtyVCListLock must be write locked.
  */
-int afs_CheckDeletedChildren(struct vcache *avc)
+int
+afs_CheckDeletedChildren(struct vcache *avc)
 {
     struct dcache *tdc;
     struct DirtyChildrenCount dcc;
@@ -391,10 +388,9 @@ int afs_CheckDeletedChildren(struct vcache *avc)
 /*!
  * Changes a file's parent fid references.
  */
-int fix_children_fids_hook(void *hdata,
-                               char *aname,
-                               afs_int32 vnode,
-                               afs_int32 unique)
+static int
+fix_children_fids_hook(void *hdata, char *aname, afs_int32 vnode,
+                      afs_int32 unique)
 {
     struct VenusFid tfid;
     struct VenusFid *afid = (struct VenusFid *) hdata;
@@ -454,7 +450,8 @@ int fix_children_fids_hook(void *hdata,
  * \param old_fid The current dir's fid.
  * \param new_fid The new dir's fid.
  */
-void afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
+void
+afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
 {
     struct dcache *tdc;
 
@@ -467,13 +464,15 @@ void afs_FixChildrenFids(struct VenusFid *old_fid, struct VenusFid *new_fid)
     }
 }
 
-int list_dir_hook(void *hdata, char *aname, afs_int32 vnode, afs_int32 unique)
+static int
+list_dir_hook(void *hdata, char *aname, afs_int32 vnode, afs_int32 unique)
 {
-    printf("list_dir_hook: %s v:%u u:%u\n", aname, vnode, unique);
+    /* printf("list_dir_hook: %s v:%u u:%u\n", aname, vnode, unique); */
     return 0;
 }
 
-void afs_DbgListDirEntries(struct VenusFid *afid)
+void
+afs_DbgListDirEntries(struct VenusFid *afid)
 {
     struct dcache *tdc;
 
@@ -499,7 +498,7 @@ void afs_DbgListDirEntries(struct VenusFid *afid)
  */
 
 int
-afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid, 
+afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid,
                    char *aname, struct vcache **adp)
 {
     int code;
@@ -507,13 +506,13 @@ afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid,
     *adp = NULL;
 
     if (afs_GetParentDirFid(avc, afid)) {
-       printf("afs_GetParentVCache: Couldn't find parent dir's FID.\n");
-       return ENOENT;
+       /* printf("afs_GetParentVCache: Couldn't find parent dir's FID.\n"); */
+       return ENETDOWN;
     }
 
     code = afs_GetVnodeName(avc, afid, aname, deleted);
     if (code) {
-       printf("afs_GetParentVCache: Couldn't find file name\n");
+       /* printf("afs_GetParentVCache: Couldn't find file name\n"); */
        goto end;
     }
 
@@ -521,20 +520,22 @@ afs_GetParentVCache(struct vcache *avc, int deleted, struct VenusFid *afid,
     *adp = afs_FindVCache(afid, 0, 1);
     ReleaseSharedLock(&afs_xvcache);
     if (!*adp) {
-       printf("afs_GetParentVCache: Couldn't find parent dir's vcache\n");
-       code = ENOENT;
+       /* printf("afs_GetParentVCache: Couldn't find parent dir's vcache\n"); */
+       code = ENETDOWN;
        goto end;
     }
 
     if ((*adp)->f.ddirty_flags & VDisconCreate) {
-       printf("afs_GetParentVCache: deferring until parent exists\n");
+       /* printf("afs_GetParentVCache: deferring until parent exists\n"); */
        code = EAGAIN;
        goto end;
     }
 
 end:
-    if (code && *adp)
+    if (code && *adp) {
        afs_PutVCache(*adp);
+       *adp = NULL;
+    }
     return code;
 }
 
@@ -545,13 +546,15 @@ end:
  * - Get the new name from the current dir.
  * - Old dir fid and new dir fid are collected along the way.
  * */
-int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
+int
+afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
 {
     struct VenusFid old_pdir_fid, new_pdir_fid;
     char *old_name = NULL, *new_name = NULL;
     struct AFSFetchStatus OutOldDirStatus, OutNewDirStatus;
     struct AFSVolSync tsync;
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
     afs_uint32 code = 0;
     XSTATS_DECLS;
 
@@ -562,21 +565,21 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     old_pdir_fid.Fid.Unique = avc->f.oldParent.unique;
 
     /* Get old name. */
-    old_name = (char *) afs_osi_Alloc(AFSNAMEMAX);
+    old_name = afs_osi_Alloc(AFSNAMEMAX);
     if (!old_name) {
-       printf("afs_ProcessOpRename: Couldn't alloc space for old name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't alloc space for old name.\n"); */
        return ENOMEM;
     }
     code = afs_GetVnodeName(avc, &old_pdir_fid, old_name, 1);
     if (code) {
-       printf("afs_ProcessOpRename: Couldn't find old name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't find old name.\n"); */
        goto done;
     }
 
     /* Alloc data first. */
-    new_name = (char *) afs_osi_Alloc(AFSNAMEMAX);
+    new_name = afs_osi_Alloc(AFSNAMEMAX);
     if (!new_name) {
-       printf("afs_ProcessOpRename: Couldn't alloc space for new name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't alloc space for new name.\n"); */
        code = ENOMEM;
        goto done;
     }
@@ -589,8 +592,8 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     } else {
        /* Get parent dir's FID.*/
        if (afs_GetParentDirFid(avc, &new_pdir_fid)) {
-           printf("afs_ProcessOpRename: Couldn't find new parent dir FID.\n");
-           code = ENOENT;
+           /* printf("afs_ProcessOpRename: Couldn't find new parent dir FID.\n"); */
+           code = ENETDOWN;
            goto done;
         }
     }
@@ -598,17 +601,17 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
     /* And finally get the new name. */
     code = afs_GetVnodeName(avc, &new_pdir_fid, new_name, 0);
     if (code) {
-       printf("afs_ProcessOpRename: Couldn't find new name.\n");
+       /* printf("afs_ProcessOpRename: Couldn't find new name.\n"); */
        goto done;
     }
 
     /* Send to data to server. */
     do {
-       tc = afs_Conn(&old_pdir_fid, areq, SHARED_LOCK);
+       tc = afs_Conn(&old_pdir_fid, areq, SHARED_LOCK, &rxconn);
        if (tc) {
            XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RENAME);
            RX_AFS_GUNLOCK();
-           code = RXAFS_Rename(tc->id,
+           code = RXAFS_Rename(rxconn,
                (struct AFSFid *)&old_pdir_fid.Fid,
                old_name,
                (struct AFSFid *)&new_pdir_fid.Fid,
@@ -622,6 +625,7 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
            code = -1;
 
     } while (afs_Analyze(tc,
+                rxconn,
                code,
                &new_pdir_fid,
                areq,
@@ -629,8 +633,7 @@ int afs_ProcessOpRename(struct vcache *avc, struct vrequest *areq)
                SHARED_LOCK,
                NULL));
 
-    if (code)
-       printf("afs_ProcessOpRename: server code=%u\n", code);
+    /* if (code) printf("afs_ProcessOpRename: server code=%u\n", code); */
 done:
     if (new_name)
        afs_osi_Free(new_name, AFSNAMEMAX);
@@ -646,8 +649,9 @@ done:
  * - Handle errors.
  * - Reorder vhash and dcaches in their hashes, using the newly acquired fid.
  */
-int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
-                       struct AFS_UCRED *acred)
+int
+afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
+                   afs_ucred_t *acred)
 {
     char *tname = NULL, *ttargetName = NULL;
     struct AFSStoreStatus InStatus;
@@ -658,17 +662,19 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
     struct vcache *tdp = NULL, *tvc = NULL;
     struct dcache *tdc = NULL;
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
     afs_int32 hash, new_hash, index;
     afs_size_t tlen;
-    int code, op;
+    int code, op = 0;
     XSTATS_DECLS;
 
     tname = afs_osi_Alloc(AFSNAMEMAX);
     if (!tname)
        return ENOMEM;
+    memset(&InStatus, 0, sizeof(InStatus));
 
     code = afs_GetParentVCache(avc, 0, &pdir_fid, tname, &tdp);
-    if (code) 
+    if (code)
        goto end;
 
     /* This data may also be in linkData, but then we have to deal with
@@ -682,7 +688,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
 
        tdc = afs_GetDCache(avc, 0, areq, &offset, &tlen, 0);
        if (!tdc) {
-           code = ENOENT;
+           code = ENETDOWN;
            goto end;
        }
 
@@ -696,7 +702,8 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
        ttargetName = afs_osi_Alloc(tlen);
        if (!ttargetName) {
            afs_PutDCache(tdc);
-           return ENOMEM;
+           code = ENOMEM;
+           goto end;
        }
        ObtainReadLock(&tdc->lock);
        tfile = afs_CFileOpen(&tdc->f.inode);
@@ -705,19 +712,18 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
        afs_CFileClose(tfile);
        ReleaseReadLock(&tdc->lock);
        afs_PutDCache(tdc);
-       printf("Read target name as %s\n",ttargetName);
     }
-       
+
     /* Set status. */
     InStatus.Mask = AFS_SETMODTIME | AFS_SETMODE | AFS_SETGROUP;
     InStatus.ClientModTime = avc->f.m.Date;
     InStatus.Owner = avc->f.m.Owner;
-    InStatus.Group = (afs_int32) acred->cr_gid;
+    InStatus.Group = (afs_int32) afs_cr_gid(acred);
     /* Only care about protection bits. */
     InStatus.UnixModeBits = avc->f.m.Mode & 0xffff;
 
     do {
-       tc = afs_Conn(&tdp->f.fid, areq, SHARED_LOCK);
+       tc = afs_Conn(&tdp->f.fid, areq, SHARED_LOCK, &rxconn);
        if (tc) {
            switch (vType(avc)) {
            case VREG:
@@ -725,7 +731,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
                op = AFS_STATS_FS_RPCIDX_CREATEFILE;
                XSTATS_START_TIME(op);
                 RX_AFS_GUNLOCK();
-                code = RXAFS_CreateFile(tc->id,
+                code = RXAFS_CreateFile(rxconn,
                                        (struct AFSFid *)&tdp->f.fid.Fid,
                                        tname, &InStatus,
                                        (struct AFSFid *) &newFid.Fid,
@@ -739,7 +745,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
                op = AFS_STATS_FS_RPCIDX_MAKEDIR;
                XSTATS_START_TIME(op);
                 RX_AFS_GUNLOCK();
-               code = RXAFS_MakeDir(tc->id, (struct AFSFid *) &tdp->f.fid.Fid,
+               code = RXAFS_MakeDir(rxconn, (struct AFSFid *) &tdp->f.fid.Fid,
                                     tname, &InStatus,
                                     (struct AFSFid *) &newFid.Fid,
                                     &OutFidStatus, &OutDirStatus,
@@ -752,7 +758,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
                op = AFS_STATS_FS_RPCIDX_SYMLINK;
                XSTATS_START_TIME(op);
                RX_AFS_GUNLOCK();
-               code = RXAFS_Symlink(tc->id,
+               code = RXAFS_Symlink(rxconn,
                                (struct AFSFid *) &tdp->f.fid.Fid,
                                tname, ttargetName, &InStatus,
                                (struct AFSFid *) &newFid.Fid,
@@ -767,11 +773,11 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
            }
         } else
            code = -1;
-    } while (afs_Analyze(tc, code, &tdp->f.fid, areq, op, SHARED_LOCK, NULL));
+    } while (afs_Analyze(tc, rxconn, code, &tdp->f.fid, areq, op, SHARED_LOCK, NULL));
 
     /* TODO: Handle errors. */
     if (code) {
-       printf("afs_ProcessOpCreate: error while creating vnode on server, code=%d .\n", code);
+       /* printf("afs_ProcessOpCreate: error while creating vnode on server, code=%d .\n", code); */
        goto end;
     }
 
@@ -796,11 +802,11 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
         */
        tdc = afs_FindDCacheByFid(&avc->f.fid);
        if (tdc) {
-           afs_dir_ChangeFid(tdc, ".", &avc->f.fid.Fid.Vnode, 
+           afs_dir_ChangeFid(tdc, ".", &avc->f.fid.Fid.Vnode,
                              &newFid.Fid.Vnode);
 
            if (avc->f.m.LinkCount >= 2)
-               /* For non empty dirs, fix children's parentVnode and 
+               /* For non empty dirs, fix children's parentVnode and
                 * parentUnique reference.
                 */
                afs_FixChildrenFids(&avc->f.fid, &newFid);
@@ -851,7 +857,7 @@ int afs_ProcessOpCreate(struct vcache *avc, struct vrequest *areq,
     ObtainWriteLock(&afs_xdcache, 743);
     for (index = afs_dvhashTbl[hash]; index != NULLIDX; index = hash) {
         hash = afs_dvnextTbl[index];
-        tdc = afs_GetDSlot(index, NULL);
+        tdc = afs_GetValidDSlot(index);
         ReleaseReadLock(&tdc->tlock);
        if (afs_indexUnique[index] == avc->f.fid.Fid.Unique) {
             if (!FidCmp(&tdc->f.fid, &avc->f.fid)) {
@@ -884,7 +890,7 @@ end:
     if (tdp)
        afs_PutVCache(tdp);
     afs_osi_Free(tname, AFSNAMEMAX);
-    if (ttargetName) 
+    if (ttargetName)
        afs_osi_Free(ttargetName, tlen);
     return code;
 }
@@ -903,20 +909,22 @@ end:
  *
  * \note avc must be write locked.
  */
-int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
+int
+afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
 {
     char *tname = NULL;
     struct AFSFetchStatus OutDirStatus;
     struct VenusFid pdir_fid;
     struct AFSVolSync tsync;
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
     struct vcache *tdp = NULL;
     int code = 0;
     XSTATS_DECLS;
 
     tname = afs_osi_Alloc(AFSNAMEMAX);
     if (!tname) {
-       printf("afs_ProcessOpRemove: Couldn't alloc space for file name\n");
+       /* printf("afs_ProcessOpRemove: Couldn't alloc space for file name\n"); */
        return ENOMEM;
     }
 
@@ -935,11 +943,11 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
     if (vType(avc) == VREG || vType(avc) == VLNK) {
        /* Remove file on server. */
        do {
-           tc = afs_Conn(&pdir_fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&pdir_fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEFILE);
                RX_AFS_GUNLOCK();
-               code = RXAFS_RemoveFile(tc->id,
+               code = RXAFS_RemoveFile(rxconn,
                                &pdir_fid.Fid,
                                tname,
                                &OutDirStatus,
@@ -950,6 +958,7 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
            } else
                code = -1;
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &pdir_fid,
                        areq,
@@ -960,11 +969,11 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
     } else if (vType(avc) == VDIR) {
        /* Remove dir on server. */
        do {
-           tc = afs_Conn(&pdir_fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&pdir_fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_REMOVEDIR);
                RX_AFS_GUNLOCK();
-               code = RXAFS_RemoveDir(tc->id,
+               code = RXAFS_RemoveDir(rxconn,
                                &pdir_fid.Fid,
                                tname,
                                &OutDirStatus,
@@ -974,6 +983,7 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
           } else
                code = -1;
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &pdir_fid,
                        areq,
@@ -983,8 +993,7 @@ int afs_ProcessOpRemove(struct vcache *avc, struct vrequest *areq)
 
     }                          /* if (vType(avc) == VREG) */
 
-    if (code)
-       printf("afs_ProcessOpRemove: server returned code=%u\n", code);
+    /* if (code) printf("afs_ProcessOpRemove: server returned code=%u\n", code); */
 
 end:
     afs_osi_Free(tname, AFSNAMEMAX);
@@ -1001,9 +1010,11 @@ end:
  *
  * \return 0 for success. On failure, other error codes.
  */
-int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
+int
+afs_SendChanges(struct vcache *avc, struct vrequest *areq)
 {
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
     struct AFSStoreStatus sstat;
     struct AFSFetchStatus fstat;
     struct AFSVolSync tsync;
@@ -1017,12 +1028,12 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
        /* Turn dirty vc data into a new store status... */
        if (afs_GenStoreStatus(avc, &sstat) > 0) {
            do {
-               tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
+               tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
                if (tc) {
                    /* ... and send it. */
                    XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_STORESTATUS);
                    RX_AFS_GUNLOCK();
-                   code = RXAFS_StoreStatus(tc->id,
+                   code = RXAFS_StoreStatus(rxconn,
                                (struct AFSFid *) &avc->f.fid.Fid,
                                &sstat,
                                &fstat,
@@ -1034,6 +1045,7 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
                    code = -1;
 
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &avc->f.fid,
                        areq,
@@ -1055,7 +1067,7 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
 
        /* Truncate OP: */
        do {
-           tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&avc->f.fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
                /* Set storing flags. XXX: A tad inefficient ... */
                if (avc->f.ddirty_flags & VDisconWriteClose)
@@ -1072,6 +1084,7 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
                code = -1;
 
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &avc->f.fid,
                        areq,
@@ -1097,15 +1110,16 @@ int afs_SendChanges(struct vcache *avc, struct vrequest *areq)
  * \note For now, it's the request from the PDiscon pioctl.
  *
  */
-int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
+int
+afs_ResyncDisconFiles(struct vrequest *areq, afs_ucred_t *acred)
 {
     struct afs_conn *tc;
+    struct rx_connection *rxconn;
     struct vcache *tvc;
     struct AFSFetchStatus fstat;
     struct AFSCallBack callback;
     struct AFSVolSync tsync;
     int code = 0;
-    int ucode;
     afs_int32 start = 0;
     XSTATS_DECLS;
     /*AFS_STATCNT(afs_ResyncDisconFiles);*/
@@ -1141,11 +1155,11 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
 #if 0
        /* Get server write lock. */
        do {
-           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_SETLOCK);
                RX_AFS_GUNLOCK();
-               code = RXAFS_SetLock(tc->id,
+               code = RXAFS_SetLock(rxconn,
                                        (struct AFSFid *)&tvc->f.fid.Fid,
                                        LockWrite,
                                        &tsync);
@@ -1155,6 +1169,7 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
                code = -1;
 
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &tvc->f.fid,
                        areq,
@@ -1174,13 +1189,13 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
 
        /* Issue a FetchStatus to get info about DV and callbacks. */
        do {
-           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
-               tvc->callback = tc->srvr->server;
+               tvc->callback = tc->parent->srvr->server;
                start = osi_Time();
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_FETCHSTATUS);
                RX_AFS_GUNLOCK();
-               code = RXAFS_FetchStatus(tc->id,
+               code = RXAFS_FetchStatus(rxconn,
                                (struct AFSFid *)&tvc->f.fid.Fid,
                                &fstat,
                                &callback,
@@ -1191,6 +1206,7 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
                code = -1;
 
        } while (afs_Analyze(tc,
+                       rxconn,
                        code,
                        &tvc->f.fid,
                        areq,
@@ -1220,21 +1236,21 @@ int afs_ResyncDisconFiles(struct vrequest *areq, struct AFS_UCRED *acred)
        } else if (afs_ConflictPolicy == SERVER_WINS) {
            /* DV mismatch, apply collision resolution policy. */
            /* Discard this files chunks and remove from current dir. */
-           afs_ResetVCache(tvc, acred);
+           afs_ResetVCache(tvc, acred, 0);
            tvc->f.truncPos = AFS_NOTRUNC;
        } else {
-           printf("afs_ResyncDisconFiles: no resolution policy selected.\n");
+           /* printf("afs_ResyncDisconFiles: no resolution policy selected.\n"); */
        }               /* if DV match or client wins policy */
 
 unlock_srv_file:
        /* Release server write lock. */
 #if 0
        do {
-           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&tvc->f.fid, areq, SHARED_LOCK, &rxconn);
            if (tc) {
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RELEASELOCK);
                RX_AFS_GUNLOCK();
-               ucode = RXAFS_ReleaseLock(tc->id,
+               ucode = RXAFS_ReleaseLock(rxconn,
                                (struct AFSFid *) &tvc->f.fid.Fid,
                                &tsync);
                RX_AFS_GLOCK();
@@ -1242,6 +1258,7 @@ unlock_srv_file:
            } else
                ucode = -1;
        } while (afs_Analyze(tc,
+                       rxconn,
                        ucode,
                        &tvc->f.fid,
                        areq,
@@ -1252,14 +1269,14 @@ unlock_srv_file:
 next_file:
        ObtainWriteLock(&afs_disconDirtyLock, 710);
        if (code == 0) {
-           /* Replayed successfully - pull the vcache from the 
+           /* Replayed successfully - pull the vcache from the
             * disconnected list */
            tvc->f.ddirty_flags = 0;
            QRemove(&tvc->dirtyq);
            afs_PutVCache(tvc);
        } else {
            if (code == EAGAIN) {
-               /* Operation was deferred. Pull it from the current place in 
+               /* Operation was deferred. Pull it from the current place in
                 * the list, and stick it at the end again */
                QRemove(&tvc->dirtyq);
                QAdd(&afs_disconDirty, &tvc->dirtyq);
@@ -1291,7 +1308,7 @@ next_file:
  * Discard all of our shadow directory copies. If squash is true, then
  * we also invalidate the vcache holding the shadow directory, to ensure
  * that any disconnected changes are deleted
- * 
+ *
  * \param squash
  * \param acred
  *
@@ -1300,7 +1317,8 @@ next_file:
  */
 
 static void
-afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
+afs_DisconDiscardAllShadows(int squash, afs_ucred_t *acred)
+{
    struct vcache *tvc;
 
    while (!QEmpty(&afs_disconShadow)) {
@@ -1310,12 +1328,10 @@ afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
        ReleaseWriteLock(&afs_disconDirtyLock);
        ObtainWriteLock(&tvc->lock, 706);
 
-       afs_DeleteShadowDir(tvc);
-       tvc->f.shadow.vnode = 0;
-       tvc->f.shadow.unique = 0;
-
        if (squash)
-          afs_ResetVCache(tvc, acred);
+          afs_ResetVCache(tvc, acred, 0);
+
+       afs_DeleteShadowDir(tvc);
 
        ReleaseWriteLock(&tvc->lock);
        ObtainWriteLock(&afs_disconDirtyLock, 709);
@@ -1330,21 +1346,23 @@ afs_DisconDiscardAllShadows(int squash, struct AFS_UCRED *acred) {
  * \param acred
  *
  */
-void 
-afs_DisconDiscardAll(struct AFS_UCRED *acred) {
+void
+afs_DisconDiscardAll(afs_ucred_t *acred)
+{
     struct vcache *tvc;
 
     ObtainWriteLock(&afs_disconDirtyLock, 717);
     while (!QEmpty(&afs_disconDirty)) {
        tvc = QEntry(QPrev(&afs_disconDirty), struct vcache, dirtyq);
+       QRemove(&tvc->dirtyq);
        ReleaseWriteLock(&afs_disconDirtyLock);
 
        ObtainWriteLock(&tvc->lock, 718);
-       afs_ResetVCache(tvc, acred);
+       afs_ResetVCache(tvc, acred, 0);
        tvc->f.truncPos = AFS_NOTRUNC;
        ReleaseWriteLock(&tvc->lock);
-       afs_PutVCache(tvc);
        ObtainWriteLock(&afs_disconDirtyLock, 719);
+       afs_PutVCache(tvc);
     }
 
     afs_DisconDiscardAllShadows(1, acred);
@@ -1357,19 +1375,20 @@ afs_DisconDiscardAll(struct AFS_UCRED *acred) {
  *
  * \note Call with afs_DDirtyVCListLock read locked.
  */
-void afs_DbgDisconFiles()
+void
+afs_DbgDisconFiles(void)
 {
     struct vcache *tvc;
     struct afs_q *q;
     int i = 0;
 
-    printf("List of dirty files: \n");
+    afs_warn("List of dirty files: \n");
 
     ObtainReadLock(&afs_disconDirtyLock);
     for (q = QPrev(&afs_disconDirty); q != &afs_disconDirty; q = QPrev(q)) {
         tvc = QEntry(q, struct vcache, dirtyq);
 
-       printf("Cell=%u Volume=%u VNode=%u Unique=%u\n",
+       afs_warn("Cell=%u Volume=%u VNode=%u Unique=%u\n",
                tvc->f.fid.Cell,
                tvc->f.fid.Fid.Volume,
                tvc->f.fid.Fid.Vnode,
@@ -1392,7 +1411,8 @@ void afs_DbgDisconFiles()
  *
  * \note Don't forget to fill in afid with Cell and Volume.
  */
-void afs_GenShadowFid(struct VenusFid *afid)
+void
+afs_GenShadowFid(struct VenusFid *afid)
 {
     afs_uint32 i, index, max_unique = 1;
     struct vcache *tvc = NULL;
@@ -1438,7 +1458,8 @@ void afs_GenShadowFid(struct VenusFid *afid)
  *
  * \note The cell number must be completed somewhere else.
  */
-void afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
+void
+afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
 {
     struct vcache *tvc;
     afs_uint32 max_unique = 0, i;
@@ -1481,10 +1502,12 @@ void afs_GenFakeFid(struct VenusFid *afid, afs_uint32 avtype, int lock)
  *
  * \note Call with avc write locked.
  */
-void afs_GenDisconStatus(struct vcache *adp, struct vcache *avc, 
-                        struct VenusFid *afid, struct vattr *attrs,
-                        struct vrequest *areq, int file_type)
+void
+afs_GenDisconStatus(struct vcache *adp, struct vcache *avc,
+                   struct VenusFid *afid, struct vattr *attrs,
+                   struct vrequest *areq, int file_type)
 {
+    afs_hyper_t zero;
     memcpy(&avc->f.fid, afid, sizeof(struct VenusFid));
     avc->f.m.Mode = attrs->va_mode;
     /* Used to do this:
@@ -1495,7 +1518,8 @@ void afs_GenDisconStatus(struct vcache *adp, struct vcache *avc,
      */
     avc->f.m.Group = adp->f.m.Group;
     avc->f.m.Owner = adp->f.m.Owner;
-    hset64(avc->f.m.DataVersion, 0, 0);
+    hzero(zero);
+    afs_SetDataVersion(avc, &zero);
     avc->f.m.Length = attrs->va_size;
     avc->f.m.Date = osi_Time();
     switch(file_type) {
@@ -1515,7 +1539,7 @@ void afs_GenDisconStatus(struct vcache *adp, struct vcache *avc,
        vSetType(avc, VLNK);
        avc->f.m.Mode |= S_IFLNK;
        if ((avc->f.m.Mode & 0111) == 0)
-           avc->mvstat = 1;
+           avc->mvstat = AFS_MVSTAT_MTPT;
        avc->f.parent.vnode = adp->f.fid.Fid.Vnode;
        avc->f.parent.unique = adp->f.fid.Fid.Unique;
        break;
@@ -1529,4 +1553,3 @@ void afs_GenDisconStatus(struct vcache *adp, struct vcache *avc,
     avc->f.states |= CStatd;
     avc->f.states &= ~CBulkFetching;
 }
-#endif