render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Pablo Greco 40546a
From 2396295b2654156d62165bc1d94e2a3f4d1e4733 Mon Sep 17 00:00:00 2001
Pablo Greco 40546a
Message-Id: <2396295b2654156d62165bc1d94e2a3f4d1e4733@dist-git>
Pablo Greco 40546a
From: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Date: Mon, 1 Jul 2019 17:06:21 +0200
Pablo Greco 40546a
Subject: [PATCH] util: introduce vircgroupbackend files
Pablo Greco 40546a
MIME-Version: 1.0
Pablo Greco 40546a
Content-Type: text/plain; charset=UTF-8
Pablo Greco 40546a
Content-Transfer-Encoding: 8bit
Pablo Greco 40546a
Pablo Greco 40546a
We will need to extract current cgroup v1 implementation into separate
Pablo Greco 40546a
backend because there will be new cgroup v2 implementation and both will
Pablo Greco 40546a
have to co-exist.
Pablo Greco 40546a
Pablo Greco 40546a
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
(cherry picked from commit 1a2dbb5595871efa8de1ed258d94f0b60561a040)
Pablo Greco 40546a
Pablo Greco 40546a
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Pablo Greco 40546a
Pablo Greco 40546a
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Pablo Greco 40546a
Message-Id: <dbe1f56fc1ba95c077092303b1f17b67e8f9075a.1561993100.git.phrdina@redhat.com>
Pablo Greco 40546a
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Pablo Greco 40546a
---
Pablo Greco 40546a
 src/Makefile.am             |  1 +
Pablo Greco 40546a
 src/libvirt_private.syms    |  3 ++
Pablo Greco 40546a
 src/util/Makefile.inc.am    |  2 ++
Pablo Greco 40546a
 src/util/vircgroupbackend.c | 64 +++++++++++++++++++++++++++++++++++++
Pablo Greco 40546a
 src/util/vircgroupbackend.h | 46 ++++++++++++++++++++++++++
Pablo Greco 40546a
 5 files changed, 116 insertions(+)
Pablo Greco 40546a
 create mode 100644 src/util/vircgroupbackend.c
Pablo Greco 40546a
 create mode 100644 src/util/vircgroupbackend.h
Pablo Greco 40546a
Pablo Greco 40546a
diff --git a/src/Makefile.am b/src/Makefile.am
Pablo Greco 40546a
index db8c8ebd1a..c4e797f5a2 100644
Pablo Greco 40546a
--- a/src/Makefile.am
Pablo Greco 40546a
+++ b/src/Makefile.am
Pablo Greco 40546a
@@ -678,6 +678,7 @@ libvirt_setuid_rpc_client_la_SOURCES = \
Pablo Greco 40546a
 		util/virbitmap.c \
Pablo Greco 40546a
 		util/virbuffer.c \
Pablo Greco 40546a
 		util/vircgroup.c \
Pablo Greco 40546a
+		util/vircgroupbackend.c \
Pablo Greco 40546a
 		util/vircommand.c \
Pablo Greco 40546a
 		util/virconf.c \
Pablo Greco 40546a
 		util/virdbus.c \
Pablo Greco 40546a
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
Pablo Greco 40546a
index 8c4be84fd5..627eb5e587 100644
Pablo Greco 40546a
--- a/src/libvirt_private.syms
Pablo Greco 40546a
+++ b/src/libvirt_private.syms
Pablo Greco 40546a
@@ -1591,6 +1591,9 @@ virCgroupSetOwner;
Pablo Greco 40546a
 virCgroupSupportsCpuBW;
Pablo Greco 40546a
 virCgroupTerminateMachine;
Pablo Greco 40546a
 
Pablo Greco 40546a
+# util/vircgroupbackend.h
Pablo Greco 40546a
+virCgroupBackendGetAll;
Pablo Greco 40546a
+virCgroupBackendRegister;
Pablo Greco 40546a
 
Pablo Greco 40546a
 # util/virclosecallbacks.h
Pablo Greco 40546a
 virCloseCallbacksGet;
Pablo Greco 40546a
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
Pablo Greco 40546a
index 2cef465208..a9185bd7b7 100644
Pablo Greco 40546a
--- a/src/util/Makefile.inc.am
Pablo Greco 40546a
+++ b/src/util/Makefile.inc.am
Pablo Greco 40546a
@@ -23,6 +23,8 @@ UTIL_SOURCES = \
Pablo Greco 40546a
 	util/virperf.h \
Pablo Greco 40546a
 	util/vircgroup.c \
Pablo Greco 40546a
 	util/vircgroup.h util/vircgrouppriv.h \
Pablo Greco 40546a
+	util/vircgroupbackend.c \
Pablo Greco 40546a
+	util/vircgroupbackend.h \
Pablo Greco 40546a
 	util/virclosecallbacks.c \
Pablo Greco 40546a
 	util/virclosecallbacks.h \
