From nobody Mon Feb 9 20:41:42 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 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