From nobody Sun Feb 8 16:33:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 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