render / rpms / libvirt

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