]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add disk UUID to GuestDiskInfo
authorOliver Kurth <okurth@vmware.com>
Tue, 19 Feb 2019 20:51:31 +0000 (12:51 -0800)
committerOliver Kurth <okurth@vmware.com>
Tue, 19 Feb 2019 20:51:31 +0000 (12:51 -0800)
Add UUID/Serial number to the GuestDiskInfo.

open-vm-tools/services/plugins/guestInfo/diskInfo.c
open-vm-tools/services/plugins/guestInfo/diskInfoPosix.c
open-vm-tools/services/plugins/guestInfo/guestInfoInt.h
open-vm-tools/services/plugins/guestInfo/guestInfoServer.c

index 21a31ad8a9abdcb21c01847aa26e25cd45306bdf..33515f0bbff2bc6fb7382a1c75e1bc903796207a 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2014-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2014-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
@@ -51,7 +51,7 @@
  */
 
 void
-GuestInfo_FreeDiskInfo(GuestDiskInfo *di)
+GuestInfo_FreeDiskInfo(GuestDiskInfoInt *di)
 {
    if (di) {
       free(di->partitionList);
@@ -71,13 +71,13 @@ GuestInfo_FreeDiskInfo(GuestDiskInfo *di)
  *
  * Uses wiper library to enumerate fixed volumes and lookup utilization data.
  *
- * @return Pointer to a GuestDiskInfo structure on success or NULL on failure.
- *         Caller should free returned pointer with GuestInfoFreeDiskInfo.
+ * @return Pointer to a GuestDiskInfoInt structure on success or NULL on failure.
+ *         Caller should free returned pointer with GuestInfo_FreeDiskInfo.
  *
  ******************************************************************************
  */
 
-GuestDiskInfo *
+GuestDiskInfoInt *
 GuestInfoGetDiskInfoWiper(Bool includeReserved)  // IN
 {
    WiperPartition_List pl;
@@ -87,7 +87,7 @@ GuestInfoGetDiskInfoWiper(Bool includeReserved)  // IN
    uint64 totalBytes = 0;
    unsigned int partNameSize = 0;
    Bool success = FALSE;
-   GuestDiskInfo *di;
+   GuestDiskInfoInt *di;
 
    /* Get partition list. */
    if (!WiperPartition_Open(&pl, FALSE)) {
@@ -102,8 +102,8 @@ GuestInfoGetDiskInfoWiper(Bool includeReserved)  // IN
       WiperPartition *part = DblLnkLst_Container(curr, WiperPartition, link);
 
       if (part->type != PARTITION_UNSUPPORTED) {
-         PPartitionEntry newPartitionList;
-         PPartitionEntry partEntry;
+         PartitionEntryInt *newPartitionList;
+         PartitionEntryInt *partEntry;
          unsigned char *error;
          if (includeReserved) {
             error = WiperSinglePartition_GetSpace(part, NULL,
index 625c9883053cb61f0167337b1092dbaad1685fb6..b9517f87b2ca23667e3f3e6b822662993c516981 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2014-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2014-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
  *
  * Uses wiper library to enumerate fixed volumes and lookup utilization data.
  *
- * @return Pointer to a GuestDiskInfo structure on success or NULL on failure.
- *         Caller should free returned pointer with GuestInfoFreeDiskInfo.
+ * @return Pointer to a GuestDiskInfoInt structure on success or NULL on failure.
+ *         Caller should free returned pointer with GuestInfo_FreeDiskInfo.
  *
  ******************************************************************************
  */
 
-GuestDiskInfo *
+GuestDiskInfoInt *
 GuestInfo_GetDiskInfo(const ToolsAppCtx *ctx)
 {
    gboolean includeReserved;
index 70f4bc1c082d4c631f2be0683361260df09697ac..81cc8faec70510b5f79e77491dec0fe8ca9357d2 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-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
@@ -22,7 +22,7 @@
 /**
  * @file guestInfoInt.h
  *
- * Declares internal functions of the guestInfo plugin.
+ * Declares internal functions and data structures of the guestInfo plugin.
  */
 
 #define G_LOG_DOMAIN "guestinfo"
 #include "nicInfo.h"
 #include "dynbuf.h"
 
+/*
+ * Plugin-specific data structures for the DiskGuestInfo.
+ *
+ * These expand upon the GuestDiskInfo in bora/public/guestInfo.h,
+ * but are not shared and need not maintain any version compatibility.
+ */
+
+typedef struct _PartitionEntryInt {
+   uint64 freeBytes;
+   uint64 totalBytes;
+   char name[PARTITION_NAME_SIZE];
+#ifdef _WIN32
+   /* UUID of the disk, if known.  Currently only Windows */
+   char uuid[PARTITION_NAME_SIZE];
+#endif
+} PartitionEntryInt;
+
+typedef struct _GuestDiskInfoInt {
+   unsigned int numEntries;
+   PartitionEntryInt *partitionList;
+} GuestDiskInfoInt;
+
 extern int guestInfoPollInterval;
 
 Bool
@@ -41,14 +63,14 @@ GuestInfo_ServerReportStats(ToolsAppCtx *ctx,  // IN
 gboolean
 GuestInfo_StatProviderPoll(gpointer data);
 
-GuestDiskInfo *
+GuestDiskInfoInt *
 GuestInfoGetDiskInfoWiper(Bool includeReserved);
 
-GuestDiskInfo *
+GuestDiskInfoInt *
 GuestInfo_GetDiskInfo(const ToolsAppCtx *ctx);
 
 void
-GuestInfo_FreeDiskInfo(GuestDiskInfo *di);
+GuestInfo_FreeDiskInfo(GuestDiskInfoInt *di);
 
 void
 GuestInfo_StatProviderShutdown(void);
index fd90f8ca55ba70ab031d4b2a55950cb47227404b..bc843e25f9ecd08a5c9a590c8c487af0a7b1a0da 100644 (file)
@@ -119,7 +119,7 @@ typedef struct _GuestInfoCache {
    HostinfoDetailedDataHeader  *detailedData;
    NicInfoV3                   *nicInfo;
    NicInfoMethod                method;
-   GuestDiskInfo               *diskInfo;
+   GuestDiskInfoInt            *diskInfo;
    Bool                         diskInfoUseJson;
 } GuestInfoCache;
 
@@ -184,7 +184,7 @@ static Bool SetGuestInfo(ToolsAppCtx *ctx,
                          GuestInfoType key,
                          const char *value);
 static void SendUptime(ToolsAppCtx *ctx);
-static Bool DiskInfoChanged(const GuestDiskInfo *diskInfo);
+static Bool DiskInfoChanged(const GuestDiskInfoInt *diskInfo);
 static void GuestInfoClearCache(void);
 static GuestNicList *NicInfoV3ToV2(const NicInfoV3 *infoV3);
 static void TweakGatherLoops(ToolsAppCtx *ctx,
@@ -533,7 +533,7 @@ GuestInfoGather(gpointer data)
                     // "Host names are limited to 255 bytes"
 #if !defined(USERWORLD)
    gboolean disableQueryDiskInfo;
-   GuestDiskInfo *diskInfo = NULL;
+   GuestDiskInfoInt *diskInfo = NULL;
 #endif
    NicInfoV3 *nicInfo = NULL;
    ToolsAppCtx *ctx = data;
@@ -1196,7 +1196,7 @@ GuestInfoSendNicInfo(ToolsAppCtx *ctx,             // IN
  * RPC
  *
  * @param[in] ctx       Application context.
- * @param[in] pdi       GuestDiskInfo *
+ * @param[in] pdi       GuestDiskInfoInt *
  * @param[in] infoSize  Size of disk info.
  *
  * @retval TRUE  Update sent successfully.
@@ -1207,7 +1207,7 @@ GuestInfoSendNicInfo(ToolsAppCtx *ctx,             // IN
 
 static Bool
 GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
-                        GuestDiskInfo *pdi,           // IN
+                        GuestDiskInfoInt *pdi,        // IN
                         size_t infoSize)              // IN
 {
    DynBuf dynBuffer;
@@ -1233,7 +1233,7 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
    static char jsonSuffix[] = "]}";
    int i;
 
-   // 20 bytes per numbr for ascii representation
+   // 20 bytes per number for ascii representation
    ASSERT_ON_COMPILE(sizeof tmpBuf > sizeof jsonPerDiskFmt +
                      PARTITION_NAME_SIZE + 20 + 20);
 
@@ -1290,7 +1290,7 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
  * format.
  *
  * @param[in] ctx       Application context.
- * @param[in] pdi       GuestDiskInfo *
+ * @param[in] pdiInt    GuestDiskInfoInt *
  * @param[in] infoSize  Size of disk info.
  *
  * @retval TRUE  Update sent successfully.
@@ -1301,7 +1301,7 @@ GuestInfoSendDiskInfoV1(ToolsAppCtx *ctx,             // IN
 
 static Bool
 GuestInfoSendDiskInfoV0(ToolsAppCtx *ctx,             // IN
-                        GuestDiskInfo *pdi,           // IN
+                        GuestDiskInfoInt *pdiInt,     // IN
                         size_t infoSize)              // IN
 {
    /*
@@ -1316,9 +1316,27 @@ GuestInfoSendDiskInfoV0(ToolsAppCtx *ctx,             // IN
    char *reply;
    size_t replyLen;
    Bool status;
+   GuestDiskInfo *pdi;
+   int i;
 
-   ASSERT((pdi->numEntries && pdi->partitionList) ||
-          (!pdi->numEntries && !pdi->partitionList));
+   ASSERT((pdiInt->numEntries && pdiInt->partitionList) ||
+          (!pdiInt->numEntries && !pdiInt->partitionList));
+
+   /*
+    * Build a GuestDiskInfo structure to provide the expected binary
+    * format for the binary RPC, copying out the V0 elements.
+    */
+   pdi = Util_SafeCalloc(1, sizeof *pdi);
+   pdi->numEntries = pdiInt->numEntries;
+   pdi->partitionList = Util_SafeCalloc(pdi->numEntries,
+                                        sizeof *pdi->partitionList);
+   for (i = 0; i < pdi->numEntries; i++) {
+      pdi->partitionList[i].freeBytes = pdiInt->partitionList[i].freeBytes;
+      pdi->partitionList[i].totalBytes = pdiInt->partitionList[i].totalBytes;
+      Str_Strcpy(pdi->partitionList[i].name,
+                 pdiInt->partitionList[i].name,
+                 PARTITION_NAME_SIZE);
+   }
 
    /* partitionCount is a uint8 and cannot be larger than UCHAR_MAX. */
    if (pdi->numEntries > UCHAR_MAX) {
@@ -1372,6 +1390,9 @@ GuestInfoSendDiskInfoV0(ToolsAppCtx *ctx,             // IN
    vm_free(request);
    vm_free(reply);
 
+   vm_free(pdi->partitionList);
+   vm_free(pdi);
+
    return status;
 }
 
@@ -1383,7 +1404,7 @@ GuestInfoSendDiskInfoV0(ToolsAppCtx *ctx,             // IN
  * Push updated Disk info to the VMX.
  *
  * @param[in] ctx       Application context.
- * @param[in] info      GuestDiskInfo *
+ * @param[in] info      GuestDiskInfoInt *
  * @param[in] infoSize  Size of disk info.
  *
  * @retval TRUE  Update sent successfully.
@@ -1394,7 +1415,7 @@ GuestInfoSendDiskInfoV0(ToolsAppCtx *ctx,             // IN
 
 static Bool
 GuestInfoSendDiskInfo(ToolsAppCtx *ctx,             // IN
-                      GuestDiskInfo *info,          // IN
+                      GuestDiskInfoInt *info,       // IN
                       size_t infoSize)              // IN
 {
    if (gInfoCache.diskInfoUseJson &&
@@ -1661,13 +1682,13 @@ GuestInfoFindMacAddress(NicInfoV3 *nicInfo,     // IN/OUT
  */
 
 static Bool
-DiskInfoChanged(const GuestDiskInfo *diskInfo)
+DiskInfoChanged(const GuestDiskInfoInt *diskInfo)
 {
    int index;
    char *name;
    int i;
    int matchedPartition;
-   PGuestDiskInfo cachedDiskInfo;
+   GuestDiskInfoInt *cachedDiskInfo;
 
    cachedDiskInfo = gInfoCache.diskInfo;