]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Internal branch sync. Included in this change:
authorVMware, Inc <>
Sat, 28 May 2011 19:38:28 +0000 (12:38 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Sat, 28 May 2011 19:38:28 +0000 (12:38 -0700)
. Split the disk shrink toolbox command workflow into 2 separate steps,
  one for wiping the disk and another for performing the disk shrink
  operation only.

. changes in shared code that don't affect open-vm-tools functionality.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/misc/hostinfoPosix.c
open-vm-tools/lib/wiper/wiperCommon.c
open-vm-tools/toolbox/toolboxcmd-shrink.c

index edc4211e603bdbc54bfed5205fced87387780220..68b3d6486a1cedbaf3dc4ae86ee3a327ec334d33 100644 (file)
@@ -633,7 +633,7 @@ HostinfoReadDistroFile(char *filename,  // IN: distro version file name
                        int distroSize,  // IN: size of OS distro name buffer
                        char *distro)    // OUT: full distro name
 {
-   int fd;
+   int fd = -1;
    int buf_sz;
    struct stat st;
    Bool ret = FALSE;
@@ -642,10 +642,8 @@ HostinfoReadDistroFile(char *filename,  // IN: distro version file name
    char *tmpDistroPos = NULL;
    int i = 0;
 
-   if ((fd = open(filename, O_RDONLY)) < 0) {
-      Warning("%s: could not open file%s: %d\n", __FUNCTION__, filename,
-              errno);
-
+   /* It's OK for the file to not exist, don't warn for this.  */
+   if ((fd = Posix_Open(filename, O_RDONLY)) == -1) {
       return FALSE;
    }
 
@@ -669,9 +667,7 @@ HostinfoReadDistroFile(char *filename,  // IN: distro version file name
 
    if (distroOrig == NULL) {
       Warning("%s: could not allocate memory\n", __FUNCTION__);
-      close(fd);
-
-      return FALSE;
+      goto out;
    }
 
    if (read(fd, distroOrig, buf_sz) != buf_sz) {
@@ -718,7 +714,9 @@ HostinfoReadDistroFile(char *filename,  // IN: distro version file name
    ret = TRUE;
 
 out:
-   close(fd);
+   if (fd != -1) {
+      close(fd);
+   }
    free(distroOrig);
 
    return ret;
index cd3c0fb0949aad02e7a948ca2d1d665e4181bfac..88fc95485ae0555f0698e9c0c5e1359ff2512ee1 100644 (file)
@@ -55,7 +55,7 @@ WiperSinglePartition_Allocate(void)
       memset(p->mountPoint, 0, sizeof p->mountPoint);
       p->type = PARTITION_UNSUPPORTED;
       p->comment = NULL;
-      p->attemptUnmaps = FALSE;
+      p->attemptUnmaps = TRUE;
       DblLnkLst_Init(&p->link);
    }
 
index bf66cad3b6281b3bf1c3a11da2c8c55b10b9b0ad..325cf54df22ffcccbea6a8ba539a7da4180ace52 100644 (file)
@@ -189,10 +189,89 @@ ShrinkList(void)
 /*
  *-----------------------------------------------------------------------------
  *
- * ShrinkDoShrink  --
+ * ShrinkDiskSendRPC  --
+ *
+ *      Shrink all shrinkable disks/partitions, returning only when the shrink
+ *      RPC operation is done or canceled.
+ *
+ * Results:
+ *      EXIT_SUCCESS on success.
+ *      EX_TEMPFAIL on failure.
+ *
+ * Side effects:
+ *      Prints to stderr on errors.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static int
+ShrinkDiskSendRPC(void)
+{
+   char *result;
+   size_t resultLen;
+
+   ToolsCmd_PrintErr("\n");
+
+   if (ToolsCmd_SendRPC(DISK_SHRINK_CMD, sizeof DISK_SHRINK_CMD - 1,
+                        &result, &resultLen)) {
+      ToolsCmd_Print("%s",
+                     SU_(disk.shrink.complete, "Disk shrinking complete.\n"));
+      return EXIT_SUCCESS;
+   }
+
+   ToolsCmd_PrintErr(SU_(disk.shrink.error, "Error while shrinking: %s\n"), result);
+   return EX_TEMPFAIL;
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ShrinkDoAllDiskShrinkOnly  --
+ *
+ *      Shrink all shrinkable disks/partitions if it is enabled. Layered around
+ *      ShrinkDoAllDiskShrinkCommon. This routine does not invoke the disk wipe
+ *      operation step.
+ *
+ * Results:
+ *      EXIT_SUCCESS on success.
+ *      EX_TEMPFAIL on failure.
+ *
+ * Side effects:
+ *      Prints to stderr on errors.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+static int
+ShrinkDoAllDiskShrinkOnly(void)
+{
+#ifndef _WIN32
+   signal(SIGINT, ShrinkWiperDestroy);
+#endif
+
+   /*
+    * Verify that shrinking is permitted.
+    */
+   if (!GuestApp_IsDiskShrinkEnabled()) {
+      ToolsCmd_PrintErr("%s",
+                        SU_(disk.shrink.conflict, SHRINK_CONFLICT_ERR));
+      return EX_TEMPFAIL;
+   }
+
+   return ShrinkDiskSendRPC();
+}
+
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * ShrinkDoWipeAndShrink  --
  *
  *      Wipe a single partition, returning only when the wiper
  *      operation is done or canceled.
+ *      Caller can optionally indicate whether a disk shrink operation is required
+ *      to be performed after the wipe operation or not.
  *
  * Results:
  *      EXIT_SUCCESS on success.
@@ -207,8 +286,9 @@ ShrinkList(void)
  */
 
 static int
-ShrinkDoShrink(char *mountPoint, // IN: mount point
-               gboolean quiet)   // IN: verbosity flag
+ShrinkDoWipeAndShrink(char *mountPoint,         // IN: mount point
+                      gboolean quiet,           // IN: verbosity flag
+                      gboolean performShrink)   // IN: perform a shrink operation
 {
    int i;
    int progress = 0;
@@ -274,26 +354,15 @@ ShrinkDoShrink(char *mountPoint, // IN: mount point
       }
    }
 
-   if (progress >= 100) {
-      char *result;
-      size_t resultLen;
-
-      ToolsCmd_PrintErr("\n");
-
-      if (ToolsCmd_SendRPC(DISK_SHRINK_CMD, sizeof DISK_SHRINK_CMD - 1,
-                           &result, &resultLen)) {
-         ToolsCmd_Print("%s",
-                        SU_(disk.shrink.complete, "Disk shrinking complete.\n"));
-         rc = EXIT_SUCCESS;
-         goto out;
-      }
-
-      ToolsCmd_PrintErr(SU_(disk.shrink.error, "Error while shrinking: %s\n"), result);
+   rc = EX_TEMPFAIL;
+   if (progress >= 100 && performShrink) {
+      rc = ShrinkDiskSendRPC();
    }
 
-   ToolsCmd_PrintErr("%s",
-                     SU_(disk.shrink.incomplete, "Shrinking not completed.\n"));
-   rc = EX_TEMPFAIL;
+   if (rc != EXIT_SUCCESS) {
+      ToolsCmd_PrintErr("%s",
+                        SU_(disk.shrink.incomplete, "Shrinking not completed.\n"));
+   }
 
 out:
    WiperSinglePartition_Close(part);
@@ -362,8 +431,18 @@ Disk_Command(char **argv,      // IN: command line arguments
       if (++optind >= argc) {
          ToolsCmd_MissingEntityError(argv[0], SU_(arg.mountpoint, "mount point"));
       } else {
-         return ShrinkDoShrink(argv[optind], quiet);
+         return ShrinkDoWipeAndShrink(argv[optind], quiet,
+                                      TRUE /* perform shrink */);
+      }
+   } else if (toolbox_strcmp(argv[optind], "wipe") == 0) {
+      if (++optind >= argc) {
+         ToolsCmd_MissingEntityError(argv[0], SU_(arg.mountpoint, "mount point"));
+      } else {
+         return ShrinkDoWipeAndShrink(argv[optind], quiet,
+                                      FALSE /* do not perform shrink */);
       }
+   } else if (toolbox_strcmp(argv[optind], "shrinkonly") == 0) {
+      return ShrinkDoAllDiskShrinkOnly();
    } else {
       ToolsCmd_UnknownEntityError(argv[0],
                                   SU_(arg.subcommand, "subcommand"),
@@ -396,8 +475,10 @@ Disk_Help(const char *progName, // IN: The name of the program obtained from arg
    g_print(SU_(help.disk, "%s: perform disk shrink operations\n"
                           "Usage: %s %s <subcommand> [args]\n\n"
                           "Subcommands:\n"
-                          "   list: list available mountpoints\n"
-                          "   shrink <mount-point>: shrinks a file system at the given mountpoint\n"),
+                          "   list: list available locations\n"
+                          "   shrink <location>: wipes and shrinks a file system at the given location\n"
+                          "   shrinkonly: shrinks all disks\n"
+                          "   wipe <location>: wipes a file system at the given location\n"),
            cmd, progName, cmd);
 }