From nobody Mon Feb 9 04:31:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537285582911415.99333752504367; Tue, 18 Sep 2018 08:46:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A71F80F6D; Tue, 18 Sep 2018 15:46:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 33EFB7A412; Tue, 18 Sep 2018 15:46:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 26C8918005DF; Tue, 18 Sep 2018 15:46:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8IFkDN8011897 for ; Tue, 18 Sep 2018 11:46:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC7874DC48; Tue, 18 Sep 2018 15:46:13 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70B8B5D9C7 for ; Tue, 18 Sep 2018 15:46:13 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:22 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/47] util: introduce vircgroupbackend files X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Sep 2018 15:46:21 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We will need to extract current cgroup v1 implementation into separate backend because there will be new cgroup v2 implementation and both will have to co-exit. Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/Makefile.am | 1 + src/libvirt_private.syms | 3 ++ src/util/Makefile.inc.am | 2 ++ src/util/vircgroupbackend.c | 64 +++++++++++++++++++++++++++++++++++++ src/util/vircgroupbackend.h | 46 ++++++++++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 src/util/vircgroupbackend.c create mode 100644 src/util/vircgroupbackend.h diff --git a/src/Makefile.am b/src/Makefile.am index 2a3ed0d42d..3465629005 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -673,6 +673,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ util/virbitmap.c \ util/virbuffer.c \ util/vircgroup.c \ + util/vircgroupbackend.c \ util/vircommand.c \ util/virconf.c \ util/virdbus.c \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 75c59fbf89..eb302b3559 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1576,6 +1576,9 @@ virCgroupSetOwner; virCgroupSupportsCpuBW; virCgroupTerminateMachine; =20 +# util/vircgroupbackend.h +virCgroupBackendGetAll; +virCgroupBackendRegister; =20 # util/virclosecallbacks.h virCloseCallbacksGet; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index a22265606c..1b236ca62b 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -23,6 +23,8 @@ UTIL_SOURCES =3D \ util/virperf.h \ util/vircgroup.c \ util/vircgroup.h util/vircgrouppriv.h \ + util/vircgroupbackend.c \ + util/vircgroupbackend.h \ util/virclosecallbacks.c \ util/virclosecallbacks.h \ util/vircommand.c \ diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c new file mode 100644 index 0000000000..e014bfc0e6 --- /dev/null +++ b/src/util/vircgroupbackend.c @@ -0,0 +1,64 @@ +/* + * vircgroupbackend.c: methods for cgroups backend + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ +#include + +#include "vircgroupbackend.h" +#include "virerror.h" +#include "virthread.h" + +#define VIR_FROM_THIS VIR_FROM_CGROUP + +VIR_ENUM_DECL(virCgroupBackend); +VIR_ENUM_IMPL(virCgroupBackend, VIR_CGROUP_BACKEND_TYPE_LAST, + "cgroup V1"); + +static virOnceControl virCgroupBackendOnce =3D VIR_ONCE_CONTROL_INITIALIZE= R; +static virCgroupBackendPtr virCgroupBackends[VIR_CGROUP_BACKEND_TYPE_LAST]= =3D { 0 }; + +void +virCgroupBackendRegister(virCgroupBackendPtr backend) +{ + if (virCgroupBackends[backend->type]) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cgroup backend '%s' already registered."), + virCgroupBackendTypeToString(backend->type)); + return; + } + + virCgroupBackends[backend->type] =3D backend; +} + + +static void +virCgroupBackendOnceInit(void) +{ +} + + +virCgroupBackendPtr * +virCgroupBackendGetAll(void) +{ + if (virOnce(&virCgroupBackendOnce, virCgroupBackendOnceInit) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to initialize cgroup backend.")); + return NULL; + } + return virCgroupBackends; +} diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h new file mode 100644 index 0000000000..db052485a8 --- /dev/null +++ b/src/util/vircgroupbackend.h @@ -0,0 +1,46 @@ +/* + * vircgroupbackend.h: methods for cgroups backend + * + * Copyright (C) 2018 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef __VIR_CGROUP_BACKEND_H__ +# define __VIR_CGROUP_BACKEND_H__ + +# include "internal.h" + +# include "vircgroup.h" + + +typedef enum { + VIR_CGROUP_BACKEND_TYPE_V1 =3D 0, + VIR_CGROUP_BACKEND_TYPE_LAST, +} virCgroupBackendType; + +struct _virCgroupBackend { + virCgroupBackendType type; +}; +typedef struct _virCgroupBackend virCgroupBackend; +typedef virCgroupBackend *virCgroupBackendPtr; + +void +virCgroupBackendRegister(virCgroupBackendPtr backend); + +virCgroupBackendPtr * +virCgroupBackendGetAll(void); + +#endif /* __VIR_CGROUP_BACKEND_H__ */ --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list