]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
hosted file locking: An upper bound on creating the lock directory
authorOliver Kurth <okurth@vmware.com>
Mon, 23 Oct 2017 21:21:19 +0000 (14:21 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 23 Oct 2017 21:21:19 +0000 (14:21 -0700)
There is currently no upper bound on how long we wait to enter a hosted
file lock (create lock directory and the direct entry (the "D")). Fix
this.

open-vm-tools/lib/file/fileLockPrimitive.c

index 3e534a310236f22b8efb76d59f3745294966324b..e58377164ec1a112c4d823c74a830b4f84c8dd17 100644 (file)
@@ -1259,8 +1259,8 @@ FileLockCreateEntryDirectory(const char *lockDir,    // IN:
                              char **memberFilePath,  // OUT:
                              char **memberName)      // OUT:
 {
-   int err = 0;
-   uint32 randomNumber = 0;
+   int err;
+   VmTimeType startTimeMsec;
 
    ASSERT(lockDir != NULL);
 
@@ -1270,10 +1270,13 @@ FileLockCreateEntryDirectory(const char *lockDir,    // IN:
    *memberName = NULL;
 
    /* Fun at the races */
+   startTimeMsec = Hostinfo_SystemTimerMS();
 
    while (TRUE) {
       char *temp;
       FileData fileData;
+      VmTimeType ageMsec;
+      uint32 randomNumber;
 
       err = FileAttributesRobust(lockDir, &fileData);
       if (err == 0) {
@@ -1393,6 +1396,21 @@ FileLockCreateEntryDirectory(const char *lockDir,    // IN:
       *entryFilePath = NULL;
       *memberFilePath = NULL;
       *memberName = NULL;
+
+      /*
+       * If we've been trying to get the locking started for a unacceptable
+       * amount of time, bail. Something is seriously wrong, probably the
+       * file system or networking. Nothing we can do about it.
+       */
+
+      ageMsec = Hostinfo_SystemTimerMS() - startTimeMsec;
+
+      if (ageMsec > FILELOCK_PROGRESS_DEARTH) {
+         Warning(LGPFX" %s lack of progress on '%s'\n", __FUNCTION__, lockDir);
+
+         err = EBUSY;
+         break;
+      }
    }
 
    if (err != 0) {