FBSD, DFBSD (future) vnode_pager_setsize updates
[openafs.git] / src / afs / VNOPS / afs_vnop_rename.c
index 647d744..45aaefa 100644 (file)
@@ -17,8 +17,6 @@
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
 
 #include "afs/sysincludes.h"   /* Standard vendor system headers */
 #include "afsincludes.h"       /* Afs-based standard headers */
@@ -34,10 +32,10 @@ extern afs_rwlock_t afs_xcbhash;
 
 int
 afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
-         char *aname2, struct AFS_UCRED *acred, struct vrequest *areq)
+         char *aname2, afs_ucred_t *acred, struct vrequest *areq)
 {
-    register struct conn *tc;
-    register afs_int32 code = 0;
+    struct afs_conn *tc;
+    afs_int32 code = 0;
     afs_int32 returnCode;
     int oneDir, doLocally;
     afs_size_t offset, len;
@@ -67,14 +65,14 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
        goto done;
 
     /* lock in appropriate order, after some checks */
-    if (aodp->fid.Cell != andp->fid.Cell
-       || aodp->fid.Fid.Volume != andp->fid.Fid.Volume) {
+    if (aodp->f.fid.Cell != andp->f.fid.Cell
+       || aodp->f.fid.Fid.Volume != andp->f.fid.Fid.Volume) {
        code = EXDEV;
        goto done;
     }
     oneDir = 0;
     code = 0;
-    if (andp->fid.Fid.Vnode == aodp->fid.Fid.Vnode) {
+    if (andp->f.fid.Fid.Vnode == aodp->f.fid.Fid.Vnode) {
        if (!strcmp(aname1, aname2)) {
            /* Same directory and same name; this is a noop and just return success
             * to save cycles and follow posix standards */
@@ -97,10 +95,10 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
        }
        tdc2 = tdc1;
        oneDir = 1;             /* only one dude locked */
-    } else if ((andp->states & CRO) || (aodp->states & CRO)) {
+    } else if ((andp->f.states & CRO) || (aodp->f.states & CRO)) {
        code = EROFS;
        goto done;
-    } else if (andp->fid.Fid.Vnode < aodp->fid.Fid.Vnode) {
+    } else if (andp->f.fid.Fid.Vnode < aodp->f.fid.Fid.Vnode) {
        ObtainWriteLock(&andp->lock, 148);      /* lock smaller one first */
        ObtainWriteLock(&aodp->lock, 149);
        tdc2 = afs_FindDCache(andp, (afs_size_t) 0);
@@ -132,8 +130,8 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
      * received a callback while we were waiting for the write lock.
      */
     if (tdc1) {
-       if (!(aodp->states & CStatd)
-           || !hsame(aodp->m.DataVersion, tdc1->f.versionNo)) {
+       if (!(aodp->f.states & CStatd)
+           || !hsame(aodp->f.m.DataVersion, tdc1->f.versionNo)) {
 
            ReleaseWriteLock(&aodp->lock);
            if (!oneDir) {
@@ -170,15 +168,15 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
     if (!AFS_IS_DISCON_RW) {
        /* Connected. */
        do {
-           tc = afs_Conn(&aodp->fid, areq, SHARED_LOCK);
+           tc = afs_Conn(&aodp->f.fid, areq, SHARED_LOCK);
            if (tc) {
                XSTATS_START_TIME(AFS_STATS_FS_RPCIDX_RENAME);
                RX_AFS_GUNLOCK();
                code =
                    RXAFS_Rename(tc->id,
-                                       (struct AFSFid *)&aodp->fid.Fid,
+                                       (struct AFSFid *)&aodp->f.fid.Fid,
                                        aname1,
-                                       (struct AFSFid *)&andp->fid.Fid,
+                                       (struct AFSFid *)&andp->f.fid.Fid,
                                        aname2,
                                        &OutOldDirStatus,
                                        &OutNewDirStatus,
@@ -189,67 +187,51 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
                code = -1;
 
        } while (afs_Analyze
-            (tc, code, &andp->fid, areq, AFS_STATS_FS_RPCIDX_RENAME,
+            (tc, code, &andp->f.fid, areq, AFS_STATS_FS_RPCIDX_RENAME,
              SHARED_LOCK, NULL));
 
     } else {
-#if defined(AFS_DISCON_ENV)
        /* Disconnected. */
 
        /* Seek moved file vcache. */
-       fileFid.Cell = aodp->fid.Cell;
-       fileFid.Fid.Volume = aodp->fid.Fid.Volume;
+       fileFid.Cell = aodp->f.fid.Cell;
+       fileFid.Fid.Volume = aodp->f.fid.Fid.Volume;
        ObtainSharedLock(&afs_xvcache, 754);
        tvc = afs_FindVCache(&fileFid, 0 , 1);
        ReleaseSharedLock(&afs_xvcache);
 
        if (tvc) {
-           if (!(tvc->ddirty_flags & VDisconRename)) {
-               /* We only care about vnodes that haven't been
-                * renamed. Those that have been renamed at least once
-                * already have an asociated shadow dir and the flags set
-                * for the first old location, which is what interests us
-                * when reconnecting.
+           /* XXX - We're locking this vcache whilst holding dcaches. Ooops */
+           ObtainWriteLock(&tvc->lock, 750);
+           if (!(tvc->f.ddirty_flags & (VDisconRename|VDisconCreate))) {
+               /* If the vnode was created locally, then we don't care
+                * about recording the rename - we'll do it automatically
+                * on replay. If we've already renamed, we've already stored
+                * the required information about where we came from.
                 */
-
-               if (!(aodp->ddirty_flags & VDisconShadowed) &&
-                       !(tvc->ddirty_flags & VDisconCreate)) {
-                   /*
-                    * Make shadow copy of parent dir only.
-                    * Files that are created locally and renamed,
-                    * don't need a shadow dir, so skip this step.
-                    */
-                   if (tdc1)
-                       ReleaseWriteLock(&tdc1->lock);
-                   afs_MakeShadowDir(aodp);
-                   if (tdc1)
-                       ObtainWriteLock(&tdc1->lock, 753);
+               
+               if (!aodp->f.shadow.vnode) {
+                   /* Make shadow copy of parent dir only. */
+                   afs_MakeShadowDir(aodp, tdc1);
                }
 
-               if (!tvc->ddirty_flags ||
-                       (tvc->ddirty_flags == VDisconShadowed)) {
-                   /* Add in dirty list.*/
-                   ObtainWriteLock(&afs_DDirtyVCListLock, 751);
-                   AFS_DISCON_ADD_DIRTY(tvc);
-                   ReleaseWriteLock(&afs_DDirtyVCListLock);
-               }
-
-               ObtainWriteLock(&tvc->lock, 750);
-               /* Save old parent dir fid so it will be searchable
+               /* Save old parent dir fid so it will be searchable
                 * in the shadow dir.
                 */
-               tvc->oldVnode = aodp->fid.Fid.Vnode;
-               tvc->oldUnique = aodp->fid.Fid.Unique;
-               /* Set discon state flag. */
-               tvc->ddirty_flags |= VDisconRename;
-               if (oneDir)
-                   tvc->ddirty_flags |= VDisconRenameSameDir;
-               ReleaseWriteLock(&tvc->lock);
-           }                   /* if not previously renamed */
+               tvc->f.oldParent.vnode = aodp->f.fid.Fid.Vnode;
+               tvc->f.oldParent.unique = aodp->f.fid.Fid.Unique;
+
+               afs_DisconAddDirty(tvc, 
+                                  VDisconRename 
+                                    | (oneDir ? VDisconRenameSameDir:0), 
+                                  1);
+           }
+
+           ReleaseWriteLock(&tvc->lock);
+           afs_PutVCache(tvc);
        } else {
            code = ENOENT;
        }                       /* if (tvc) */
-#endif
     }                          /* if !(AFS_IS_DISCON_RW)*/
     returnCode = code;         /* remember for later */
 
@@ -315,12 +297,19 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
            }
        }
 
+
        /* update dir link counts */
-       aodp->m.LinkCount = AFS_IS_DISCON_RW ?
-                       (aodp->m.LinkCount - 1):OutOldDirStatus.LinkCount;
-       if (!oneDir)
-           andp->m.LinkCount = AFS_IS_DISCON_RW ?
-                       (andp->m.LinkCount + 1):OutNewDirStatus.LinkCount;
+       if (AFS_IS_DISCON_RW) {
+           if (!oneDir) {
+               aodp->f.m.LinkCount--;
+               andp->f.m.LinkCount++;
+           }
+           /* If we're in the same directory, link count doesn't change */
+       } else {
+           aodp->f.m.LinkCount = OutOldDirStatus.LinkCount;
+           if (!oneDir)
+               andp->f.m.LinkCount = OutNewDirStatus.LinkCount;
+       }
 
     } else {                   /* operation failed (code != 0) */
        if (code < 0) {
@@ -329,8 +318,8 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
            ObtainWriteLock(&afs_xcbhash, 498);
            afs_DequeueCallback(aodp);
            afs_DequeueCallback(andp);
-           andp->states &= ~CStatd;
-           aodp->states &= ~CStatd;
+           andp->f.states &= ~CStatd;
+           aodp->f.states &= ~CStatd;
            ReleaseWriteLock(&afs_xcbhash);
            osi_dnlc_purgedp(andp);
            osi_dnlc_purgedp(aodp);
@@ -349,8 +338,11 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
     }
 
     ReleaseWriteLock(&aodp->lock);
-    if (!oneDir)
+
+    if (!oneDir) {
        ReleaseWriteLock(&andp->lock);
+    }
+
     if (returnCode) {
        code = returnCode;
        goto done;
@@ -365,8 +357,8 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
      * entry */
     if (unlinkFid.Fid.Vnode) {
 
-       unlinkFid.Fid.Volume = aodp->fid.Fid.Volume;
-       unlinkFid.Cell = aodp->fid.Cell;
+       unlinkFid.Fid.Volume = aodp->f.fid.Fid.Volume;
+       unlinkFid.Cell = aodp->f.fid.Cell;
        tvc = NULL;
        if (!unlinkFid.Fid.Unique) {
            tvc = afs_LookupVCache(&unlinkFid, areq, NULL, aodp, aname1);
@@ -379,9 +371,9 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
            afs_BozonLock(&tvc->pvnLock, tvc);  /* Since afs_TryToSmush will do a pvn_vptrunc */
 #endif
            ObtainWriteLock(&tvc->lock, 151);
-           tvc->m.LinkCount--;
-           tvc->states &= ~CUnique;    /* For the dfs xlator */
-           if (tvc->m.LinkCount == 0 && !osi_Active(tvc)) {
+           tvc->f.m.LinkCount--;
+           tvc->f.states &= ~CUnique;  /* For the dfs xlator */
+           if (tvc->f.m.LinkCount == 0 && !osi_Active(tvc)) {
                /* if this was last guy (probably) discard from cache.
                 * We have to be careful to not get rid of the stat
                 * information, since otherwise operations will start
@@ -403,8 +395,8 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
 
     /* now handle ".." invalidation */
     if (!oneDir) {
-       fileFid.Fid.Volume = aodp->fid.Fid.Volume;
-       fileFid.Cell = aodp->fid.Cell;
+       fileFid.Fid.Volume = aodp->f.fid.Fid.Volume;
+       fileFid.Cell = aodp->f.fid.Cell;
        if (!fileFid.Fid.Unique)
            tvc = afs_LookupVCache(&fileFid, areq, NULL, andp, aname2);
        else
@@ -414,13 +406,11 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
            tdc1 = afs_FindDCache(tvc, (afs_size_t) 0);
            if (tdc1) {
                if (AFS_IS_DISCON_RW) {
-#if defined(AFS_DISCON_ENV)
                    /* If disconnected, we need to fix (not discard) the "..".*/
                    afs_dir_ChangeFid(tdc1,
                        "..",
-                       &aodp->fid.Fid.Vnode,
-                       &andp->fid.Fid.Vnode);
-#endif
+                       &aodp->f.fid.Fid.Vnode,
+                       &andp->f.fid.Fid.Vnode);
                } else {
                    ObtainWriteLock(&tdc1->lock, 648);
                    ZapDCE(tdc1);       /* mark as unknown */
@@ -433,8 +423,9 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
            ReleaseWriteLock(&tvc->lock);
            afs_PutVCache(tvc);
        } else if (AFS_IS_DISCON_RW && tvc && (vType(tvc) == VREG)) {
-           tvc->parentVnode = andp->fid.Fid.Vnode;
-           tvc->parentUnique = andp->fid.Fid.Unique;
+           /* XXX - Should tvc not get locked here? */
+           tvc->f.parent.vnode = andp->f.fid.Fid.Vnode;
+           tvc->f.parent.unique = andp->f.fid.Fid.Unique;
        } else if (tvc) {
            /* True we shouldn't come here since tvc SHOULD be a dir, but we
             * 'syntactically' need to unless  we change the 'if' above...
@@ -449,12 +440,12 @@ afsrename(struct vcache *aodp, char *aname1, struct vcache *andp,
 
 int
 #if defined(AFS_SGI_ENV)
-afs_rename(OSI_VC_DECL(aodp), char *aname1, struct vcache *andp, char *aname2, struct pathname *npnp, struct AFS_UCRED *acred)
+afs_rename(OSI_VC_DECL(aodp), char *aname1, struct vcache *andp, char *aname2, struct pathname *npnp, afs_ucred_t *acred)
 #else
-afs_rename(OSI_VC_DECL(aodp), char *aname1, struct vcache *andp, char *aname2, struct AFS_UCRED *acred)
+afs_rename(OSI_VC_DECL(aodp), char *aname1, struct vcache *andp, char *aname2, afs_ucred_t *acred)
 #endif
 {
-    register afs_int32 code;
+    afs_int32 code;
     struct afs_fakestat_state ofakestate;
     struct afs_fakestat_state nfakestate;
     struct vrequest treq;