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