Pablo Greco 40546a
 	util/vircommand.c \
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c
Pablo Greco 40546a
new file mode 100644
Pablo Greco 40546a
index 0000000000..e014bfc0e6
Pablo Greco 40546a
--- /dev/null
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.c
Pablo Greco 40546a
@@ -0,0 +1,64 @@
Pablo Greco 40546a
+/*
Pablo Greco 40546a
+ * vircgroupbackend.c: methods for cgroups backend
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Copyright (C) 2018 Red Hat, Inc.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * This library is free software; you can redistribute it and/or
Pablo Greco 40546a
+ * modify it under the terms of the GNU Lesser General Public
Pablo Greco 40546a
+ * License as published by the Free Software Foundation; either
Pablo Greco 40546a
+ * version 2.1 of the License, or (at your option) any later version.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * This library is distributed in the hope that it will be useful,
Pablo Greco 40546a
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Pablo Greco 40546a
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Pablo Greco 40546a
+ * Lesser General Public License for more details.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * You should have received a copy of the GNU Lesser General Public
Pablo Greco 40546a
+ * License along with this library.  If not, see
Pablo Greco 40546a
+ * <http://www.gnu.org/licenses/>.
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+#include <config.h>
Pablo Greco 40546a
+
Pablo Greco 40546a
+#include "vircgroupbackend.h"
Pablo Greco 40546a
+#include "virerror.h"
Pablo Greco 40546a
+#include "virthread.h"
Pablo Greco 40546a
+
Pablo Greco 40546a
+#define VIR_FROM_THIS VIR_FROM_CGROUP
Pablo Greco 40546a
+
Pablo Greco 40546a
+VIR_ENUM_DECL(virCgroupBackend);
Pablo Greco 40546a
+VIR_ENUM_IMPL(virCgroupBackend, VIR_CGROUP_BACKEND_TYPE_LAST,
Pablo Greco 40546a
+              "cgroup V1");
Pablo Greco 40546a
+
Pablo Greco 40546a
+static virOnceControl virCgroupBackendOnce = VIR_ONCE_CONTROL_INITIALIZER;
Pablo Greco 40546a
+static virCgroupBackendPtr virCgroupBackends[VIR_CGROUP_BACKEND_TYPE_LAST] = { 0 };
Pablo Greco 40546a
+
Pablo Greco 40546a
+void
Pablo Greco 40546a
+virCgroupBackendRegister(virCgroupBackendPtr backend)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    if (virCgroupBackends[backend->type]) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR,
Pablo Greco 40546a
+                       _("Cgroup backend '%s' already registered."),
Pablo Greco 40546a
+                       virCgroupBackendTypeToString(backend->type));
Pablo Greco 40546a
+        return;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+
Pablo Greco 40546a
+    virCgroupBackends[backend->type] = backend;
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+static void
Pablo Greco 40546a
+virCgroupBackendOnceInit(void)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+}
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+virCgroupBackendPtr *
Pablo Greco 40546a
+virCgroupBackendGetAll(void)
Pablo Greco 40546a
+{
Pablo Greco 40546a
+    if (virOnce(&virCgroupBackendOnce, virCgroupBackendOnceInit) < 0) {
Pablo Greco 40546a
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
Pablo Greco 40546a
+                       _("Failed to initialize cgroup backend."));
Pablo Greco 40546a
+        return NULL;
Pablo Greco 40546a
+    }
Pablo Greco 40546a
+    return virCgroupBackends;
Pablo Greco 40546a
+}
Pablo Greco 40546a
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
Pablo Greco 40546a
new file mode 100644
Pablo Greco 40546a
index 0000000000..db052485a8
Pablo Greco 40546a
--- /dev/null
Pablo Greco 40546a
+++ b/src/util/vircgroupbackend.h
Pablo Greco 40546a
@@ -0,0 +1,46 @@
Pablo Greco 40546a
+/*
Pablo Greco 40546a
+ * vircgroupbackend.h: methods for cgroups backend
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * Copyright (C) 2018 Red Hat, Inc.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * This library is free software; you can redistribute it and/or
Pablo Greco 40546a
+ * modify it under the terms of the GNU Lesser General Public
Pablo Greco 40546a
+ * License as published by the Free Software Foundation; either
Pablo Greco 40546a
+ * version 2.1 of the License, or (at your option) any later version.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * This library is distributed in the hope that it will be useful,
Pablo Greco 40546a
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
Pablo Greco 40546a
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Pablo Greco 40546a
+ * Lesser General Public License for more details.
Pablo Greco 40546a
+ *
Pablo Greco 40546a
+ * You should have received a copy of the GNU Lesser General Public
Pablo Greco 40546a
+ * License along with this library.  If not, see
Pablo Greco 40546a
+ * <http://www.gnu.org/licenses/>.
Pablo Greco 40546a
+ */
Pablo Greco 40546a
+
Pablo Greco 40546a
+#ifndef __VIR_CGROUP_BACKEND_H__
Pablo Greco 40546a
+# define __VIR_CGROUP_BACKEND_H__
Pablo Greco 40546a
+
Pablo Greco 40546a
+# include "internal.h"
Pablo Greco 40546a
+
Pablo Greco 40546a
+# include "vircgroup.h"
Pablo Greco 40546a
+
Pablo Greco 40546a
+
Pablo Greco 40546a
+typedef enum {
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_TYPE_V1 = 0,
Pablo Greco 40546a
+    VIR_CGROUP_BACKEND_TYPE_LAST,
Pablo Greco 40546a
+} virCgroupBackendType;
Pablo Greco 40546a
+
Pablo Greco 40546a
+struct _virCgroupBackend {
Pablo Greco 40546a
+    virCgroupBackendType type;
Pablo Greco 40546a
+};
Pablo Greco 40546a
+typedef struct _virCgroupBackend virCgroupBackend;
Pablo Greco 40546a
+typedef virCgroupBackend *virCgroupBackendPtr;
Pablo Greco 40546a
+
Pablo Greco 40546a
+void
Pablo Greco 40546a
+virCgroupBackendRegister(virCgroupBackendPtr backend);
Pablo Greco 40546a
+
Pablo Greco 40546a
+virCgroupBackendPtr *
Pablo Greco 40546a
+virCgroupBackendGetAll(void);
Pablo Greco 40546a
+
Pablo Greco 40546a
+#endif /* __VIR_CGROUP_BACKEND_H__ */
Pablo Greco 40546a
-- 
Pablo Greco 40546a
2.22.0
Pablo Greco 40546a