SHA256
1
0
forked from pool/libvirt
libvirt/0002-lxc-implement-connectGetAllDomainStats.patch
James Fehlig 061a75b436 Accepting request 959272 from home:jfehlig:branches:Virtualization
- qemu: Fix segmentation fault in qemuDomainUndefineFlags
  823a62ec-qemu-fix-undefine-crash.patch

- Update to libvirt 8.1.0
  - Many incremental improvements and bug fixes, see
    https://libvirt.org/news.html#v8-1-0-2022-03-01
  - Dropped patches:
    3be5ba11-libvirt-guests-install.patch,
    16172741-libvirt-guests-manpage.patch,
    8eb44616-remove-sysconfig-files.patch,
    31e937fb-libxl-save-lock-indicator.patch,
    105dace2-revert-virProcessGetStatInfo.patch,
    e0241f33-libxl-mark-allocated-graphics-ports.patch,
    18ec405a-libxl-release-graphics-ports.patch,
    76deb656-qemu-fix-snapshot-revert.patch,
    454b927d-libxl-fix-dom-restore.patch

OBS-URL: https://build.opensuse.org/request/show/959272
OBS-URL: https://build.opensuse.org/package/show/Virtualization/libvirt?expand=0&rev=925
2022-03-03 17:31:09 +00:00

162 lines
5.0 KiB
Diff

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(+)
Index: libvirt-8.1.0/src/lxc/lxc_driver.c
===================================================================
--- libvirt-8.1.0.orig/src/lxc/lxc_driver.c
+++ libvirt-8.1.0/src/lxc/lxc_driver.c
@@ -74,6 +74,8 @@
#include "netdev_bandwidth_conf.h"
#include "virsocket.h"
#include "virutil.h"
+#include "viralloc.h"
+#include "domain_stats.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -5039,6 +5041,128 @@ lxcDomainHasManagedSaveImage(virDomainPt
return ret;
}
+static int
+lxcDomainGetStatsCpu(virDomainObj *dom,
+ virTypedParamList *params)
+{
+ virLXCDomainObjPrivate *priv = dom->privateData;
+ return virCgroupGetStatsCpu(priv->cgroup, params);
+}
+
+typedef int
+(*lxcDomainGetStatsFunc)(virDomainObj *dom,
+ virTypedParamList *params);
+
+
+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,
+ virDomainObj *dom,
+ unsigned int stats,
+ virDomainStatsRecordPtr *record)
+{
+ g_autofree virDomainStatsRecordPtr tmp = g_new0(virDomainStatsRecord, 1);
+ g_autoptr(virTypedParamList) params = g_new0(virTypedParamList, 1);
+ size_t i;
+
+ for (i = 0; lxcDomainGetStatsWorkers[i].func; i++) {
+ if (stats & lxcDomainGetStatsWorkers[i].stats) {
+ if (lxcDomainGetStatsWorkers[i].func(dom, params) < 0)
+ return -1;
+ }
+ }
+
+ if (!(tmp->dom = virGetDomain(conn, dom->def->name,
+ dom->def->uuid, dom->def->id)))
+ return -1;
+
+ tmp->nparams = virTypedParamListStealParams(params, &tmp->params);
+ *record = g_steal_pointer(&tmp);
+ return 0;
+}
+
+static int
+lxcConnectGetAllDomainStats(virConnectPtr conn,
+ virDomainPtr *doms,
+ unsigned int ndoms,
+ unsigned int stats,
+ virDomainStatsRecordPtr **retStats,
+ unsigned int flags)
+{
+ virLXCDriver *driver = conn->privateData;
+ virDomainObj **vms = NULL;
+ virDomainObj *vm;
+ 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;
+ }
+
+ tmpstats = g_new0(virDomainStatsRecordPtr, nvms + 1);
+
+ 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 = {
@@ -5136,6 +5260,7 @@ static virHypervisorDriver lxcHypervisor
.nodeGetFreePages = lxcNodeGetFreePages, /* 1.2.6 */
.nodeAllocPages = lxcNodeAllocPages, /* 1.2.9 */
.domainHasManagedSaveImage = lxcDomainHasManagedSaveImage, /* 1.2.13 */
+ .connectGetAllDomainStats = lxcConnectGetAllDomainStats, /* 3.11.0 */
};
static virConnectDriver lxcConnectDriver = {