mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
nodeinfo: make nodeGetInfo() call nodeGetMemory for memory size
The nodeGetInfo() method currently has its own code for getting memory size in KB, that basically just re-invents what nodeGetMemory already does. Remove it and just call nodeGetMemory, converting its result from bytes to KB, allowing removal of more platform specific conditional code. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
08ea852c25
commit
912813de27
@ -81,33 +81,6 @@ appleFreebsdNodeGetCPUCount(void)
|
|||||||
|
|
||||||
return ncpu;
|
return ncpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VIR_HW_PHYSMEM - the resulting value of HW_PHYSMEM of FreeBSD
|
|
||||||
* is 64 bits while that of Mac OS X is still 32 bits.
|
|
||||||
* Mac OS X provides HW_MEMSIZE for 64 bits version of HW_PHYSMEM
|
|
||||||
* since 10.6.8 (Snow Leopard) at least.
|
|
||||||
*/
|
|
||||||
# ifdef HW_MEMSIZE
|
|
||||||
# define VIR_HW_PHYSMEM HW_MEMSIZE
|
|
||||||
# else
|
|
||||||
# define VIR_HW_PHYSMEM HW_PHYSMEM
|
|
||||||
# endif
|
|
||||||
static int
|
|
||||||
appleFreebsdNodeGetMemorySize(unsigned long *memory)
|
|
||||||
{
|
|
||||||
int mib[2] = { CTL_HW, VIR_HW_PHYSMEM };
|
|
||||||
unsigned long physmem;
|
|
||||||
size_t len = sizeof(physmem);
|
|
||||||
|
|
||||||
if (sysctl(mib, 2, &physmem, &len, NULL, 0) == -1) {
|
|
||||||
virReportSystemError(errno, "%s", _("cannot obtain memory size"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*memory = (unsigned long)(physmem / 1024);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif /* defined(__FreeBSD__) || defined(__APPLE__) */
|
#endif /* defined(__FreeBSD__) || defined(__APPLE__) */
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
#ifdef __FreeBSD__
|
||||||
@ -1192,12 +1165,17 @@ int
|
|||||||
nodeGetInfo(virNodeInfoPtr nodeinfo)
|
nodeGetInfo(virNodeInfoPtr nodeinfo)
|
||||||
{
|
{
|
||||||
virArch hostarch = virArchFromHost();
|
virArch hostarch = virArchFromHost();
|
||||||
|
unsigned long long memorybytes;
|
||||||
|
|
||||||
memset(nodeinfo, 0, sizeof(*nodeinfo));
|
memset(nodeinfo, 0, sizeof(*nodeinfo));
|
||||||
|
|
||||||
if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
|
if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (nodeGetMemory(&memorybytes, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
nodeinfo->memory = memorybytes / 1024;
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -1213,9 +1191,6 @@ nodeGetInfo(virNodeInfoPtr nodeinfo)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Convert to KB. */
|
|
||||||
nodeinfo->memory = physmem_total() / 1024;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FORCE_FCLOSE(cpuinfo);
|
VIR_FORCE_FCLOSE(cpuinfo);
|
||||||
return ret;
|
return ret;
|
||||||
@ -1251,9 +1226,6 @@ nodeGetInfo(virNodeInfoPtr nodeinfo)
|
|||||||
nodeinfo->mhz = cpu_freq / 1000000;
|
nodeinfo->mhz = cpu_freq / 1000000;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (appleFreebsdNodeGetMemorySize(&nodeinfo->memory) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user