From 4fe975fe4ea15032a7ea65fb467914c2975c0bb9 Mon Sep 17 00:00:00 2001 From: Adam Litke Date: Sun, 20 Dec 2009 13:34:21 +0100 Subject: [PATCH] domMemoryStats: Add public symbol to libvirt API * src/libvirt.c: implement the main entry point * src/libvirt_public.syms: add it to the exported symbols --- src/libvirt.c | 71 +++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 1 + 2 files changed, 72 insertions(+) diff --git a/src/libvirt.c b/src/libvirt.c index 16c851ff3e..1ae2932250 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -4166,6 +4166,77 @@ error: return -1; } +/** + * virDomainMemoryStats: + * @dom: pointer to the domain object + * @stats: nr_stats-sized array of stat structures (returned) + * @nr_stats: number of memory statistics requested + * @flags: unused, always pass 0 + * + * This function provides memory statistics for the domain. + * + * Up to 'nr_stats' elements of 'stats' will be populated with memory statistics + * from the domain. Only statistics supported by the domain, the driver, and + * this version of libvirt will be returned. + * + * Memory Statistics: + * + * VIR_DOMAIN_MEMORY_STAT_SWAP_IN: + * The total amount of data read from swap space (in kb). + * VIR_DOMAIN_MEMORY_STAT_SWAP_OUT: + * The total amount of memory written out to swap space (in kb). + * VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT: + * The number of page faults that required disk IO to service. + * VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT: + * The number of page faults serviced without disk IO. + * VIR_DOMAIN_MEMORY_STAT_UNUSED: + * The amount of memory which is not being used for any purpose (in kb). + * VIR_DOMAIN_MEMORY_STAT_AVAILABLE: + * The total amount of memory available to the domain's OS (in kb). + * + * Returns: The number of stats provided or -1 in case of failure. + */ +int virDomainMemoryStats (virDomainPtr dom, virDomainMemoryStatPtr stats, + unsigned int nr_stats, unsigned int flags) +{ + virConnectPtr conn; + unsigned long nr_stats_ret = 0; + DEBUG("domain=%p, stats=%p, nr_stats=%u", dom, stats, nr_stats); + + if (flags != 0) { + virLibDomainError (dom, VIR_ERR_INVALID_ARG, + _("flags must be zero")); + goto error; + } + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN (dom)) { + virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return -1; + } + if (!stats || nr_stats == 0) + return 0; + + if (nr_stats > VIR_DOMAIN_MEMORY_STAT_NR) + nr_stats = VIR_DOMAIN_MEMORY_STAT_NR; + + conn = dom->conn; + if (conn->driver->domainMemoryStats) { + nr_stats_ret = conn->driver->domainMemoryStats (dom, stats, nr_stats); + if (nr_stats_ret == -1) + goto error; + return nr_stats_ret; + } + + virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + /* Copy to connection error object for back compatability */ + virSetConnError(dom->conn); + return -1; +} + /** * virDomainBlockPeek: * @dom: pointer to the domain object diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 538b4d4efb..0521158a20 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -346,6 +346,7 @@ LIBVIRT_0.7.3 { LIBVIRT_0.7.5 { global: virConnectCompareCPU; + virDomainMemoryStats; } LIBVIRT_0.7.3; # .... define new API here using predicted next version number ....