From nobody Wed May 1 20:13:19 2024 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 From nobody Wed May 1 20:13:19 2024 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 1537285601304508.0696777541374; Tue, 18 Sep 2018 08:46:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55A1F6B; Tue, 18 Sep 2018 15:46:39 +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 183C77B014; Tue, 18 Sep 2018 15:46:39 +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 A92D8181A139; Tue, 18 Sep 2018 15:46:38 +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 w8IFkEWU011905 for ; Tue, 18 Sep 2018 11:46:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8FF85D9C7; Tue, 18 Sep 2018 15:46:14 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B9E882AF8 for ; Tue, 18 Sep 2018 15:46:14 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:23 +0200 Message-Id: <76d3b0c1fad5426a6ca5e68de3a4bb352a6319fd.1537285203.git.phrdina@redhat.com> 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 02/47] vircgroup: introduce cgroup v1 backend 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Sep 2018 15:46:40 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 | 2 ++ src/util/vircgroupv1.c | 55 +++++++++++++++++++++++++++++++++++++ src/util/vircgroupv1.h | 27 ++++++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 src/util/vircgroupv1.c create mode 100644 src/util/vircgroupv1.h diff --git a/src/Makefile.am b/src/Makefile.am index 3465629005..f515569fd5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -674,6 +674,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ util/virbuffer.c \ util/vircgroup.c \ util/vircgroupbackend.c \ + util/vircgroupv1.c \ util/vircommand.c \ util/virconf.c \ util/virdbus.c \ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index eb302b3559..00598b97de 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1580,6 +1580,9 @@ virCgroupTerminateMachine; virCgroupBackendGetAll; virCgroupBackendRegister; =20 +# util/vircgroupv1.h +virCgroupV1Register; + # util/virclosecallbacks.h virCloseCallbacksGet; virCloseCallbacksGetConn; diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 1b236ca62b..ad3be91867 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -25,6 +25,8 @@ UTIL_SOURCES =3D \ util/vircgroup.h util/vircgrouppriv.h \ util/vircgroupbackend.c \ util/vircgroupbackend.h \ + util/vircgroupv1.c \ + util/vircgroupv1.h \ util/virclosecallbacks.c \ util/virclosecallbacks.h \ util/vircommand.c \ diff --git a/src/util/vircgroupbackend.c b/src/util/vircgroupbackend.c index e014bfc0e6..d854c9711d 100644 --- a/src/util/vircgroupbackend.c +++ b/src/util/vircgroupbackend.c @@ -20,6 +20,7 @@ #include =20 #include "vircgroupbackend.h" +#include "vircgroupv1.h" #include "virerror.h" #include "virthread.h" =20 @@ -49,6 +50,7 @@ virCgroupBackendRegister(virCgroupBackendPtr backend) static void virCgroupBackendOnceInit(void) { + virCgroupV1Register(); } =20 =20 diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c new file mode 100644 index 0000000000..711ebf1128 --- /dev/null +++ b/src/util/vircgroupv1.c @@ -0,0 +1,55 @@ +/* + * vircgroupv1.c: methods for cgroups v1 backedn + * + * Copyright (C) 2010-2015,2018 Red Hat, Inc. + * Copyright IBM Corp. 2008 + * + * 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 "internal.h" + +#define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ +#include "vircgrouppriv.h" +#undef __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ + +#include "vircgroup.h" +#include "vircgroupbackend.h" +#include "vircgroupv1.h" +#include "virlog.h" + +VIR_LOG_INIT("util.cgroup"); + +#define VIR_FROM_THIS VIR_FROM_CGROUP + + +VIR_ENUM_DECL(virCgroupV1Controller); +VIR_ENUM_IMPL(virCgroupV1Controller, VIR_CGROUP_CONTROLLER_LAST, + "cpu", "cpuacct", "cpuset", "memory", "devices", + "freezer", "blkio", "net_cls", "perf_event", + "name=3Dsystemd"); + + +virCgroupBackend virCgroupV1Backend =3D { + .type =3D VIR_CGROUP_BACKEND_TYPE_V1, +}; + + +void +virCgroupV1Register(void) +{ + virCgroupBackendRegister(&virCgroupV1Backend); +} diff --git a/src/util/vircgroupv1.h b/src/util/vircgroupv1.h new file mode 100644 index 0000000000..e75b85a50a --- /dev/null +++ b/src/util/vircgroupv1.h @@ -0,0 +1,27 @@ +/* + * vircgroupv1.h: methods for cgroups v1 backedn + * + * 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_V1_H__ +# define __VIR_CGROUP_V1_H__ + +void +virCgroupV1Register(void); + +#endif /* __VIR_CGROUP_V1_H__ */ --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285582858846.5559639067221; Tue, 18 Sep 2018 08:46:22 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC17581E05; 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 597675D9C7; Tue, 18 Sep 2018 15:46:20 +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 B08A9181A12D; Tue, 18 Sep 2018 15:46:19 +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 w8IFkFWV011912 for ; Tue, 18 Sep 2018 11:46:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9EAB35D9C7; Tue, 18 Sep 2018 15:46:15 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2385082213 for ; Tue, 18 Sep 2018 15:46:14 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:24 +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 03/47] vircgroup: extract virCgroupV1Available 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); 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" Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 28 +++++++++------------------- src/util/vircgroupbackend.h | 7 +++++++ src/util/vircgroupv1.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e85e0bde24..a5478a3fa4 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -51,6 +51,7 @@ =20 #include "virutil.h" #include "viralloc.h" +#include "vircgroupbackend.h" #include "virerror.h" #include "virlog.h" #include "virfile.h" @@ -64,8 +65,6 @@ =20 VIR_LOG_INIT("util.cgroup"); =20 -#define CGROUP_MAX_VAL 512 - #define VIR_FROM_THIS VIR_FROM_CGROUP =20 #define CGROUP_NB_TOTAL_CPU_STAT_PARAM 3 @@ -132,29 +131,20 @@ virCgroupGetDevicePermsString(int perms) bool virCgroupAvailable(void) { - bool ret =3D false; - FILE *mounts =3D NULL; - struct mntent entry; - char buf[CGROUP_MAX_VAL]; + size_t i; + virCgroupBackendPtr *backends =3D virCgroupBackendGetAll(); =20 - if (!virFileExists("/proc/cgroups")) + if (!backends) return false; =20 - if (!(mounts =3D fopen("/proc/mounts", "r"))) - return false; - - while (getmntent_r(mounts, &entry, buf, sizeof(buf)) !=3D NULL) { - /* We're looking for at least one 'cgroup' fs mount, - * which is *not* a named mount. */ - if (STREQ(entry.mnt_type, "cgroup") && - !strstr(entry.mnt_opts, "name=3D")) { - ret =3D true; - break; + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (backends[i] && backends[i]->available && + backends[i]->available()) { + return true; } } =20 - VIR_FORCE_FCLOSE(mounts); - return ret; + return false; } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index db052485a8..88f51416b0 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -25,14 +25,21 @@ =20 # include "vircgroup.h" =20 +# define CGROUP_MAX_VAL 512 =20 typedef enum { VIR_CGROUP_BACKEND_TYPE_V1 =3D 0, VIR_CGROUP_BACKEND_TYPE_LAST, } virCgroupBackendType; =20 +typedef bool +(*virCgroupAvailableCB)(void); + struct _virCgroupBackend { virCgroupBackendType type; + + /* Mandatory callbacks that need to be implemented for every backend. = */ + virCgroupAvailableCB available; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 711ebf1128..c5bd2f6a3b 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -20,6 +20,10 @@ */ #include =20 +#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R +# include +#endif + #include "internal.h" =20 #define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ @@ -29,6 +33,7 @@ #include "vircgroup.h" #include "vircgroupbackend.h" #include "vircgroupv1.h" +#include "virfile.h" #include "virlog.h" =20 VIR_LOG_INIT("util.cgroup"); @@ -43,8 +48,38 @@ VIR_ENUM_IMPL(virCgroupV1Controller, VIR_CGROUP_CONTROLL= ER_LAST, "name=3Dsystemd"); =20 =20 +/* We're looking for at least one 'cgroup' fs mount, + * which is *not* a named mount. */ +static bool +virCgroupV1Available(void) +{ + bool ret =3D false; + FILE *mounts =3D NULL; + struct mntent entry; + char buf[CGROUP_MAX_VAL]; + + if (!virFileExists("/proc/cgroups")) + return false; + + if (!(mounts =3D fopen("/proc/mounts", "r"))) + return false; + + while (getmntent_r(mounts, &entry, buf, sizeof(buf)) !=3D NULL) { + if (STREQ(entry.mnt_type, "cgroup") && !strstr(entry.mnt_opts, "na= me=3D")) { + ret =3D true; + break; + } + } + + VIR_FORCE_FCLOSE(mounts); + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, + + .available =3D virCgroupV1Available, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285598686264.29183878045853; Tue, 18 Sep 2018 08:46:38 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C13A3A26E; Tue, 18 Sep 2018 15:46:36 +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 5CA587B012; Tue, 18 Sep 2018 15:46:36 +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 00DF0181A130; Tue, 18 Sep 2018 15:46:35 +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 w8IFkGUw011917 for ; Tue, 18 Sep 2018 11:46:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A3094DC48; Tue, 18 Sep 2018 15:46:16 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE75E5D9C7 for ; Tue, 18 Sep 2018 15:46:15 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:25 +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 04/47] vircgroup: detect available backend for cgroup 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Sep 2018 15:46:37 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We need to update one test-case because now new cgroup object will be created only if there is any cgroup backend available. Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 18 ++++++++++++++++++ src/util/vircgrouppriv.h | 3 +++ tests/vircgrouptest.c | 38 +++----------------------------------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index a5478a3fa4..0ffb5db93c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -713,10 +713,28 @@ virCgroupDetect(virCgroupPtr group, virCgroupPtr parent) { int rc; + size_t i; + virCgroupBackendPtr *backends =3D virCgroupBackendGetAll(); =20 VIR_DEBUG("group=3D%p controllers=3D%d path=3D%s parent=3D%p", group, controllers, path, parent); =20 + if (!backends) + return -1; + + for (i =3D 0; i < VIR_CGROUP_BACKEND_TYPE_LAST; i++) { + if (backends[i] && backends[i]->available()) { + group->backend =3D backends[i]; + break; + } + } + + if (!group->backend) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("no cgroup backend available")); + return -1; + } + if (parent) { if (virCgroupCopyMounts(group, parent) < 0) return -1; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 046c96c52c..2caa966fee 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -30,6 +30,7 @@ # define __VIR_CGROUP_PRIV_H__ =20 # include "vircgroup.h" +# include "vircgroupbackend.h" =20 struct _virCgroupController { int type; @@ -47,6 +48,8 @@ typedef virCgroupController *virCgroupControllerPtr; struct _virCgroup { char *path; =20 + virCgroupBackendPtr backend; + virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index bbbe6ffbe5..be3143ea52 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -114,16 +114,6 @@ const char *mountsAllInOne[VIR_CGROUP_CONTROLLER_LAST]= =3D { [VIR_CGROUP_CONTROLLER_BLKIO] =3D "/not/really/sys/fs/cgroup", [VIR_CGROUP_CONTROLLER_SYSTEMD] =3D NULL, }; -const char *mountsLogind[VIR_CGROUP_CONTROLLER_LAST] =3D { - [VIR_CGROUP_CONTROLLER_CPU] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUACCT] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUSET] =3D NULL, - [VIR_CGROUP_CONTROLLER_MEMORY] =3D NULL, - [VIR_CGROUP_CONTROLLER_DEVICES] =3D NULL, - [VIR_CGROUP_CONTROLLER_FREEZER] =3D NULL, - [VIR_CGROUP_CONTROLLER_BLKIO] =3D NULL, - [VIR_CGROUP_CONTROLLER_SYSTEMD] =3D "/not/really/sys/fs/cgroup/systemd= ", -}; =20 const char *links[VIR_CGROUP_CONTROLLER_LAST] =3D { [VIR_CGROUP_CONTROLLER_CPU] =3D "/not/really/sys/fs/cgroup/cpu", @@ -147,17 +137,6 @@ const char *linksAllInOne[VIR_CGROUP_CONTROLLER_LAST] = =3D { [VIR_CGROUP_CONTROLLER_SYSTEMD] =3D NULL, }; =20 -const char *linksLogind[VIR_CGROUP_CONTROLLER_LAST] =3D { - [VIR_CGROUP_CONTROLLER_CPU] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUACCT] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUSET] =3D NULL, - [VIR_CGROUP_CONTROLLER_MEMORY] =3D NULL, - [VIR_CGROUP_CONTROLLER_DEVICES] =3D NULL, - [VIR_CGROUP_CONTROLLER_FREEZER] =3D NULL, - [VIR_CGROUP_CONTROLLER_BLKIO] =3D NULL, - [VIR_CGROUP_CONTROLLER_SYSTEMD] =3D NULL, -}; - =20 static int testCgroupDetectMounts(const void *args) @@ -541,24 +520,13 @@ static int testCgroupNewForSelfLogind(const void *arg= s ATTRIBUTE_UNUSED) { virCgroupPtr cgroup =3D NULL; int ret =3D -1; - const char *placement[VIR_CGROUP_CONTROLLER_LAST] =3D { - [VIR_CGROUP_CONTROLLER_CPU] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUACCT] =3D NULL, - [VIR_CGROUP_CONTROLLER_CPUSET] =3D NULL, - [VIR_CGROUP_CONTROLLER_MEMORY] =3D NULL, - [VIR_CGROUP_CONTROLLER_DEVICES] =3D NULL, - [VIR_CGROUP_CONTROLLER_FREEZER] =3D NULL, - [VIR_CGROUP_CONTROLLER_BLKIO] =3D NULL, - [VIR_CGROUP_CONTROLLER_SYSTEMD] =3D "/", - }; =20 - if (virCgroupNewSelf(&cgroup) < 0) { - fprintf(stderr, "Cannot create cgroup for self\n"); + if (virCgroupNewSelf(&cgroup) =3D=3D 0) { + fprintf(stderr, "Expected cgroup creation to fail.\n"); goto cleanup; } =20 - ret =3D validateCgroup(cgroup, "", mountsLogind, linksLogind, placemen= t); - + ret =3D 0; cleanup: virCgroupFree(&cgroup); return ret; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285607223559.4290591292274; Tue, 18 Sep 2018 08:46:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AF133001765; Tue, 18 Sep 2018 15:46:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 450C810021B1; Tue, 18 Sep 2018 15:46:41 +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 BE7824A465; Tue, 18 Sep 2018 15:46:40 +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 w8IFkHH5011926 for ; Tue, 18 Sep 2018 11:46:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4F11D4DC48; Tue, 18 Sep 2018 15:46:17 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6A665D9C7 for ; Tue, 18 Sep 2018 15:46:16 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:26 +0200 Message-Id: <27406c6a9b1567f919c5ffc06ba1fa7a9bfd3e3b.1537285203.git.phrdina@redhat.com> 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 05/47] vircgroup: extract virCgroupV1ValidateMachineGroup 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 18 Sep 2018 15:46:42 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 85 +------------------------------------ src/util/vircgroupbackend.h | 7 +++ src/util/vircgrouppriv.h | 2 + src/util/vircgroupv1.c | 84 ++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 83 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0ffb5db93c..9d6eebc2b9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -218,7 +218,7 @@ virCgroupPartitionNeedsEscaping(const char *path) } =20 =20 -static int +int virCgroupPartitionEscape(char **path) { int rc; @@ -237,87 +237,6 @@ virCgroupPartitionEscape(char **path) } =20 =20 -static bool -virCgroupValidateMachineGroup(virCgroupPtr group, - const char *name, - const char *drivername, - const char *machinename) -{ - size_t i; - VIR_AUTOFREE(char *) partname =3D NULL; - VIR_AUTOFREE(char *) scopename_old =3D NULL; - VIR_AUTOFREE(char *) scopename_new =3D NULL; - VIR_AUTOFREE(char *) partmachinename =3D NULL; - - if (virAsprintf(&partname, "%s.libvirt-%s", - name, drivername) < 0) - return false; - - if (virCgroupPartitionEscape(&partname) < 0) - return false; - - if (virAsprintf(&partmachinename, "%s.libvirt-%s", - machinename, drivername) < 0 || - virCgroupPartitionEscape(&partmachinename) < 0) - return false; - - if (!(scopename_old =3D virSystemdMakeScopeName(name, drivername, true= ))) - return false; - - if (!(scopename_new =3D virSystemdMakeScopeName(machinename, - drivername, false))) - return false; - - if (virCgroupPartitionEscape(&scopename_old) < 0) - return false; - - if (virCgroupPartitionEscape(&scopename_new) < 0) - return false; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *tmp; - - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - if (!group->controllers[i].placement) - continue; - - tmp =3D strrchr(group->controllers[i].placement, '/'); - if (!tmp) - return false; - - if (i =3D=3D VIR_CGROUP_CONTROLLER_CPU || - i =3D=3D VIR_CGROUP_CONTROLLER_CPUACCT || - i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET) { - if (STREQ(tmp, "/emulator")) - *tmp =3D '\0'; - tmp =3D strrchr(group->controllers[i].placement, '/'); - if (!tmp) - return false; - } - - tmp++; - - if (STRNEQ(tmp, name) && - STRNEQ(tmp, machinename) && - STRNEQ(tmp, partname) && - STRNEQ(tmp, partmachinename) && - STRNEQ(tmp, scopename_old) && - STRNEQ(tmp, scopename_new)) { - VIR_DEBUG("Name '%s' for controller '%s' does not match " - "'%s', '%s', '%s', '%s' or '%s'", - tmp, virCgroupControllerTypeToString(i), - name, machinename, partname, - scopename_old, scopename_new); - return false; - } - } - - return true; -} - - static int virCgroupCopyMounts(virCgroupPtr group, virCgroupPtr parent) @@ -1502,7 +1421,7 @@ virCgroupNewDetectMachine(const char *name, return -1; } =20 - if (!virCgroupValidateMachineGroup(*group, name, drivername, machinena= me)) { + if (!(*group)->backend->validateMachineGroup(*group, name, drivername,= machinename)) { VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", name, drivername); virCgroupFree(group); diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 88f51416b0..daf47bac09 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -35,11 +35,18 @@ typedef enum { typedef bool (*virCgroupAvailableCB)(void); =20 +typedef bool +(*virCgroupValidateMachineGroupCB)(virCgroupPtr group, + const char *name, + const char *drivername, + const char *machinename); + struct _virCgroupBackend { virCgroupBackendType type; =20 /* Mandatory callbacks that need to be implemented for every backend. = */ virCgroupAvailableCB available; + virCgroupValidateMachineGroupCB validateMachineGroup; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 2caa966fee..e7f4a1f0fc 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -53,6 +53,8 @@ struct _virCgroup { virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 +int virCgroupPartitionEscape(char **path); + int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c5bd2f6a3b..48e3d412ae 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -35,6 +35,8 @@ #include "vircgroupv1.h" #include "virfile.h" #include "virlog.h" +#include "virstring.h" +#include "virsystemd.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -76,10 +78,92 @@ virCgroupV1Available(void) } =20 =20 +static bool +virCgroupV1ValidateMachineGroup(virCgroupPtr group, + const char *name, + const char *drivername, + const char *machinename) +{ + size_t i; + VIR_AUTOFREE(char *) partname =3D NULL; + VIR_AUTOFREE(char *) scopename_old =3D NULL; + VIR_AUTOFREE(char *) scopename_new =3D NULL; + VIR_AUTOFREE(char *) partmachinename =3D NULL; + + if (virAsprintf(&partname, "%s.libvirt-%s", + name, drivername) < 0) + return false; + + if (virCgroupPartitionEscape(&partname) < 0) + return false; + + if (virAsprintf(&partmachinename, "%s.libvirt-%s", + machinename, drivername) < 0 || + virCgroupPartitionEscape(&partmachinename) < 0) + return false; + + if (!(scopename_old =3D virSystemdMakeScopeName(name, drivername, true= ))) + return false; + + if (!(scopename_new =3D virSystemdMakeScopeName(machinename, + drivername, false))) + return false; + + if (virCgroupPartitionEscape(&scopename_old) < 0) + return false; + + if (virCgroupPartitionEscape(&scopename_new) < 0) + return false; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + char *tmp; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (!group->controllers[i].placement) + continue; + + tmp =3D strrchr(group->controllers[i].placement, '/'); + if (!tmp) + return false; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_CPU || + i =3D=3D VIR_CGROUP_CONTROLLER_CPUACCT || + i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET) { + if (STREQ(tmp, "/emulator")) + *tmp =3D '\0'; + tmp =3D strrchr(group->controllers[i].placement, '/'); + if (!tmp) + return false; + } + + tmp++; + + if (STRNEQ(tmp, name) && + STRNEQ(tmp, machinename) && + STRNEQ(tmp, partname) && + STRNEQ(tmp, partmachinename) && + STRNEQ(tmp, scopename_old) && + STRNEQ(tmp, scopename_new)) { + VIR_DEBUG("Name '%s' for controller '%s' does not match " + "'%s', '%s', '%s', '%s' or '%s'", + tmp, virCgroupV1ControllerTypeToString(i), + name, machinename, partname, + scopename_old, scopename_new); + return false; + } + } + + return true; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 .available =3D virCgroupV1Available, + .validateMachineGroup =3D virCgroupV1ValidateMachineGroup, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285599398928.0832317508787; Tue, 18 Sep 2018 08:46:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD6E065995; Tue, 18 Sep 2018 15:46:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74BDF30912F4; Tue, 18 Sep 2018 15:46:36 +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 1A96D4A460; Tue, 18 Sep 2018 15:46:36 +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 w8IFkIYU011939 for ; Tue, 18 Sep 2018 11:46:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2479C5D9C7; Tue, 18 Sep 2018 15:46:18 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D6ED82213 for ; Tue, 18 Sep 2018 15:46:17 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:27 +0200 Message-Id: <34957737d3d68f59b372e72b5c3aae5f2af23023.1537285203.git.phrdina@redhat.com> 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 06/47] vircgroup: extract virCgroupV1CopyMounts 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Sep 2018 15:46:37 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 23 +---------------------- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 9d6eebc2b9..f5b2a14df9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -237,27 +237,6 @@ virCgroupPartitionEscape(char **path) } =20 =20 -static int -virCgroupCopyMounts(virCgroupPtr group, - virCgroupPtr parent) -{ - size_t i; - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!parent->controllers[i].mountPoint) - continue; - - if (VIR_STRDUP(group->controllers[i].mountPoint, - parent->controllers[i].mountPoint) < 0) - return -1; - - if (VIR_STRDUP(group->controllers[i].linkPoint, - parent->controllers[i].linkPoint) < 0) - return -1; - } - return 0; -} - - static int virCgroupResolveMountLink(const char *mntDir, const char *typeStr, @@ -655,7 +634,7 @@ virCgroupDetect(virCgroupPtr group, } =20 if (parent) { - if (virCgroupCopyMounts(group, parent) < 0) + if (group->backend->copyMounts(group, parent) < 0) return -1; } else { if (virCgroupDetectMounts(group) < 0) diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index daf47bac09..81ee597fc8 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -41,12 +41,17 @@ typedef bool const char *drivername, const char *machinename); =20 +typedef int +(*virCgroupCopyMountsCB)(virCgroupPtr group, + virCgroupPtr parent); + struct _virCgroupBackend { virCgroupBackendType type; =20 /* Mandatory callbacks that need to be implemented for every backend. = */ virCgroupAvailableCB available; virCgroupValidateMachineGroupCB validateMachineGroup; + virCgroupCopyMountsCB copyMounts; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 48e3d412ae..00c3349aee 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -159,11 +159,33 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group, } =20 =20 +static int +virCgroupV1CopyMounts(virCgroupPtr group, + virCgroupPtr parent) +{ + size_t i; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!parent->controllers[i].mountPoint) + continue; + + if (VIR_STRDUP(group->controllers[i].mountPoint, + parent->controllers[i].mountPoint) < 0) + return -1; + + if (VIR_STRDUP(group->controllers[i].linkPoint, + parent->controllers[i].linkPoint) < 0) + return -1; + } + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 .available =3D virCgroupV1Available, .validateMachineGroup =3D virCgroupV1ValidateMachineGroup, + .copyMounts =3D virCgroupV1CopyMounts, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285609954957.0986333123144; Tue, 18 Sep 2018 08:46:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A873B307D865; Tue, 18 Sep 2018 15:46:47 +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 5E78916E3A; Tue, 18 Sep 2018 15:46:47 +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 C4097181A13C; Tue, 18 Sep 2018 15:46:46 +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 w8IFkJ2d011948 for ; Tue, 18 Sep 2018 11:46:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 07E594DC48; Tue, 18 Sep 2018 15:46:19 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 745915D9C7 for ; Tue, 18 Sep 2018 15:46:18 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:28 +0200 Message-Id: <0daf846914007db602e712c699295e3038e06a96.1537285203.git.phrdina@redhat.com> 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 07/47] vircgroup: extract v1 detect functions 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 18 Sep 2018 15:46:48 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 138 ++----------------------------- src/util/vircgroupbackend.h | 14 ++++ src/util/vircgroupv1.c | 158 ++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+), 130 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f5b2a14df9..7557fc5576 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -237,82 +237,6 @@ virCgroupPartitionEscape(char **path) } =20 =20 -static int -virCgroupResolveMountLink(const char *mntDir, - const char *typeStr, - virCgroupControllerPtr controller) -{ - VIR_AUTOFREE(char *) linkSrc =3D NULL; - VIR_AUTOFREE(char *) tmp =3D NULL; - char *dirName; - struct stat sb; - - if (VIR_STRDUP(tmp, mntDir) < 0) - return -1; - - dirName =3D strrchr(tmp, '/'); - if (!dirName) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Missing '/' separator in cgroup mount '%s'"), tm= p); - return -1; - } - - if (!strchr(dirName + 1, ',')) - return 0; - - *dirName =3D '\0'; - if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0) - return -1; - *dirName =3D '/'; - - if (lstat(linkSrc, &sb) < 0) { - if (errno =3D=3D ENOENT) { - VIR_WARN("Controller %s co-mounted at %s is missing symlink at= %s", - typeStr, tmp, linkSrc); - } else { - virReportSystemError(errno, _("Cannot stat %s"), linkSrc); - return -1; - } - } else { - if (!S_ISLNK(sb.st_mode)) { - VIR_WARN("Expecting a symlink at %s for controller %s", - linkSrc, typeStr); - } else { - VIR_STEAL_PTR(controller->linkPoint, linkSrc); - } - } - - return 0; -} - - -static bool -virCgroupMountOptsMatchController(const char *mntOpts, - const char *typeStr) -{ - const char *tmp =3D mntOpts; - int typeLen =3D strlen(typeStr); - - while (tmp) { - const char *next =3D strchr(tmp, ','); - int len; - if (next) { - len =3D next - tmp; - next++; - } else { - len =3D strlen(tmp); - } - - if (typeLen =3D=3D len && STREQLEN(typeStr, tmp, len)) - return true; - - tmp =3D next; - } - - return false; -} - - /* * Process /proc/mounts figuring out what controllers are * mounted and where @@ -320,7 +244,6 @@ virCgroupMountOptsMatchController(const char *mntOpts, static int virCgroupDetectMounts(virCgroupPtr group) { - size_t i; FILE *mounts =3D NULL; struct mntent entry; char buf[CGROUP_MAX_VAL]; @@ -333,34 +256,11 @@ virCgroupDetectMounts(virCgroupPtr group) } =20 while (getmntent_r(mounts, &entry, buf, sizeof(buf)) !=3D NULL) { - if (STRNEQ(entry.mnt_type, "cgroup")) - continue; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - const char *typestr =3D virCgroupControllerTypeToString(i); - - if (virCgroupMountOptsMatchController(entry.mnt_opts, typestr)= ) { - /* Note that the lines in /proc/mounts have the same - * order than the mount operations, and that there may - * be duplicates due to bind mounts. This means - * that the same mount point may be processed more than - * once. We need to save the results of the last one, - * and we need to be careful to release the memory used - * by previous processing. */ - virCgroupControllerPtr controller =3D &group->controllers[= i]; - - VIR_FREE(controller->mountPoint); - VIR_FREE(controller->linkPoint); - if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) < 0) - goto cleanup; - - /* If it is a co-mount it has a filename like "cpu,cpuacct" - * and we must identify the symlink path */ - if (virCgroupResolveMountLink(entry.mnt_dir, typestr, - controller) < 0) { - goto cleanup; - } - } + if (group->backend->detectMounts(group, + entry.mnt_type, + entry.mnt_opts, + entry.mnt_dir) < 0) { + goto cleanup; } } =20 @@ -434,7 +334,6 @@ virCgroupDetectPlacement(virCgroupPtr group, pid_t pid, const char *path) { - size_t i; FILE *mapping =3D NULL; char line[1024]; int ret =3D -1; @@ -474,30 +373,9 @@ virCgroupDetectPlacement(virCgroupPtr group, controllers++; selfpath++; =20 - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - const char *typestr =3D virCgroupControllerTypeToString(i); - - if (virCgroupMountOptsMatchController(controllers, typestr) && - group->controllers[i].mountPoint !=3D NULL && - group->controllers[i].placement =3D=3D NULL) { - /* - * selfpath =3D=3D "/" + path=3D"" -> "/" - * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> = "/libvirt.service" - * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" = -> "/libvirt.service/foo" - */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { - if (VIR_STRDUP(group->controllers[i].placement, - selfpath) < 0) - goto cleanup; - } else { - if (virAsprintf(&group->controllers[i].placement, - "%s%s%s", selfpath, - (STREQ(selfpath, "/") || - STREQ(path, "") ? "" : "/"), - path) < 0) - goto cleanup; - } - } + if (group->backend->detectPlacement(group, path, controllers, + selfpath) < 0) { + goto cleanup; } } =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 81ee597fc8..fadc7efdcf 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -45,6 +45,18 @@ typedef int (*virCgroupCopyMountsCB)(virCgroupPtr group, virCgroupPtr parent); =20 +typedef int +(*virCgroupDetectMountsCB)(virCgroupPtr group, + const char *mntType, + const char *mntOpts, + const char *mntDir); + +typedef int +(*virCgroupDetectPlacementCB)(virCgroupPtr group, + const char *path, + const char *controllers, + const char *selfpath); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -52,6 +64,8 @@ struct _virCgroupBackend { virCgroupAvailableCB available; virCgroupValidateMachineGroupCB validateMachineGroup; virCgroupCopyMountsCB copyMounts; + virCgroupDetectMountsCB detectMounts; + virCgroupDetectPlacementCB detectPlacement; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 00c3349aee..2882a19be2 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -23,6 +23,7 @@ #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R # include #endif +#include =20 #include "internal.h" =20 @@ -37,6 +38,7 @@ #include "virlog.h" #include "virstring.h" #include "virsystemd.h" +#include "virerror.h" =20 VIR_LOG_INIT("util.cgroup"); =20 @@ -180,12 +182,168 @@ virCgroupV1CopyMounts(virCgroupPtr group, } =20 =20 +static int +virCgroupV1ResolveMountLink(const char *mntDir, + const char *typeStr, + virCgroupControllerPtr controller) +{ + VIR_AUTOFREE(char *) linkSrc =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; + char *dirName; + struct stat sb; + + if (VIR_STRDUP(tmp, mntDir) < 0) + return -1; + + dirName =3D strrchr(tmp, '/'); + if (!dirName) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Missing '/' separator in cgroup mount '%s'"), tm= p); + return -1; + } + + if (!strchr(dirName + 1, ',')) + return 0; + + *dirName =3D '\0'; + if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0) + return -1; + *dirName =3D '/'; + + if (lstat(linkSrc, &sb) < 0) { + if (errno =3D=3D ENOENT) { + VIR_WARN("Controller %s co-mounted at %s is missing symlink at= %s", + typeStr, tmp, linkSrc); + } else { + virReportSystemError(errno, _("Cannot stat %s"), linkSrc); + return -1; + } + } else { + if (!S_ISLNK(sb.st_mode)) { + VIR_WARN("Expecting a symlink at %s for controller %s", + linkSrc, typeStr); + } else { + VIR_STEAL_PTR(controller->linkPoint, linkSrc); + } + } + + return 0; +} + + +static bool +virCgroupV1MountOptsMatchController(const char *mntOpts, + const char *typeStr) +{ + const char *tmp =3D mntOpts; + int typeLen =3D strlen(typeStr); + + while (tmp) { + const char *next =3D strchr(tmp, ','); + int len; + if (next) { + len =3D next - tmp; + next++; + } else { + len =3D strlen(tmp); + } + + if (typeLen =3D=3D len && STREQLEN(typeStr, tmp, len)) + return true; + + tmp =3D next; + } + + return false; +} + + +static int +virCgroupV1DetectMounts(virCgroupPtr group, + const char *mntType, + const char *mntOpts, + const char *mntDir) +{ + size_t i; + + if (STRNEQ(mntType, "cgroup")) + return 0; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + const char *typestr =3D virCgroupV1ControllerTypeToString(i); + + if (virCgroupV1MountOptsMatchController(mntOpts, typestr)) { + /* Note that the lines in /proc/mounts have the same + * order than the mount operations, and that there may + * be duplicates due to bind mounts. This means + * that the same mount point may be processed more than + * once. We need to save the results of the last one, + * and we need to be careful to release the memory used + * by previous processing. */ + virCgroupControllerPtr controller =3D &group->controllers[i]; + + VIR_FREE(controller->mountPoint); + VIR_FREE(controller->linkPoint); + if (VIR_STRDUP(controller->mountPoint, mntDir) < 0) + return -1; + + /* If it is a co-mount it has a filename like "cpu,cpuacct" + * and we must identify the symlink path */ + if (virCgroupV1ResolveMountLink(mntDir, typestr, controller) <= 0) + return -1; + } + } + + return 0; +} + + +static int +virCgroupV1DetectPlacement(virCgroupPtr group, + const char *path, + const char *controllers, + const char *selfpath) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + const char *typestr =3D virCgroupV1ControllerTypeToString(i); + + if (virCgroupV1MountOptsMatchController(controllers, typestr) && + group->controllers[i].mountPoint !=3D NULL && + group->controllers[i].placement =3D=3D NULL) { + /* + * selfpath =3D=3D "/" + path=3D"" -> "/" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/li= bvirt.service" + * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "= /libvirt.service/foo" + */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { + if (VIR_STRDUP(group->controllers[i].placement, + selfpath) < 0) + return -1; + } else { + if (virAsprintf(&group->controllers[i].placement, + "%s%s%s", selfpath, + (STREQ(selfpath, "/") || + STREQ(path, "") ? "" : "/"), + path) < 0) + return -1; + } + } + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 .available =3D virCgroupV1Available, .validateMachineGroup =3D virCgroupV1ValidateMachineGroup, .copyMounts =3D virCgroupV1CopyMounts, + .detectMounts =3D virCgroupV1DetectMounts, + .detectPlacement =3D virCgroupV1DetectPlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285607236348.24591258004966; Tue, 18 Sep 2018 08:46:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1B1580F6C; Tue, 18 Sep 2018 15:46:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C423308BDA1; Tue, 18 Sep 2018 15:46:41 +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 E2E704A46C; Tue, 18 Sep 2018 15:46:40 +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 w8IFkK3Z011956 for ; Tue, 18 Sep 2018 11:46:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 366964DC48; Tue, 18 Sep 2018 15:46:20 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55BDC5D9C7 for ; Tue, 18 Sep 2018 15:46:19 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:29 +0200 Message-Id: <55d95eff241d32b8bc9f2857ae151c2e8ae7e33d.1537285203.git.phrdina@redhat.com> 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 08/47] vircgroup: extract virCgroupV1CopyPlacement 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.84 on 10.5.11.24 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:42 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 38 +------------------------------------ src/util/vircgroupbackend.h | 6 ++++++ src/util/vircgroupv1.c | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 7557fc5576..0fcb047a0c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -271,42 +271,6 @@ virCgroupDetectMounts(virCgroupPtr group) } =20 =20 -static int -virCgroupCopyPlacement(virCgroupPtr group, - const char *path, - virCgroupPtr parent) -{ - size_t i; - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) - continue; - - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - if (path[0] =3D=3D '/') { - if (VIR_STRDUP(group->controllers[i].placement, path) < 0) - return -1; - } else { - /* - * parent =3D=3D "/" + path=3D"" =3D> "/" - * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/li= bvirt.service" - * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "= /libvirt.service/foo" - */ - if (virAsprintf(&group->controllers[i].placement, - "%s%s%s", - parent->controllers[i].placement, - (STREQ(parent->controllers[i].placement, "/") = || - STREQ(path, "") ? "" : "/"), - path) < 0) - return -1; - } - } - - return 0; -} - - /* * virCgroupDetectPlacement: * @group: the group to process @@ -534,7 +498,7 @@ virCgroupDetect(virCgroupPtr group, * based on the parent cgroup... */ if ((parent || path[0] =3D=3D '/') && - virCgroupCopyPlacement(group, path, parent) < 0) + group->backend->copyPlacement(group, path, parent) < 0) return -1; =20 /* ... but use /proc/cgroups to fill in the rest */ diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index fadc7efdcf..85906e7191 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -45,6 +45,11 @@ typedef int (*virCgroupCopyMountsCB)(virCgroupPtr group, virCgroupPtr parent); =20 +typedef int +(*virCgroupCopyPlacementCB)(virCgroupPtr group, + const char *path, + virCgroupPtr parent); + typedef int (*virCgroupDetectMountsCB)(virCgroupPtr group, const char *mntType, @@ -64,6 +69,7 @@ struct _virCgroupBackend { virCgroupAvailableCB available; virCgroupValidateMachineGroupCB validateMachineGroup; virCgroupCopyMountsCB copyMounts; + virCgroupCopyPlacementCB copyPlacement; virCgroupDetectMountsCB detectMounts; virCgroupDetectPlacementCB detectPlacement; }; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2882a19be2..f73f40db0e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -182,6 +182,42 @@ virCgroupV1CopyMounts(virCgroupPtr group, } =20 =20 +static int +virCgroupV1CopyPlacement(virCgroupPtr group, + const char *path, + virCgroupPtr parent) +{ + size_t i; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!group->controllers[i].mountPoint) + continue; + + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + if (path[0] =3D=3D '/') { + if (VIR_STRDUP(group->controllers[i].placement, path) < 0) + return -1; + } else { + /* + * parent =3D=3D "/" + path=3D"" =3D> "/" + * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/li= bvirt.service" + * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "= /libvirt.service/foo" + */ + if (virAsprintf(&group->controllers[i].placement, + "%s%s%s", + parent->controllers[i].placement, + (STREQ(parent->controllers[i].placement, "/") = || + STREQ(path, "") ? "" : "/"), + path) < 0) + return -1; + } + } + + return 0; +} + + static int virCgroupV1ResolveMountLink(const char *mntDir, const char *typeStr, @@ -342,6 +378,7 @@ virCgroupBackend virCgroupV1Backend =3D { .available =3D virCgroupV1Available, .validateMachineGroup =3D virCgroupV1ValidateMachineGroup, .copyMounts =3D virCgroupV1CopyMounts, + .copyPlacement =3D virCgroupV1CopyPlacement, .detectMounts =3D virCgroupV1DetectMounts, .detectPlacement =3D virCgroupV1DetectPlacement, }; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285617424690.8360831448991; Tue, 18 Sep 2018 08:46:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C08B93084034; Tue, 18 Sep 2018 15:46:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6EE4A106A7BB; Tue, 18 Sep 2018 15:46:53 +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 D5C0F4A470; Tue, 18 Sep 2018 15:46:52 +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 w8IFkL4i011971 for ; Tue, 18 Sep 2018 11:46:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 33C074F9A1; Tue, 18 Sep 2018 15:46:21 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 845564DC48 for ; Tue, 18 Sep 2018 15:46:20 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:30 +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 09/47] vircgroup: extract virCgroupV1ValidatePlacement 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 18 Sep 2018 15:46:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 32 +------------------------------- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0fcb047a0c..864dd876b0 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -351,36 +351,6 @@ virCgroupDetectPlacement(virCgroupPtr group, } =20 =20 -static int -virCgroupValidatePlacement(virCgroupPtr group, - pid_t pid) -{ - size_t i; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) - continue; - - if (!group->controllers[i].placement) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find placement for controller %s a= t %s"), - virCgroupControllerTypeToString(i), - group->controllers[i].placement); - return -1; - } - - VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld", - i, - virCgroupControllerTypeToString(i), - group->controllers[i].mountPoint, - group->controllers[i].placement, - (long long) pid); - } - - return 0; -} - - static int virCgroupDetectControllers(virCgroupPtr group, int controllers) @@ -506,7 +476,7 @@ virCgroupDetect(virCgroupPtr group, return -1; =20 /* Check that for every mounted controller, we found our placement */ - if (virCgroupValidatePlacement(group, pid) < 0) + if (group->backend->validatePlacement(group, pid) < 0) return -1; =20 return 0; diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 85906e7191..086cfb8090 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -62,6 +62,10 @@ typedef int const char *controllers, const char *selfpath); =20 +typedef int +(*virCgroupValidatePlacementCB)(virCgroupPtr group, + pid_t pid); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -72,6 +76,7 @@ struct _virCgroupBackend { virCgroupCopyPlacementCB copyPlacement; virCgroupDetectMountsCB detectMounts; virCgroupDetectPlacementCB detectPlacement; + virCgroupValidatePlacementCB validatePlacement; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index f73f40db0e..68df323d72 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -372,6 +372,36 @@ virCgroupV1DetectPlacement(virCgroupPtr group, } =20 =20 +static int +virCgroupV1ValidatePlacement(virCgroupPtr group, + pid_t pid) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!group->controllers[i].mountPoint) + continue; + + if (!group->controllers[i].placement) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find placement for v1 controller %= s at %s"), + virCgroupV1ControllerTypeToString(i), + group->controllers[i].placement); + return -1; + } + + VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld", + i, + virCgroupV1ControllerTypeToString(i), + group->controllers[i].mountPoint, + group->controllers[i].placement, + (long long) pid); + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -381,6 +411,7 @@ virCgroupBackend virCgroupV1Backend =3D { .copyPlacement =3D virCgroupV1CopyPlacement, .detectMounts =3D virCgroupV1DetectMounts, .detectPlacement =3D virCgroupV1DetectPlacement, + .validatePlacement =3D virCgroupV1ValidatePlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285610734490.1557588715974; Tue, 18 Sep 2018 08:46:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE58BA0C39; Tue, 18 Sep 2018 15:46:47 +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 81EEE106A7B2; Tue, 18 Sep 2018 15:46:47 +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 D980F181A369; Tue, 18 Sep 2018 15:46:46 +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 w8IFkMQ6011981 for ; Tue, 18 Sep 2018 11:46:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B3EA4DC48; Tue, 18 Sep 2018 15:46:22 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81F265D9C7 for ; Tue, 18 Sep 2018 15:46:21 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:31 +0200 Message-Id: <5989e7e9aba0047893b84bf3cb8d29397ab8b342.1537285203.git.phrdina@redhat.com> 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 10/47] vircgroup: extract virCgroupV1GetPlacement 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:46:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 3 +-- src/util/vircgroupbackend.h | 4 ++++ src/util/vircgroupv1.c | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 864dd876b0..ff102e2cb0 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1317,8 +1317,7 @@ virCgroupNewMachineSystemd(const char *name, &init) < 0) return -1; =20 - path =3D init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement; - init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement =3D NULL; + path =3D init->backend->getPlacement(init); virCgroupFree(&init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 086cfb8090..1856164c6b 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -66,6 +66,9 @@ typedef int (*virCgroupValidatePlacementCB)(virCgroupPtr group, pid_t pid); =20 +typedef char * +(*virCgroupGetPlacementCB)(virCgroupPtr group); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -77,6 +80,7 @@ struct _virCgroupBackend { virCgroupDetectMountsCB detectMounts; virCgroupDetectPlacementCB detectPlacement; virCgroupValidatePlacementCB validatePlacement; + virCgroupGetPlacementCB getPlacement; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 68df323d72..ab8988cd59 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -402,6 +402,17 @@ virCgroupV1ValidatePlacement(virCgroupPtr group, } =20 =20 +static char * +virCgroupV1GetPlacement(virCgroupPtr group) +{ + char *ret =3D NULL; + + ignore_value(VIR_STRDUP(ret, group->controllers[VIR_CGROUP_CONTROLLER_= SYSTEMD].placement)); + + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -412,6 +423,7 @@ virCgroupBackend virCgroupV1Backend =3D { .detectMounts =3D virCgroupV1DetectMounts, .detectPlacement =3D virCgroupV1DetectPlacement, .validatePlacement =3D virCgroupV1ValidatePlacement, + .getPlacement =3D virCgroupV1GetPlacement, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 15372856166016.0635226803644855; Tue, 18 Sep 2018 08:46:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6681462E83; Tue, 18 Sep 2018 15:46:54 +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 2E1825D9C7; Tue, 18 Sep 2018 15:46:54 +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 C97E2181A531; Tue, 18 Sep 2018 15:46:53 +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 w8IFkMim011988 for ; Tue, 18 Sep 2018 11:46:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id D50F24DC48; Tue, 18 Sep 2018 15:46:22 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 594B85D9C7 for ; Tue, 18 Sep 2018 15:46:22 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:32 +0200 Message-Id: <0220967781a24ca17b665a9222b7e7c2445f83e5.1537285203.git.phrdina@redhat.com> 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 11/47] vircgroup: extract virCgroupV1DetectControllers 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:46:55 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 66 +------------------------------------ src/util/vircgroupbackend.h | 5 +++ src/util/vircgroupv1.c | 65 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 65 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index ff102e2cb0..7822eec683 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -351,70 +351,6 @@ virCgroupDetectPlacement(virCgroupPtr group, } =20 =20 -static int -virCgroupDetectControllers(virCgroupPtr group, - int controllers) -{ - size_t i; - size_t j; - - if (controllers >=3D 0) { - VIR_DEBUG("Filtering controllers %d", controllers); - /* First mark requested but non-existing controllers to be ignored= */ - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (((1 << i) & controllers)) { - /* Remove non-existent controllers */ - if (!group->controllers[i].mountPoint) { - VIR_DEBUG("Requested controller '%s' not mounted, igno= ring", - virCgroupControllerTypeToString(i)); - controllers &=3D ~(1 << i); - } - } - } - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_DEBUG("Controller '%s' wanted=3D%s, mount=3D'%s'", - virCgroupControllerTypeToString(i), - (1 << i) & controllers ? "yes" : "no", - NULLSTR(group->controllers[i].mountPoint)); - if (!((1 << i) & controllers) && - group->controllers[i].mountPoint) { - /* Check whether a request to disable a controller - * clashes with co-mounting of controllers */ - for (j =3D 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) { - if (j =3D=3D i) - continue; - if (!((1 << j) & controllers)) - continue; - - if (STREQ_NULLABLE(group->controllers[i].mountPoint, - group->controllers[j].mountPoint)) { - virReportSystemError(EINVAL, - _("Controller '%s' is not wan= ted, but '%s' is co-mounted"), - virCgroupControllerTypeToStri= ng(i), - virCgroupControllerTypeToStri= ng(j)); - return -1; - } - } - VIR_FREE(group->controllers[i].mountPoint); - } - } - } else { - VIR_DEBUG("Auto-detecting controllers"); - controllers =3D 0; - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_DEBUG("Controller '%s' present=3D%s", - virCgroupControllerTypeToString(i), - group->controllers[i].mountPoint ? "yes" : "no"); - if (group->controllers[i].mountPoint =3D=3D NULL) - continue; - controllers |=3D (1 << i); - } - } - - return controllers; -} - - static int virCgroupDetect(virCgroupPtr group, pid_t pid, @@ -453,7 +389,7 @@ virCgroupDetect(virCgroupPtr group, return -1; } =20 - rc =3D virCgroupDetectControllers(group, controllers); + rc =3D group->backend->detectControllers(group, controllers); if (rc < 0) return -1; =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 1856164c6b..31be70688c 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -69,6 +69,10 @@ typedef int typedef char * (*virCgroupGetPlacementCB)(virCgroupPtr group); =20 +typedef int +(*virCgroupDetectControllersCB)(virCgroupPtr group, + int controllers); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -81,6 +85,7 @@ struct _virCgroupBackend { virCgroupDetectPlacementCB detectPlacement; virCgroupValidatePlacementCB validatePlacement; virCgroupGetPlacementCB getPlacement; + virCgroupDetectControllersCB detectControllers; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index ab8988cd59..4dbb3020f5 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -413,6 +413,70 @@ virCgroupV1GetPlacement(virCgroupPtr group) } =20 =20 +static int +virCgroupV1DetectControllers(virCgroupPtr group, + int controllers) +{ + size_t i; + size_t j; + + if (controllers >=3D 0) { + VIR_DEBUG("Filtering controllers %d", controllers); + /* First mark requested but non-existing controllers to be ignored= */ + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (((1 << i) & controllers)) { + /* Remove non-existent controllers */ + if (!group->controllers[i].mountPoint) { + VIR_DEBUG("Requested controller '%s' not mounted, igno= ring", + virCgroupV1ControllerTypeToString(i)); + controllers &=3D ~(1 << i); + } + } + } + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_DEBUG("Controller '%s' wanted=3D%s, mount=3D'%s'", + virCgroupV1ControllerTypeToString(i), + (1 << i) & controllers ? "yes" : "no", + NULLSTR(group->controllers[i].mountPoint)); + if (!((1 << i) & controllers) && + group->controllers[i].mountPoint) { + /* Check whether a request to disable a controller + * clashes with co-mounting of controllers */ + for (j =3D 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) { + if (j =3D=3D i) + continue; + if (!((1 << j) & controllers)) + continue; + + if (STREQ_NULLABLE(group->controllers[i].mountPoint, + group->controllers[j].mountPoint)) { + virReportSystemError(EINVAL, + _("V1 controller '%s' is not = wanted, but '%s' is co-mounted"), + virCgroupV1ControllerTypeToSt= ring(i), + virCgroupV1ControllerTypeToSt= ring(j)); + return -1; + } + } + VIR_FREE(group->controllers[i].mountPoint); + } + } + } else { + VIR_DEBUG("Auto-detecting controllers"); + controllers =3D 0; + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_DEBUG("Controller '%s' present=3D%s", + virCgroupV1ControllerTypeToString(i), + group->controllers[i].mountPoint ? "yes" : "no"); + if (group->controllers[i].mountPoint =3D=3D NULL) + continue; + controllers |=3D (1 << i); + } + } + + return controllers; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -424,6 +488,7 @@ virCgroupBackend virCgroupV1Backend =3D { .detectPlacement =3D virCgroupV1DetectPlacement, .validatePlacement =3D virCgroupV1ValidatePlacement, .getPlacement =3D virCgroupV1GetPlacement, + .detectControllers =3D virCgroupV1DetectControllers, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285622099204.99811471361897; Tue, 18 Sep 2018 08:47:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6CC63082261; Tue, 18 Sep 2018 15:46:59 +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 9F2A8187AF; Tue, 18 Sep 2018 15:46:59 +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 310F9181A721; Tue, 18 Sep 2018 15:46:59 +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 w8IFkNqc011999 for ; Tue, 18 Sep 2018 11:46:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1CB35D9C7; Tue, 18 Sep 2018 15:46:23 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2ECC582213 for ; Tue, 18 Sep 2018 15:46:23 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:33 +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 12/47] vircgroup: extract virCgroupV1HasController 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Tue, 18 Sep 2018 15:47:00 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 3 ++- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 7822eec683..3d10ac2427 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1437,7 +1437,8 @@ virCgroupHasController(virCgroupPtr cgroup, int contr= oller) return false; if (controller < 0 || controller >=3D VIR_CGROUP_CONTROLLER_LAST) return false; - return cgroup->controllers[controller].mountPoint !=3D NULL; + + return cgroup->backend->hasController(cgroup, controller); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 31be70688c..8b751af355 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -73,6 +73,10 @@ typedef int (*virCgroupDetectControllersCB)(virCgroupPtr group, int controllers); =20 +typedef bool +(*virCgroupHasControllerCB)(virCgroupPtr cgroup, + int controller); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -86,6 +90,7 @@ struct _virCgroupBackend { virCgroupValidatePlacementCB validatePlacement; virCgroupGetPlacementCB getPlacement; virCgroupDetectControllersCB detectControllers; + virCgroupHasControllerCB hasController; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 4dbb3020f5..c040d50141 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -477,6 +477,14 @@ virCgroupV1DetectControllers(virCgroupPtr group, } =20 =20 +static bool +virCgroupV1HasController(virCgroupPtr group, + int controller) +{ + return group->controllers[controller].mountPoint !=3D NULL; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -489,6 +497,7 @@ virCgroupBackend virCgroupV1Backend =3D { .validatePlacement =3D virCgroupV1ValidatePlacement, .getPlacement =3D virCgroupV1GetPlacement, .detectControllers =3D virCgroupV1DetectControllers, + .hasController =3D virCgroupV1HasController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285627338595.3144283386368; Tue, 18 Sep 2018 08:47:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 472533084049; Tue, 18 Sep 2018 15:47:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 00F885D9C7; Tue, 18 Sep 2018 15:47:04 +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 9540B4A478; Tue, 18 Sep 2018 15:47:04 +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 w8IFkOMM012011 for ; Tue, 18 Sep 2018 11:46:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id A8C394DC48; Tue, 18 Sep 2018 15:46:24 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D5FC5D9C7 for ; Tue, 18 Sep 2018 15:46:24 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:34 +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 13/47] vircgroup: extract virCgroupV1GetAnyController 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 18 Sep 2018 15:47:06 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 16 ++++------------ src/util/vircgroupbackend.h | 4 ++++ src/util/vircgroupv1.c | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 3d10ac2427..817ee8f6ca 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3167,19 +3167,11 @@ virCgroupPathOfAnyController(virCgroupPtr group, const char *name, char **keypath) { - size_t i; + int controller; =20 - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - /* Reject any controller with a placement - * of '/' to avoid doing bad stuff to the root - * cgroup - */ - if (group->controllers[i].mountPoint && - group->controllers[i].placement && - STRNEQ(group->controllers[i].placement, "/")) { - return virCgroupPathOfController(group, i, name, keypath); - } - } + controller =3D group->backend->getAnyController(group); + if (controller >=3D 0) + return virCgroupPathOfController(group, controller, name, keypath); =20 virReportSystemError(ENOSYS, "%s", _("No controllers are mounted")); diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 8b751af355..933f59151a 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -77,6 +77,9 @@ typedef bool (*virCgroupHasControllerCB)(virCgroupPtr cgroup, int controller); =20 +typedef int +(*virCgroupGetAnyControllerCB)(virCgroupPtr group); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -91,6 +94,7 @@ struct _virCgroupBackend { virCgroupGetPlacementCB getPlacement; virCgroupDetectControllersCB detectControllers; virCgroupHasControllerCB hasController; + virCgroupGetAnyControllerCB getAnyController; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c040d50141..105024ddde 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -485,6 +485,27 @@ virCgroupV1HasController(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetAnyController(virCgroupPtr group) +{ + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + /* Reject any controller with a placement + * of '/' to avoid doing bad stuff to the root + * cgroup + */ + if (group->controllers[i].mountPoint && + group->controllers[i].placement && + STRNEQ(group->controllers[i].placement, "/")) { + return i; + } + } + + return -1; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -498,6 +519,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getPlacement =3D virCgroupV1GetPlacement, .detectControllers =3D virCgroupV1DetectControllers, .hasController =3D virCgroupV1HasController, + .getAnyController =3D virCgroupV1GetAnyController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285621725971.4173440362325; Tue, 18 Sep 2018 08:47:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D97C1CFFB; Tue, 18 Sep 2018 15:46:58 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83FB282AD2; Tue, 18 Sep 2018 15:46:58 +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 20A4C4A46D; Tue, 18 Sep 2018 15:46:58 +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 w8IFkP05012037 for ; Tue, 18 Sep 2018 11:46:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DBEA82216; Tue, 18 Sep 2018 15:46:25 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02BAB5D9C7 for ; Tue, 18 Sep 2018 15:46:24 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:35 +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 14/47] vircgroup: extract virCgroupV1PathOfController 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Sep 2018 15:46:59 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 22 +--------------------- src/util/vircgroupbackend.h | 7 +++++++ src/util/vircgroupv1.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 817ee8f6ca..55122a5ab9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1454,27 +1454,7 @@ virCgroupPathOfController(virCgroupPtr group, return -1; } =20 - if (group->controllers[controller].mountPoint =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not mounted"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (group->controllers[controller].placement =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Controller '%s' is not enabled for group"), - virCgroupControllerTypeToString(controller)); - return -1; - } - - if (virAsprintf(path, "%s%s/%s", - group->controllers[controller].mountPoint, - group->controllers[controller].placement, - key ? key : "") < 0) - return -1; - - return 0; + return group->backend->pathOfController(group, controller, key, path); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 933f59151a..cf000529c4 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -80,6 +80,12 @@ typedef bool typedef int (*virCgroupGetAnyControllerCB)(virCgroupPtr group); =20 +typedef int +(*virCgroupPathOfControllerCB)(virCgroupPtr group, + int controller, + const char *key, + char **path); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -95,6 +101,7 @@ struct _virCgroupBackend { virCgroupDetectControllersCB detectControllers; virCgroupHasControllerCB hasController; virCgroupGetAnyControllerCB getAnyController; + virCgroupPathOfControllerCB pathOfController; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 105024ddde..7d92150dc3 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -506,6 +506,36 @@ virCgroupV1GetAnyController(virCgroupPtr group) } =20 =20 +static int +virCgroupV1PathOfController(virCgroupPtr group, + int controller, + const char *key, + char **path) +{ + if (group->controllers[controller].mountPoint =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("v1 controller '%s' is not mounted"), + virCgroupV1ControllerTypeToString(controller)); + return -1; + } + + if (group->controllers[controller].placement =3D=3D NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("v1 controller '%s' is not enabled for group"), + virCgroupV1ControllerTypeToString(controller)); + return -1; + } + + if (virAsprintf(path, "%s%s/%s", + group->controllers[controller].mountPoint, + group->controllers[controller].placement, + key ? key : "") < 0) + return -1; + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -520,6 +550,7 @@ virCgroupBackend virCgroupV1Backend =3D { .detectControllers =3D virCgroupV1DetectControllers, .hasController =3D virCgroupV1HasController, .getAnyController =3D virCgroupV1GetAnyController, + .pathOfController =3D virCgroupV1PathOfController, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285609412849.837326990881; Tue, 18 Sep 2018 08:46:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2276A750D5; Tue, 18 Sep 2018 15:46:47 +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 626942CFBC; Tue, 18 Sep 2018 15:46:46 +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 CB1BC1800533; Tue, 18 Sep 2018 15:46:45 +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 w8IFkQMJ012150 for ; Tue, 18 Sep 2018 11:46:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7B10E82216; Tue, 18 Sep 2018 15:46:26 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC1FB5D9C7 for ; Tue, 18 Sep 2018 15:46:25 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:36 +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 15/47] vircgroup: extract virCgroupV1MakeGroup 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:46:47 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 141 ++---------------------------------- src/util/vircgroupbackend.h | 15 ++++ src/util/vircgrouppriv.h | 20 +++++ src/util/vircgroupv1.c | 132 +++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+), 134 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 55122a5ab9..8083e4596d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -80,14 +80,6 @@ VIR_ENUM_IMPL(virCgroupController, VIR_CGROUP_CONTROLLER= _LAST, "freezer", "blkio", "net_cls", "perf_event", "name=3Dsystemd"); =20 -typedef enum { - VIR_CGROUP_NONE =3D 0, /* create subdir under each cgroup if possible.= */ - VIR_CGROUP_MEM_HIERACHY =3D 1 << 0, /* call virCgroupSetMemoryUseHiera= rchy - * before creating subcgroups and - * attaching tasks - */ -} virCgroupFlags; - =20 /** * virCgroupGetDevicePermsString: @@ -448,7 +440,7 @@ virCgroupGetBlockDevString(const char *path) } =20 =20 -static int +int virCgroupSetValueStr(virCgroupPtr group, int controller, const char *key, @@ -478,7 +470,7 @@ virCgroupSetValueStr(virCgroupPtr group, } =20 =20 -static int +int virCgroupGetValueStr(virCgroupPtr group, int controller, const char *key, @@ -539,7 +531,7 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, } =20 =20 -static int +int virCgroupSetValueU64(virCgroupPtr group, int controller, const char *key, @@ -591,7 +583,7 @@ virCgroupGetValueI64(virCgroupPtr group, } =20 =20 -static int +int virCgroupGetValueU64(virCgroupPtr group, int controller, const char *key, @@ -613,137 +605,18 @@ virCgroupGetValueU64(virCgroupPtr group, } =20 =20 -static int -virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPtr group) -{ - size_t i; - const char *inherit_values[] =3D { - "cpuset.cpus", - "cpuset.mems", - "cpuset.memory_migrate", - }; - - VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path= ); - for (i =3D 0; i < ARRAY_CARDINALITY(inherit_values); i++) { - VIR_AUTOFREE(char *) value =3D NULL; - - if (virCgroupGetValueStr(parent, - VIR_CGROUP_CONTROLLER_CPUSET, - inherit_values[i], - &value) < 0) - return -1; - - VIR_DEBUG("Inherit %s =3D %s", inherit_values[i], value); - - if (virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - inherit_values[i], - value) < 0) - return -1; - } - - return 0; -} - - -static int -virCgroupSetMemoryUseHierarchy(virCgroupPtr group) -{ - unsigned long long value; - const char *filename =3D "memory.use_hierarchy"; - - if (virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - filename, &value) < 0) - return -1; - - /* Setting twice causes error, so if already enabled, skip setting */ - if (value =3D=3D 1) - return 0; - - VIR_DEBUG("Setting up %s/%s", group->path, filename); - if (virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - filename, 1) < 0) - return -1; - - return 0; -} - - static int virCgroupMakeGroup(virCgroupPtr parent, virCgroupPtr group, bool create, unsigned int flags) { - size_t i; - - VIR_DEBUG("Make group %s", group->path); - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_AUTOFREE(char *) path =3D NULL; - - /* We must never mkdir() in systemd's hierarchy */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { - VIR_DEBUG("Not creating systemd controller group"); - continue; - } - - /* Skip over controllers that aren't mounted */ - if (!group->controllers[i].mountPoint) { - VIR_DEBUG("Skipping unmounted controller %s", - virCgroupControllerTypeToString(i)); - continue; - } - - if (virCgroupPathOfController(group, i, "", &path) < 0) - goto error; - - VIR_DEBUG("Make controller %s", path); - if (!virFileExists(path)) { - if (!create || - mkdir(path, 0755) < 0) { - if (errno =3D=3D EEXIST) - continue; - /* With a kernel that doesn't support multi-level directory - * for blkio controller, libvirt will fail and disable all - * other controllers even though they are available. So - * treat blkio as unmounted if mkdir fails. */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_BLKIO) { - VIR_DEBUG("Ignoring mkdir failure with blkio controlle= r. Kernel probably too old"); - VIR_FREE(group->controllers[i].mountPoint); - continue; - } else { - virReportSystemError(errno, - _("Failed to create controller %s= for group"), - virCgroupControllerTypeToString(i= )); - goto error; - } - } - if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET && - group->controllers[i].mountPoint !=3D NULL && - virCgroupCpuSetInherit(parent, group) < 0) { - goto error; - } - /* - * Note that virCgroupSetMemoryUseHierarchy should always be - * called prior to creating subcgroups and attaching tasks. - */ - if ((flags & VIR_CGROUP_MEM_HIERACHY) && - i =3D=3D VIR_CGROUP_CONTROLLER_MEMORY && - group->controllers[i].mountPoint !=3D NULL && - virCgroupSetMemoryUseHierarchy(group) < 0) { - goto error; - } - } + if (group->backend->makeGroup(parent, group, create, flags) < 0) { + virCgroupRemove(group); + return -1; } =20 - VIR_DEBUG("Done making controllers for group"); return 0; - - error: - virCgroupRemove(group); - return -1; } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index cf000529c4..214c9f0726 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -27,6 +27,14 @@ =20 # define CGROUP_MAX_VAL 512 =20 +typedef enum { + VIR_CGROUP_NONE =3D 0, /* create subdir under each cgroup if possible.= */ + VIR_CGROUP_MEM_HIERACHY =3D 1 << 0, /* call virCgroupSetMemoryUseHiera= rchy + * before creating subcgroups and + * attaching tasks + */ +} virCgroupBackendFlags; + typedef enum { VIR_CGROUP_BACKEND_TYPE_V1 =3D 0, VIR_CGROUP_BACKEND_TYPE_LAST, @@ -86,6 +94,12 @@ typedef int const char *key, char **path); =20 +typedef int +(*virCgroupMakeGroupCB)(virCgroupPtr parent, + virCgroupPtr group, + bool create, + unsigned int flags); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -102,6 +116,7 @@ struct _virCgroupBackend { virCgroupHasControllerCB hasController; virCgroupGetAnyControllerCB getAnyController; virCgroupPathOfControllerCB pathOfController; + virCgroupMakeGroupCB makeGroup; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index e7f4a1f0fc..2e731458d5 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -53,6 +53,26 @@ struct _virCgroup { virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 +int virCgroupSetValueStr(virCgroupPtr group, + int controller, + const char *key, + const char *value); + +int virCgroupGetValueStr(virCgroupPtr group, + int controller, + const char *key, + char **value); + +int virCgroupSetValueU64(virCgroupPtr group, + int controller, + const char *key, + unsigned long long int value); + +int virCgroupGetValueU64(virCgroupPtr group, + int controller, + const char *key, + unsigned long long int *value); + int virCgroupPartitionEscape(char **path); =20 int virCgroupNewPartition(const char *path, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 7d92150dc3..cf484216cc 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -536,6 +536,137 @@ virCgroupV1PathOfController(virCgroupPtr group, } =20 =20 +static int +virCgroupV1CpuSetInherit(virCgroupPtr parent, + virCgroupPtr group) +{ + size_t i; + const char *inherit_values[] =3D { + "cpuset.cpus", + "cpuset.mems", + "cpuset.memory_migrate", + }; + + VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path= ); + for (i =3D 0; i < ARRAY_CARDINALITY(inherit_values); i++) { + VIR_AUTOFREE(char *) value =3D NULL; + + if (virCgroupGetValueStr(parent, + VIR_CGROUP_CONTROLLER_CPUSET, + inherit_values[i], + &value) < 0) + return -1; + + VIR_DEBUG("Inherit %s =3D %s", inherit_values[i], value); + + if (virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + inherit_values[i], + value) < 0) + return -1; + } + + return 0; +} + + +static int +virCgroupV1SetMemoryUseHierarchy(virCgroupPtr group) +{ + unsigned long long value; + const char *filename =3D "memory.use_hierarchy"; + + if (virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + filename, &value) < 0) + return -1; + + /* Setting twice causes error, so if already enabled, skip setting */ + if (value =3D=3D 1) + return 0; + + VIR_DEBUG("Setting up %s/%s", group->path, filename); + if (virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + filename, 1) < 0) + return -1; + + return 0; +} + + +static int +virCgroupV1MakeGroup(virCgroupPtr parent, + virCgroupPtr group, + bool create, + unsigned int flags) +{ + size_t i; + + VIR_DEBUG("Make group %s", group->path); + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) path =3D NULL; + + /* We must never mkdir() in systemd's hierarchy */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { + VIR_DEBUG("Not creating systemd controller group"); + continue; + } + + /* Skip over controllers that aren't mounted */ + if (!group->controllers[i].mountPoint) { + VIR_DEBUG("Skipping unmounted controller %s", + virCgroupV1ControllerTypeToString(i)); + continue; + } + + if (virCgroupV1PathOfController(group, i, "", &path) < 0) + return -1; + + VIR_DEBUG("Make controller %s", path); + if (!virFileExists(path)) { + if (!create || + mkdir(path, 0755) < 0) { + if (errno =3D=3D EEXIST) + continue; + /* With a kernel that doesn't support multi-level directory + * for blkio controller, libvirt will fail and disable all + * other controllers even though they are available. So + * treat blkio as unmounted if mkdir fails. */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_BLKIO) { + VIR_DEBUG("Ignoring mkdir failure with blkio controlle= r. Kernel probably too old"); + VIR_FREE(group->controllers[i].mountPoint); + continue; + } else { + virReportSystemError(errno, + _("Failed to create v1 controller= %s for group"), + virCgroupV1ControllerTypeToString= (i)); + return -1; + } + } + if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET && + group->controllers[i].mountPoint !=3D NULL && + virCgroupV1CpuSetInherit(parent, group) < 0) { + return -1; + } + /* + * Note that virCgroupV1SetMemoryUseHierarchy should always be + * called prior to creating subcgroups and attaching tasks. + */ + if ((flags & VIR_CGROUP_MEM_HIERACHY) && + i =3D=3D VIR_CGROUP_CONTROLLER_MEMORY && + group->controllers[i].mountPoint !=3D NULL && + virCgroupV1SetMemoryUseHierarchy(group) < 0) { + return -1; + } + } + } + + VIR_DEBUG("Done making controllers for group"); + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -551,6 +682,7 @@ virCgroupBackend virCgroupV1Backend =3D { .hasController =3D virCgroupV1HasController, .getAnyController =3D virCgroupV1GetAnyController, .pathOfController =3D virCgroupV1PathOfController, + .makeGroup =3D virCgroupV1MakeGroup, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285617400718.0196233530129; Tue, 18 Sep 2018 08:46:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C78A811A9; Tue, 18 Sep 2018 15:46:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B927F82AEB; Tue, 18 Sep 2018 15:46:52 +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 3FD894A46D; Tue, 18 Sep 2018 15:46:52 +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 w8IFkR2W012192 for ; Tue, 18 Sep 2018 11:46:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50E254DC48; Tue, 18 Sep 2018 15:46:27 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C97F982AD2 for ; Tue, 18 Sep 2018 15:46:26 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:37 +0200 Message-Id: <079330bd135229b9eb3e13c3c968c9379bc11eb8.1537285203.git.phrdina@redhat.com> 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 16/47] vircgroup: extract virCgroupV1Remove 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.14 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:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 35 ++------------------------------- src/util/vircgroupbackend.h | 4 ++++ src/util/vircgrouppriv.h | 2 ++ src/util/vircgroupv1.c | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8083e4596d..37bfd7893c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2917,7 +2917,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, ch= ar **usage) } =20 =20 -static int +int virCgroupRemoveRecursively(char *grppath) { DIR *grpdir; @@ -2980,38 +2980,7 @@ virCgroupRemoveRecursively(char *grppath) int virCgroupRemove(virCgroupPtr group) { - int rc =3D 0; - size_t i; - - VIR_DEBUG("Removing cgroup %s", group->path); - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_AUTOFREE(char *) grppath =3D NULL; - - /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) - continue; - - /* We must never rmdir() in systemd's hierarchy */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) - continue; - - /* Don't delete the root group, if we accidentally - ended up in it for some reason */ - if (STREQ(group->controllers[i].placement, "/")) - continue; - - if (virCgroupPathOfController(group, - i, - NULL, - &grppath) !=3D 0) - continue; - - VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); - rc =3D virCgroupRemoveRecursively(grppath); - } - VIR_DEBUG("Done removing cgroup %s", group->path); - - return rc; + return group->backend->remove(group); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 214c9f0726..11ed8431cf 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -100,6 +100,9 @@ typedef int bool create, unsigned int flags); =20 +typedef int +(*virCgroupRemoveCB)(virCgroupPtr group); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -117,6 +120,7 @@ struct _virCgroupBackend { virCgroupGetAnyControllerCB getAnyController; virCgroupPathOfControllerCB pathOfController; virCgroupMakeGroupCB makeGroup; + virCgroupRemoveCB remove; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 2e731458d5..a760b9bcfd 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -88,4 +88,6 @@ int virCgroupNewDomainPartition(virCgroupPtr partition, virCgroupPtr *group) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(5); =20 +int virCgroupRemoveRecursively(char *grppath); + #endif /* __VIR_CGROUP_PRIV_H__ */ diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index cf484216cc..25afd39235 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -667,6 +667,44 @@ virCgroupV1MakeGroup(virCgroupPtr parent, } =20 =20 +static int +virCgroupV1Remove(virCgroupPtr group) +{ + int rc =3D 0; + size_t i; + + VIR_DEBUG("Removing cgroup %s", group->path); + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) grppath =3D NULL; + + /* Skip over controllers not mounted */ + if (!group->controllers[i].mountPoint) + continue; + + /* We must never rmdir() in systemd's hierarchy */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) + continue; + + /* Don't delete the root group, if we accidentally + ended up in it for some reason */ + if (STREQ(group->controllers[i].placement, "/")) + continue; + + if (virCgroupV1PathOfController(group, + i, + NULL, + &grppath) !=3D 0) + continue; + + VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); + rc =3D virCgroupRemoveRecursively(grppath); + } + VIR_DEBUG("Done removing cgroup %s", group->path); + + return rc; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -683,6 +721,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getAnyController =3D virCgroupV1GetAnyController, .pathOfController =3D virCgroupV1PathOfController, .makeGroup =3D virCgroupV1MakeGroup, + .remove =3D virCgroupV1Remove, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285633224276.15578213435947; Tue, 18 Sep 2018 08:47:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EB1CA9642; Tue, 18 Sep 2018 15:47:11 +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 BF9EA10694C0; Tue, 18 Sep 2018 15:47:10 +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 5B9A8181AC31; Tue, 18 Sep 2018 15:47:10 +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 w8IFkSSX012263 for ; Tue, 18 Sep 2018 11:46:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 269C44DC48; Tue, 18 Sep 2018 15:46:28 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EE7B5D9C7 for ; Tue, 18 Sep 2018 15:46:27 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:38 +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 17/47] vircgroup: extract virCgroupV1AddTask 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Sep 2018 15:47:12 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 48 +++++-------------------------------- src/util/vircgroupbackend.h | 12 ++++++++++ src/util/vircgrouppriv.h | 5 ++++ src/util/vircgroupv1.c | 31 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 37bfd7893c..5dd736930b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -546,7 +546,7 @@ virCgroupSetValueU64(virCgroupPtr group, } =20 =20 -static int +int virCgroupSetValueI64(virCgroupPtr group, int controller, const char *key, @@ -674,42 +674,6 @@ virCgroupNew(pid_t pid, } =20 =20 -typedef enum { - VIR_CGROUP_TASK_PROCESS =3D 0, - VIR_CGROUP_TASK_SYSTEMD =3D 1 << 0, - VIR_CGROUP_TASK_THREAD =3D 1 << 1, -} virCgroupTaskFlags; - - -static int -virCgroupAddTaskInternal(virCgroupPtr group, - pid_t pid, - unsigned int flags) -{ - int ret =3D -1; - size_t i; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) - continue; - - /* We must never add tasks in systemd's hierarchy - * unless we're intentionally trying to move a - * task into a systemd machine scope */ - if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD && - !(flags & VIR_CGROUP_TASK_SYSTEMD)) - continue; - - if (virCgroupSetValueI64(group, i, "tasks", pid) < 0) - goto cleanup; - } - - ret =3D 0; - cleanup: - return ret; -} - /** * virCgroupAddProcess: * @@ -724,7 +688,7 @@ virCgroupAddTaskInternal(virCgroupPtr group, int virCgroupAddProcess(virCgroupPtr group, pid_t pid) { - return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_PROCESS); + return group->backend->addTask(group, pid, VIR_CGROUP_TASK_PROCESS); } =20 /** @@ -741,9 +705,9 @@ virCgroupAddProcess(virCgroupPtr group, pid_t pid) int virCgroupAddMachineProcess(virCgroupPtr group, pid_t pid) { - return virCgroupAddTaskInternal(group, pid, - VIR_CGROUP_TASK_PROCESS | - VIR_CGROUP_TASK_SYSTEMD); + return group->backend->addTask(group, pid, + VIR_CGROUP_TASK_PROCESS | + VIR_CGROUP_TASK_SYSTEMD); } =20 /** @@ -761,7 +725,7 @@ int virCgroupAddThread(virCgroupPtr group, pid_t pid) { - return virCgroupAddTaskInternal(group, pid, VIR_CGROUP_TASK_THREAD); + return group->backend->addTask(group, pid, VIR_CGROUP_TASK_THREAD); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 11ed8431cf..4661d82132 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -35,6 +35,12 @@ typedef enum { */ } virCgroupBackendFlags; =20 +typedef enum { + VIR_CGROUP_TASK_PROCESS =3D 0, + VIR_CGROUP_TASK_SYSTEMD =3D 1 << 0, + VIR_CGROUP_TASK_THREAD =3D 1 << 1, +} virCgroupBackendTaskFlags; + typedef enum { VIR_CGROUP_BACKEND_TYPE_V1 =3D 0, VIR_CGROUP_BACKEND_TYPE_LAST, @@ -103,6 +109,11 @@ typedef int typedef int (*virCgroupRemoveCB)(virCgroupPtr group); =20 +typedef int +(*virCgroupAddTaskCB)(virCgroupPtr group, + pid_t pid, + unsigned int flags); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -121,6 +132,7 @@ struct _virCgroupBackend { virCgroupPathOfControllerCB pathOfController; virCgroupMakeGroupCB makeGroup; virCgroupRemoveCB remove; + virCgroupAddTaskCB addTask; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index a760b9bcfd..01714370be 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -73,6 +73,11 @@ int virCgroupGetValueU64(virCgroupPtr group, const char *key, unsigned long long int *value); =20 +int virCgroupSetValueI64(virCgroupPtr group, + int controller, + const char *key, + long long int value); + int virCgroupPartitionEscape(char **path); =20 int virCgroupNewPartition(const char *path, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 25afd39235..c9f6fd925a 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -705,6 +705,36 @@ virCgroupV1Remove(virCgroupPtr group) } =20 =20 +static int +virCgroupV1AddTask(virCgroupPtr group, + pid_t pid, + unsigned int flags) +{ + int ret =3D -1; + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + /* Skip over controllers not mounted */ + if (!group->controllers[i].mountPoint) + continue; + + /* We must never add tasks in systemd's hierarchy + * unless we're intentionally trying to move a + * task into a systemd machine scope */ + if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD && + !(flags & VIR_CGROUP_TASK_SYSTEMD)) + continue; + + if (virCgroupSetValueI64(group, i, "tasks", pid) < 0) + goto cleanup; + } + + ret =3D 0; + cleanup: + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -722,6 +752,7 @@ virCgroupBackend virCgroupV1Backend =3D { .pathOfController =3D virCgroupV1PathOfController, .makeGroup =3D virCgroupV1MakeGroup, .remove =3D virCgroupV1Remove, + .addTask =3D virCgroupV1AddTask, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285637718923.4714054023137; Tue, 18 Sep 2018 08:47:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EB21D308212D; Tue, 18 Sep 2018 15:47:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC3737E4C9; Tue, 18 Sep 2018 15:47:15 +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 584EB4A47B; Tue, 18 Sep 2018 15:47:15 +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 w8IFkV7F012380 for ; Tue, 18 Sep 2018 11:46:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id F10F882216; Tue, 18 Sep 2018 15:46:30 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74CBF4F9A1 for ; Tue, 18 Sep 2018 15:46:28 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:39 +0200 Message-Id: <57a7e299d6e43fc1a82e3cd3ddf7de420bdb8635.1537285203.git.phrdina@redhat.com> 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 18/47] vircgroup: extract virCgroupV1HasEmptyTasks 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 18 Sep 2018 15:47:16 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 13 +------------ src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5dd736930b..f5ae23836f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3467,18 +3467,7 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup) int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller) { - int ret =3D -1; - VIR_AUTOFREE(char *) content =3D NULL; - - if (!cgroup) - return -1; - - ret =3D virCgroupGetValueStr(cgroup, controller, "tasks", &content); - - if (ret =3D=3D 0 && content[0] =3D=3D '\0') - ret =3D 1; - - return ret; + return cgroup->backend->hasEmptyTasks(cgroup, controller); } =20 bool diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 4661d82132..1964a48ff0 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -114,6 +114,10 @@ typedef int pid_t pid, unsigned int flags); =20 +typedef int +(*virCgroupHasEmptyTasksCB)(virCgroupPtr cgroup, + int controller); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -133,6 +137,7 @@ struct _virCgroupBackend { virCgroupMakeGroupCB makeGroup; virCgroupRemoveCB remove; virCgroupAddTaskCB addTask; + virCgroupHasEmptyTasksCB hasEmptyTasks; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index c9f6fd925a..57bcb6a685 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -735,6 +735,25 @@ virCgroupV1AddTask(virCgroupPtr group, } =20 =20 +static int +virCgroupV1HasEmptyTasks(virCgroupPtr cgroup, + int controller) +{ + int ret =3D -1; + VIR_AUTOFREE(char *) content =3D NULL; + + if (!cgroup) + return -1; + + ret =3D virCgroupGetValueStr(cgroup, controller, "tasks", &content); + + if (ret =3D=3D 0 && content[0] =3D=3D '\0') + ret =3D 1; + + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -753,6 +772,7 @@ virCgroupBackend virCgroupV1Backend =3D { .makeGroup =3D virCgroupV1MakeGroup, .remove =3D virCgroupV1Remove, .addTask =3D virCgroupV1AddTask, + .hasEmptyTasks =3D virCgroupV1HasEmptyTasks, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285644493212.79184463748982; Tue, 18 Sep 2018 08:47:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 706F730039BA; Tue, 18 Sep 2018 15:47:21 +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 25559308BDAD; Tue, 18 Sep 2018 15:47:21 +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 AC113181A531; Tue, 18 Sep 2018 15:47:20 +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 w8IFkVmU012392 for ; Tue, 18 Sep 2018 11:46:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id CA2144F9A1; Tue, 18 Sep 2018 15:46:31 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C5855D9C7 for ; Tue, 18 Sep 2018 15:46:31 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:40 +0200 Message-Id: <748153255d57c7494ccca8eb55efff28eb4ceff8.1537285203.git.phrdina@redhat.com> 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 19/47] vircgroup: extract virCgroupV1BindMount 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 18 Sep 2018 15:47:22 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 102 +------------------------------- src/util/vircgroupbackend.h | 6 ++ src/util/vircgroupv1.c | 113 ++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 101 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index f5ae23836f..29faf5fb2c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3181,35 +3181,6 @@ virCgroupKillPainfully(virCgroupPtr group) } =20 =20 -static char * -virCgroupIdentifyRoot(virCgroupPtr group) -{ - char *ret =3D NULL; - size_t i; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *tmp; - if (!group->controllers[i].mountPoint) - continue; - if (!(tmp =3D strrchr(group->controllers[i].mountPoint, '/'))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not find directory separator in %s"), - group->controllers[i].mountPoint); - return NULL; - } - - if (VIR_STRNDUP(ret, group->controllers[i].mountPoint, - tmp - group->controllers[i].mountPoint) < 0) - return NULL; - return ret; - } - - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not find any mounted controllers")); - return NULL; -} - - /** * virCgroupGetCpuCfsQuota: * @@ -3304,78 +3275,7 @@ int virCgroupBindMount(virCgroupPtr group, const char *oldroot, const char *mountopts) { - size_t i; - VIR_AUTOFREE(char *) opts =3D NULL; - VIR_AUTOFREE(char *) root =3D NULL; - - if (!(root =3D virCgroupIdentifyRoot(group))) - return -1; - - VIR_DEBUG("Mounting cgroups at '%s'", root); - - if (virFileMakePath(root) < 0) { - virReportSystemError(errno, - _("Unable to create directory %s"), - root); - return -1; - } - - if (virAsprintf(&opts, - "mode=3D755,size=3D65536%s", mountopts) < 0) - return -1; - - if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) = < 0) { - virReportSystemError(errno, - _("Failed to mount %s on %s type %s"), - "tmpfs", root, "tmpfs"); - return -1; - } - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) - continue; - - if (!virFileExists(group->controllers[i].mountPoint)) { - VIR_AUTOFREE(char *) src =3D NULL; - if (virAsprintf(&src, "%s%s", - oldroot, - group->controllers[i].mountPoint) < 0) - return -1; - - VIR_DEBUG("Create mount point '%s'", - group->controllers[i].mountPoint); - if (virFileMakePath(group->controllers[i].mountPoint) < 0) { - virReportSystemError(errno, - _("Unable to create directory %s"), - group->controllers[i].mountPoint); - return -1; - } - - if (mount(src, group->controllers[i].mountPoint, "none", MS_BI= ND, - NULL) < 0) { - virReportSystemError(errno, - _("Failed to bind cgroup '%s' on '%s'= "), - src, group->controllers[i].mountPoint= ); - return -1; - } - } - - if (group->controllers[i].linkPoint) { - VIR_DEBUG("Link mount point '%s' to '%s'", - group->controllers[i].mountPoint, - group->controllers[i].linkPoint); - if (symlink(group->controllers[i].mountPoint, - group->controllers[i].linkPoint) < 0) { - virReportSystemError(errno, - _("Unable to symlink directory %s to = %s"), - group->controllers[i].mountPoint, - group->controllers[i].linkPoint); - return -1; - } - } - } - - return 0; + return group->backend->bindMount(group, oldroot, mountopts); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 1964a48ff0..70deb47461 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -118,6 +118,11 @@ typedef int (*virCgroupHasEmptyTasksCB)(virCgroupPtr cgroup, int controller); =20 +typedef int +(*virCgroupBindMountCB)(virCgroupPtr group, + const char *oldroot, + const char *mountopts); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -138,6 +143,7 @@ struct _virCgroupBackend { virCgroupRemoveCB remove; virCgroupAddTaskCB addTask; virCgroupHasEmptyTasksCB hasEmptyTasks; + virCgroupBindMountCB bindMount; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 57bcb6a685..0514ba392d 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -24,6 +24,9 @@ # include #endif #include +#if defined HAVE_SYS_MOUNT_H +# include +#endif =20 #include "internal.h" =20 @@ -754,6 +757,115 @@ virCgroupV1HasEmptyTasks(virCgroupPtr cgroup, } =20 =20 +static char * +virCgroupV1IdentifyRoot(virCgroupPtr group) +{ + char *ret =3D NULL; + size_t i; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + char *tmp; + if (!group->controllers[i].mountPoint) + continue; + if (!(tmp =3D strrchr(group->controllers[i].mountPoint, '/'))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find directory separator in %s"), + group->controllers[i].mountPoint); + return NULL; + } + + if (VIR_STRNDUP(ret, group->controllers[i].mountPoint, + tmp - group->controllers[i].mountPoint) < 0) + return NULL; + return ret; + } + + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find any mounted v1 controllers")); + return NULL; +} + + +static int +virCgroupV1BindMount(virCgroupPtr group, + const char *oldroot, + const char *mountopts) +{ + size_t i; + VIR_AUTOFREE(char *) opts =3D NULL; + VIR_AUTOFREE(char *) root =3D NULL; + + if (!(root =3D virCgroupV1IdentifyRoot(group))) + return -1; + + VIR_DEBUG("Mounting cgroups at '%s'", root); + + if (virFileMakePath(root) < 0) { + virReportSystemError(errno, + _("Unable to create directory %s"), + root); + return -1; + } + + if (virAsprintf(&opts, + "mode=3D755,size=3D65536%s", mountopts) < 0) + return -1; + + if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) = < 0) { + virReportSystemError(errno, + _("Failed to mount %s on %s type %s"), + "tmpfs", root, "tmpfs"); + return -1; + } + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + if (!group->controllers[i].mountPoint) + continue; + + if (!virFileExists(group->controllers[i].mountPoint)) { + VIR_AUTOFREE(char *) src =3D NULL; + if (virAsprintf(&src, "%s%s", + oldroot, + group->controllers[i].mountPoint) < 0) + return -1; + + VIR_DEBUG("Create mount point '%s'", + group->controllers[i].mountPoint); + if (virFileMakePath(group->controllers[i].mountPoint) < 0) { + virReportSystemError(errno, + _("Unable to create directory %s"), + group->controllers[i].mountPoint); + return -1; + } + + if (mount(src, group->controllers[i].mountPoint, "none", MS_BI= ND, + NULL) < 0) { + virReportSystemError(errno, + _("Failed to bind cgroup '%s' on '%s'= "), + src, group->controllers[i].mountPoint= ); + return -1; + } + } + + if (group->controllers[i].linkPoint) { + VIR_DEBUG("Link mount point '%s' to '%s'", + group->controllers[i].mountPoint, + group->controllers[i].linkPoint); + if (symlink(group->controllers[i].mountPoint, + group->controllers[i].linkPoint) < 0) { + virReportSystemError(errno, + _("Unable to symlink directory %s to = %s"), + group->controllers[i].mountPoint, + group->controllers[i].linkPoint); + return -1; + } + } + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -773,6 +885,7 @@ virCgroupBackend virCgroupV1Backend =3D { .remove =3D virCgroupV1Remove, .addTask =3D virCgroupV1AddTask, .hasEmptyTasks =3D virCgroupV1HasEmptyTasks, + .bindMount =3D virCgroupV1BindMount, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285621266515.4945945332119; Tue, 18 Sep 2018 08:47:01 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 249B2308FF16; Tue, 18 Sep 2018 15:46:59 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB3CF68C99; Tue, 18 Sep 2018 15:46:58 +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 789774A470; Tue, 18 Sep 2018 15:46:58 +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 w8IFkW45012402 for ; Tue, 18 Sep 2018 11:46:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id C45115D9C7; Tue, 18 Sep 2018 15:46:32 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 221DD82AD2 for ; Tue, 18 Sep 2018 15:46:31 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:41 +0200 Message-Id: <3aa9a9ec8c137f8119f27ac50dbd57e07a927932.1537285203.git.phrdina@redhat.com> 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 20/47] vircgroup: extract virCgroupV1SetOwner 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 18 Sep 2018 15:47:00 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: J=EF=BF=BDn Tomko --- src/util/vircgroup.c | 54 +----------------------------- src/util/vircgroupbackend.h | 7 ++++ src/util/vircgroupv1.c | 65 +++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 53 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 29faf5fb2c..479a2bf664 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -3284,59 +3284,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup, gid_t gid, int controllers) { - int ret =3D -1; - size_t i; - DIR *dh =3D NULL; - int direrr; - - for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_AUTOFREE(char *) base =3D NULL; - struct dirent *de; - - if (!((1 << i) & controllers)) - continue; - - if (!cgroup->controllers[i].mountPoint) - continue; - - if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPoint, - cgroup->controllers[i].placement) < 0) - goto cleanup; - - if (virDirOpen(&dh, base) < 0) - goto cleanup; - - while ((direrr =3D virDirRead(dh, &de, base)) > 0) { - VIR_AUTOFREE(char *) entry =3D NULL; - - if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0) - goto cleanup; - - if (chown(entry, uid, gid) < 0) { - virReportSystemError(errno, - _("cannot chown '%s' to (%u, %u)"), - entry, uid, gid); - goto cleanup; - } - } - if (direrr < 0) - goto cleanup; - - if (chown(base, uid, gid) < 0) { - virReportSystemError(errno, - _("cannot chown '%s' to (%u, %u)"), - base, uid, gid); - goto cleanup; - } - - VIR_DIR_CLOSE(dh); - } - - ret =3D 0; - - cleanup: - VIR_DIR_CLOSE(dh); - return ret; + return cgroup->backend->setOwner(cgroup, uid, gid, controllers); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 70deb47461..4538654068 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -123,6 +123,12 @@ typedef int const char *oldroot, const char *mountopts); =20 +typedef int +(*virCgroupSetOwnerCB)(virCgroupPtr cgroup, + uid_t uid, + gid_t gid, + int controllers); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -144,6 +150,7 @@ struct _virCgroupBackend { virCgroupAddTaskCB addTask; virCgroupHasEmptyTasksCB hasEmptyTasks; virCgroupBindMountCB bindMount; + virCgroupSetOwnerCB setOwner; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 0514ba392d..d74fc8ff96 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -866,6 +866,70 @@ virCgroupV1BindMount(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetOwner(virCgroupPtr cgroup, + uid_t uid, + gid_t gid, + int controllers) +{ + int ret =3D -1; + size_t i; + VIR_AUTOFREE(char *) base =3D NULL; + VIR_AUTOFREE(char *) entry =3D NULL; + DIR *dh =3D NULL; + int direrr; + + for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + struct dirent *de; + + if (!((1 << i) & controllers)) + continue; + + if (!cgroup->controllers[i].mountPoint) + continue; + + if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPoint, + cgroup->controllers[i].placement) < 0) + goto cleanup; + + if (virDirOpen(&dh, base) < 0) + goto cleanup; + + while ((direrr =3D virDirRead(dh, &de, base)) > 0) { + if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0) + goto cleanup; + + if (chown(entry, uid, gid) < 0) { + virReportSystemError(errno, + _("cannot chown '%s' to (%u, %u)"), + entry, uid, gid); + goto cleanup; + } + + VIR_FREE(entry); + } + if (direrr < 0) + goto cleanup; + + if (chown(base, uid, gid) < 0) { + virReportSystemError(errno, + _("cannot chown '%s' to (%u, %u)"), + base, uid, gid); + goto cleanup; + } + + VIR_FREE(base); + VIR_DIR_CLOSE(dh); + } + + ret =3D 0; + + cleanup: + VIR_DIR_CLOSE(dh); + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -886,6 +950,7 @@ virCgroupBackend virCgroupV1Backend =3D { .addTask =3D virCgroupV1AddTask, .hasEmptyTasks =3D virCgroupV1HasEmptyTasks, .bindMount =3D virCgroupV1BindMount, + .setOwner =3D virCgroupV1SetOwner, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285652206834.4499568933419; Tue, 18 Sep 2018 08:47:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 502BA804E0; Tue, 18 Sep 2018 15:47:27 +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 A4240308BDAE; Tue, 18 Sep 2018 15:47:26 +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 49A2F181D0A9; Tue, 18 Sep 2018 15:47:26 +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 w8IFkXgw012407 for ; Tue, 18 Sep 2018 11:46:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BD8A4F9A1; Tue, 18 Sep 2018 15:46:33 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EA2182AD2 for ; Tue, 18 Sep 2018 15:46:32 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:42 +0200 Message-Id: <487895c40219aaba1f12503fe82c851e3d71eb7d.1537285203.git.phrdina@redhat.com> 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 21/47] vircgroup: extract virCgroupV1(Set|Get)BlkioWeight 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.84 on 10.5.11.24 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:47:30 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 14 ++------------ src/util/vircgroupbackend.h | 20 ++++++++++++++++++++ src/util/vircgroupv1.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 479a2bf664..cb9f03d488 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1512,10 +1512,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, int virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", - weight); + VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight); } =20 =20 @@ -1530,14 +1527,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned= int weight) int virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight) { - unsigned long long tmp; - int ret; - ret =3D virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight", &tmp); - if (ret =3D=3D 0) - *weight =3D tmp; - return ret; + VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 4538654068..2c42227297 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -129,6 +129,14 @@ typedef int gid_t gid, int controllers); =20 +typedef int +(*virCgroupSetBlkioWeightCB)(virCgroupPtr group, + unsigned int weight); + +typedef int +(*virCgroupGetBlkioWeightCB)(virCgroupPtr group, + unsigned int *weight); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -151,6 +159,10 @@ struct _virCgroupBackend { virCgroupHasEmptyTasksCB hasEmptyTasks; virCgroupBindMountCB bindMount; virCgroupSetOwnerCB setOwner; + + /* Optional cgroup controller specific callbacks. */ + virCgroupSetBlkioWeightCB setBlkioWeight; + virCgroupGetBlkioWeightCB getBlkioWeight; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; @@ -161,4 +173,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend); virCgroupBackendPtr * virCgroupBackendGetAll(void); =20 +# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \ + if (!group->backend->func) { \ + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", \ + _("operation '" #func "' not supported")); \ + return ret; \ + } \ + return group->backend->func(group, ##__VA_ARGS__); + #endif /* __VIR_CGROUP_BACKEND_H__ */ diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index d74fc8ff96..380a310589 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -930,6 +930,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, } =20 =20 +static int +virCgroupV1SetBlkioWeight(virCgroupPtr group, + unsigned int weight) +{ + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", + weight); +} + + +static int +virCgroupV1GetBlkioWeight(virCgroupPtr group, + unsigned int *weight) +{ + unsigned long long tmp; + int ret; + ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight", &tmp); + if (ret =3D=3D 0) + *weight =3D tmp; + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -951,6 +977,9 @@ virCgroupBackend virCgroupV1Backend =3D { .hasEmptyTasks =3D virCgroupV1HasEmptyTasks, .bindMount =3D virCgroupV1BindMount, .setOwner =3D virCgroupV1SetOwner, + + .setBlkioWeight =3D virCgroupV1SetBlkioWeight, + .getBlkioWeight =3D virCgroupV1GetBlkioWeight, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285627681241.87481668115583; Tue, 18 Sep 2018 08:47:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 90326CF3C; Tue, 18 Sep 2018 15:47:05 +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 2C5107EED8; Tue, 18 Sep 2018 15:47:05 +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 B1B25181A12F; Tue, 18 Sep 2018 15:47:04 +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 w8IFkYUj012414 for ; Tue, 18 Sep 2018 11:46:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 71A9B5D9C7; Tue, 18 Sep 2018 15:46:34 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E905C82AD3 for ; Tue, 18 Sep 2018 15:46:33 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:43 +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 22/47] vircgroup: extract virCgroupV1GetBlkioIoServiced 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Sep 2018 15:47:06 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 87 ++-------------------------------- src/util/vircgroupbackend.h | 8 ++++ src/util/vircgroupv1.c | 94 +++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 84 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cb9f03d488..a9b67f7d53 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1313,90 +1313,9 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - long long stats_val; - VIR_AUTOFREE(char *) str1 =3D NULL; - VIR_AUTOFREE(char *) str2 =3D NULL; - char *p1 =3D NULL; - char *p2 =3D NULL; - size_t i; - - const char *value_names[] =3D { - "Read ", - "Write " - }; - long long *bytes_ptrs[] =3D { - bytes_read, - bytes_write - }; - long long *requests_ptrs[] =3D { - requests_read, - requests_write - }; - - *bytes_read =3D 0; - *bytes_write =3D 0; - *requests_read =3D 0; - *requests_write =3D 0; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_service_bytes", &str1) < 0) - return -1; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_serviced", &str2) < 0) - return -1; - - /* sum up all entries of the same kind, from all devices */ - for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { - p1 =3D str1; - p2 =3D str2; - - while ((p1 =3D strstr(p1, value_names[i]))) { - p1 +=3D strlen(value_names[i]); - if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse byte %sstat '%s'"), - value_names[i], - p1); - return -1; - } - - if (stats_val < 0 || - (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)= )) - { - virReportError(VIR_ERR_OVERFLOW, - _("Sum of byte %sstat overflows"), - value_names[i]); - return -1; - } - *bytes_ptrs[i] +=3D stats_val; - } - - while ((p2 =3D strstr(p2, value_names[i]))) { - p2 +=3D strlen(value_names[i]); - if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse %srequest stat '%s'"), - value_names[i], - p2); - return -1; - } - - if (stats_val < 0 || - (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_v= al))) - { - virReportError(VIR_ERR_OVERFLOW, - _("Sum of %srequest stat overflows"), - value_names[i]); - return -1; - } - *requests_ptrs[i] +=3D stats_val; - } - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioIoServiced, -1, + bytes_read, bytes_write, + requests_read, requests_write); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 2c42227297..90584947fd 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -137,6 +137,13 @@ typedef int (*virCgroupGetBlkioWeightCB)(virCgroupPtr group, unsigned int *weight); =20 +typedef int +(*virCgroupGetBlkioIoServicedCB)(virCgroupPtr group, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -163,6 +170,7 @@ struct _virCgroupBackend { /* Optional cgroup controller specific callbacks. */ virCgroupSetBlkioWeightCB setBlkioWeight; virCgroupGetBlkioWeightCB getBlkioWeight; + virCgroupGetBlkioIoServicedCB getBlkioIoServiced; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 380a310589..4b9c03830c 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -956,6 +956,99 @@ virCgroupV1GetBlkioWeight(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetBlkioIoServiced(virCgroupPtr group, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write) +{ + long long stats_val; + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + char *p1, *p2; + size_t i; + + const char *value_names[] =3D { + "Read ", + "Write " + }; + long long *bytes_ptrs[] =3D { + bytes_read, + bytes_write + }; + long long *requests_ptrs[] =3D { + requests_read, + requests_write + }; + + *bytes_read =3D 0; + *bytes_write =3D 0; + *requests_read =3D 0; + *requests_write =3D 0; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_service_bytes", &str1) < 0) + return -1; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_serviced", &str2) < 0) + return -1; + + /* sum up all entries of the same kind, from all devices */ + for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { + p1 =3D str1; + p2 =3D str2; + + while ((p1 =3D strstr(p1, value_names[i]))) { + p1 +=3D strlen(value_names[i]); + if (virStrToLong_ll(p1, &p1, 10, &stats_val) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse byte %sstat '%s'"), + value_names[i], + p1); + return -1; + } + + if (stats_val < 0 || + (stats_val > 0 && *bytes_ptrs[i] > (LLONG_MAX - stats_val)= )) + { + virReportError(VIR_ERR_OVERFLOW, + _("Sum of byte %sstat overflows"), + value_names[i]); + return -1; + } + *bytes_ptrs[i] +=3D stats_val; + } + + while ((p2 =3D strstr(p2, value_names[i]))) { + p2 +=3D strlen(value_names[i]); + if (virStrToLong_ll(p2, &p2, 10, &stats_val) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %srequest stat '%s'"), + value_names[i], + p2); + return -1; + } + + if (stats_val < 0 || + (stats_val > 0 && *requests_ptrs[i] > (LLONG_MAX - stats_v= al))) + { + virReportError(VIR_ERR_OVERFLOW, + _("Sum of %srequest stat overflows"), + value_names[i]); + return -1; + } + *requests_ptrs[i] +=3D stats_val; + } + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -980,6 +1073,7 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .setBlkioWeight =3D virCgroupV1SetBlkioWeight, .getBlkioWeight =3D virCgroupV1GetBlkioWeight, + .getBlkioIoServiced =3D virCgroupV1GetBlkioIoServiced, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285633957582.5190827999523; Tue, 18 Sep 2018 08:47:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 735A081F0D; Tue, 18 Sep 2018 15:47:11 +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 273357E4C6; Tue, 18 Sep 2018 15:47:11 +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 B635E181AC87; Tue, 18 Sep 2018 15:47:10 +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 w8IFkZZb012426 for ; Tue, 18 Sep 2018 11:46:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 47DEC5D9C7; Tue, 18 Sep 2018 15:46:35 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C03E182216 for ; Tue, 18 Sep 2018 15:46:34 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:44 +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 23/47] vircgroup: extract virCgroupV1GetBlkioIoDeviceServiced 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.16 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:47:12 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 83 ++-------------------------------- src/util/vircgroupbackend.h | 9 ++++ src/util/vircgrouppriv.h | 2 + src/util/vircgroupv1.c | 89 +++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 79 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index a9b67f7d53..0d93860df6 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -411,7 +411,7 @@ virCgroupDetect(virCgroupPtr group, } =20 =20 -static char * +char * virCgroupGetBlockDevString(const char *path) { char *ret =3D NULL; @@ -1339,84 +1339,9 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - VIR_AUTOFREE(char *) str1 =3D NULL; - VIR_AUTOFREE(char *) str2 =3D NULL; - VIR_AUTOFREE(char *) str3 =3D NULL; - char *p1 =3D NULL; - char *p2 =3D NULL; - size_t i; - - const char *value_names[] =3D { - "Read ", - "Write " - }; - long long *bytes_ptrs[] =3D { - bytes_read, - bytes_write - }; - long long *requests_ptrs[] =3D { - requests_read, - requests_write - }; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_service_bytes", &str1) < 0) - return -1; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.io_serviced", &str2) < 0) - return -1; - - if (!(str3 =3D virCgroupGetBlockDevString(path))) - return -1; - - if (!(p1 =3D strstr(str1, str3))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find byte stats for block device '%s'"), - str3); - return -1; - } - - if (!(p2 =3D strstr(str2, str3))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find request stats for block device '%s'"= ), - str3); - return -1; - } - - for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { - if (!(p1 =3D strstr(p1, value_names[i]))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find byte %sstats for block device '%= s'"), - value_names[i], str3); - return -1; - } - - if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_pt= rs[i]) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse %sstat '%s'"), - value_names[i], p1 + strlen(value_names[i])); - return -1; - } - - if (!(p2 =3D strstr(p2, value_names[i]))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot find request %sstats for block device= '%s'"), - value_names[i], str3); - return -1; - } - - if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests= _ptrs[i]) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse %sstat '%s'"), - value_names[i], p2 + strlen(value_names[i])); - return -1; - } - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioIoDeviceServiced, -1, + path, bytes_read, bytes_write, + requests_read, requests_write); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 90584947fd..bd78c5b937 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -144,6 +144,14 @@ typedef int long long *requests_read, long long *requests_write); =20 +typedef int +(*virCgroupGetBlkioIoDeviceServicedCB)(virCgroupPtr group, + const char *path, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -171,6 +179,7 @@ struct _virCgroupBackend { virCgroupSetBlkioWeightCB setBlkioWeight; virCgroupGetBlkioWeightCB getBlkioWeight; virCgroupGetBlkioIoServicedCB getBlkioIoServiced; + virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 01714370be..525c288a9a 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -80,6 +80,8 @@ int virCgroupSetValueI64(virCgroupPtr group, =20 int virCgroupPartitionEscape(char **path); =20 +char *virCgroupGetBlockDevString(const char *path); + int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 4b9c03830c..206318d436 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1049,6 +1049,94 @@ virCgroupV1GetBlkioIoServiced(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group, + const char *path, + long long *bytes_read, + long long *bytes_write, + long long *requests_read, + long long *requests_write) +{ + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + VIR_AUTOFREE(char *) str3 =3D NULL; + char *p1, *p2; + size_t i; + + const char *value_names[] =3D { + "Read ", + "Write " + }; + long long *bytes_ptrs[] =3D { + bytes_read, + bytes_write + }; + long long *requests_ptrs[] =3D { + requests_read, + requests_write + }; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_service_bytes", &str1) < 0) + return -1; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.io_serviced", &str2) < 0) + return -1; + + if (!(str3 =3D virCgroupGetBlockDevString(path))) + return -1; + + if (!(p1 =3D strstr(str1, str3))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte stats for block device '%s'"), + str3); + return -1; + } + + if (!(p2 =3D strstr(str2, str3))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find request stats for block device '%s'"= ), + str3); + return -1; + } + + for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { + if (!(p1 =3D strstr(p1, value_names[i]))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find byte %sstats for block device '%= s'"), + value_names[i], str3); + return -1; + } + + if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_pt= rs[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %sstat '%s'"), + value_names[i], p1 + strlen(value_names[i])); + return -1; + } + + if (!(p2 =3D strstr(p2, value_names[i]))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot find request %sstats for block device= '%s'"), + value_names[i], str3); + return -1; + } + + if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests= _ptrs[i]) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse %sstat '%s'"), + value_names[i], p2 + strlen(value_names[i])); + return -1; + } + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1074,6 +1162,7 @@ virCgroupBackend virCgroupV1Backend =3D { .setBlkioWeight =3D virCgroupV1SetBlkioWeight, .getBlkioWeight =3D virCgroupV1GetBlkioWeight, .getBlkioIoServiced =3D virCgroupV1GetBlkioIoServiced, + .getBlkioIoDeviceServiced =3D virCgroupV1GetBlkioIoDeviceServiced, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285638830103.75574962423673; Tue, 18 Sep 2018 08:47:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 583267F3F7; Tue, 18 Sep 2018 15:47:16 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15E633091384; Tue, 18 Sep 2018 15:47:16 +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 A37C84A48C; Tue, 18 Sep 2018 15:47:15 +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 w8IFkaiC012436 for ; Tue, 18 Sep 2018 11:46:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23A084F9A1; Tue, 18 Sep 2018 15:46:36 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97EAB82213 for ; Tue, 18 Sep 2018 15:46:35 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:45 +0200 Message-Id: <6e46b41406327fee2203f7fae58baf23124ca0cd.1537285203.git.phrdina@redhat.com> 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 24/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWeight 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Sep 2018 15:47:17 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 36 +++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgrouppriv.h | 6 +++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0d93860df6..465d540bb2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -500,7 +500,7 @@ virCgroupGetValueStr(virCgroupPtr group, } =20 =20 -static int +int virCgroupGetValueForBlkDev(virCgroupPtr group, int controller, const char *key, @@ -1503,19 +1503,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight); } =20 /** @@ -1667,25 +1655,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.weight_device", - path, - &str) < 0) - return -1; - - if (!str) { - *weight =3D 0; - } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index bd78c5b937..a84417ddb7 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -152,6 +152,16 @@ typedef int long long *requests_read, long long *requests_write); =20 +typedef int +(*virCgroupSetBlkioDeviceWeightCB)(virCgroupPtr group, + const char *path, + unsigned int weight); + +typedef int +(*virCgroupGetBlkioDeviceWeightCB)(virCgroupPtr group, + const char *path, + unsigned int *weight); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -180,6 +190,8 @@ struct _virCgroupBackend { virCgroupGetBlkioWeightCB getBlkioWeight; virCgroupGetBlkioIoServicedCB getBlkioIoServiced; virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced; + virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight; + virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 525c288a9a..3a968c1ce2 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -82,6 +82,12 @@ int virCgroupPartitionEscape(char **path); =20 char *virCgroupGetBlockDevString(const char *path); =20 +int virCgroupGetValueForBlkDev(virCgroupPtr group, + int controller, + const char *key, + const char *path, + char **value); + int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 206318d436..b627a9d516 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1137,6 +1137,54 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr gro= up, } =20 =20 +static int +virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group, + const char *path, + unsigned int weight) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, + const char *path, + unsigned int *weight) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.weight_device", + path, + &str) < 0) + return -1; + + if (!str) { + *weight =3D 0; + } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1163,6 +1211,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioWeight =3D virCgroupV1GetBlkioWeight, .getBlkioIoServiced =3D virCgroupV1GetBlkioIoServiced, .getBlkioIoDeviceServiced =3D virCgroupV1GetBlkioIoDeviceServiced, + .setBlkioDeviceWeight =3D virCgroupV1SetBlkioDeviceWeight, + .getBlkioDeviceWeight =3D virCgroupV1GetBlkioDeviceWeight, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285626297380.01059226982875; Tue, 18 Sep 2018 08:47:06 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3CD3300207A; Tue, 18 Sep 2018 15:47:03 +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 955C43091385; Tue, 18 Sep 2018 15:47:03 +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 4AD6D181A73C; Tue, 18 Sep 2018 15:47:03 +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 w8IFkawZ012443 for ; Tue, 18 Sep 2018 11:46:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA64E82AD3; Tue, 18 Sep 2018 15:46:36 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EEB14F9A1 for ; Tue, 18 Sep 2018 15:46:36 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:46 +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 25/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadIops 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 18 Sep 2018 15:47:05 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 34 ++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 465d540bb2..5fbad25d5c 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1387,19 +1387,7 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%u", blkstr, riops) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_iops_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadIops, -1, path, riops= ); } =20 =20 @@ -1519,25 +1507,7 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_iops_device", - path, - &str) < 0) - return -1; - - if (!str) { - *riops =3D 0; - } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadIops, -1, path, riops= ); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index a84417ddb7..813ed61b6a 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -162,6 +162,16 @@ typedef int const char *path, unsigned int *weight); =20 +typedef int +(*virCgroupSetBlkioDeviceReadIopsCB)(virCgroupPtr group, + const char *path, + unsigned int riops); + +typedef int +(*virCgroupGetBlkioDeviceReadIopsCB)(virCgroupPtr group, + const char *path, + unsigned int *riops); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -192,6 +202,8 @@ struct _virCgroupBackend { virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced; virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight; virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight; + virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops; + virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index b627a9d516..d418ef41df 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1185,6 +1185,54 @@ virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetBlkioDeviceReadIops(virCgroupPtr group, + const char *path, + unsigned int riops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%u", blkstr, riops) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_iops_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group, + const char *path, + unsigned int *riops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_iops_device", + path, + &str) < 0) + return -1; + + if (!str) { + *riops =3D 0; + } else if (virStrToLong_ui(str, NULL, 10, riops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1213,6 +1261,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioIoDeviceServiced =3D virCgroupV1GetBlkioIoDeviceServiced, .setBlkioDeviceWeight =3D virCgroupV1SetBlkioDeviceWeight, .getBlkioDeviceWeight =3D virCgroupV1GetBlkioDeviceWeight, + .setBlkioDeviceReadIops =3D virCgroupV1SetBlkioDeviceReadIops, + .getBlkioDeviceReadIops =3D virCgroupV1GetBlkioDeviceReadIops, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285645141498.17102491570745; Tue, 18 Sep 2018 08:47:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ABDD98831E; Tue, 18 Sep 2018 15:47:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69D5B7DE4D; Tue, 18 Sep 2018 15:47:22 +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 E0C0D4A496; Tue, 18 Sep 2018 15:47:21 +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 w8IFkb7k012452 for ; Tue, 18 Sep 2018 11:46:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0F744F9A1; Tue, 18 Sep 2018 15:46:37 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44A6C5D9C7 for ; Tue, 18 Sep 2018 15:46:37 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:47 +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 26/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteIops 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Sep 2018 15:47:23 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 34 ++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 5fbad25d5c..3fa8aebe04 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1404,19 +1404,7 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_iops_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteIops, -1, path, wiop= s); } =20 =20 @@ -1523,25 +1511,7 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_iops_device", - path, - &str) < 0) - return -1; - - if (!str) { - *wiops =3D 0; - } else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteIops, -1, path, wiop= s); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 813ed61b6a..e19a3820bf 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -172,6 +172,16 @@ typedef int const char *path, unsigned int *riops); =20 +typedef int +(*virCgroupSetBlkioDeviceWriteIopsCB)(virCgroupPtr group, + const char *path, + unsigned int wiops); + +typedef int +(*virCgroupGetBlkioDeviceWriteIopsCB)(virCgroupPtr group, + const char *path, + unsigned int *wiops); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -204,6 +214,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight; virCgroupSetBlkioDeviceReadIopsCB setBlkioDeviceReadIops; virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops; + virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops; + virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index d418ef41df..feeefc287d 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1233,6 +1233,54 @@ virCgroupV1GetBlkioDeviceReadIops(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int wiops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_iops_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr group, + const char *path, + unsigned int *wiops) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_iops_device", + path, + &str) < 0) + return -1; + + if (!str) { + *wiops =3D 0; + } else if (virStrToLong_ui(str, NULL, 10, wiops) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1263,6 +1311,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceWeight =3D virCgroupV1GetBlkioDeviceWeight, .setBlkioDeviceReadIops =3D virCgroupV1SetBlkioDeviceReadIops, .getBlkioDeviceReadIops =3D virCgroupV1GetBlkioDeviceReadIops, + .setBlkioDeviceWriteIops =3D virCgroupV1SetBlkioDeviceWriteIops, + .getBlkioDeviceWriteIops =3D virCgroupV1GetBlkioDeviceWriteIops, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 153728563156319.200863905177584; Tue, 18 Sep 2018 08:47:11 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9ADA2C05D410; Tue, 18 Sep 2018 15:47:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5032C2015C23; Tue, 18 Sep 2018 15:47:09 +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 CB9FD4A47A; Tue, 18 Sep 2018 15:47:08 +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 w8IFkcvp012465 for ; Tue, 18 Sep 2018 11:46:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 973544F9A1; Tue, 18 Sep 2018 15:46:38 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B23D5D9C7 for ; Tue, 18 Sep 2018 15:46:37 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:48 +0200 Message-Id: <2175fd84239740107a9ff34a517c757d052e0bad.1537285203.git.phrdina@redhat.com> 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 27/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceReadBps 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Sep 2018 15:47:10 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 34 ++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 3fa8aebe04..08b8387fba 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1421,19 +1421,7 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_bps_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceReadBps, -1, path, rbps); } =20 /** @@ -1527,25 +1515,7 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.read_bps_device", - path, - &str) < 0) - return -1; - - if (!str) { - *rbps =3D 0; - } else if (virStrToLong_ull(str, NULL, 10, rbps) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceReadBps, -1, path, rbps); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index e19a3820bf..3ec9a95327 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -182,6 +182,16 @@ typedef int const char *path, unsigned int *wiops); =20 +typedef int +(*virCgroupSetBlkioDeviceReadBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long rbps); + +typedef int +(*virCgroupGetBlkioDeviceReadBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long *rbps); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -216,6 +226,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceReadIopsCB getBlkioDeviceReadIops; virCgroupSetBlkioDeviceWriteIopsCB setBlkioDeviceWriteIops; virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops; + virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps; + virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index feeefc287d..2c19e6147a 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1281,6 +1281,54 @@ virCgroupV1GetBlkioDeviceWriteIops(virCgroupPtr grou= p, } =20 =20 +static int +virCgroupV1SetBlkioDeviceReadBps(virCgroupPtr group, + const char *path, + unsigned long long rbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_bps_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group, + const char *path, + unsigned long long *rbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.read_bps_device", + path, + &str) < 0) + return -1; + + if (!str) { + *rbps =3D 0; + } else if (virStrToLong_ull(str, NULL, 10, rbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1313,6 +1361,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceReadIops =3D virCgroupV1GetBlkioDeviceReadIops, .setBlkioDeviceWriteIops =3D virCgroupV1SetBlkioDeviceWriteIops, .getBlkioDeviceWriteIops =3D virCgroupV1GetBlkioDeviceWriteIops, + .setBlkioDeviceReadBps =3D virCgroupV1SetBlkioDeviceReadBps, + .getBlkioDeviceReadBps =3D virCgroupV1GetBlkioDeviceReadBps, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285654996651.8975575431214; Tue, 18 Sep 2018 08:47:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1DF883002617; Tue, 18 Sep 2018 15:47:32 +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 E07D17E66D; Tue, 18 Sep 2018 15:47:31 +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 79412181D0AF; Tue, 18 Sep 2018 15:47:31 +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 w8IFkdkm012477 for ; Tue, 18 Sep 2018 11:46:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CBF15D9C7; Tue, 18 Sep 2018 15:46:39 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id E51F482216 for ; Tue, 18 Sep 2018 15:46:38 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:49 +0200 Message-Id: <52eaca00e90fa18ac7bebb94bb6f2f927633363d.1537285203.git.phrdina@redhat.com> 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 28/47] vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWriteBps 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 18 Sep 2018 15:47:33 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 34 ++----------------------- src/util/vircgroupbackend.h | 12 +++++++++ src/util/vircgroupv1.c | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 08b8387fba..ab50342dbb 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1437,19 +1437,7 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - VIR_AUTOFREE(char *) str =3D NULL; - VIR_AUTOFREE(char *) blkstr =3D NULL; - - if (!(blkstr =3D virCgroupGetBlockDevString(path))) - return -1; - - if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) - return -1; - - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_bps_device", - str); + VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWriteBps, -1, path, wbps); } =20 =20 @@ -1531,25 +1519,7 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - VIR_AUTOFREE(char *) str =3D NULL; - - if (virCgroupGetValueForBlkDev(group, - VIR_CGROUP_CONTROLLER_BLKIO, - "blkio.throttle.write_bps_device", - path, - &str) < 0) - return -1; - - if (!str) { - *wbps =3D 0; - } else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to parse '%s' as an integer"), - str); - return -1; - } - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWriteBps, -1, path, wbps); } =20 /** diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 3ec9a95327..b59462d6ab 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -192,6 +192,16 @@ typedef int const char *path, unsigned long long *rbps); =20 +typedef int +(*virCgroupSetBlkioDeviceWriteBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long wbps); + +typedef int +(*virCgroupGetBlkioDeviceWriteBpsCB)(virCgroupPtr group, + const char *path, + unsigned long long *wbps); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -228,6 +238,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceWriteIopsCB getBlkioDeviceWriteIops; virCgroupSetBlkioDeviceReadBpsCB setBlkioDeviceReadBps; virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; + virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps; + virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 2c19e6147a..4f6d20e31f 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1329,6 +1329,54 @@ virCgroupV1GetBlkioDeviceReadBps(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; + + if (!(blkstr =3D virCgroupGetBlockDevString(path))) + return -1; + + if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) + return -1; + + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_bps_device", + str); +} + + +static int +virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, + const char *path, + unsigned long long *wbps) +{ + VIR_AUTOFREE(char *) str =3D NULL; + + if (virCgroupGetValueForBlkDev(group, + VIR_CGROUP_CONTROLLER_BLKIO, + "blkio.throttle.write_bps_device", + path, + &str) < 0) + return -1; + + if (!str) { + *wbps =3D 0; + } else if (virStrToLong_ull(str, NULL, 10, wbps) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to parse '%s' as an integer"), + str); + return -1; + } + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1363,6 +1411,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceWriteIops =3D virCgroupV1GetBlkioDeviceWriteIops, .setBlkioDeviceReadBps =3D virCgroupV1SetBlkioDeviceReadBps, .getBlkioDeviceReadBps =3D virCgroupV1GetBlkioDeviceReadBps, + .setBlkioDeviceWriteBps =3D virCgroupV1SetBlkioDeviceWriteBps, + .getBlkioDeviceWriteBps =3D virCgroupV1GetBlkioDeviceWriteBps, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285636608102.1645656453635; Tue, 18 Sep 2018 08:47:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0FCF9F744; Tue, 18 Sep 2018 15:47:14 +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 9DB9E7E4C5; Tue, 18 Sep 2018 15:47:14 +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 4BB41181B9FC; Tue, 18 Sep 2018 15:47:14 +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 w8IFkeIO012484 for ; Tue, 18 Sep 2018 11:46:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 43AAA5D9C7; Tue, 18 Sep 2018 15:46:40 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCE4B82216 for ; Tue, 18 Sep 2018 15:46:39 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:50 +0200 Message-Id: <0bacf3826568ffc3f40ad894b528aa7dca1e600b.1537285203.git.phrdina@redhat.com> 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 29/47] vircgroup: extract virCgroupV1SetMemory 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:47:15 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 20 +------------------- src/util/vircgroupbackend.h | 6 ++++++ src/util/vircgroupv1.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index ab50342dbb..b1c1bc9cf0 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1595,25 +1595,7 @@ virCgroupGetMemoryUnlimitedKB(void) int virCgroupSetMemory(virCgroupPtr group, unsigned long long kb) { - unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - if (kb > maxkb) { - virReportError(VIR_ERR_INVALID_ARG, - _("Memory '%llu' must be less than %llu"), - kb, maxkb); - return -1; - } - - if (kb =3D=3D maxkb) - return virCgroupSetValueI64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", - -1); - else - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", - kb << 10); + VIR_CGROUP_BACKEND_CALL(group, setMemory, -1, kb); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index b59462d6ab..2d59e4af20 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -202,6 +202,10 @@ typedef int const char *path, unsigned long long *wbps); =20 +typedef int +(*virCgroupSetMemoryCB)(virCgroupPtr group, + unsigned long long kb); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -240,6 +244,8 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceReadBpsCB getBlkioDeviceReadBps; virCgroupSetBlkioDeviceWriteBpsCB setBlkioDeviceWriteBps; virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; + + virCgroupSetMemoryCB setMemory; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 4f6d20e31f..3235ef3d2d 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1377,6 +1377,32 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetMemory(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", + -1); + else + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", + kb << 10); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1413,6 +1439,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceReadBps =3D virCgroupV1GetBlkioDeviceReadBps, .setBlkioDeviceWriteBps =3D virCgroupV1SetBlkioDeviceWriteBps, .getBlkioDeviceWriteBps =3D virCgroupV1GetBlkioDeviceWriteBps, + + .setMemory =3D virCgroupV1SetMemory, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285660779699.5334515185251; Tue, 18 Sep 2018 08:47:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9447BA0906; Tue, 18 Sep 2018 15:47:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4DBAE7E656; Tue, 18 Sep 2018 15:47:37 +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 E2EC041F72; Tue, 18 Sep 2018 15:47:36 +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 w8IFkfAG012489 for ; Tue, 18 Sep 2018 11:46:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C8C582AD2; Tue, 18 Sep 2018 15:46:41 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 945624F9A1 for ; Tue, 18 Sep 2018 15:46:40 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:51 +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 30/47] vircgroup: extract virCgroupV1GetMemoryStat 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:47:39 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 67 +++------------------------------- src/util/vircgroupbackend.h | 10 ++++++ src/util/vircgroupv1.c | 71 +++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 63 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b1c1bc9cf0..22db0a4bf1 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1621,69 +1621,10 @@ virCgroupGetMemoryStat(virCgroupPtr group, unsigned long long *inactiveFile, unsigned long long *unevictable) { - int ret =3D -1; - char *stat =3D NULL; - char *line =3D NULL; - unsigned long long cacheVal =3D 0; - unsigned long long activeAnonVal =3D 0; - unsigned long long inactiveAnonVal =3D 0; - unsigned long long activeFileVal =3D 0; - unsigned long long inactiveFileVal =3D 0; - unsigned long long unevictableVal =3D 0; - - if (virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.stat", - &stat) < 0) { - return -1; - } - - line =3D stat; - - while (line) { - char *newLine =3D strchr(line, '\n'); - char *valueStr =3D strchr(line, ' '); - unsigned long long value; - - if (newLine) - *newLine =3D '\0'; - - if (!valueStr) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Cannot parse 'memory.stat' cgroup file.")); - goto cleanup; - } - *valueStr =3D '\0'; - - if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) - goto cleanup; - - if (STREQ(line, "cache")) - cacheVal =3D value >> 10; - else if (STREQ(line, "active_anon")) - activeAnonVal =3D value >> 10; - else if (STREQ(line, "inactive_anon")) - inactiveAnonVal =3D value >> 10; - else if (STREQ(line, "active_file")) - activeFileVal =3D value >> 10; - else if (STREQ(line, "inactive_file")) - inactiveFileVal =3D value >> 10; - else if (STREQ(line, "unevictable")) - unevictableVal =3D value >> 10; - } - - *cache =3D cacheVal; - *activeAnon =3D activeAnonVal; - *inactiveAnon =3D inactiveAnonVal; - *activeFile =3D activeFileVal; - *inactiveFile =3D inactiveFileVal; - *unevictable =3D unevictableVal; - - ret =3D 0; - - cleanup: - VIR_FREE(stat); - return ret; + VIR_CGROUP_BACKEND_CALL(group, getMemoryStat, -1, cache, + activeAnon, inactiveAnon, + activeFile, inactiveFile, + unevictable); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 2d59e4af20..5ccda8e044 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -206,6 +206,15 @@ typedef int (*virCgroupSetMemoryCB)(virCgroupPtr group, unsigned long long kb); =20 +typedef int +(*virCgroupGetMemoryStatCB)(virCgroupPtr group, + unsigned long long *cache, + unsigned long long *activeAnon, + unsigned long long *inactiveAnon, + unsigned long long *activeFile, + unsigned long long *inactiveFile, + unsigned long long *unevictable); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -246,6 +255,7 @@ struct _virCgroupBackend { virCgroupGetBlkioDeviceWriteBpsCB getBlkioDeviceWriteBps; =20 virCgroupSetMemoryCB setMemory; + virCgroupGetMemoryStatCB getMemoryStat; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 3235ef3d2d..cfe29649fb 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1403,6 +1403,76 @@ virCgroupV1SetMemory(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetMemoryStat(virCgroupPtr group, + unsigned long long *cache, + unsigned long long *activeAnon, + unsigned long long *inactiveAnon, + unsigned long long *activeFile, + unsigned long long *inactiveFile, + unsigned long long *unevictable) +{ + VIR_AUTOFREE(char *) stat =3D NULL; + char *line =3D NULL; + unsigned long long cacheVal =3D 0; + unsigned long long activeAnonVal =3D 0; + unsigned long long inactiveAnonVal =3D 0; + unsigned long long activeFileVal =3D 0; + unsigned long long inactiveFileVal =3D 0; + unsigned long long unevictableVal =3D 0; + + if (virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.stat", + &stat) < 0) { + return -1; + } + + line =3D stat; + + while (line) { + char *newLine =3D strchr(line, '\n'); + char *valueStr =3D strchr(line, ' '); + unsigned long long value; + + if (newLine) + *newLine =3D '\0'; + + if (!valueStr) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot parse 'memory.stat' cgroup file.")); + return -1; + } + *valueStr =3D '\0'; + + if (virStrToLong_ull(valueStr + 1, NULL, 10, &value) < 0) + return -1; + + if (STREQ(line, "cache")) + cacheVal =3D value >> 10; + else if (STREQ(line, "active_anon")) + activeAnonVal =3D value >> 10; + else if (STREQ(line, "inactive_anon")) + inactiveAnonVal =3D value >> 10; + else if (STREQ(line, "active_file")) + activeFileVal =3D value >> 10; + else if (STREQ(line, "inactive_file")) + inactiveFileVal =3D value >> 10; + else if (STREQ(line, "unevictable")) + unevictableVal =3D value >> 10; + } + + *cache =3D cacheVal; + *activeAnon =3D activeAnonVal; + *inactiveAnon =3D inactiveAnonVal; + *activeFile =3D activeFileVal; + *inactiveFile =3D inactiveFileVal; + *unevictable =3D unevictableVal; + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1441,6 +1511,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getBlkioDeviceWriteBps =3D virCgroupV1GetBlkioDeviceWriteBps, =20 .setMemory =3D virCgroupV1SetMemory, + .getMemoryStat =3D virCgroupV1GetMemoryStat, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285642990205.59327006470915; Tue, 18 Sep 2018 08:47: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 7B8D73091D66; Tue, 18 Sep 2018 15:47: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 3B4E37A429; Tue, 18 Sep 2018 15:47:20 +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 B2861181A13B; Tue, 18 Sep 2018 15:47:19 +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 w8IFkitn012519 for ; Tue, 18 Sep 2018 11:46:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D757D5D9C7; Tue, 18 Sep 2018 15:46:44 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C90982AE1 for ; Tue, 18 Sep 2018 15:46:41 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:52 +0200 Message-Id: <96ecfb103999db3c222e3e20dc10cb7fc21d8290.1537285203.git.phrdina@redhat.com> 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 31/47] vircgroup: extract virCgroupV1GetMemoryUsage 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.42]); Tue, 18 Sep 2018 15:47:21 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 9 +-------- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 22db0a4bf1..1229959300 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1639,14 +1639,7 @@ virCgroupGetMemoryStat(virCgroupPtr group, int virCgroupGetMemoryUsage(virCgroupPtr group, unsigned long *kb) { - long long unsigned int usage_in_bytes; - int ret; - ret =3D virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.usage_in_bytes", &usage_in_bytes); - if (ret =3D=3D 0) - *kb =3D (unsigned long) usage_in_bytes >> 10; - return ret; + VIR_CGROUP_BACKEND_CALL(group, getMemoryUsage, -1, kb); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 5ccda8e044..672fb082c1 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -215,6 +215,10 @@ typedef int unsigned long long *inactiveFile, unsigned long long *unevictable); =20 +typedef int +(*virCgroupGetMemoryUsageCB)(virCgroupPtr group, + unsigned long *kb); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -256,6 +260,7 @@ struct _virCgroupBackend { =20 virCgroupSetMemoryCB setMemory; virCgroupGetMemoryStatCB getMemoryStat; + virCgroupGetMemoryUsageCB getMemoryUsage; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index cfe29649fb..7abb137b81 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1473,6 +1473,21 @@ virCgroupV1GetMemoryStat(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetMemoryUsage(virCgroupPtr group, + unsigned long *kb) +{ + long long unsigned int usage_in_bytes; + int ret; + ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.usage_in_bytes", &usage_in_bytes); + if (ret =3D=3D 0) + *kb =3D (unsigned long) usage_in_bytes >> 10; + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1512,6 +1527,7 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .setMemory =3D virCgroupV1SetMemory, .getMemoryStat =3D virCgroupV1GetMemoryStat, + .getMemoryUsage =3D virCgroupV1GetMemoryUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285651479466.8824024824196; Tue, 18 Sep 2018 08:47:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D7143001974; Tue, 18 Sep 2018 15:47:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 566CB897F6; Tue, 18 Sep 2018 15:47:28 +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 D9CA941F54; Tue, 18 Sep 2018 15:47:27 +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 w8IFkros012537 for ; Tue, 18 Sep 2018 11:46:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 069994F9A1; Tue, 18 Sep 2018 15:46:53 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49F4082AE8 for ; Tue, 18 Sep 2018 15:46:45 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:53 +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 32/47] vircgroup: extract virCgroupV1(Set|Get)Memory*Limit 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 18 Sep 2018 15:47:30 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" They all need virCgroupV1GetMemoryUnlimitedKB() so it's easier to move them in one commit. Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 128 ++------------------------- src/util/vircgroupbackend.h | 30 +++++++ src/util/vircgrouppriv.h | 6 ++ src/util/vircgroupv1.c | 168 ++++++++++++++++++++++++++++++++++++ 4 files changed, 211 insertions(+), 121 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 1229959300..cd6b087a69 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -636,7 +636,7 @@ virCgroupMakeGroup(virCgroupPtr parent, * * Returns 0 on success, -1 on error */ -static int +int virCgroupNew(pid_t pid, const char *path, virCgroupPtr parent, @@ -1539,51 +1539,6 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, } =20 =20 -/* - * Retrieve the "memory.limit_in_bytes" value from the memory controller - * root dir. This value cannot be modified by userspace and therefore - * is the maximum limit value supported by cgroups on the local system. - * Returns this value scaled to KB or falls back to the original - * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED. Either way, remember the return - * value to avoid unnecessary cgroup filesystem access. - */ -static unsigned long long int virCgroupMemoryUnlimitedKB; -static virOnceControl virCgroupMemoryOnce =3D VIR_ONCE_CONTROL_INITIALIZER; - -static void -virCgroupMemoryOnceInit(void) -{ - virCgroupPtr group; - unsigned long long int mem_unlimited =3D 0ULL; - - if (virCgroupNew(-1, "/", NULL, -1, &group) < 0) - goto cleanup; - - if (!virCgroupHasController(group, VIR_CGROUP_CONTROLLER_MEMORY)) - goto cleanup; - - ignore_value(virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", - &mem_unlimited)); - cleanup: - virCgroupFree(&group); - virCgroupMemoryUnlimitedKB =3D mem_unlimited >> 10; -} - -static unsigned long long int -virCgroupGetMemoryUnlimitedKB(void) -{ - if (virOnce(&virCgroupMemoryOnce, virCgroupMemoryOnceInit) < 0) - VIR_DEBUG("Init failed, will fall back to defaults."); - - if (virCgroupMemoryUnlimitedKB) - return virCgroupMemoryUnlimitedKB; - else - return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; -} - - /** * virCgroupSetMemory: * @@ -1654,7 +1609,7 @@ virCgroupGetMemoryUsage(virCgroupPtr group, unsigned = long *kb) int virCgroupSetMemoryHardLimit(virCgroupPtr group, unsigned long long kb) { - return virCgroupSetMemory(group, kb); + VIR_CGROUP_BACKEND_CALL(group, setMemoryHardLimit, -1, kb); } =20 =20 @@ -1669,18 +1624,7 @@ virCgroupSetMemoryHardLimit(virCgroupPtr group, unsi= gned long long kb) int virCgroupGetMemoryHardLimit(virCgroupPtr group, unsigned long long *kb) { - long long unsigned int limit_in_bytes; - - if (virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.limit_in_bytes", &limit_in_bytes) < 0) - return -1; - - *kb =3D limit_in_bytes >> 10; - if (*kb >=3D virCgroupGetMemoryUnlimitedKB()) - *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getMemoryHardLimit, -1, kb); } =20 =20 @@ -1695,25 +1639,7 @@ virCgroupGetMemoryHardLimit(virCgroupPtr group, unsi= gned long long *kb) int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned long long kb) { - unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - if (kb > maxkb) { - virReportError(VIR_ERR_INVALID_ARG, - _("Memory '%llu' must be less than %llu"), - kb, maxkb); - return -1; - } - - if (kb =3D=3D maxkb) - return virCgroupSetValueI64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.soft_limit_in_bytes", - -1); - else - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.soft_limit_in_bytes", - kb << 10); + VIR_CGROUP_BACKEND_CALL(group, setMemorySoftLimit, -1, kb); } =20 =20 @@ -1728,18 +1654,7 @@ virCgroupSetMemorySoftLimit(virCgroupPtr group, unsi= gned long long kb) int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb) { - long long unsigned int limit_in_bytes; - - if (virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.soft_limit_in_bytes", &limit_in_bytes= ) < 0) - return -1; - - *kb =3D limit_in_bytes >> 10; - if (*kb >=3D virCgroupGetMemoryUnlimitedKB()) - *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getMemorySoftLimit, -1, kb); } =20 =20 @@ -1754,25 +1669,7 @@ virCgroupGetMemorySoftLimit(virCgroupPtr group, unsi= gned long long *kb) int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb) { - unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - if (kb > maxkb) { - virReportError(VIR_ERR_INVALID_ARG, - _("Memory '%llu' must be less than %llu"), - kb, maxkb); - return -1; - } - - if (kb =3D=3D maxkb) - return virCgroupSetValueI64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.memsw.limit_in_bytes", - -1); - else - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.memsw.limit_in_bytes", - kb << 10); + VIR_CGROUP_BACKEND_CALL(group, setMemSwapHardLimit, -1, kb); } =20 =20 @@ -1787,18 +1684,7 @@ virCgroupSetMemSwapHardLimit(virCgroupPtr group, uns= igned long long kb) int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb) { - long long unsigned int limit_in_bytes; - - if (virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.memsw.limit_in_bytes", &limit_in_byte= s) < 0) - return -1; - - *kb =3D limit_in_bytes >> 10; - if (*kb >=3D virCgroupGetMemoryUnlimitedKB()) - *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getMemSwapHardLimit, -1, kb); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 672fb082c1..5e75e495c3 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -219,6 +219,30 @@ typedef int (*virCgroupGetMemoryUsageCB)(virCgroupPtr group, unsigned long *kb); =20 +typedef int +(*virCgroupSetMemoryHardLimitCB)(virCgroupPtr group, + unsigned long long kb); + +typedef int +(*virCgroupGetMemoryHardLimitCB)(virCgroupPtr group, + unsigned long long *kb); + +typedef int +(*virCgroupSetMemorySoftLimitCB)(virCgroupPtr group, + unsigned long long kb); + +typedef int +(*virCgroupGetMemorySoftLimitCB)(virCgroupPtr group, + unsigned long long *kb); + +typedef int +(*virCgroupSetMemSwapHardLimitCB)(virCgroupPtr group, + unsigned long long kb); + +typedef int +(*virCgroupGetMemSwapHardLimitCB)(virCgroupPtr group, + unsigned long long *kb); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -261,6 +285,12 @@ struct _virCgroupBackend { virCgroupSetMemoryCB setMemory; virCgroupGetMemoryStatCB getMemoryStat; virCgroupGetMemoryUsageCB getMemoryUsage; + virCgroupSetMemoryHardLimitCB setMemoryHardLimit; + virCgroupGetMemoryHardLimitCB getMemoryHardLimit; + virCgroupSetMemorySoftLimitCB setMemorySoftLimit; + virCgroupGetMemorySoftLimitCB getMemorySoftLimit; + virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit; + virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 3a968c1ce2..7b985280e1 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -88,6 +88,12 @@ int virCgroupGetValueForBlkDev(virCgroupPtr group, const char *path, char **value); =20 +int virCgroupNew(pid_t pid, + const char *path, + virCgroupPtr parent, + int controllers, + virCgroupPtr *group); + int virCgroupNewPartition(const char *path, bool create, int controllers, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 7abb137b81..5fc046afad 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1377,6 +1377,51 @@ virCgroupV1GetBlkioDeviceWriteBps(virCgroupPtr group, } =20 =20 +/* + * Retrieve the "memory.limit_in_bytes" value from the memory controller + * root dir. This value cannot be modified by userspace and therefore + * is the maximum limit value supported by cgroups on the local system. + * Returns this value scaled to KB or falls back to the original + * VIR_DOMAIN_MEMORY_PARAM_UNLIMITED. Either way, remember the return + * value to avoid unnecessary cgroup filesystem access. + */ +static unsigned long long int virCgroupV1MemoryUnlimitedKB; +static virOnceControl virCgroupV1MemoryOnce =3D VIR_ONCE_CONTROL_INITIALIZ= ER; + +static void +virCgroupV1MemoryOnceInit(void) +{ + virCgroupPtr group; + unsigned long long int mem_unlimited =3D 0ULL; + + if (virCgroupNew(-1, "/", NULL, -1, &group) < 0) + goto cleanup; + + if (!virCgroupV1HasController(group, VIR_CGROUP_CONTROLLER_MEMORY)) + goto cleanup; + + ignore_value(virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", + &mem_unlimited)); + cleanup: + virCgroupFree(&group); + virCgroupV1MemoryUnlimitedKB =3D mem_unlimited >> 10; +} + +static unsigned long long int +virCgroupV1GetMemoryUnlimitedKB(void) +{ + if (virOnce(&virCgroupV1MemoryOnce, virCgroupV1MemoryOnceInit) < 0) + VIR_DEBUG("Init failed, will fall back to defaults."); + + if (virCgroupV1MemoryUnlimitedKB) + return virCgroupV1MemoryUnlimitedKB; + else + return VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; +} + + static int virCgroupV1SetMemory(virCgroupPtr group, unsigned long long kb) @@ -1488,6 +1533,123 @@ virCgroupV1GetMemoryUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetMemoryHardLimit(virCgroupPtr group, + unsigned long long kb) +{ + return virCgroupV1SetMemory(group, kb); +} + + +static int +virCgroupV1GetMemoryHardLimit(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int limit_in_bytes; + + if (virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.limit_in_bytes", &limit_in_bytes) < 0) + return -1; + + *kb =3D limit_in_bytes >> 10; + if (*kb >=3D virCgroupV1GetMemoryUnlimitedKB()) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + +static int +virCgroupV1SetMemorySoftLimit(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.soft_limit_in_bytes", + -1); + else + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.soft_limit_in_bytes", + kb << 10); +} + + +static int +virCgroupV1GetMemorySoftLimit(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int limit_in_bytes; + + if (virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.soft_limit_in_bytes", &limit_in_bytes= ) < 0) + return -1; + + *kb =3D limit_in_bytes >> 10; + if (*kb >=3D virCgroupV1GetMemoryUnlimitedKB()) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + +static int +virCgroupV1SetMemSwapHardLimit(virCgroupPtr group, + unsigned long long kb) +{ + unsigned long long maxkb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + if (kb > maxkb) { + virReportError(VIR_ERR_INVALID_ARG, + _("Memory '%llu' must be less than %llu"), + kb, maxkb); + return -1; + } + + if (kb =3D=3D maxkb) + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.memsw.limit_in_bytes", + -1); + else + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.memsw.limit_in_bytes", + kb << 10); +} + + +static int +virCgroupV1GetMemSwapHardLimit(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int limit_in_bytes; + + if (virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.memsw.limit_in_bytes", &limit_in_byte= s) < 0) + return -1; + + *kb =3D limit_in_bytes >> 10; + if (*kb >=3D virCgroupV1GetMemoryUnlimitedKB()) + *kb =3D VIR_DOMAIN_MEMORY_PARAM_UNLIMITED; + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1528,6 +1690,12 @@ virCgroupBackend virCgroupV1Backend =3D { .setMemory =3D virCgroupV1SetMemory, .getMemoryStat =3D virCgroupV1GetMemoryStat, .getMemoryUsage =3D virCgroupV1GetMemoryUsage, + .setMemoryHardLimit =3D virCgroupV1SetMemoryHardLimit, + .getMemoryHardLimit =3D virCgroupV1GetMemoryHardLimit, + .setMemorySoftLimit =3D virCgroupV1SetMemorySoftLimit, + .getMemorySoftLimit =3D virCgroupV1GetMemorySoftLimit, + .setMemSwapHardLimit =3D virCgroupV1SetMemSwapHardLimit, + .getMemSwapHardLimit =3D virCgroupV1GetMemSwapHardLimit, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285659079895.102540203502; Tue, 18 Sep 2018 08:47:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8248B8831D; Tue, 18 Sep 2018 15:47:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2AA007E4D4; Tue, 18 Sep 2018 15:47:34 +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 92E2941F6C; Tue, 18 Sep 2018 15:47:33 +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 w8IFkwFJ012560 for ; Tue, 18 Sep 2018 11:46:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3FAEF4F9A1; Tue, 18 Sep 2018 15:46:58 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3BF982AD3 for ; Tue, 18 Sep 2018 15:46:53 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:54 +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 33/47] vircgroup: extract virCgroupV1GetMemSwapUsage 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Sep 2018 15:47:37 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 9 +-------- src/util/vircgroupbackend.h | 5 +++++ src/util/vircgroupv1.c | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index cd6b087a69..38a30b759f 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1699,14 +1699,7 @@ virCgroupGetMemSwapHardLimit(virCgroupPtr group, uns= igned long long *kb) int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb) { - long long unsigned int usage_in_bytes; - int ret; - ret =3D virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_MEMORY, - "memory.memsw.usage_in_bytes", &usage_in_by= tes); - if (ret =3D=3D 0) - *kb =3D usage_in_bytes >> 10; - return ret; + VIR_CGROUP_BACKEND_CALL(group, getMemSwapUsage, -1, kb); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 5e75e495c3..f5454e41f7 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -243,6 +243,10 @@ typedef int (*virCgroupGetMemSwapHardLimitCB)(virCgroupPtr group, unsigned long long *kb); =20 +typedef int +(*virCgroupGetMemSwapUsageCB)(virCgroupPtr group, + unsigned long long *kb); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -291,6 +295,7 @@ struct _virCgroupBackend { virCgroupGetMemorySoftLimitCB getMemorySoftLimit; virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit; virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit; + virCgroupGetMemSwapUsageCB getMemSwapUsage; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 5fc046afad..936cf1b1f5 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1650,6 +1650,21 @@ virCgroupV1GetMemSwapHardLimit(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetMemSwapUsage(virCgroupPtr group, + unsigned long long *kb) +{ + long long unsigned int usage_in_bytes; + int ret; + ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_MEMORY, + "memory.memsw.usage_in_bytes", &usage_in_by= tes); + if (ret =3D=3D 0) + *kb =3D usage_in_bytes >> 10; + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1696,6 +1711,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getMemorySoftLimit =3D virCgroupV1GetMemorySoftLimit, .setMemSwapHardLimit =3D virCgroupV1SetMemSwapHardLimit, .getMemSwapHardLimit =3D virCgroupV1GetMemSwapHardLimit, + .getMemSwapUsage =3D virCgroupV1GetMemSwapUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285651232792.045461648868; Tue, 18 Sep 2018 08:47:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06AC5C03347A; Tue, 18 Sep 2018 15:47:27 +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 B85865E98F; Tue, 18 Sep 2018 15:47:26 +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 5BC14181D0AA; Tue, 18 Sep 2018 15:47:26 +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 w8IFl7A1012637 for ; Tue, 18 Sep 2018 11:47:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 587884F9A1; Tue, 18 Sep 2018 15:47:07 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1A9482AE2 for ; Tue, 18 Sep 2018 15:46:58 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:55 +0200 Message-Id: <1499f9df5d0cb381448d9f79908b7a8ce86b3573.1537285203.git.phrdina@redhat.com> 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 34/47] vircgroup: extract virCgroupV1(Allow|Deny)Device 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Sep 2018 15:47:30 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 68 +++++++----------------------------- src/util/vircgroupbackend.h | 17 +++++++++ src/util/vircgroupv1.c | 69 +++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 56 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 38a30b759f..8a54437dfa 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1877,29 +1877,7 @@ int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_AUTOFREE(char *) devstr =3D NULL; - VIR_AUTOFREE(char *) majorstr =3D NULL; - VIR_AUTOFREE(char *) minorstr =3D NULL; - - if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || - (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - return -1; - - if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || - (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - return -1; - - if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, - virCgroupGetDevicePermsString(perms)) < 0) - return -1; - - if (virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_DEVICES, - "devices.allow", - devstr) < 0) - return -1; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, type, major, minor, pe= rms); } =20 =20 @@ -1938,11 +1916,11 @@ virCgroupAllowDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - return virCgroupAllowDevice(group, - S_ISCHR(sb.st_mode) ? 'c' : 'b', - major(sb.st_rdev), - minor(sb.st_rdev), - perms); + VIR_CGROUP_BACKEND_CALL(group, allowDevice, -1, + S_ISCHR(sb.st_mode) ? 'c' : 'b', + major(sb.st_rdev), + minor(sb.st_rdev), + perms); } =20 =20 @@ -1961,29 +1939,7 @@ int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - VIR_AUTOFREE(char *) devstr =3D NULL; - VIR_AUTOFREE(char *) majorstr =3D NULL; - VIR_AUTOFREE(char *) minorstr =3D NULL; - - if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || - (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - return -1; - - if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || - (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - return -1; - - if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, - virCgroupGetDevicePermsString(perms)) < 0) - return -1; - - if (virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_DEVICES, - "devices.deny", - devstr) < 0) - return -1; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, type, major, minor, per= ms); } =20 =20 @@ -2022,11 +1978,11 @@ virCgroupDenyDevicePath(virCgroupPtr group, if (!S_ISCHR(sb.st_mode) && !S_ISBLK(sb.st_mode)) return 1; =20 - return virCgroupDenyDevice(group, - S_ISCHR(sb.st_mode) ? 'c' : 'b', - major(sb.st_rdev), - minor(sb.st_rdev), - perms); + VIR_CGROUP_BACKEND_CALL(group, denyDevice, -1, + S_ISCHR(sb.st_mode) ? 'c' : 'b', + major(sb.st_rdev), + minor(sb.st_rdev), + perms); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index f5454e41f7..d7250cffdb 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -247,6 +247,20 @@ typedef int (*virCgroupGetMemSwapUsageCB)(virCgroupPtr group, unsigned long long *kb); =20 +typedef int +(*virCgroupAllowDeviceCB)(virCgroupPtr group, + char type, + int major, + int minor, + int perms); + +typedef int +(*virCgroupDenyDeviceCB)(virCgroupPtr group, + char type, + int major, + int minor, + int perms); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -296,6 +310,9 @@ struct _virCgroupBackend { virCgroupSetMemSwapHardLimitCB setMemSwapHardLimit; virCgroupGetMemSwapHardLimitCB getMemSwapHardLimit; virCgroupGetMemSwapUsageCB getMemSwapUsage; + + virCgroupAllowDeviceCB allowDevice; + virCgroupDenyDeviceCB denyDevice; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 936cf1b1f5..9ac0ef555c 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1665,6 +1665,72 @@ virCgroupV1GetMemSwapUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV1AllowDevice(virCgroupPtr group, + char type, + int major, + int minor, + int perms) +{ + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; + + if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || + (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) + return -1; + + if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || + (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) + return -1; + + if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, + virCgroupGetDevicePermsString(perms)) < 0) + return -1; + + if (virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_DEVICES, + "devices.allow", + devstr) < 0) + return -1; + + return 0; +} + + +static int +virCgroupV1DenyDevice(virCgroupPtr group, + char type, + int major, + int minor, + int perms) +{ + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; + + if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || + (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) + return -1; + + if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || + (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) + return -1; + + if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, + virCgroupGetDevicePermsString(perms)) < 0) + return -1; + + if (virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_DEVICES, + "devices.deny", + devstr) < 0) + return -1; + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1712,6 +1778,9 @@ virCgroupBackend virCgroupV1Backend =3D { .setMemSwapHardLimit =3D virCgroupV1SetMemSwapHardLimit, .getMemSwapHardLimit =3D virCgroupV1GetMemSwapHardLimit, .getMemSwapUsage =3D virCgroupV1GetMemSwapUsage, + + .allowDevice =3D virCgroupV1AllowDevice, + .denyDevice =3D virCgroupV1DenyDevice, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285655316460.4877174733638; Tue, 18 Sep 2018 08:47:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1EE098667E; Tue, 18 Sep 2018 15:47:32 +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 D9D8A7E673; Tue, 18 Sep 2018 15:47:31 +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 6A66B181D0AE; Tue, 18 Sep 2018 15:47:31 +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 w8IFlEjZ012686 for ; Tue, 18 Sep 2018 11:47:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2ADE782AD3; Tue, 18 Sep 2018 15:47:14 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27FF82AE1 for ; Tue, 18 Sep 2018 15:47:07 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:56 +0200 Message-Id: <3d174ce46aa694c2b4bd5b744383c4ee6b6f683e.1537285203.git.phrdina@redhat.com> 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 35/47] vircgroup: extract virCgroupV1(Allow|Deny)AllDevices 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Sep 2018 15:47:34 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 18 ++---------------- src/util/vircgroupbackend.h | 9 +++++++++ src/util/vircgroupv1.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8a54437dfa..ca36984472 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1824,10 +1824,7 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cp= us) int virCgroupDenyAllDevices(virCgroupPtr group) { - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_DEVICES, - "devices.deny", - "a"); + VIR_CGROUP_BACKEND_CALL(group, denyAllDevices, -1); } =20 /** @@ -1847,18 +1844,7 @@ virCgroupDenyAllDevices(virCgroupPtr group) int virCgroupAllowAllDevices(virCgroupPtr group, int perms) { - int ret =3D -1; - - if (virCgroupAllowDevice(group, 'b', -1, -1, perms) < 0) - goto cleanup; - - if (virCgroupAllowDevice(group, 'c', -1, -1, perms) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - return ret; + VIR_CGROUP_BACKEND_CALL(group, allowAllDevices, -1, perms); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index d7250cffdb..ce165fead4 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -261,6 +261,13 @@ typedef int int minor, int perms); =20 +typedef int +(*virCgroupAllowAllDevicesCB)(virCgroupPtr group, + int perms); + +typedef int +(*virCgroupDenyAllDevicesCB)(virCgroupPtr group); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -313,6 +320,8 @@ struct _virCgroupBackend { =20 virCgroupAllowDeviceCB allowDevice; virCgroupDenyDeviceCB denyDevice; + virCgroupAllowAllDevicesCB allowAllDevices; + virCgroupDenyAllDevicesCB denyAllDevices; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 9ac0ef555c..bd6914f878 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1731,6 +1731,35 @@ virCgroupV1DenyDevice(virCgroupPtr group, } =20 =20 +static int +virCgroupV1AllowAllDevices(virCgroupPtr group, + int perms) +{ + int ret =3D -1; + + if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0) + goto cleanup; + + if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + return ret; +} + + +static int +virCgroupV1DenyAllDevices(virCgroupPtr group) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_DEVICES, + "devices.deny", + "a"); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1781,6 +1810,8 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .allowDevice =3D virCgroupV1AllowDevice, .denyDevice =3D virCgroupV1DenyDevice, + .allowAllDevices =3D virCgroupV1AllowAllDevices, + .denyAllDevices =3D virCgroupV1DenyAllDevices, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285662994207.61598084859713; Tue, 18 Sep 2018 08:47:42 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9C383001DDA; Tue, 18 Sep 2018 15:47:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5581308BDA1; Tue, 18 Sep 2018 15:47:40 +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 3DE8D41F7C; Tue, 18 Sep 2018 15:47:40 +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 w8IFlGGK012771 for ; Tue, 18 Sep 2018 11:47:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3591E82AD3; Tue, 18 Sep 2018 15:47:16 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE1F182AE4 for ; Tue, 18 Sep 2018 15:47:14 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:57 +0200 Message-Id: <1017a110ffb5a6c3c3689640e5d3f25f18cfb05c.1537285203.git.phrdina@redhat.com> 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 36/47] vircgroup: extract virCgroupV1(Set|Get)CpuShares 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 18 Sep 2018 15:47:41 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 8 ++------ src/util/vircgroupbackend.h | 11 +++++++++++ src/util/vircgroupv1.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index ca36984472..d7d11062e5 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2207,18 +2207,14 @@ virCgroupGetDomainTotalCpuStats(virCgroupPtr group, int virCgroupSetCpuShares(virCgroupPtr group, unsigned long long shares) { - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.shares", shares); + VIR_CGROUP_BACKEND_CALL(group, setCpuShares, -1, shares); } =20 =20 int virCgroupGetCpuShares(virCgroupPtr group, unsigned long long *shares) { - return virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.shares", shares); + VIR_CGROUP_BACKEND_CALL(group, getCpuShares, -1, shares); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index ce165fead4..7dbe005319 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -268,6 +268,14 @@ typedef int typedef int (*virCgroupDenyAllDevicesCB)(virCgroupPtr group); =20 +typedef int +(*virCgroupSetCpuSharesCB)(virCgroupPtr group, + unsigned long long shares); + +typedef int +(*virCgroupGetCpuSharesCB)(virCgroupPtr group, + unsigned long long *shares); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -322,6 +330,9 @@ struct _virCgroupBackend { virCgroupDenyDeviceCB denyDevice; virCgroupAllowAllDevicesCB allowAllDevices; virCgroupDenyAllDevicesCB denyAllDevices; + + virCgroupSetCpuSharesCB setCpuShares; + virCgroupGetCpuSharesCB getCpuShares; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index bd6914f878..d2989b0a63 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1760,6 +1760,26 @@ virCgroupV1DenyAllDevices(virCgroupPtr group) } =20 =20 +static int +virCgroupV1SetCpuShares(virCgroupPtr group, + unsigned long long shares) +{ + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.shares", shares); +} + + +static int +virCgroupV1GetCpuShares(virCgroupPtr group, + unsigned long long *shares) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.shares", shares); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1812,6 +1832,9 @@ virCgroupBackend virCgroupV1Backend =3D { .denyDevice =3D virCgroupV1DenyDevice, .allowAllDevices =3D virCgroupV1AllowAllDevices, .denyAllDevices =3D virCgroupV1DenyAllDevices, + + .setCpuShares =3D virCgroupV1SetCpuShares, + .getCpuShares =3D virCgroupV1GetCpuShares, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285660694388.92463831815337; Tue, 18 Sep 2018 08:47:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 981C6BCD57; Tue, 18 Sep 2018 15:47:37 +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 32A3F88EC0; Tue, 18 Sep 2018 15:47:37 +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 C3136181D0B2; Tue, 18 Sep 2018 15:47:36 +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 w8IFlJve013062 for ; Tue, 18 Sep 2018 11:47:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 89D8B4F9A1; Tue, 18 Sep 2018 15:47:19 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CD2B82AD8 for ; Tue, 18 Sep 2018 15:47:16 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:58 +0200 Message-Id: <8cc43a2de0180c96ea505194c57cbabcc1043b3a.1537285203.git.phrdina@redhat.com> 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 37/47] vircgroup: extract virCgroupV1(Set|Get)CpuCfsPeriod 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.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Sep 2018 15:47:39 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 18 ++---------------- src/util/vircgroupbackend.h | 10 ++++++++++ src/util/vircgroupv1.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index d7d11062e5..beb661df4b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2229,19 +2229,7 @@ virCgroupGetCpuShares(virCgroupPtr group, unsigned l= ong long *shares) int virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned long long cfs_period) { - /* The cfs_period should be greater or equal than 1ms, and less or equ= al - * than 1s. - */ - if (cfs_period < 1000 || cfs_period > 1000000) { - virReportError(VIR_ERR_INVALID_ARG, - _("cfs_period '%llu' must be in range (1000, 100000= 0)"), - cfs_period); - return -1; - } - - return virCgroupSetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_period_us", cfs_period); + VIR_CGROUP_BACKEND_CALL(group, setCpuCfsPeriod, -1, cfs_period); } =20 =20 @@ -2256,9 +2244,7 @@ virCgroupSetCpuCfsPeriod(virCgroupPtr group, unsigned= long long cfs_period) int virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigned long long *cfs_perio= d) { - return virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_period_us", cfs_period); + VIR_CGROUP_BACKEND_CALL(group, getCpuCfsPeriod, -1, cfs_period); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 7dbe005319..59f68169ba 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -276,6 +276,14 @@ typedef int (*virCgroupGetCpuSharesCB)(virCgroupPtr group, unsigned long long *shares); =20 +typedef int +(*virCgroupSetCpuCfsPeriodCB)(virCgroupPtr group, + unsigned long long cfs_period); + +typedef int +(*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group, + unsigned long long *cfs_period); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -333,6 +341,8 @@ struct _virCgroupBackend { =20 virCgroupSetCpuSharesCB setCpuShares; virCgroupGetCpuSharesCB getCpuShares; + virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod; + virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index d2989b0a63..3641371512 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1780,6 +1780,36 @@ virCgroupV1GetCpuShares(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetCpuCfsPeriod(virCgroupPtr group, + unsigned long long cfs_period) +{ + /* The cfs_period should be greater or equal than 1ms, and less or equ= al + * than 1s. + */ + if (cfs_period < 1000 || cfs_period > 1000000) { + virReportError(VIR_ERR_INVALID_ARG, + _("cfs_period '%llu' must be in range (1000, 100000= 0)"), + cfs_period); + return -1; + } + + return virCgroupSetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_period_us", cfs_period); +} + + +static int +virCgroupV1GetCpuCfsPeriod(virCgroupPtr group, + unsigned long long *cfs_period) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_period_us", cfs_period); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1835,6 +1865,8 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .setCpuShares =3D virCgroupV1SetCpuShares, .getCpuShares =3D virCgroupV1GetCpuShares, + .setCpuCfsPeriod =3D virCgroupV1SetCpuCfsPeriod, + .getCpuCfsPeriod =3D virCgroupV1GetCpuCfsPeriod, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285665129215.00635225735687; Tue, 18 Sep 2018 08:47:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E80A730A3AE9; Tue, 18 Sep 2018 15:47:42 +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 A9C0B7E674; Tue, 18 Sep 2018 15:47:42 +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 479BD181D0B4; Tue, 18 Sep 2018 15:47:42 +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 w8IFlKq2013087 for ; Tue, 18 Sep 2018 11:47:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7F6482AD8; Tue, 18 Sep 2018 15:47:20 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B5D082AD7 for ; Tue, 18 Sep 2018 15:47:19 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:45:59 +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 38/47] vircgroup: extract virCgroupV1(Set|Get)CpuCfsQuota 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Tue, 18 Sep 2018 15:47:43 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 20 +++----------------- src/util/vircgroupbackend.h | 10 ++++++++++ src/util/vircgrouppriv.h | 5 +++++ src/util/vircgroupv1.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index beb661df4b..17b8c13cf9 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -561,7 +561,7 @@ virCgroupSetValueI64(virCgroupPtr group, } =20 =20 -static int +int virCgroupGetValueI64(virCgroupPtr group, int controller, const char *key, @@ -2260,19 +2260,7 @@ virCgroupGetCpuCfsPeriod(virCgroupPtr group, unsigne= d long long *cfs_period) int virCgroupSetCpuCfsQuota(virCgroupPtr group, long long cfs_quota) { - /* The cfs_quota should be greater or equal than 1ms */ - if (cfs_quota >=3D 0 && - (cfs_quota < 1000 || - cfs_quota > ULLONG_MAX / 1000)) { - virReportError(VIR_ERR_INVALID_ARG, - _("cfs_quota '%lld' must be in range (1000, %llu)"), - cfs_quota, ULLONG_MAX / 1000); - return -1; - } - - return virCgroupSetValueI64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_quota_us", cfs_quota); + VIR_CGROUP_BACKEND_CALL(group, setCpuCfsQuota, -1, cfs_quota); } =20 =20 @@ -2596,9 +2584,7 @@ virCgroupKillPainfully(virCgroupPtr group) int virCgroupGetCpuCfsQuota(virCgroupPtr group, long long *cfs_quota) { - return virCgroupGetValueI64(group, - VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_quota_us", cfs_quota); + VIR_CGROUP_BACKEND_CALL(group, getCpuCfsQuota, -1, cfs_quota); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 59f68169ba..b94a89069a 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -284,6 +284,14 @@ typedef int (*virCgroupGetCpuCfsPeriodCB)(virCgroupPtr group, unsigned long long *cfs_period); =20 +typedef int +(*virCgroupSetCpuCfsQuotaCB)(virCgroupPtr group, + long long cfs_quota); + +typedef int +(*virCgroupGetCpuCfsQuotaCB)(virCgroupPtr group, + long long *cfs_quota); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -343,6 +351,8 @@ struct _virCgroupBackend { virCgroupGetCpuSharesCB getCpuShares; virCgroupSetCpuCfsPeriodCB setCpuCfsPeriod; virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod; + virCgroupSetCpuCfsQuotaCB setCpuCfsQuota; + virCgroupGetCpuCfsQuotaCB getCpuCfsQuota; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 7b985280e1..38c911e8ed 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -78,6 +78,11 @@ int virCgroupSetValueI64(virCgroupPtr group, const char *key, long long int value); =20 +int virCgroupGetValueI64(virCgroupPtr group, + int controller, + const char *key, + long long int *value); + int virCgroupPartitionEscape(char **path); =20 char *virCgroupGetBlockDevString(const char *path); diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 3641371512..5de6d27f48 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1810,6 +1810,36 @@ virCgroupV1GetCpuCfsPeriod(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetCpuCfsQuota(virCgroupPtr group, + long long cfs_quota) +{ + /* The cfs_quota should be greater or equal than 1ms */ + if (cfs_quota >=3D 0 && + (cfs_quota < 1000 || + cfs_quota > ULLONG_MAX / 1000)) { + virReportError(VIR_ERR_INVALID_ARG, + _("cfs_quota '%lld' must be in range (1000, %llu)"), + cfs_quota, ULLONG_MAX / 1000); + return -1; + } + + return virCgroupSetValueI64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_quota_us", cfs_quota); +} + + +static int +virCgroupV1GetCpuCfsQuota(virCgroupPtr group, + long long *cfs_quota) +{ + return virCgroupGetValueI64(group, + VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_quota_us", cfs_quota); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1867,6 +1897,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getCpuShares =3D virCgroupV1GetCpuShares, .setCpuCfsPeriod =3D virCgroupV1SetCpuCfsPeriod, .getCpuCfsPeriod =3D virCgroupV1GetCpuCfsPeriod, + .setCpuCfsQuota =3D virCgroupV1SetCpuCfsQuota, + .getCpuCfsQuota =3D virCgroupV1GetCpuCfsQuota, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 153728566969236.540882460634975; Tue, 18 Sep 2018 08:47:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C726230A56A0; Tue, 18 Sep 2018 15:47:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 81DD23091384; Tue, 18 Sep 2018 15:47:47 +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 32F4C41F36; Tue, 18 Sep 2018 15:47:47 +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 w8IFlLJP013106 for ; Tue, 18 Sep 2018 11:47:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F58B82AD3; Tue, 18 Sep 2018 15:47:21 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 217BE82AD7 for ; Tue, 18 Sep 2018 15:47:20 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:00 +0200 Message-Id: <327960981cd7e1067e8f780fb46fc891d2880820.1537285203.git.phrdina@redhat.com> 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 39/47] vircgroup: extract virCgroupV1SupportsCpuBW 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 18 Sep 2018 15:47:48 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 13 +------------ src/util/vircgroupbackend.h | 4 ++++ src/util/vircgroupv1.c | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 17b8c13cf9..bdbed65be2 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2687,18 +2687,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup, bool virCgroupSupportsCpuBW(virCgroupPtr cgroup) { - VIR_AUTOFREE(char *) path =3D NULL; - - if (!cgroup) - return false; - - if (virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_CPU, - "cpu.cfs_period_us", &path) < 0) { - virResetLastError(); - return false; - } - - return virFileExists(path); + VIR_CGROUP_BACKEND_CALL(cgroup, supportsCpuBW, false); } =20 int diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index b94a89069a..049f9040bd 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -292,6 +292,9 @@ typedef int (*virCgroupGetCpuCfsQuotaCB)(virCgroupPtr group, long long *cfs_quota); =20 +typedef bool +(*virCgroupSupportsCpuBWCB)(virCgroupPtr cgroup); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -353,6 +356,7 @@ struct _virCgroupBackend { virCgroupGetCpuCfsPeriodCB getCpuCfsPeriod; virCgroupSetCpuCfsQuotaCB setCpuCfsQuota; virCgroupGetCpuCfsQuotaCB getCpuCfsQuota; + virCgroupSupportsCpuBWCB supportsCpuBW; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 5de6d27f48..88912778b5 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1840,6 +1840,24 @@ virCgroupV1GetCpuCfsQuota(virCgroupPtr group, } =20 =20 +static bool +virCgroupV1SupportsCpuBW(virCgroupPtr cgroup) +{ + VIR_AUTOFREE(char *) path =3D NULL; + + if (!cgroup) + return false; + + if (virCgroupV1PathOfController(cgroup, VIR_CGROUP_CONTROLLER_CPU, + "cpu.cfs_period_us", &path) < 0) { + virResetLastError(); + return false; + } + + return virFileExists(path); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1899,6 +1917,7 @@ virCgroupBackend virCgroupV1Backend =3D { .getCpuCfsPeriod =3D virCgroupV1GetCpuCfsPeriod, .setCpuCfsQuota =3D virCgroupV1SetCpuCfsQuota, .getCpuCfsQuota =3D virCgroupV1GetCpuCfsQuota, + .supportsCpuBW =3D virCgroupV1SupportsCpuBW, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 153728566772686.77857439209026; Tue, 18 Sep 2018 08:47:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17EA965991; Tue, 18 Sep 2018 15:47:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9A743091384; Tue, 18 Sep 2018 15:47:45 +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 8B0DF41F7D; Tue, 18 Sep 2018 15:47:45 +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 w8IFlMAN013126 for ; Tue, 18 Sep 2018 11:47:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 74EEB4F9A1; Tue, 18 Sep 2018 15:47:22 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBCC482ADB for ; Tue, 18 Sep 2018 15:47:21 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:01 +0200 Message-Id: <11d1fc15a23ea82e003204cd620b2d3399b97b14.1537285203.git.phrdina@redhat.com> 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 40/47] vircgroup: extract virCgroupV1GetCpuacct*Usage 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Sep 2018 15:47:46 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 7 ++----- src/util/vircgroupbackend.h | 11 +++++++++++ src/util/vircgroupv1.c | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index bdbed65be2..598147acf7 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2267,8 +2267,7 @@ virCgroupSetCpuCfsQuota(virCgroupPtr group, long long= cfs_quota) int virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage) { - return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage_percpu", usage); + VIR_CGROUP_BACKEND_CALL(group, getCpuacctPercpuUsage, -1, usage); } =20 =20 @@ -2591,9 +2590,7 @@ virCgroupGetCpuCfsQuota(virCgroupPtr group, long long= *cfs_quota) int virCgroupGetCpuacctUsage(virCgroupPtr group, unsigned long long *usage) { - return virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.usage", usage); + VIR_CGROUP_BACKEND_CALL(group, getCpuacctUsage, -1, usage); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 049f9040bd..380ab9850d 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -295,6 +295,14 @@ typedef int typedef bool (*virCgroupSupportsCpuBWCB)(virCgroupPtr cgroup); =20 +typedef int +(*virCgroupGetCpuacctUsageCB)(virCgroupPtr group, + unsigned long long *usage); + +typedef int +(*virCgroupGetCpuacctPercpuUsageCB)(virCgroupPtr group, + char **usage); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -357,6 +365,9 @@ struct _virCgroupBackend { virCgroupSetCpuCfsQuotaCB setCpuCfsQuota; virCgroupGetCpuCfsQuotaCB getCpuCfsQuota; virCgroupSupportsCpuBWCB supportsCpuBW; + + virCgroupGetCpuacctUsageCB getCpuacctUsage; + virCgroupGetCpuacctPercpuUsageCB getCpuacctPercpuUsage; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 88912778b5..a827917db1 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1858,6 +1858,25 @@ virCgroupV1SupportsCpuBW(virCgroupPtr cgroup) } =20 =20 +static int +virCgroupV1GetCpuacctUsage(virCgroupPtr group, + unsigned long long *usage) +{ + return virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.usage", usage); +} + + +static int +virCgroupV1GetCpuacctPercpuUsage(virCgroupPtr group, + char **usage) +{ + return virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.usage_percpu", usage); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1918,6 +1937,9 @@ virCgroupBackend virCgroupV1Backend =3D { .setCpuCfsQuota =3D virCgroupV1SetCpuCfsQuota, .getCpuCfsQuota =3D virCgroupV1GetCpuCfsQuota, .supportsCpuBW =3D virCgroupV1SupportsCpuBW, + + .getCpuacctUsage =3D virCgroupV1GetCpuacctUsage, + .getCpuacctPercpuUsage =3D virCgroupV1GetCpuacctPercpuUsage, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285674843584.1762769035981; Tue, 18 Sep 2018 08:47:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5F4A3091DC1; Tue, 18 Sep 2018 15:47:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F0B33091385; Tue, 18 Sep 2018 15:47:52 +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 BAAD03FCC3; Tue, 18 Sep 2018 15:47:49 +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 w8IFlO4S013153 for ; Tue, 18 Sep 2018 11:47:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 06E7C82AE7; Tue, 18 Sep 2018 15:47:24 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7CDA982AE1 for ; Tue, 18 Sep 2018 15:47:22 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:02 +0200 Message-Id: <9bbd5b22e8101dbe8024c424ce19ceb71840e101.1537285203.git.phrdina@redhat.com> 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 41/47] vircgroup: extract virCgroupV1GetCpuacctStat 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 18 Sep 2018 15:47:53 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina Reviewed-by: Fabiano Fid=C3=AAncio --- src/util/vircgroup.c | 39 +----------------------------- src/util/vircgroupbackend.h | 6 +++++ src/util/vircgroupv1.c | 47 +++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 598147acf7..9ba2318c0b 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2598,44 +2598,7 @@ int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, unsigned long long *sys) { - VIR_AUTOFREE(char *) str =3D NULL; - char *p; - static double scale =3D -1.0; - - if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, - "cpuacct.stat", &str) < 0) - return -1; - - if (!(p =3D STRSKIP(str, "user ")) || - virStrToLong_ull(p, &p, 10, user) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse user stat '%s'"), - p); - return -1; - } - if (!(p =3D STRSKIP(p, "\nsystem ")) || - virStrToLong_ull(p, NULL, 10, sys) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot parse sys stat '%s'"), - p); - return -1; - } - /* times reported are in system ticks (generally 100 Hz), but that - * rate can theoretically vary between machines. Scale things - * into approximate nanoseconds. */ - if (scale < 0) { - long ticks_per_sec =3D sysconf(_SC_CLK_TCK); - if (ticks_per_sec =3D=3D -1) { - virReportSystemError(errno, "%s", - _("Cannot determine system clock HZ")); - return -1; - } - scale =3D 1000000000.0 / ticks_per_sec; - } - *user *=3D scale; - *sys *=3D scale; - - return 0; + VIR_CGROUP_BACKEND_CALL(group, getCpuacctStat, -1, user, sys); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 380ab9850d..a80ad0b5d3 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -303,6 +303,11 @@ typedef int (*virCgroupGetCpuacctPercpuUsageCB)(virCgroupPtr group, char **usage); =20 +typedef int +(*virCgroupGetCpuacctStatCB)(virCgroupPtr group, + unsigned long long *user, + unsigned long long *sys); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -368,6 +373,7 @@ struct _virCgroupBackend { =20 virCgroupGetCpuacctUsageCB getCpuacctUsage; virCgroupGetCpuacctPercpuUsageCB getCpuacctPercpuUsage; + virCgroupGetCpuacctStatCB getCpuacctStat; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index a827917db1..f99cf5c6d6 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1877,6 +1877,52 @@ virCgroupV1GetCpuacctPercpuUsage(virCgroupPtr group, } =20 =20 +static int +virCgroupV1GetCpuacctStat(virCgroupPtr group, + unsigned long long *user, + unsigned long long *sys) +{ + VIR_AUTOFREE(char *) str =3D NULL; + char *p; + static double scale =3D -1.0; + + if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, + "cpuacct.stat", &str) < 0) + return -1; + + if (!(p =3D STRSKIP(str, "user ")) || + virStrToLong_ull(p, &p, 10, user) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse user stat '%s'"), + p); + return -1; + } + if (!(p =3D STRSKIP(p, "\nsystem ")) || + virStrToLong_ull(p, NULL, 10, sys) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot parse sys stat '%s'"), + p); + return -1; + } + /* times reported are in system ticks (generally 100 Hz), but that + * rate can theoretically vary between machines. Scale things + * into approximate nanoseconds. */ + if (scale < 0) { + long ticks_per_sec =3D sysconf(_SC_CLK_TCK); + if (ticks_per_sec =3D=3D -1) { + virReportSystemError(errno, "%s", + _("Cannot determine system clock HZ")); + return -1; + } + scale =3D 1000000000.0 / ticks_per_sec; + } + *user *=3D scale; + *sys *=3D scale; + + return 0; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1940,6 +1986,7 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .getCpuacctUsage =3D virCgroupV1GetCpuacctUsage, .getCpuacctPercpuUsage =3D virCgroupV1GetCpuacctPercpuUsage, + .getCpuacctStat =3D virCgroupV1GetCpuacctStat, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285676777805.6806856402623; Tue, 18 Sep 2018 08:47:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE7ECC01EE9A; Tue, 18 Sep 2018 15:47:54 +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 9849B10021B1; Tue, 18 Sep 2018 15:47:54 +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 3CE7A181A73C; Tue, 18 Sep 2018 15:47:54 +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 w8IFlO72013167 for ; Tue, 18 Sep 2018 11:47:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6BBC82AD6; Tue, 18 Sep 2018 15:47:24 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 533CA4F9A1 for ; Tue, 18 Sep 2018 15:47:24 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:03 +0200 Message-Id: <3cb195710a15ab8b8718224b3e8209963ff3007b.1537285203.git.phrdina@redhat.com> 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 42/47] vircgroup: extract virCgroupV1(Set|Get)FreezerState 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Sep 2018 15:47:55 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 8 ++------ src/util/vircgroupbackend.h | 11 +++++++++++ src/util/vircgroupv1.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 9ba2318c0b..8744cd067d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -2605,18 +2605,14 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigne= d long long *user, int virCgroupSetFreezerState(virCgroupPtr group, const char *state) { - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); + VIR_CGROUP_BACKEND_CALL(group, setFreezerState, -1, state); } =20 =20 int virCgroupGetFreezerState(virCgroupPtr group, char **state) { - return virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_FREEZER, - "freezer.state", state); + VIR_CGROUP_BACKEND_CALL(group, getFreezerState, -1, state); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index a80ad0b5d3..0369b48f2b 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -308,6 +308,14 @@ typedef int unsigned long long *user, unsigned long long *sys); =20 +typedef int +(*virCgroupSetFreezerStateCB)(virCgroupPtr group, + const char *state); + +typedef int +(*virCgroupGetFreezerStateCB)(virCgroupPtr group, + char **state); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -374,6 +382,9 @@ struct _virCgroupBackend { virCgroupGetCpuacctUsageCB getCpuacctUsage; virCgroupGetCpuacctPercpuUsageCB getCpuacctPercpuUsage; virCgroupGetCpuacctStatCB getCpuacctStat; + + virCgroupSetFreezerStateCB setFreezerState; + virCgroupGetFreezerStateCB getFreezerState; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index f99cf5c6d6..a1b2f3eb23 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1923,6 +1923,26 @@ virCgroupV1GetCpuacctStat(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetFreezerState(virCgroupPtr group, + const char *state) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + + +static int +virCgroupV1GetFreezerState(virCgroupPtr group, + char **state) +{ + return virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_FREEZER, + "freezer.state", state); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -1987,6 +2007,9 @@ virCgroupBackend virCgroupV1Backend =3D { .getCpuacctUsage =3D virCgroupV1GetCpuacctUsage, .getCpuacctPercpuUsage =3D virCgroupV1GetCpuacctPercpuUsage, .getCpuacctStat =3D virCgroupV1GetCpuacctStat, + + .setFreezerState =3D virCgroupV1SetFreezerState, + .getFreezerState =3D virCgroupV1GetFreezerState, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:19 2024 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 1537285678441482.7752513551819; Tue, 18 Sep 2018 08:47:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A295F308213E; Tue, 18 Sep 2018 15:47:54 +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 44339106A7BC; Tue, 18 Sep 2018 15:47:54 +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 70D6A181A721; Tue, 18 Sep 2018 15:47:51 +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 w8IFlPGO013176 for ; Tue, 18 Sep 2018 11:47:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id A684F82ADB; Tue, 18 Sep 2018 15:47:25 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B7874F9A1 for ; Tue, 18 Sep 2018 15:47:25 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:04 +0200 Message-Id: <255da53867ed5c86ac2b5b4b45e42fc2e249c3f9.1537285203.git.phrdina@redhat.com> 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 43/47] vircgroup: extract virCgroupV1(Set|Get)CpusetMems 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 18 Sep 2018 15:47:56 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 10 ++-------- src/util/vircgroupbackend.h | 11 +++++++++++ src/util/vircgroupv1.c | 25 +++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 8744cd067d..1e19813cb3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1714,10 +1714,7 @@ virCgroupGetMemSwapUsage(virCgroupPtr group, unsigne= d long long *kb) int virCgroupSetCpusetMems(virCgroupPtr group, const char *mems) { - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.mems", - mems); + VIR_CGROUP_BACKEND_CALL(group, setCpusetMems, -1, mems); } =20 =20 @@ -1732,10 +1729,7 @@ virCgroupSetCpusetMems(virCgroupPtr group, const cha= r *mems) int virCgroupGetCpusetMems(virCgroupPtr group, char **mems) { - return virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.mems", - mems); + VIR_CGROUP_BACKEND_CALL(group, getCpusetMems, -1, mems); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 0369b48f2b..86fe8ce2db 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -316,6 +316,14 @@ typedef int (*virCgroupGetFreezerStateCB)(virCgroupPtr group, char **state); =20 +typedef int +(*virCgroupSetCpusetMemsCB)(virCgroupPtr group, + const char *mems); + +typedef int +(*virCgroupGetCpusetMemsCB)(virCgroupPtr group, + char **mems); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -385,6 +393,9 @@ struct _virCgroupBackend { =20 virCgroupSetFreezerStateCB setFreezerState; virCgroupGetFreezerStateCB getFreezerState; + + virCgroupSetCpusetMemsCB setCpusetMems; + virCgroupGetCpusetMemsCB getCpusetMems; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index a1b2f3eb23..aff1706c5b 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1943,6 +1943,28 @@ virCgroupV1GetFreezerState(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetCpusetMems(virCgroupPtr group, + const char *mems) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.mems", + mems); +} + + +static int +virCgroupV1GetCpusetMems(virCgroupPtr group, + char **mems) +{ + return virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.mems", + mems); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -2010,6 +2032,9 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .setFreezerState =3D virCgroupV1SetFreezerState, .getFreezerState =3D virCgroupV1GetFreezerState, + + .setCpusetMems =3D virCgroupV1SetCpusetMems, + .getCpusetMems =3D virCgroupV1GetCpusetMems, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:20 2024 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 1537285679390535.8312041708149; Tue, 18 Sep 2018 08:47:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79CACA039A; Tue, 18 Sep 2018 15:47:56 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41B3B68C98; Tue, 18 Sep 2018 15:47:56 +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 E51F13FCDF; Tue, 18 Sep 2018 15:47:55 +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 w8IFlQ7W013189 for ; Tue, 18 Sep 2018 11:47:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DA144F9A1; Tue, 18 Sep 2018 15:47:26 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0204182AE1 for ; Tue, 18 Sep 2018 15:47:25 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:05 +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 44/47] vircgroup: extract virCgroupV1(Set|Get)CpusetMemoryMigrate 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Sep 2018 15:47:58 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 13 ++----------- src/util/vircgroupbackend.h | 10 ++++++++++ src/util/vircgroupv1.c | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 1e19813cb3..c37ada7c26 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1744,10 +1744,7 @@ virCgroupGetCpusetMems(virCgroupPtr group, char **me= ms) int virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, bool migrate) { - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.memory_migrate", - migrate ? "1" : "0"); + VIR_CGROUP_BACKEND_CALL(group, setCpusetMemoryMigrate, -1, migrate); } =20 =20 @@ -1762,13 +1759,7 @@ virCgroupSetCpusetMemoryMigrate(virCgroupPtr group, = bool migrate) int virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, bool *migrate) { - unsigned long long value =3D 0; - int ret =3D virCgroupGetValueU64(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.memory_migrate", - &value); - *migrate =3D !!value; - return ret; + VIR_CGROUP_BACKEND_CALL(group, getCpusetMemoryMigrate, -1, migrate); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 86fe8ce2db..887a508a15 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -324,6 +324,14 @@ typedef int (*virCgroupGetCpusetMemsCB)(virCgroupPtr group, char **mems); =20 +typedef int +(*virCgroupSetCpusetMemoryMigrateCB)(virCgroupPtr group, + bool migrate); + +typedef int +(*virCgroupGetCpusetMemoryMigrateCB)(virCgroupPtr group, + bool *migrate); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -396,6 +404,8 @@ struct _virCgroupBackend { =20 virCgroupSetCpusetMemsCB setCpusetMems; virCgroupGetCpusetMemsCB getCpusetMems; + virCgroupSetCpusetMemoryMigrateCB setCpusetMemoryMigrate; + virCgroupGetCpusetMemoryMigrateCB getCpusetMemoryMigrate; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index aff1706c5b..8070aede3e 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1965,6 +1965,31 @@ virCgroupV1GetCpusetMems(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetCpusetMemoryMigrate(virCgroupPtr group, + bool migrate) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.memory_migrate", + migrate ? "1" : "0"); +} + + +static int +virCgroupV1GetCpusetMemoryMigrate(virCgroupPtr group, + bool *migrate) +{ + unsigned long long value =3D 0; + int ret =3D virCgroupGetValueU64(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.memory_migrate", + &value); + *migrate =3D !!value; + return ret; +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -2035,6 +2060,8 @@ virCgroupBackend virCgroupV1Backend =3D { =20 .setCpusetMems =3D virCgroupV1SetCpusetMems, .getCpusetMems =3D virCgroupV1GetCpusetMems, + .setCpusetMemoryMigrate =3D virCgroupV1SetCpusetMemoryMigrate, + .getCpusetMemoryMigrate =3D virCgroupV1GetCpusetMemoryMigrate, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:20 2024 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 1537285682575507.14818628652847; Tue, 18 Sep 2018 08:48:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BEFCD3091D4E; Tue, 18 Sep 2018 15:48:00 +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 820AC2015AFD; Tue, 18 Sep 2018 15:48:00 +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 264FB181A139; Tue, 18 Sep 2018 15:48:00 +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 w8IFlRbk013215 for ; Tue, 18 Sep 2018 11:47:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5513482216; Tue, 18 Sep 2018 15:47:27 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB6934F9A1 for ; Tue, 18 Sep 2018 15:47:26 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:06 +0200 Message-Id: <6ee6fcab239ddf9a208cc0a966a0a9a38c4e8501.1537285203.git.phrdina@redhat.com> 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 45/47] vircgroup: extract virCgroupV1(Set|Get)CpusetCpus 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 18 Sep 2018 15:48:01 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 10 ++-------- src/util/vircgroupbackend.h | 10 ++++++++++ src/util/vircgroupv1.c | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index c37ada7c26..b61c6bf2f3 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1774,10 +1774,7 @@ virCgroupGetCpusetMemoryMigrate(virCgroupPtr group, = bool *migrate) int virCgroupSetCpusetCpus(virCgroupPtr group, const char *cpus) { - return virCgroupSetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.cpus", - cpus); + VIR_CGROUP_BACKEND_CALL(group, setCpusetCpus, -1, cpus); } =20 =20 @@ -1792,10 +1789,7 @@ virCgroupSetCpusetCpus(virCgroupPtr group, const cha= r *cpus) int virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus) { - return virCgroupGetValueStr(group, - VIR_CGROUP_CONTROLLER_CPUSET, - "cpuset.cpus", - cpus); + VIR_CGROUP_BACKEND_CALL(group, getCpusetCpus, -1, cpus); } =20 =20 diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h index 887a508a15..fc7745d714 100644 --- a/src/util/vircgroupbackend.h +++ b/src/util/vircgroupbackend.h @@ -332,6 +332,14 @@ typedef int (*virCgroupGetCpusetMemoryMigrateCB)(virCgroupPtr group, bool *migrate); =20 +typedef int +(*virCgroupSetCpusetCpusCB)(virCgroupPtr group, + const char *cpus); + +typedef int +(*virCgroupGetCpusetCpusCB)(virCgroupPtr group, + char **cpus); + struct _virCgroupBackend { virCgroupBackendType type; =20 @@ -406,6 +414,8 @@ struct _virCgroupBackend { virCgroupGetCpusetMemsCB getCpusetMems; virCgroupSetCpusetMemoryMigrateCB setCpusetMemoryMigrate; virCgroupGetCpusetMemoryMigrateCB getCpusetMemoryMigrate; + virCgroupSetCpusetCpusCB setCpusetCpus; + virCgroupGetCpusetCpusCB getCpusetCpus; }; typedef struct _virCgroupBackend virCgroupBackend; typedef virCgroupBackend *virCgroupBackendPtr; diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index 8070aede3e..be0be0f582 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -1990,6 +1990,28 @@ virCgroupV1GetCpusetMemoryMigrate(virCgroupPtr group, } =20 =20 +static int +virCgroupV1SetCpusetCpus(virCgroupPtr group, + const char *cpus) +{ + return virCgroupSetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.cpus", + cpus); +} + + +static int +virCgroupV1GetCpusetCpus(virCgroupPtr group, + char **cpus) +{ + return virCgroupGetValueStr(group, + VIR_CGROUP_CONTROLLER_CPUSET, + "cpuset.cpus", + cpus); +} + + virCgroupBackend virCgroupV1Backend =3D { .type =3D VIR_CGROUP_BACKEND_TYPE_V1, =20 @@ -2062,6 +2084,8 @@ virCgroupBackend virCgroupV1Backend =3D { .getCpusetMems =3D virCgroupV1GetCpusetMems, .setCpusetMemoryMigrate =3D virCgroupV1SetCpusetMemoryMigrate, .getCpusetMemoryMigrate =3D virCgroupV1GetCpusetMemoryMigrate, + .setCpusetCpus =3D virCgroupV1SetCpusetCpus, + .getCpusetCpus =3D virCgroupV1GetCpusetCpus, }; =20 =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:20 2024 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 1537285667831955.5561487283327; Tue, 18 Sep 2018 08:47:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB1A6804ED; Tue, 18 Sep 2018 15:47:45 +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 B61D289E07; Tue, 18 Sep 2018 15:47:43 +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 2D473181D0B7; Tue, 18 Sep 2018 15:47:43 +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 w8IFlSs9013228 for ; Tue, 18 Sep 2018 11:47:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2927E82AD7; Tue, 18 Sep 2018 15:47:28 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A14DD4F9A1 for ; Tue, 18 Sep 2018 15:47:27 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:07 +0200 Message-Id: <22af09ed9d2ccedfa99b36519e251c40518fe83d.1537285203.git.phrdina@redhat.com> 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 46/47] vircgroup: rename virCgroupController into virCgroupV1Controller 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.84 on 10.5.11.27 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:47:46 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgrouppriv.h | 8 ++++---- src/util/vircgroupv1.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 38c911e8ed..ee6aeedbb5 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -32,7 +32,7 @@ # include "vircgroup.h" # include "vircgroupbackend.h" =20 -struct _virCgroupController { +struct _virCgroupV1Controller { int type; char *mountPoint; /* If mountPoint holds several controllers co-mounted, @@ -42,15 +42,15 @@ struct _virCgroupController { char *linkPoint; char *placement; }; -typedef struct _virCgroupController virCgroupController; -typedef virCgroupController *virCgroupControllerPtr; +typedef struct _virCgroupV1Controller virCgroupV1Controller; +typedef virCgroupV1Controller *virCgroupV1ControllerPtr; =20 struct _virCgroup { char *path; =20 virCgroupBackendPtr backend; =20 - virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; + virCgroupV1Controller controllers[VIR_CGROUP_CONTROLLER_LAST]; }; =20 int virCgroupSetValueStr(virCgroupPtr group, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index be0be0f582..f0f703f811 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -224,7 +224,7 @@ virCgroupV1CopyPlacement(virCgroupPtr group, static int virCgroupV1ResolveMountLink(const char *mntDir, const char *typeStr, - virCgroupControllerPtr controller) + virCgroupV1ControllerPtr controller) { VIR_AUTOFREE(char *) linkSrc =3D NULL; VIR_AUTOFREE(char *) tmp =3D NULL; @@ -319,7 +319,7 @@ virCgroupV1DetectMounts(virCgroupPtr group, * once. We need to save the results of the last one, * and we need to be careful to release the memory used * by previous processing. */ - virCgroupControllerPtr controller =3D &group->controllers[i]; + virCgroupV1ControllerPtr controller =3D &group->controllers[i]; =20 VIR_FREE(controller->mountPoint); VIR_FREE(controller->linkPoint); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 20:13:20 2024 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 1537285671046865.4104993793267; Tue, 18 Sep 2018 08:47:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06DB5804F1; Tue, 18 Sep 2018 15:47:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 830547E4F1; Tue, 18 Sep 2018 15:47:48 +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 E834E41091; Tue, 18 Sep 2018 15:47:47 +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 w8IFlTUn013241 for ; Tue, 18 Sep 2018 11:47:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08E3882AD8; Tue, 18 Sep 2018 15:47:29 +0000 (UTC) Received: from antique-work.brq.redhat.com (unknown [10.43.2.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7790A4F9A1 for ; Tue, 18 Sep 2018 15:47:28 +0000 (UTC) From: Pavel Hrdina To: libvir-list@redhat.com Date: Tue, 18 Sep 2018 17:46:08 +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 47/47] vircgroup: rename controllers to legacy 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.16 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:47:49 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Pavel Hrdina --- src/util/vircgroup.c | 6 +- src/util/vircgrouppriv.h | 2 +- src/util/vircgroupv1.c | 140 +++++++++++++++++++-------------------- tests/vircgrouptest.c | 14 ++-- 4 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b61c6bf2f3..e031e82914 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1248,9 +1248,9 @@ virCgroupFree(virCgroupPtr *group) return; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_FREE((*group)->controllers[i].mountPoint); - VIR_FREE((*group)->controllers[i].linkPoint); - VIR_FREE((*group)->controllers[i].placement); + VIR_FREE((*group)->legacy[i].mountPoint); + VIR_FREE((*group)->legacy[i].linkPoint); + VIR_FREE((*group)->legacy[i].placement); } =20 VIR_FREE((*group)->path); diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index ee6aeedbb5..c50a25f195 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -50,7 +50,7 @@ struct _virCgroup { =20 virCgroupBackendPtr backend; =20 - virCgroupV1Controller controllers[VIR_CGROUP_CONTROLLER_LAST]; + virCgroupV1Controller legacy[VIR_CGROUP_CONTROLLER_LAST]; }; =20 int virCgroupSetValueStr(virCgroupPtr group, diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c index f0f703f811..e4364009e5 100644 --- a/src/util/vircgroupv1.c +++ b/src/util/vircgroupv1.c @@ -126,10 +126,10 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group, if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) continue; =20 - if (!group->controllers[i].placement) + if (!group->legacy[i].placement) continue; =20 - tmp =3D strrchr(group->controllers[i].placement, '/'); + tmp =3D strrchr(group->legacy[i].placement, '/'); if (!tmp) return false; =20 @@ -138,7 +138,7 @@ virCgroupV1ValidateMachineGroup(virCgroupPtr group, i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET) { if (STREQ(tmp, "/emulator")) *tmp =3D '\0'; - tmp =3D strrchr(group->controllers[i].placement, '/'); + tmp =3D strrchr(group->legacy[i].placement, '/'); if (!tmp) return false; } @@ -170,15 +170,15 @@ virCgroupV1CopyMounts(virCgroupPtr group, { size_t i; for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!parent->controllers[i].mountPoint) + if (!parent->legacy[i].mountPoint) continue; =20 - if (VIR_STRDUP(group->controllers[i].mountPoint, - parent->controllers[i].mountPoint) < 0) + if (VIR_STRDUP(group->legacy[i].mountPoint, + parent->legacy[i].mountPoint) < 0) return -1; =20 - if (VIR_STRDUP(group->controllers[i].linkPoint, - parent->controllers[i].linkPoint) < 0) + if (VIR_STRDUP(group->legacy[i].linkPoint, + parent->legacy[i].linkPoint) < 0) return -1; } return 0; @@ -192,14 +192,14 @@ virCgroupV1CopyPlacement(virCgroupPtr group, { size_t i; for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; =20 if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) continue; =20 if (path[0] =3D=3D '/') { - if (VIR_STRDUP(group->controllers[i].placement, path) < 0) + if (VIR_STRDUP(group->legacy[i].placement, path) < 0) return -1; } else { /* @@ -207,10 +207,10 @@ virCgroupV1CopyPlacement(virCgroupPtr group, * parent =3D=3D "/libvirt.service" + path =3D=3D "" =3D> "/li= bvirt.service" * parent =3D=3D "/libvirt.service" + path =3D=3D "foo" =3D> "= /libvirt.service/foo" */ - if (virAsprintf(&group->controllers[i].placement, + if (virAsprintf(&group->legacy[i].placement, "%s%s%s", - parent->controllers[i].placement, - (STREQ(parent->controllers[i].placement, "/") = || + parent->legacy[i].placement, + (STREQ(parent->legacy[i].placement, "/") || STREQ(path, "") ? "" : "/"), path) < 0) return -1; @@ -319,7 +319,7 @@ virCgroupV1DetectMounts(virCgroupPtr group, * once. We need to save the results of the last one, * and we need to be careful to release the memory used * by previous processing. */ - virCgroupV1ControllerPtr controller =3D &group->controllers[i]; + virCgroupV1ControllerPtr controller =3D &group->legacy[i]; =20 VIR_FREE(controller->mountPoint); VIR_FREE(controller->linkPoint); @@ -349,19 +349,19 @@ virCgroupV1DetectPlacement(virCgroupPtr group, const char *typestr =3D virCgroupV1ControllerTypeToString(i); =20 if (virCgroupV1MountOptsMatchController(controllers, typestr) && - group->controllers[i].mountPoint !=3D NULL && - group->controllers[i].placement =3D=3D NULL) { + group->legacy[i].mountPoint !=3D NULL && + group->legacy[i].placement =3D=3D NULL) { /* * selfpath =3D=3D "/" + path=3D"" -> "/" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "" -> "/li= bvirt.service" * selfpath =3D=3D "/libvirt.service" + path =3D=3D "foo" -> "= /libvirt.service/foo" */ if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { - if (VIR_STRDUP(group->controllers[i].placement, + if (VIR_STRDUP(group->legacy[i].placement, selfpath) < 0) return -1; } else { - if (virAsprintf(&group->controllers[i].placement, + if (virAsprintf(&group->legacy[i].placement, "%s%s%s", selfpath, (STREQ(selfpath, "/") || STREQ(path, "") ? "" : "/"), @@ -382,22 +382,22 @@ virCgroupV1ValidatePlacement(virCgroupPtr group, size_t i; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; =20 - if (!group->controllers[i].placement) { + if (!group->legacy[i].placement) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find placement for v1 controller %= s at %s"), virCgroupV1ControllerTypeToString(i), - group->controllers[i].placement); + group->legacy[i].placement); return -1; } =20 VIR_DEBUG("Detected mount/mapping %zu:%s at %s in %s for pid %lld", i, virCgroupV1ControllerTypeToString(i), - group->controllers[i].mountPoint, - group->controllers[i].placement, + group->legacy[i].mountPoint, + group->legacy[i].placement, (long long) pid); } =20 @@ -410,7 +410,7 @@ virCgroupV1GetPlacement(virCgroupPtr group) { char *ret =3D NULL; =20 - ignore_value(VIR_STRDUP(ret, group->controllers[VIR_CGROUP_CONTROLLER_= SYSTEMD].placement)); + ignore_value(VIR_STRDUP(ret, group->legacy[VIR_CGROUP_CONTROLLER_SYSTE= MD].placement)); =20 return ret; } @@ -429,7 +429,7 @@ virCgroupV1DetectControllers(virCgroupPtr group, for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { if (((1 << i) & controllers)) { /* Remove non-existent controllers */ - if (!group->controllers[i].mountPoint) { + if (!group->legacy[i].mountPoint) { VIR_DEBUG("Requested controller '%s' not mounted, igno= ring", virCgroupV1ControllerTypeToString(i)); controllers &=3D ~(1 << i); @@ -440,9 +440,9 @@ virCgroupV1DetectControllers(virCgroupPtr group, VIR_DEBUG("Controller '%s' wanted=3D%s, mount=3D'%s'", virCgroupV1ControllerTypeToString(i), (1 << i) & controllers ? "yes" : "no", - NULLSTR(group->controllers[i].mountPoint)); + NULLSTR(group->legacy[i].mountPoint)); if (!((1 << i) & controllers) && - group->controllers[i].mountPoint) { + group->legacy[i].mountPoint) { /* Check whether a request to disable a controller * clashes with co-mounting of controllers */ for (j =3D 0; j < VIR_CGROUP_CONTROLLER_LAST; j++) { @@ -451,8 +451,8 @@ virCgroupV1DetectControllers(virCgroupPtr group, if (!((1 << j) & controllers)) continue; =20 - if (STREQ_NULLABLE(group->controllers[i].mountPoint, - group->controllers[j].mountPoint)) { + if (STREQ_NULLABLE(group->legacy[i].mountPoint, + group->legacy[j].mountPoint)) { virReportSystemError(EINVAL, _("V1 controller '%s' is not = wanted, but '%s' is co-mounted"), virCgroupV1ControllerTypeToSt= ring(i), @@ -460,7 +460,7 @@ virCgroupV1DetectControllers(virCgroupPtr group, return -1; } } - VIR_FREE(group->controllers[i].mountPoint); + VIR_FREE(group->legacy[i].mountPoint); } } } else { @@ -469,8 +469,8 @@ virCgroupV1DetectControllers(virCgroupPtr group, for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { VIR_DEBUG("Controller '%s' present=3D%s", virCgroupV1ControllerTypeToString(i), - group->controllers[i].mountPoint ? "yes" : "no"); - if (group->controllers[i].mountPoint =3D=3D NULL) + group->legacy[i].mountPoint ? "yes" : "no"); + if (group->legacy[i].mountPoint =3D=3D NULL) continue; controllers |=3D (1 << i); } @@ -484,7 +484,7 @@ static bool virCgroupV1HasController(virCgroupPtr group, int controller) { - return group->controllers[controller].mountPoint !=3D NULL; + return group->legacy[controller].mountPoint !=3D NULL; } =20 =20 @@ -498,9 +498,9 @@ virCgroupV1GetAnyController(virCgroupPtr group) * of '/' to avoid doing bad stuff to the root * cgroup */ - if (group->controllers[i].mountPoint && - group->controllers[i].placement && - STRNEQ(group->controllers[i].placement, "/")) { + if (group->legacy[i].mountPoint && + group->legacy[i].placement && + STRNEQ(group->legacy[i].placement, "/")) { return i; } } @@ -515,14 +515,14 @@ virCgroupV1PathOfController(virCgroupPtr group, const char *key, char **path) { - if (group->controllers[controller].mountPoint =3D=3D NULL) { + if (group->legacy[controller].mountPoint =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("v1 controller '%s' is not mounted"), virCgroupV1ControllerTypeToString(controller)); return -1; } =20 - if (group->controllers[controller].placement =3D=3D NULL) { + if (group->legacy[controller].placement =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, _("v1 controller '%s' is not enabled for group"), virCgroupV1ControllerTypeToString(controller)); @@ -530,8 +530,8 @@ virCgroupV1PathOfController(virCgroupPtr group, } =20 if (virAsprintf(path, "%s%s/%s", - group->controllers[controller].mountPoint, - group->controllers[controller].placement, + group->legacy[controller].mountPoint, + group->legacy[controller].placement, key ? key : "") < 0) return -1; =20 @@ -617,7 +617,7 @@ virCgroupV1MakeGroup(virCgroupPtr parent, } =20 /* Skip over controllers that aren't mounted */ - if (!group->controllers[i].mountPoint) { + if (!group->legacy[i].mountPoint) { VIR_DEBUG("Skipping unmounted controller %s", virCgroupV1ControllerTypeToString(i)); continue; @@ -638,7 +638,7 @@ virCgroupV1MakeGroup(virCgroupPtr parent, * treat blkio as unmounted if mkdir fails. */ if (i =3D=3D VIR_CGROUP_CONTROLLER_BLKIO) { VIR_DEBUG("Ignoring mkdir failure with blkio controlle= r. Kernel probably too old"); - VIR_FREE(group->controllers[i].mountPoint); + VIR_FREE(group->legacy[i].mountPoint); continue; } else { virReportSystemError(errno, @@ -648,7 +648,7 @@ virCgroupV1MakeGroup(virCgroupPtr parent, } } if (i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET && - group->controllers[i].mountPoint !=3D NULL && + group->legacy[i].mountPoint !=3D NULL && virCgroupV1CpuSetInherit(parent, group) < 0) { return -1; } @@ -658,7 +658,7 @@ virCgroupV1MakeGroup(virCgroupPtr parent, */ if ((flags & VIR_CGROUP_MEM_HIERACHY) && i =3D=3D VIR_CGROUP_CONTROLLER_MEMORY && - group->controllers[i].mountPoint !=3D NULL && + group->legacy[i].mountPoint !=3D NULL && virCgroupV1SetMemoryUseHierarchy(group) < 0) { return -1; } @@ -681,7 +681,7 @@ virCgroupV1Remove(virCgroupPtr group) VIR_AUTOFREE(char *) grppath =3D NULL; =20 /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; =20 /* We must never rmdir() in systemd's hierarchy */ @@ -690,7 +690,7 @@ virCgroupV1Remove(virCgroupPtr group) =20 /* Don't delete the root group, if we accidentally ended up in it for some reason */ - if (STREQ(group->controllers[i].placement, "/")) + if (STREQ(group->legacy[i].placement, "/")) continue; =20 if (virCgroupV1PathOfController(group, @@ -718,7 +718,7 @@ virCgroupV1AddTask(virCgroupPtr group, =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { /* Skip over controllers not mounted */ - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; =20 /* We must never add tasks in systemd's hierarchy @@ -765,17 +765,17 @@ virCgroupV1IdentifyRoot(virCgroupPtr group) =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { char *tmp; - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; - if (!(tmp =3D strrchr(group->controllers[i].mountPoint, '/'))) { + if (!(tmp =3D strrchr(group->legacy[i].mountPoint, '/'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find directory separator in %s"), - group->controllers[i].mountPoint); + group->legacy[i].mountPoint); return NULL; } =20 - if (VIR_STRNDUP(ret, group->controllers[i].mountPoint, - tmp - group->controllers[i].mountPoint) < 0) + if (VIR_STRNDUP(ret, group->legacy[i].mountPoint, + tmp - group->legacy[i].mountPoint) < 0) return NULL; return ret; } @@ -819,44 +819,44 @@ virCgroupV1BindMount(virCgroupPtr group, } =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - if (!group->controllers[i].mountPoint) + if (!group->legacy[i].mountPoint) continue; =20 - if (!virFileExists(group->controllers[i].mountPoint)) { + if (!virFileExists(group->legacy[i].mountPoint)) { VIR_AUTOFREE(char *) src =3D NULL; if (virAsprintf(&src, "%s%s", oldroot, - group->controllers[i].mountPoint) < 0) + group->legacy[i].mountPoint) < 0) return -1; =20 VIR_DEBUG("Create mount point '%s'", - group->controllers[i].mountPoint); - if (virFileMakePath(group->controllers[i].mountPoint) < 0) { + group->legacy[i].mountPoint); + if (virFileMakePath(group->legacy[i].mountPoint) < 0) { virReportSystemError(errno, _("Unable to create directory %s"), - group->controllers[i].mountPoint); + group->legacy[i].mountPoint); return -1; } =20 - if (mount(src, group->controllers[i].mountPoint, "none", MS_BI= ND, + if (mount(src, group->legacy[i].mountPoint, "none", MS_BIND, NULL) < 0) { virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'= "), - src, group->controllers[i].mountPoint= ); + src, group->legacy[i].mountPoint); return -1; } } =20 - if (group->controllers[i].linkPoint) { + if (group->legacy[i].linkPoint) { VIR_DEBUG("Link mount point '%s' to '%s'", - group->controllers[i].mountPoint, - group->controllers[i].linkPoint); - if (symlink(group->controllers[i].mountPoint, - group->controllers[i].linkPoint) < 0) { + group->legacy[i].mountPoint, + group->legacy[i].linkPoint); + if (symlink(group->legacy[i].mountPoint, + group->legacy[i].linkPoint) < 0) { virReportSystemError(errno, _("Unable to symlink directory %s to = %s"), - group->controllers[i].mountPoint, - group->controllers[i].linkPoint); + group->legacy[i].mountPoint, + group->legacy[i].linkPoint); return -1; } } @@ -885,11 +885,11 @@ virCgroupV1SetOwner(virCgroupPtr cgroup, if (!((1 << i) & controllers)) continue; =20 - if (!cgroup->controllers[i].mountPoint) + if (!cgroup->legacy[i].mountPoint) continue; =20 - if (virAsprintf(&base, "%s%s", cgroup->controllers[i].mountPoint, - cgroup->controllers[i].placement) < 0) + if (virAsprintf(&base, "%s%s", cgroup->legacy[i].mountPoint, + cgroup->legacy[i].placement) < 0) goto cleanup; =20 if (virDirOpen(&dh, base) < 0) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index be3143ea52..725f44c62e 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -56,25 +56,25 @@ static int validateCgroup(virCgroupPtr cgroup, =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { if (STRNEQ_NULLABLE(expectMountPoint[i], - cgroup->controllers[i].mountPoint)) { + cgroup->legacy[i].mountPoint)) { fprintf(stderr, "Wrong mount '%s', expected '%s' for '%s'\n", - cgroup->controllers[i].mountPoint, + cgroup->legacy[i].mountPoint, expectMountPoint[i], virCgroupControllerTypeToString(i)); return -1; } if (STRNEQ_NULLABLE(expectLinkPoint[i], - cgroup->controllers[i].linkPoint)) { + cgroup->legacy[i].linkPoint)) { fprintf(stderr, "Wrong link '%s', expected '%s' for '%s'\n", - cgroup->controllers[i].linkPoint, + cgroup->legacy[i].linkPoint, expectLinkPoint[i], virCgroupControllerTypeToString(i)); return -1; } if (STRNEQ_NULLABLE(expectPlacement[i], - cgroup->controllers[i].placement)) { + cgroup->legacy[i].placement)) { fprintf(stderr, "Wrong placement '%s', expected '%s' for '%s'\= n", - cgroup->controllers[i].placement, + cgroup->legacy[i].placement, expectPlacement[i], virCgroupControllerTypeToString(i)); return -1; @@ -160,7 +160,7 @@ testCgroupDetectMounts(const void *args) for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { virBufferAsprintf(&buf, "%-12s %s\n", virCgroupControllerTypeToString(i), - NULLSTR(group->controllers[i].mountPoint)); + NULLSTR(group->legacy[i].mountPoint)); } if (virBufferCheckError(&buf) < 0) goto cleanup; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list