From: VMware, Inc <> Date: Sat, 28 May 2011 19:38:28 +0000 (-0700) Subject: Internal branch sync. Included in this change: X-Git-Tag: 2011.05.27-420096~58 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1afc5b5c69bd01ce98f8bf710d5ecdf8726dda9a;p=thirdparty%2Fopen-vm-tools.git Internal branch sync. Included in this change: . 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 --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index edc4211e6..68b3d6486 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -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; diff --git a/open-vm-tools/lib/wiper/wiperCommon.c b/open-vm-tools/lib/wiper/wiperCommon.c index cd3c0fb09..88fc95485 100644 --- a/open-vm-tools/lib/wiper/wiperCommon.c +++ b/open-vm-tools/lib/wiper/wiperCommon.c @@ -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); } diff --git a/open-vm-tools/toolbox/toolboxcmd-shrink.c b/open-vm-tools/toolbox/toolboxcmd-shrink.c index bf66cad3b..325cf54df 100644 --- a/open-vm-tools/toolbox/toolboxcmd-shrink.c +++ b/open-vm-tools/toolbox/toolboxcmd-shrink.c @@ -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 [args]\n\n" "Subcommands:\n" - " list: list available mountpoints\n" - " shrink : shrinks a file system at the given mountpoint\n"), + " list: list available locations\n" + " shrink : wipes and shrinks a file system at the given location\n" + " shrinkonly: shrinks all disks\n" + " wipe : wipes a file system at the given location\n"), cmd, progName, cmd); }