From nobody Wed May 14 13:49:24 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522075395231144.42082519931535; Mon, 26 Mar 2018 07:43:15 -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 6AC55A6E1E; Mon, 26 Mar 2018 14:43:13 +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 0C7D017C75; Mon, 26 Mar 2018 14:43:13 +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 7198F180613A; Mon, 26 Mar 2018 14:43:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2QEhAM5032032 for ; Mon, 26 Mar 2018 10:43:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 442352026E04; Mon, 26 Mar 2018 14:43:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-33.brq.redhat.com [10.40.204.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA1D92026E03 for ; Mon, 26 Mar 2018 14:43:09 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 26 Mar 2018 16:43:02 +0200 Message-Id: <5ef524117ffdd14dafaf9c1d6e9222fc18d051db.1522075241.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/3] qemu: Handle device mapper targets properly 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.38]); Mon, 26 Mar 2018 14:43:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1557769 Problem with device mapper targets is that there can be several other devices 'hidden' behind them. For instance, /dev/dm-1 can consist of /dev/sda, /dev/sdb and /dev/sdc. Therefore, when setting up devices CGroup and namespaces we have to take this into account. Signed-off-by: Michal Privoznik --- libvirt.spec.in | 2 ++ src/qemu/qemu_cgroup.c | 42 ++++++++++++++++++++++++++++++--- src/qemu/qemu_domain.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 105 insertions(+), 3 deletions(-) diff --git a/libvirt.spec.in b/libvirt.spec.in index b55a947ec9..ebfac10866 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -796,6 +796,8 @@ Requires: gzip Requires: bzip2 Requires: lzop Requires: xz +# For mpath devices +Requires: device-mapper %if 0%{?fedora} || 0%{?rhel} > 7 Requires: systemd-container %endif diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index b604edb31c..e17b3d21b5 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -37,6 +37,7 @@ #include "virtypedparam.h" #include "virnuma.h" #include "virsystemd.h" +#include "virdevmapper.h" =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -60,7 +61,13 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm, { qemuDomainObjPrivatePtr priv =3D vm->privateData; int perms =3D VIR_CGROUP_DEVICE_READ; - int ret; + unsigned int *maj =3D NULL; + unsigned int *min =3D NULL; + size_t nmaj =3D 0; + size_t i; + char *devPath =3D NULL; + int rv; + int ret =3D -1; =20 if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) return 0; @@ -71,12 +78,41 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm, VIR_DEBUG("Allow path %s, perms: %s", path, virCgroupGetDevicePermsString(perms)); =20 - ret =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, true); + rv =3D virCgroupAllowDevicePath(priv->cgroup, path, perms, true); =20 virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, virCgroupGetDevicePermsString(perms), - ret); + rv); + if (rv < 0) + goto cleanup; =20 + if (virDevMapperGetTargets(path, &maj, &min, &nmaj) < 0 && + errno !=3D ENOSYS && errno !=3D EBADF) { + virReportSystemError(errno, + _("Unable to get devmapper targets for %s"), + path); + goto cleanup; + } + + for (i =3D 0; i < nmaj; i++) { + if (virAsprintf(&devPath, "/dev/block/%u:%u", maj[i], min[i]) < 0) + goto cleanup; + + rv =3D virCgroupAllowDevicePath(priv->cgroup, devPath, perms, true= ); + + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", devPath, + virCgroupGetDevicePermsString(perms), + rv); + if (rv < 0) + goto cleanup; + VIR_FREE(devPath); + } + + ret =3D 0; + cleanup: + VIR_FREE(devPath); + VIR_FREE(min); + VIR_FREE(maj); return ret; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 580e0f830d..5f56324502 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -54,6 +54,7 @@ #include "secret_util.h" #include "logging/log_manager.h" #include "locking/domain_lock.h" +#include "virdevmapper.h" =20 #ifdef MAJOR_IN_MKDEV # include @@ -10108,6 +10109,11 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg ATT= RIBUTE_UNUSED, { virStorageSourcePtr next; char *dst =3D NULL; + unsigned int *maj =3D NULL; + unsigned int *min =3D NULL; + size_t nmaj =3D 0; + char *devPath =3D NULL; + size_t i; int ret =3D -1; =20 for (next =3D disk->src; virStorageSourceIsBacking(next); next =3D nex= t->backingStore) { @@ -10118,10 +10124,31 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg AT= TRIBUTE_UNUSED, =20 if (qemuDomainCreateDevice(next->path, data, false) < 0) goto cleanup; + + if (virDevMapperGetTargets(next->path, &maj, &min, &nmaj) < 0 && + errno !=3D ENOSYS && errno !=3D EBADF) { + virReportSystemError(errno, + _("Unable to get mpath targets for %s"), + next->path); + goto cleanup; + } + + for (i =3D 0; i < nmaj; i++) { + if (virAsprintf(&devPath, "/dev/block/%u:%u", maj[i], min[i]) = < 0) + goto cleanup; + + if (qemuDomainCreateDevice(devPath, data, false) < 0) + goto cleanup; + + VIR_FREE(devPath); + } } =20 ret =3D 0; cleanup: + VIR_FREE(devPath); + VIR_FREE(min); + VIR_FREE(maj); VIR_FREE(dst); return ret; } @@ -11131,6 +11158,12 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr next; char **paths =3D NULL; size_t npaths =3D 0; + unsigned int *maj =3D NULL; + unsigned int *min =3D NULL; + size_t nmaj =3D 0; + char **devmapperPaths =3D NULL; + size_t ndevmapperPaths =3D 0; + size_t i; int ret =3D -1; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) @@ -11145,6 +11178,32 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, =20 if (VIR_APPEND_ELEMENT_COPY(paths, npaths, next->path) < 0) goto cleanup; + + if (virDevMapperGetTargets(next->path, &maj, &min, &nmaj) < 0 && + errno !=3D ENOSYS && errno !=3D EBADF) { + virReportSystemError(errno, + _("Unable to get mpath targets for %s"), + next->path); + goto cleanup; + } + + if (VIR_REALLOC_N(devmapperPaths, ndevmapperPaths + nmaj) < 0) + goto cleanup; + + for (i =3D 0; i < nmaj; i++) { + if (virAsprintf(&devmapperPaths[ndevmapperPaths], + "/sys/block/%u:%u", + maj[i], min[i]) < 0) + goto cleanup; + ndevmapperPaths++; + + if (VIR_APPEND_ELEMENT_COPY(paths, npaths, + devmapperPaths[ndevmapperPaths - 1= ]) < 0) + goto cleanup; + } + + VIR_FREE(min); + VIR_FREE(maj); } =20 if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < = 0) @@ -11152,6 +11211,11 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, =20 ret =3D 0; cleanup: + for (i =3D 0; i < ndevmapperPaths; i++) + VIR_FREE(devmapperPaths[i]); + VIR_FREE(devmapperPaths); + VIR_FREE(min); + VIR_FREE(maj); VIR_FREE(paths); return ret; } --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list