]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Query disks for UUID
authorOliver Kurth <okurth@vmware.com>
Thu, 28 Mar 2019 19:43:00 +0000 (12:43 -0700)
committerOliver Kurth <okurth@vmware.com>
Thu, 28 Mar 2019 19:43:00 +0000 (12:43 -0700)
As part of identifying a guest disk so it can be associated with a vmdk,
query its serial number, which is the same as the vmdk's ddb.uuid

open-vm-tools/lib/include/conf.h
open-vm-tools/services/plugins/guestInfo/guestInfoInt.h
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c

index 6d33f40871a2871194d0d9354c887b43fe9e3c60..2c30978f667ad0dd24c10e40d044967a52675abb 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2002-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2002-2019 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
  */
 #define CONFNAME_DISKINFO_INCLUDERESERVED "diskinfo-include-reserved"
 
+/**
+ * Report UUID of disks for vmdk mapping via vim.
+ *
+ * @param boolean Set to true to report UUID to VMX.
+ */
+#define CONFNAME_DISKINFO_REPORT_UUID  "diskinfo-report-uuid"
+
 /*
  * END GuestInfo goodies.
  ******************************************************************************
index 81cc8faec70510b5f79e77491dec0fe8ca9357d2..068e48244f99b6976528bbbf2c447d4c11a03a26 100644 (file)
@@ -32,6 +32,9 @@
 #include "nicInfo.h"
 #include "dynbuf.h"
 
+/* Default for whether to query and report disk UUIDs */
+#define  CONFIG_GUESTINFO_REPORT_UUID_DEFAULT  FALSE
+
 /*
  * Plugin-specific data structures for the DiskGuestInfo.
  *
index bc843e25f9ecd08a5c9a590c8c487af0a7b1a0da..92320b1d788ee458e1abbe228d2a207ec2b66362 100644 (file)
@@ -1217,6 +1217,13 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
    char *reply = NULL;
    size_t replyLen;
    Bool status;
+#ifdef _WIN32
+   Bool reportUUID = VMTools_ConfigGetBoolean(ctx->config,
+                                              CONFGROUPNAME_GUESTINFO,
+                                              CONFNAME_DISKINFO_REPORT_UUID,
+                                              CONFIG_GUESTINFO_REPORT_UUID_DEFAULT);
+#endif
+
    /*
     * Currently this format is fixed; the order should not be changed.
     * If a change is required, then DISK_INFO_VERSION must be bumped.
@@ -1229,13 +1236,18 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
    static char jsonPerDiskFmt[] = "{"
                                   "\"name\":\"%s\","
                                   "\"free\":\"%"FMT64"u\","
-                                  "\"size\":\"%"FMT64"u\"},\n";
+                                  "\"size\":\"%"FMT64"u\"";
+#ifdef _WIN32
+   static char jsonPerDiskUUIDFmt[] = ",\"uuid\":\"%s\"";
+#endif
+   static char jsonPerDiskFmtFooter[] = "},\n";
    static char jsonSuffix[] = "]}";
    int i;
 
    // 20 bytes per number for ascii representation
+   // PARTITION_NAME_SIZE * 2 for name and (optional) uuid
    ASSERT_ON_COMPILE(sizeof tmpBuf > sizeof jsonPerDiskFmt +
-                     PARTITION_NAME_SIZE + 20 + 20);
+                     PARTITION_NAME_SIZE * 2 + 20 + 20);
 
    DynBuf_Init(&dynBuffer);
 
@@ -1243,13 +1255,33 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
                       GUEST_DISK_INFO_COMMAND, DISK_INFO_VERSION_1);
    DynBuf_Append(&dynBuffer, tmpBuf, len);
    for (i = 0; i < pdi->numEntries; i++) {
+      /*
+       * The '\' in Windows drive names needs escaping for json,
+       * so use base64 since its simple and will cover other weird
+       * cases like quotes, as well as avoid any utf-8 concerns.
+       */
+      gchar *b64name = g_base64_encode(pdi->partitionList[i].name,
+                                       strlen(pdi->partitionList[i].name));
+
       len = Str_Snprintf(tmpBuf, sizeof tmpBuf, jsonPerDiskFmt,
-                         pdi->partitionList[i].name,
+                         b64name,
                          pdi->partitionList[i].freeBytes,
                          pdi->partitionList[i].totalBytes);
       DynBuf_Append(&dynBuffer, tmpBuf, len);
+      g_free(b64name);
+#ifdef _WIN32
+      if (reportUUID) {
+         if (pdi->partitionList[i].uuid[0] != '\0') {
+            len = Str_Snprintf(tmpBuf, sizeof tmpBuf, jsonPerDiskUUIDFmt,
+                               pdi->partitionList[i].uuid);
+            DynBuf_Append(&dynBuffer, tmpBuf, len);
+         }
+      }
+#endif
+      DynBuf_Append(&dynBuffer, jsonPerDiskFmtFooter,
+                    sizeof jsonPerDiskFmtFooter - 1);
    }
-   DynBuf_Append(&dynBuffer, jsonSuffix, sizeof jsonSuffix);
+   DynBuf_Append(&dynBuffer, jsonSuffix, sizeof jsonSuffix - 1);
 
    infoReq = DynBuf_GetString(&dynBuffer);