freelance-fake-root-vol-id-fix-20040606
authorJeffrey Altman <jaltman@mit.edu>
Mon, 7 Jun 2004 07:22:57 +0000 (07:22 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Mon, 7 Jun 2004 07:22:57 +0000 (07:22 +0000)
 * add debugging to allow fs trace -dump to be used for freelance
   operations

 * Change the volume id associated with the fake root.afs from
   0x20000001 to 0x00000001 to prevent confusion of remote cell
   root.afs volumes with the fake root.afs.  (way to go Derrick.)

 * add function prototypes to cm_freelance.h

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/cm_callback.c
src/WINNT/afsd/cm_dcache.c
src/WINNT/afsd/cm_freelance.c
src/WINNT/afsd/cm_freelance.h
src/WINNT/afsd/cm_ioctl.c
src/WINNT/afsd/cm_scache.c
src/WINNT/afsd/cm_vnodeops.c

index c23efe6..43ffdf6 100644 (file)
@@ -726,6 +726,7 @@ int afsd_InitDaemons(char **reasonP)
        /* this should really be in an init daemon from here on down */
 
     if (!cm_freelanceEnabled) {
+               osi_Log0(afsd_logp, "Loading Root Volume from cell");
         code = cm_GetVolumeByName(cm_rootCellp, cm_rootVolumeName, cm_rootUserp,
                                   &req, CM_FLAG_CREATE, &cm_rootVolumep);
         afsi_log("cm_GetVolumeByName code %x root vol %x", code,
index 81f1f42..bade3f2 100644 (file)
 /* read/write lock for all global storage in this module */
 osi_rwlock_t cm_callbackLock;
 
-/*
-#ifdef AFS_FREELANCE_CLIENT
-extern int cm_fakeDirCallback;
-extern int cm_fakeGettingCallback;
-#endif
-*/
 #ifdef AFS_FREELANCE_CLIENT
 extern osi_mutex_t cm_Freelance_Lock;
 #endif
@@ -606,7 +600,7 @@ int cm_HaveCallback(cm_scache_t *scp)
     // good shape and we simply return true, provided no change is detected.
   int fdc, fgc;
 
-    if (cm_freelanceEnabled && scp->fid.cell==0x1 && scp->fid.volume==0x20000001) {    // if it's something on /afs
+    if (cm_freelanceEnabled && scp->fid.cell==0x1 && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {  // if it's something on /afs
        if (!(scp->fid.vnode==0x1 && scp->fid.unique==0x1))     // if it's not root.afs
            return 1;
        else {
@@ -764,7 +758,7 @@ long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
        // cm_MergeStatus and mark that cm_fakeDirCallback is 2
        if (cm_freelanceEnabled &&
         scp->fid.cell==0x1 &&
-               scp->fid.volume==0x20000001 &&
+               scp->fid.volume==AFS_FAKE_ROOT_VOL_ID &&
                scp->fid.unique==0x1 &&
                scp->fid.vnode==0x1) {
                // Start by indicating that we're in the process
@@ -787,9 +781,9 @@ long cm_GetCallback(cm_scache_t *scp, struct cm_user *userp,
                return 0;
        }
 
-       /*if (scp->fid.cell==0x1 && scp->fid.volume==0x20000001) {
-               afsi_log("cm_getcallback should NEVER EVER get here... ");
-       }*/
+       if (scp->fid.cell==0x1 && scp->fid.volume==AFS_FAKE_ROOT_VOL_ID) {
+               osi_Log0(afsd_logp,"cm_getcallback should NEVER EVER get here... ");
+       }
        // yj: end of getcallback modifications  ---------------
                
 #endif /* AFS_FREELANCE_CLIENT */
index 5211c87..1ea2be8 100644 (file)
@@ -1112,7 +1112,9 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up,
        // handle it differently, since it's local rather than on any
        // server
 
-       getroot = (scp==cm_rootSCachep) ;
+       getroot = (scp==cm_rootSCachep);
+       if (getroot)
+               osi_Log1(afsd_logp,"GetBuffer returns cm_rootSCachep=%x",cm_rootSCachep);
 #endif
 
        cm_AFSFidFromFid(&tfid, &scp->fid);
@@ -1188,9 +1190,6 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up,
                // 0. 
                
                lock_ObtainMutex(&cm_Freelance_Lock);
-#ifdef DEBUG
-               afsi_log("bufp->offset is %d", bufp->offset);
-#endif
                t1 = bufp->offset.LowPart;
                qdp = biod.bufListEndp;
                while (qdp) {
@@ -1199,9 +1198,6 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up,
                        memset(bufferp, 0, buf_bufferSize);
                        t2 = cm_fakeDirSize - t1;
                        if (t2>buf_bufferSize) t2=buf_bufferSize;
-#ifdef DEBUG
-                       afsi_log("t1:%d, t2:%d", t1, t2);
-#endif
                        if (t2 > 0) {
                                memcpy(bufferp, cm_FakeRootDir+t1, t2);
                        } else {
@@ -1237,7 +1233,7 @@ long cm_GetBuffer(cm_scache_t *scp, cm_buf_t *bufp, int *cpffp, cm_user_t *up,
                                     biod.length);
 
                /* now copy the data out of the pipe and put it in the buffer */
-               temp  = rx_Read(callp, &nbytes, 4);
+               temp  = rx_Read(callp, (char *)&nbytes, 4);
                if (temp == 4) {
                        nbytes = ntohl(nbytes);
             if (nbytes > biod.length) 
index 62ec62e..b3ed545 100644 (file)
@@ -34,6 +34,12 @@ void cm_InitFakeRootDir();
 
 void cm_InitFreelance() {
   
+#ifdef COMMENT
+    while ( !IsDebuggerPresent() ) {
+        Sleep(1000);
+    }
+#endif
+
        lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock");
   
        // yj: first we make a call to cm_initLocalMountPoints
@@ -103,8 +109,6 @@ void cm_InitFakeRootDir() {
        cm_FakeRootDir = malloc(dirSize);
        cm_fakeDirSize = dirSize;
 
-       
-
        // yj: when we get here, we've figured out how much memory we need and 
        // allocated the appropriate space for it. we now prceed to fill
        // it up with entries.
@@ -223,14 +227,12 @@ void cm_InitFakeRootDir() {
        cm_fakeDirCallback=1;
 
        // when we get here, we've set up everything! done!
-
-
 }
 
 int cm_FakeRootFid(cm_fid_t *fidp)
 {
       fidp->cell = 0x1;            /* root cell */
-      fidp->volume = 0x20000001;   /* root.afs ? */
+      fidp->volume = AFS_FAKE_ROOT_VOL_ID;   /* root.afs ? */
       fidp->vnode = 0x1;
       fidp->unique = 0x1;
       return 0;
@@ -261,16 +263,15 @@ int cm_reInitLocalMountPoints() {
        cm_scache_t *scp, **lscpp, *tscp;
 
        
-       printf("\n\n----- reinitialization starts ----- \n");
-
+       osi_Log0(afsd_logp,"----- freelance reinitialization starts ----- ");
 
        // first we invalidate all the SCPs that were created
        // for the local mount points
 
-       printf("Invalidating local mount point scp...  ");
+       osi_Log0(afsd_logp,"Invalidating local mount point scp...  ");
 
        aFid.cell = 0x1;
-       aFid.volume=0x20000001;
+       aFid.volume=AFS_FAKE_ROOT_VOL_ID;
        aFid.unique=0x1;
        aFid.vnode=0x2;
 
@@ -307,33 +308,33 @@ int cm_reInitLocalMountPoints() {
                aFid.vnode = aFid.vnode + 1;
        }
        lock_ReleaseWrite(&cm_scacheLock);
-       printf("\tall old scp cleared!\n");
+       osi_Log0(afsd_logp,"\tall old scp cleared!");
 
        // we must free the memory that was allocated in the prev
        // cm_InitLocalMountPoints call
-       printf("Removing old localmountpoints...  ");
+       osi_Log0(afsd_logp,"Removing old localmountpoints...  ");
        free(cm_localMountPoints);
-       printf("\tall old localmountpoints cleared!\n");
+       osi_Log0(afsd_logp,"\tall old localmountpoints cleared!");
 
        // now re-init the localmountpoints
-       printf("Creating new localmountpoints...  ");
+       osi_Log0(afsd_logp,"Creating new localmountpoints...  ");
        cm_InitLocalMountPoints();
-       printf("\tcreated new set of localmountpoints!\n");
+       osi_Log0(afsd_logp,"\tcreated new set of localmountpoints!");
        
        
        // now we have to free the memory allocated in cm_initfakerootdir
-       printf("Removing old fakedir...  ");
+       osi_Log0(afsd_logp,"Removing old fakedir...  ");
        free(cm_FakeRootDir);
-       printf("\t\told fakedir removed!\n");
+       osi_Log0(afsd_logp,"\t\told fakedir removed!");
 
        // then we re-create that dir
-       printf("Creating new fakedir...  ");
+       osi_Log0(afsd_logp,"Creating new fakedir...  ");
        cm_InitFakeRootDir();
-       printf("\t\tcreated new fakedir!\n");   
+       osi_Log0(afsd_logp,"\t\tcreated new fakedir!");
 
        lock_ReleaseMutex(&cm_Freelance_Lock);
 
-       printf("----- reinit complete -----\n\n");
+       osi_Log0(afsd_logp,"----- freelance reinit complete -----");
        return 0;
 }
 
@@ -365,9 +366,7 @@ long cm_InitLocalMountPoints() {
        }
 
        // we successfully opened the file
-#ifdef DEBUG
-       fprintf(stderr, "opened afs_freelance.ini\n");
-#endif
+       osi_Log0(afsd_logp,"opened afs_freelance.ini");
        
        // now we read the first line to see how many entries
        // there are
@@ -418,14 +417,12 @@ long cm_InitLocalMountPoints() {
                aLocalMountPoint->mountPointStringp=malloc(strlen(line) - (t-line) + 1);
                memcpy(aLocalMountPoint->mountPointStringp, t, strlen(line)-(t-line)-2);
                *(aLocalMountPoint->mountPointStringp + (strlen(line)-(t-line)-2)) = 0;
-#ifdef DEBUG
-               fprintf(stderr, "found mount point: name %s, string %s\n",
+    
+        osi_Log2(afsd_logp,"found mount point: name %s, string %s",
                        aLocalMountPoint->namep,
                        aLocalMountPoint->mountPointStringp);
-#endif
-               
-               aLocalMountPoint++;
 
+        aLocalMountPoint++;
        }
        fclose(fp);
        return 0;
@@ -447,17 +444,25 @@ long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t
     char line[200];
     char fullname[200];
     int n;
+    int alias = 0;
 
     /* before adding, verify the cell name; if it is not a valid cell,
-       don't add the mount point */
+       don't add the mount point.
+       allow partial matches as a means of poor man's alias. */
     /* major performance issue? */
-    if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE))
-      return -1;
-#if 0
-    if (strcmp(cellname, fullname) != 0)   /* no partial matches allowed */
-      return -1;
-#endif
+    osi_Log3(afsd_logp,"Freelance Add Mount request: filename=%s cellname=%s volume=%s",
+              filename, cellname, volume);
+    if (cellname[0] == '.') {
+        if (!cm_GetCell_Gen(&cellname[1], &fullname[1], CM_FLAG_CREATE))
+            return -1;
+        fullname[0]='.';
+    } else {
+        if (!cm_GetCell_Gen(cellname, fullname, CM_FLAG_CREATE))
+            return -1;
+    }
     
+    osi_Log1(afsd_logp,"Freelance Adding Mount for Cell: %s", cellname);
+
     lock_ObtainMutex(&cm_Freelance_Lock);
 
      cm_GetConfigDir(hfile);
@@ -475,13 +480,13 @@ long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t
      fclose(fp);
      lock_ReleaseMutex(&cm_Freelance_Lock);
 
-     /*cm_reInitLocalMountPoints(&vnode);*/
+     /* cm_reInitLocalMountPoints(); */
      if (fidp) {
        fidp->unique = 1;
        fidp->vnode = cm_noLocalMountPoints + 1;   /* vnode value of last mt pt */
      }
      cm_noteLocalMountPointChange();
-     
+    
      return 0;
 }
 
index 63cfae5..9ff028d 100644 (file)
@@ -13,7 +13,10 @@ extern long cm_InitLocalMountPoints();
 extern int cm_getLocalMountPointChange();
 extern int cm_reInitLocalMountPoints();
 extern cm_localMountPoint_t* cm_getLocalMountPoint(int vnode);
+extern void cm_InitFreelance();
+extern long cm_FreelanceRemoveMount(char *toremove);
+extern long cm_FreelanceAddMount(char *filename, char *cellname, char *volume, cm_fid_t *fidp);
 
 #define AFS_FREELANCE_INI "afs_freelance.ini"
-
+#define AFS_FAKE_ROOT_VOL_ID  0x00000001
 #endif // _CM_FREELANCE_H
index 1c3eba0..c2b0c7c 100644 (file)
@@ -1371,6 +1371,7 @@ long cm_IoctlCreateMountPoint(struct smb_ioctl *ioctlp, struct cm_user *userp)
        if (cm_freelanceEnabled && dscp == cm_rootSCachep) {
          /* we are adding the mount point to the root dir., so call
             the freelance code to do the add. */
+         osi_Log0(afsd_logp,"IoctlCreateMountPoint within Freelance root dir");
          code = cm_FreelanceAddMount(leaf, fullCell, volume, NULL);
          return code;
        }
index 2b8eaf7..c934ade 100644 (file)
@@ -238,30 +238,30 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
        cm_req_t *reqp)
 {
        long hash;
-        cm_scache_t *scp;
-        long code;
-        cm_volume_t *volp;
-        cm_cell_t *cellp;
+    cm_scache_t *scp;
+    long code;
+    cm_volume_t *volp;
+    cm_cell_t *cellp;
        char* mp;
        int special; // yj: boolean variable to test if file is on root.afs
        int isRoot;
         
-        hash = CM_SCACHE_HASH(fidp);
+    hash = CM_SCACHE_HASH(fidp);
         
        osi_assert(fidp->cell != 0);
 
        // yj: check if we have the scp, if so, we don't need
        // to do anything else
-        lock_ObtainWrite(&cm_scacheLock);
+    lock_ObtainWrite(&cm_scacheLock);
        for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
                if (cm_FidCmp(fidp, &scp->fid) == 0) {
                        scp->refCount++;
-                        *outScpp = scp;
-                        cm_AdjustLRU(scp);
-                        lock_ReleaseWrite(&cm_scacheLock);
+            *outScpp = scp;
+            cm_AdjustLRU(scp);
+            lock_ReleaseWrite(&cm_scacheLock);
                        return 0;
-                }
         }
+    }
         
        // yj: when we get here, it means we don't have an scp
        // so we need to either load it or fake it, depending
@@ -272,19 +272,20 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
        // because we have to fill in the status stuff 'coz we
        // don't want trybulkstat to fill it in for us
 #ifdef AFS_FREELANCE_CLIENT
-       special = (fidp->cell==0x1 && fidp->volume==0x20000001 && 
+       special = (fidp->cell==0x1 && fidp->volume==AFS_FAKE_ROOT_VOL_ID && 
                           !(fidp->vnode==0x1 && fidp->unique==0x1));
-       isRoot = (fidp->cell==0x1 && fidp->volume==0x20000001 && 
+       isRoot = (fidp->cell==0x1 && fidp->volume==AFS_FAKE_ROOT_VOL_ID && 
                           fidp->vnode==0x1 && fidp->unique==0x1);
        if (cm_freelanceEnabled && isRoot) {
+               osi_Log0(afsd_logp,"cm_getSCache Freelance and isRoot");
           /* freelance: if we are trying to get the root scp for the first
              time, we will just put in a place holder entry. */
-         volp = NULL;
+               volp = NULL;
        }
          
        if (cm_freelanceEnabled && special) {
-         /*afsi_log("cm_getscache: special"); */
-               lock_ObtainMutex(&cm_Freelance_Lock);
+               osi_Log0(afsd_logp,"cm_getSCache Freelance and special");
+           lock_ObtainMutex(&cm_Freelance_Lock);
                mp =(cm_localMountPoints+fidp->vnode-2)->mountPointStringp;
                lock_ReleaseMutex(&cm_Freelance_Lock);
                
@@ -295,7 +296,7 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
                if (scp->dotdotFidp == (cm_fid_t *) NULL)
                        scp->dotdotFidp = (cm_fid_t *) malloc (sizeof(cm_fid_t));
                scp->dotdotFidp->cell=0x1;
-               scp->dotdotFidp->volume=0x20000001;
+               scp->dotdotFidp->volume=AFS_FAKE_ROOT_VOL_ID;
                scp->dotdotFidp->unique=1;
                scp->dotdotFidp->vnode=1;
                scp->flags |= (CM_SCACHEFLAG_PURERO | CM_SCACHEFLAG_RO);
@@ -328,15 +329,17 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
        // end of yj code
 #endif /* AFS_FREELANCE_CLIENT */
 
-        /* otherwise, we need to find the volume */
+    /* otherwise, we need to find the volume */
        if (!cm_freelanceEnabled || !isRoot) {
-         lock_ReleaseWrite(&cm_scacheLock);    /* for perf. reasons */
-         cellp = cm_FindCellByID(fidp->cell);
-         if (!cellp) return CM_ERROR_NOSUCHCELL;
-
-         code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, &volp);
-         if (code) return code;
-          lock_ObtainWrite(&cm_scacheLock);
+        lock_ReleaseWrite(&cm_scacheLock);     /* for perf. reasons */
+        cellp = cm_FindCellByID(fidp->cell);
+        if (!cellp) 
+            return CM_ERROR_NOSUCHCELL;
+
+        code = cm_GetVolumeByID(cellp, fidp->volume, userp, reqp, &volp);
+        if (code) 
+            return code;
+        lock_ObtainWrite(&cm_scacheLock);
        }
         
         /* otherwise, we have the volume, now reverify that the scp doesn't
@@ -345,15 +348,15 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
        for(scp=cm_hashTablep[hash]; scp; scp=scp->nextp) {
                if (cm_FidCmp(fidp, &scp->fid) == 0) {
                        scp->refCount++;
-                        cm_AdjustLRU(scp);
-                        lock_ReleaseWrite(&cm_scacheLock);
-                        cm_PutVolume(volp);
-                        *outScpp = scp;
+            cm_AdjustLRU(scp);
+            lock_ReleaseWrite(&cm_scacheLock);
+            cm_PutVolume(volp);
+            *outScpp = scp;
                        return 0;
-                }
         }
+    }
         
-        /* now, if we don't have the fid, recycle something */
+    /* now, if we don't have the fid, recycle something */
        scp = cm_GetNewSCache();
        osi_assert(!(scp->flags & CM_SCACHEFLAG_INHASH));
        scp->fid = *fidp;
@@ -377,14 +380,13 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
        }
        scp->nextp = cm_hashTablep[hash];
        cm_hashTablep[hash] = scp;
-        scp->flags |= CM_SCACHEFLAG_INHASH;
+    scp->flags |= CM_SCACHEFLAG_INHASH;
        scp->refCount = 1;
-        lock_ReleaseWrite(&cm_scacheLock);
+    lock_ReleaseWrite(&cm_scacheLock);
         
-        /* now we have a held scache entry; just return it */
-        *outScpp = scp;
-        
-        return 0;
+    /* now we have a held scache entry; just return it */
+    *outScpp = scp;
+    return 0;
 }
 
 /* synchronize a fetch, store, read, write, fetch status or store status.
@@ -591,7 +593,7 @@ long cm_SyncOp(cm_scache_t *scp, cm_buf_t *bufp, cm_user_t *up, cm_req_t *reqp,
                        && (!cm_freelanceEnabled || !(!(scp->fid.vnode==0x1 &&
                                                         scp->fid.unique==0x1) &&
                                                         scp->fid.cell==0x1 &&
-                                                        scp->fid.volume==0x20000001))
+                                                        scp->fid.volume==AFS_FAKE_ROOT_VOL_ID))
 #endif /* AFS_FREELANCE_CLIENT */
                    ) {
                        if (!cm_HaveCallback(scp)) {
@@ -798,6 +800,7 @@ void cm_MergeStatus(cm_scache_t *scp, AFSFetchStatus *statusp, AFSVolSync *volp,
        // entries under that directory
 #ifdef AFS_FREELANCE_CLIENT
        if (cm_freelanceEnabled && scp == cm_rootSCachep) {
+               osi_Log0(afsd_logp,"cm_MergeStatus Freelance cm_rootSCachep");
                statusp->InterfaceVersion = 0x1;
                statusp->FileType = 0x2;
                statusp->LinkCount = scp->linkCount;
index ed5f82c..00b90d3 100644 (file)
@@ -1012,6 +1012,7 @@ long cm_Lookup(cm_scache_t *dscp, char *namep, long flags, cm_user_t *userp,
                 return CM_ERROR_NOSUCHFILE;
         }
         else {  /* nonexistent dir on freelance root, so add it */
+                       osi_Log1(afsd_logp,"cm_Lookup adding mount for non-existent directory: %s", namep);
             code = cm_FreelanceAddMount(namep, namep, "root.cell.",
                                        &rock.fid);
             if (code < 0) {   /* add mount point failed, so give up */
@@ -1550,10 +1551,10 @@ long cm_TryBulkProc(cm_scache_t *scp, cm_dirEntry_t *dep, void *rockp,
        // to be bulkstat-ed, instead, we call getSCache directly and under
        // getSCache, it is handled specially.
        if      (cm_freelanceEnabled &&
-           tfid.cell==0x1 && tfid.volume==0x20000001 &&
+           tfid.cell==0x1 && tfid.volume==AFS_FAKE_ROOT_VOL_ID &&
                           !(tfid.vnode==0x1 && tfid.unique==0x1) )
        {
-        osi_Log0(afsd_logp, "cm_TryBulkProc calling cm_GetSCache to avoid BulkStat");
+        osi_Log0(afsd_logp, "cm_TryBulkProc Freelance calls cm_SCache on root.afs mountpoint");
                return cm_GetSCache(&tfid, &tscp, NULL, NULL);
        }
 #endif /* AFS_FREELANCE_CLIENT */