]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Emphatically close virtual disk.
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:51 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:51 +0000 (11:23 -0700)
Sometimes I/O stack modules return EBUSY during teardown.
This may be due to an external process opening files at
inopportune moments. The workaround is to retry the affected
operations.

open-vm-tools/lib/file/file.c
open-vm-tools/lib/include/file.h

index 45418dddc29698f1876d361304121c71f81a92fe..1bed237bf3c670f137c8c8aaa91fe284b6b1f576 100644 (file)
@@ -287,6 +287,49 @@ File_UnlinkNoFollow(const char *pathName)  // IN:
 }
 
 
+/*
+ *----------------------------------------------------------------------
+ *
+ * File_UnlinkRetry --
+ *
+ *      Unlink the file, retrying on EBUSY on ESX, up to given timeout.
+ *
+ * Results:
+ *      Return 0 if the unlink is successful. Otherwise, return -1.
+ *
+ * Side effects:
+ *      The file is removed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+File_UnlinkRetry(const char *pathName,       // IN:
+                 uint32 maxWaitTimeMilliSec) // IN:
+{
+   int ret;
+
+   if (vmx86_server) {
+      uint32 const unlinkWait = 300;
+      uint32 waitMilliSec = 0;
+
+      do {
+         ret = FileDeletion(pathName, TRUE);
+         if (ret != EBUSY || waitMilliSec >= maxWaitTimeMilliSec) {
+            break;
+         }
+         Log(LGPFX" %s: %s after %u ms\n", __FUNCTION__, pathName, unlinkWait);
+         Util_Usleep(unlinkWait * 1000);
+         waitMilliSec += unlinkWait;
+      } while (TRUE);
+   } else {
+      ret = FileDeletion(pathName, TRUE);
+   }
+
+   return ret == 0 ? 0 : -1;
+}
+
+
 /*
  *----------------------------------------------------------------------
  *
index aef9932a5db3939237898ce8078ee55e028cd6f8..1a498adee08c563f31b7667f5d17a5eb0b634d3c 100644 (file)
@@ -55,6 +55,7 @@ extern "C" {
 
 #define FILE_SEARCHPATHTOKEN ";"
 
+#define FILE_UNLINK_DEFAULT_WAIT_MS 2000
 
 /*
  * Opaque, platform-specific stucture for supporting the directory walking API.
@@ -151,6 +152,9 @@ int File_UnlinkDelayed(const char *pathName);
 
 int File_UnlinkNoFollow(const char *pathName);
 
+int File_UnlinkRetry(const char *pathName,
+                     uint32 maxWaitTimeMilliSec);
+
 void File_SplitName(const char *pathName,
                     char **volume,
                     char **dir,