2018-02-09 17:35:42 +01:00
|
|
|
From 1a2be7098cf5acfd893153abb52b65e69631dcec Mon Sep 17 00:00:00 2001
|
|
|
|
From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= <cbosdonnat@suse.com>
|
|
|
|
Date: Tue, 2 Jan 2018 14:44:39 +0100
|
|
|
|
Subject: [PATCH 2/3] lxc: implement connectGetAllDomainStats
|
|
|
|
|
|
|
|
LXC containers can also provide some statistics. Allow users to fetch
|
|
|
|
them using the existing API.
|
|
|
|
---
|
|
|
|
src/lxc/lxc_driver.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
1 file changed, 138 insertions(+)
|
|
|
|
|
2021-05-18 00:14:02 +02:00
|
|
|
Index: libvirt-7.3.0/src/lxc/lxc_driver.c
|
Accepting request 583090 from home:jfehlig:branches:Virtualization
- Update to libvirt 4.1.0
- Many incremental improvements and bug fixes, see
http://libvirt.org/news.html
- Dropped patches:
72adaf2f-revert-qemu-monitor-error-report.patch,
71d56a39-nodedev-fix-parse-PCI-address.patch,
68eed56b-conf-smbios-oem-strings.patch,
76977061-qemu-smbios-oem-strings.patch,
0c710a37-libxl-resume-lock-on-mig-failure.patch,
759b4d1b-virlog-determine-the-hostname-on-startup-CVE-2018-67.patch,
c2dc6698-fix-deadlock-obtaining-hostname.patch,
c391e07e-libxl-clock-settings.patch,
ef71caea-libxl-memalign.patch,
suse-apparmor-signal.patch
OBS-URL: https://build.opensuse.org/request/show/583090
OBS-URL: https://build.opensuse.org/package/show/Virtualization/libvirt?expand=0&rev=674
2018-03-05 18:46:32 +01:00
|
|
|
===================================================================
|
2021-05-18 00:14:02 +02:00
|
|
|
--- libvirt-7.3.0.orig/src/lxc/lxc_driver.c
|
|
|
|
+++ libvirt-7.3.0/src/lxc/lxc_driver.c
|
2021-01-20 00:09:19 +01:00
|
|
|
@@ -74,6 +74,8 @@
|
2018-02-09 17:35:42 +01:00
|
|
|
#include "netdev_bandwidth_conf.h"
|
2020-03-10 02:55:25 +01:00
|
|
|
#include "virsocket.h"
|
|
|
|
#include "virutil.h"
|
2020-09-03 00:47:08 +02:00
|
|
|
+#include "viralloc.h"
|
2018-02-09 17:35:42 +01:00
|
|
|
+#include "domain_stats.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
|
|
|
|
2021-04-02 05:57:28 +02:00
|
|
|
@@ -5068,6 +5070,128 @@ lxcDomainHasManagedSaveImage(virDomainPt
|
2018-02-09 17:35:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int
|
2021-05-18 00:14:02 +02:00
|
|
|
+lxcDomainGetStatsCpu(virDomainObj *dom,
|
|
|
|
+ virTypedParamList *params)
|
2018-02-09 17:35:42 +01:00
|
|
|
+{
|
2021-05-18 00:14:02 +02:00
|
|
|
+ virLXCDomainObjPrivate *priv = dom->privateData;
|
2019-10-10 19:20:38 +02:00
|
|
|
+ return virCgroupGetStatsCpu(priv->cgroup, params);
|
2018-02-09 17:35:42 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+typedef int
|
2021-05-18 00:14:02 +02:00
|
|
|
+(*lxcDomainGetStatsFunc)(virDomainObj *dom,
|
|
|
|
+ virTypedParamList *params);
|
2019-10-10 19:20:38 +02:00
|
|
|
+
|
2018-02-09 17:35:42 +01:00
|
|
|
+
|
|
|
|
+struct lxcDomainGetStatsWorker {
|
|
|
|
+ lxcDomainGetStatsFunc func;
|
|
|
|
+ unsigned int stats;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static struct lxcDomainGetStatsWorker lxcDomainGetStatsWorkers[] = {
|
|
|
|
+ { virDomainStatsGetState, VIR_DOMAIN_STATS_STATE },
|
|
|
|
+ { lxcDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL },
|
|
|
|
+ { virDomainStatsGetInterface, VIR_DOMAIN_STATS_INTERFACE },
|
|
|
|
+ { NULL, 0 }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static int
|
|
|
|
+lxcDomainGetStats(virConnectPtr conn,
|
2021-05-18 00:14:02 +02:00
|
|
|
+ virDomainObj *dom,
|
2018-02-09 17:35:42 +01:00
|
|
|
+ unsigned int stats,
|
|
|
|
+ virDomainStatsRecordPtr *record)
|
|
|
|
+{
|
2020-07-06 18:35:15 +02:00
|
|
|
+ g_autofree virDomainStatsRecordPtr tmp = g_new0(virDomainStatsRecord, 1);
|
|
|
|
+ g_autoptr(virTypedParamList) params = g_new0(virTypedParamList, 1);
|
2018-02-09 17:35:42 +01:00
|
|
|
+ size_t i;
|
|
|
|
+
|
|
|
|
+ for (i = 0; lxcDomainGetStatsWorkers[i].func; i++) {
|
|
|
|
+ if (stats & lxcDomainGetStatsWorkers[i].stats) {
|
2019-10-10 19:20:38 +02:00
|
|
|
+ if (lxcDomainGetStatsWorkers[i].func(dom, params) < 0)
|
|
|
|
+ return -1;
|
2018-02-09 17:35:42 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!(tmp->dom = virGetDomain(conn, dom->def->name,
|
|
|
|
+ dom->def->uuid, dom->def->id)))
|
2019-10-10 19:20:38 +02:00
|
|
|
+ return -1;
|
2018-02-09 17:35:42 +01:00
|
|
|
+
|
2019-10-10 19:20:38 +02:00
|
|
|
+ tmp->nparams = virTypedParamListStealParams(params, &tmp->params);
|
2019-11-06 16:48:56 +01:00
|
|
|
+ *record = g_steal_pointer(&tmp);
|
2019-10-10 19:20:38 +02:00
|
|
|
+ return 0;
|
2018-02-09 17:35:42 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static int
|
|
|
|
+lxcConnectGetAllDomainStats(virConnectPtr conn,
|
|
|
|
+ virDomainPtr *doms,
|
|
|
|
+ unsigned int ndoms,
|
|
|
|
+ unsigned int stats,
|
|
|
|
+ virDomainStatsRecordPtr **retStats,
|
|
|
|
+ unsigned int flags)
|
|
|
|
+{
|
2021-05-18 00:14:02 +02:00
|
|
|
+ virLXCDriver *driver = conn->privateData;
|
|
|
|
+ virDomainObj **vms = NULL;
|
|
|
|
+ virDomainObj *vm;
|
2018-02-09 17:35:42 +01:00
|
|
|
+ size_t nvms;
|
|
|
|
+ virDomainStatsRecordPtr *tmpstats = NULL;
|
|
|
|
+ int nstats = 0;
|
|
|
|
+ size_t i;
|
|
|
|
+ int ret = -1;
|
|
|
|
+ unsigned int lflags = flags & (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE |
|
|
|
|
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
|
|
|
|
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE);
|
|
|
|
+
|
|
|
|
+ virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE |
|
|
|
|
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT |
|
|
|
|
+ VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE, -1);
|
|
|
|
+
|
|
|
|
+ if (virConnectGetAllDomainStatsEnsureACL(conn) < 0)
|
|
|
|
+ return -1;
|
|
|
|
+
|
|
|
|
+ /* TODO Check stats support */
|
|
|
|
+
|
|
|
|
+ if (ndoms) {
|
|
|
|
+ if (virDomainObjListConvert(driver->domains, conn, doms, ndoms, &vms,
|
|
|
|
+ &nvms, virConnectGetAllDomainStatsCheckACL,
|
|
|
|
+ lflags, true) < 0)
|
|
|
|
+ return -1;
|
|
|
|
+ } else {
|
|
|
|
+ if (virDomainObjListCollect(driver->domains, conn, &vms, &nvms,
|
|
|
|
+ virConnectGetAllDomainStatsCheckACL,
|
|
|
|
+ lflags) < 0)
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
2020-11-02 23:08:38 +01:00
|
|
|
+ tmpstats = g_new0(virDomainStatsRecordPtr, nvms + 1);
|
2018-02-09 17:35:42 +01:00
|
|
|
+
|
|
|
|
+ for (i = 0; i < nvms; i++) {
|
|
|
|
+ virDomainStatsRecordPtr tmp = NULL;
|
|
|
|
+ vm = vms[i];
|
|
|
|
+
|
|
|
|
+ virObjectLock(vm);
|
|
|
|
+
|
|
|
|
+ if (lxcDomainGetStats(conn, vm, stats, &tmp) < 0) {
|
|
|
|
+ virObjectUnlock(vm);
|
|
|
|
+ goto cleanup;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (tmp)
|
|
|
|
+ tmpstats[nstats++] = tmp;
|
|
|
|
+
|
|
|
|
+ virObjectUnlock(vm);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ *retStats = tmpstats;
|
|
|
|
+ tmpstats = NULL;
|
|
|
|
+
|
|
|
|
+ ret = nstats;
|
|
|
|
+
|
|
|
|
+ cleanup:
|
|
|
|
+ virDomainStatsRecordListFree(tmpstats);
|
|
|
|
+ virObjectListFreeCount(vms, nvms);
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
|
|
|
|
/* Function Tables */
|
|
|
|
static virHypervisorDriver lxcHypervisorDriver = {
|
2021-04-02 05:57:28 +02:00
|
|
|
@@ -5165,6 +5289,7 @@ static virHypervisorDriver lxcHypervisor
|
2018-02-09 17:35:42 +01:00
|
|
|
.nodeGetFreePages = lxcNodeGetFreePages, /* 1.2.6 */
|
|
|
|
.nodeAllocPages = lxcNodeAllocPages, /* 1.2.9 */
|
|
|
|
.domainHasManagedSaveImage = lxcDomainHasManagedSaveImage, /* 1.2.13 */
|
|
|
|
+ .connectGetAllDomainStats = lxcConnectGetAllDomainStats, /* 3.11.0 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static virConnectDriver lxcConnectDriver = {
|