From: Oliver Kurth Date: Tue, 19 Feb 2019 20:51:31 +0000 (-0800) Subject: Add disk UUID to GuestDiskInfo X-Git-Tag: stable-11.0.0~223 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=480dd20016ed0517b31b78735d50ee3630790e07;p=thirdparty%2Fopen-vm-tools.git Add disk UUID to GuestDiskInfo Add UUID/Serial number to the GuestDiskInfo. --- diff --git a/open-vm-tools/services/plugins/guestInfo/diskInfo.c b/open-vm-tools/services/plugins/guestInfo/diskInfo.c index 21a31ad8a..33515f0bb 100644 --- a/open-vm-tools/services/plugins/guestInfo/diskInfo.c +++ b/open-vm-tools/services/plugins/guestInfo/diskInfo.c @@ -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, diff --git a/open-vm-tools/services/plugins/guestInfo/diskInfoPosix.c b/open-vm-tools/services/plugins/guestInfo/diskInfoPosix.c index 625c98830..b9517f87b 100644 --- a/open-vm-tools/services/plugins/guestInfo/diskInfoPosix.c +++ b/open-vm-tools/services/plugins/guestInfo/diskInfoPosix.c @@ -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 @@ -34,13 +34,13 @@ * * 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; diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoInt.h b/open-vm-tools/services/plugins/guestInfo/guestInfoInt.h index 70f4bc1c0..81cc8faec 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoInt.h +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoInt.h @@ -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" @@ -32,6 +32,28 @@ #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); diff --git a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c index fd90f8ca5..bc843e25f 100644 --- a/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c +++ b/open-vm-tools/services/plugins/guestInfo/guestInfoServer.c @@ -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;