From nobody Mon Feb 9 15:01:20 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 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