Windows: drop cm_Freelance_Lock before call to cm_FreelanceAddMount
authorJeffrey Altman <jaltman@your-file-system.com>
Tue, 26 Jan 2010 15:23:03 +0000 (10:23 -0500)
committerJeffrey Altman <jaltman|account-1000011@unknown>
Thu, 28 Jan 2010 01:30:59 +0000 (17:30 -0800)
The cm_Freelance_Lock must not be held before calling
cm_FreelanceAddMount().  cm_InitLocalMountPoints() was violating
this requirement.   It is safe to drop the lock because the only
time the lock would be dropped is if the "Freelance" registry
key does not exist.  This should only be true during the initial
startup of the application the first time afsd_service.exe
executes on the machine.   At this point in time there is only
one thread that is executing that could be initializing the
Freelance mount point list.

LICENSE MIT

Change-Id: Ib49cf8bc830836c8e08446073e64ccf30086d354
Reviewed-on: http://gerrit.openafs.org/1164
Reviewed-by: Asanka Herath <asanka@secure-endpoints.com>
Tested-by: Asanka Herath <asanka@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/afsd/cm_freelance.c

index b117bc7..bef54ed 100644 (file)
@@ -141,6 +141,7 @@ void cm_InitFreelance() {
 
     lock_InitializeMutex(&cm_Freelance_Lock, "Freelance Lock", LOCK_HIERARCHY_FREELANCE_GLOBAL);
 
+    lock_ObtainMutex(&cm_Freelance_Lock);
     // yj: first we make a call to cm_initLocalMountPoints
     // to read all the local mount points from the registry
     cm_InitLocalMountPoints();
@@ -149,6 +150,7 @@ void cm_InitFreelance() {
     // a fake root directory based on the local mount points
     cm_InitFakeRootDir();
     // --- end of yj code
+    lock_ReleaseMutex(&cm_Freelance_Lock);
 
     /* Start the registry monitor */
     phandle = thrd_Create(NULL, 65536, (ThreadFunc) cm_FreelanceChangeNotifier,
@@ -163,7 +165,7 @@ void cm_InitFreelance() {
 }
 
 /* yj: Initialization of the fake root directory */
-/* to be called while holding freelance lock unless during init. */
+/* to be called while holding freelance lock. */
 void cm_InitFakeRootDir() {
     int i, t1, t2;
     char* currentPos;
@@ -453,7 +455,7 @@ int cm_reInitLocalMountPoints() {
 // yj: open up the registry and read all the local mount 
 // points that are stored there. Part of the initialization
 // process for the freelance client.
-/* to be called while holding freelance lock unless during init. */
+/* to be called while holding freelance lock. */
 long cm_InitLocalMountPoints() {
     FILE *fp;
     int i;
@@ -496,9 +498,11 @@ long cm_InitLocalMountPoints() {
             rootCellName[0] = '.';
             code = cm_GetRootCellName(&rootCellName[1]);
             if (code == 0) {
+                lock_ReleaseMutex(&cm_Freelance_Lock);
                 cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell.", 0, NULL);
                 cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell.", 1, NULL);
                 cm_FreelanceAddMount(".root", &rootCellName[1], "root.afs.", 1, NULL);
+                lock_ObtainMutex(&cm_Freelance_Lock);
                 dwMountPoints = 3;
             }
         }
@@ -693,9 +697,11 @@ long cm_InitLocalMountPoints() {
         rootCellName[0] = '.';
        code = cm_GetRootCellName(&rootCellName[1]);
         if (code == 0) {
+            lock_ReleaseMutex(&cm_Freelance_Lock);
             cm_FreelanceAddMount(&rootCellName[1], &rootCellName[1], "root.cell.", 0, NULL);
             cm_FreelanceAddMount(rootCellName, &rootCellName[1], "root.cell.", 1, NULL);
             cm_FreelanceAddMount(".root", &rootCellName[1], "root.afs.", 1, NULL);
+            lock_ObtainMutex(&cm_Freelance_Lock);
         }
         return 0;
     }