From: Oliver Kurth Date: Tue, 19 Feb 2019 20:51:30 +0000 (-0800) Subject: [Part 2] GuestLib support for 64bit memory shares. X-Git-Tag: stable-11.0.0~233 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6143662e1b1e89671c4b4812bdbed76d12cff14e;p=thirdparty%2Fopen-vm-tools.git [Part 2] GuestLib support for 64bit memory shares. MEMSCHED_SHARES_MAX is currently set to MAX_PPN and will not fit in 32-bit soon. 'memshares' property which is currently available in GuestSDK is an unsigned 32bit value. Starting from ESX 7.0, this value is available only if it can be fit in an unsigned 32-bit data type. 'memShares64' is the new unsigned 64-bit property added in GuestSDK for the memory shares. Added necessary APIs to retrieve the memshares64 value. The new API VMGuestLib_GetMemShares64 will first try to retrieve the memShares64 property. If the underlying host is an older one, then the API will return the memShares property. Updated the vmGuestLibTest code to retrieve and print the new memShares64 value. --- diff --git a/open-vm-tools/lib/include/vmGuestLib.h b/open-vm-tools/lib/include/vmGuestLib.h index b83f43cda..80061084f 100644 --- a/open-vm-tools/lib/include/vmGuestLib.h +++ b/open-vm-tools/lib/include/vmGuestLib.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2003-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2003-2016,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 @@ -267,10 +267,19 @@ VMGuestLibError VMGuestLib_GetMemLimitMB(VMGuestLibHandle handle, // IN /* * Retrieves the number of memory shares allocated to the virtual machine. + * This API returns an error if the memory shares exceeds the maximum + * value of 32-bit unsigned integer (0xFFFFFFFF). Therefore, + * VMGuestLib_GetMemShares64 API should be used instead of this API. */ VMGuestLibError VMGuestLib_GetMemShares(VMGuestLibHandle handle, // IN uint32 *memShares); // OUT +/* + * Retrieves the number of memory shares allocated to the virtual machine. + */ +VMGuestLibError VMGuestLib_GetMemShares64(VMGuestLibHandle handle, // IN + uint64 *memShares64); // OUT + /* * Retrieves the mapped memory size of this virtual machine. This * is the current total amount of guest memory that is backed by diff --git a/open-vm-tools/libguestlib/vmGuestLib.c b/open-vm-tools/libguestlib/vmGuestLib.c index 544e0fa4b..f3d485216 100644 --- a/open-vm-tools/libguestlib/vmGuestLib.c +++ b/open-vm-tools/libguestlib/vmGuestLib.c @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 2005-2016 VMware, Inc. All rights reserved. + * Copyright (C) 2005-2016,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 @@ -1761,6 +1761,48 @@ VMGuestLib_GetMemBalloonMaxMB(VMGuestLibHandle handle, // IN } +/* + *----------------------------------------------------------------------------- + * + * VMGuestLib_GetMemShares64 -- + * + * Retrieve memory shares. + * + * Results: + * VMGuestLibError + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +VMGuestLibError +VMGuestLib_GetMemShares64(VMGuestLibHandle handle, // IN + uint64 *memShares64) // OUT +{ + VMGuestLibError error = VMGUESTLIB_ERROR_OTHER; + VMGUESTLIB_GETSTAT_V3(handle, error, + memShares64, memShares64, + GUESTLIB_MEM_SHARES_64); + if (VMGUESTLIB_ERROR_UNSUPPORTED_VERSION == error) { + /* + * GUESTLIB_MEM_SHARES_64 is available only from ESX 7.0. + * If the host is older, then return the value of GUESTLIB_MEM_SHARES. + */ + uint32 memShares = 0; + if (VMGUESTLIB_ERROR_SUCCESS != + VMGuestLib_GetMemShares(handle, &memShares)) { + return error; + } else { + *memShares64 = memShares; + return VMGUESTLIB_ERROR_SUCCESS; + } + } + return error; +} + + /* *----------------------------------------------------------------------------- *