From nobody Wed May 1 22:30:17 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.zoho.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 1498148542034472.2268546525695; Thu, 22 Jun 2017 09:22:22 -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 90184142879; Thu, 22 Jun 2017 16:22: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 6C4486A706; Thu, 22 Jun 2017 16:22: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 285D21853E2F; Thu, 22 Jun 2017 16:22:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIe6a023563 for ; Thu, 22 Jun 2017 12:18:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 883A360608; Thu, 22 Jun 2017 16:18:40 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 052C660607 for ; Thu, 22 Jun 2017 16:18:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 90184142879 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 90184142879 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:28 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/8] conf: Rename and expose virDomainChrSourceDefPath 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]); Thu, 22 Jun 2017 16:22:21 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It comes very handy to have source path for chardevs. We already have such function: virDomainAuditChardevPath() but it's static and has name not suitable for exposing. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/conf/domain_audit.c | 44 ++++++-------------------------------------- src/conf/domain_conf.c | 33 +++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c index 1e667af73..484420a21 100644 --- a/src/conf/domain_audit.c +++ b/src/conf/domain_audit.c @@ -68,38 +68,6 @@ virDomainAuditGetRdev(const char *path ATTRIBUTE_UNUSED) #endif =20 =20 -static const char * -virDomainAuditChardevPath(virDomainChrSourceDefPtr chr) -{ - if (!chr) - return NULL; - - switch ((virDomainChrType) chr->type) { - case VIR_DOMAIN_CHR_TYPE_PTY: - case VIR_DOMAIN_CHR_TYPE_DEV: - case VIR_DOMAIN_CHR_TYPE_FILE: - case VIR_DOMAIN_CHR_TYPE_PIPE: - case VIR_DOMAIN_CHR_TYPE_NMDM: - return chr->data.file.path; - - case VIR_DOMAIN_CHR_TYPE_UNIX: - return chr->data.nix.path; - - case VIR_DOMAIN_CHR_TYPE_TCP: - case VIR_DOMAIN_CHR_TYPE_UDP: - case VIR_DOMAIN_CHR_TYPE_NULL: - case VIR_DOMAIN_CHR_TYPE_VC: - case VIR_DOMAIN_CHR_TYPE_STDIO: - case VIR_DOMAIN_CHR_TYPE_SPICEVMC: - case VIR_DOMAIN_CHR_TYPE_SPICEPORT: - case VIR_DOMAIN_CHR_TYPE_LAST: - return NULL; - } - - return NULL; -} - - static void virDomainAuditGenericDev(virDomainObjPtr vm, const char *type, @@ -178,8 +146,8 @@ virDomainAuditChardev(virDomainObjPtr vm, newsrc =3D newDef->source; =20 virDomainAuditGenericDev(vm, "chardev", - virDomainAuditChardevPath(oldsrc), - virDomainAuditChardevPath(newsrc), + virDomainChrSourceDefPath(oldsrc), + virDomainChrSourceDefPath(newsrc), reason, success); } =20 @@ -218,7 +186,7 @@ virDomainAuditSmartcard(virDomainObjPtr vm, =20 case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: virDomainAuditGenericDev(vm, "smartcard", NULL, - virDomainAuditChardevPath(def->data.p= assthru), + virDomainChrSourceDefPath(def->data.p= assthru), reason, success); break; =20 @@ -264,7 +232,7 @@ virDomainAuditRNG(virDomainObjPtr vm, break; =20 case VIR_DOMAIN_RNG_BACKEND_EGD: - newsrcpath =3D virDomainAuditChardevPath(newDef->source.charde= v); + newsrcpath =3D virDomainChrSourceDefPath(newDef->source.charde= v); break; =20 case VIR_DOMAIN_RNG_BACKEND_LAST: @@ -279,7 +247,7 @@ virDomainAuditRNG(virDomainObjPtr vm, break; =20 case VIR_DOMAIN_RNG_BACKEND_EGD: - oldsrcpath =3D virDomainAuditChardevPath(oldDef->source.charde= v); + oldsrcpath =3D virDomainChrSourceDefPath(oldDef->source.charde= v); break; =20 case VIR_DOMAIN_RNG_BACKEND_LAST: @@ -982,7 +950,7 @@ virDomainAuditShmem(virDomainObjPtr vm, { char uuidstr[VIR_UUID_STRING_BUFLEN]; char *vmname =3D virAuditEncode("vm", vm->def->name); - const char *srcpath =3D virDomainAuditChardevPath(&def->server.chr); + const char *srcpath =3D virDomainChrSourceDefPath(&def->server.chr); const char *virt =3D virDomainVirtTypeToString(vm->def->virtType); char *shmpath =3D NULL; =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0409c62ef..2cbe96b6e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2034,6 +2034,39 @@ virDomainNetDefFree(virDomainNetDefPtr def) VIR_FREE(def); } =20 + +const char * +virDomainChrSourceDefPath(virDomainChrSourceDefPtr chr) +{ + if (!chr) + return NULL; + + switch ((virDomainChrType) chr->type) { + case VIR_DOMAIN_CHR_TYPE_PTY: + case VIR_DOMAIN_CHR_TYPE_DEV: + case VIR_DOMAIN_CHR_TYPE_FILE: + case VIR_DOMAIN_CHR_TYPE_PIPE: + case VIR_DOMAIN_CHR_TYPE_NMDM: + return chr->data.file.path; + + case VIR_DOMAIN_CHR_TYPE_UNIX: + return chr->data.nix.path; + + case VIR_DOMAIN_CHR_TYPE_TCP: + case VIR_DOMAIN_CHR_TYPE_UDP: + case VIR_DOMAIN_CHR_TYPE_NULL: + case VIR_DOMAIN_CHR_TYPE_VC: + case VIR_DOMAIN_CHR_TYPE_STDIO: + case VIR_DOMAIN_CHR_TYPE_SPICEVMC: + case VIR_DOMAIN_CHR_TYPE_SPICEPORT: + case VIR_DOMAIN_CHR_TYPE_LAST: + return NULL; + } + + return NULL; +} + + void ATTRIBUTE_NONNULL(1) virDomainChrSourceDefClear(virDomainChrSourceDefPtr def) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6d9ee9787..51b830917 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3256,6 +3256,8 @@ int virDomainDefFindDevice(virDomainDefPtr def, virDomainDeviceDefPtr dev, bool reportError); =20 +const char *virDomainChrSourceDefPath(virDomainChrSourceDefPtr chr); + void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def); =20 char *virDomainObjGetMetadata(virDomainObjPtr vm, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c1e9471c5..f671da9d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -208,6 +208,7 @@ virDomainChrSerialTargetTypeToString; virDomainChrSourceDefClear; virDomainChrSourceDefCopy; virDomainChrSourceDefFree; +virDomainChrSourceDefPath; virDomainChrSpicevmcTypeFromString; virDomainChrSpicevmcTypeToString; virDomainChrTcpProtocolTypeFromString; --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148546997553.1804860380927; Thu, 22 Jun 2017 09:22:26 -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 3610B42BD8; Thu, 22 Jun 2017 16:22:24 +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 E72FC62FE2; Thu, 22 Jun 2017 16:22:23 +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 981751853E34; Thu, 22 Jun 2017 16:22:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIfdd023571 for ; Thu, 22 Jun 2017 12:18:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 66DC460607; Thu, 22 Jun 2017 16:18:41 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9F926062A for ; Thu, 22 Jun 2017 16:18:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3610B42BD8 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3610B42BD8 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:29 +0200 Message-Id: <3ab2b1939beea7bd23ec17fd3b245ba1870ac784.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/8] qemuDomainBuildNamespace: Handle special file mount points 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.30]); Thu, 22 Jun 2017 16:22:25 +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=3D1459592 In 290a00e41d I've tried to fix the process of building a qemu namespace when dealing with file mount points. What I haven't realized then is that we might be dealing not with just regular files but also special files (like sockets). Indeed, try the following: 1) socat unix-listen:/tmp/soket stdio 2) touch /dev/socket 3) mount --bind /tmp/socket /dev/socket 4) virsh start anyDomain Problem with my previous approach is that I wasn't creating the temporary location (where mount points under /dev are moved) for anything but directories and regular files. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8e7404da6..212717c80 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8356,9 +8356,11 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, goto cleanup; } =20 - /* At this point, devMountsPath is either a regular file or a dire= ctory. */ + /* At this point, devMountsPath is either: + * a file (regular or special), or + * a directory. */ if ((S_ISDIR(sb.st_mode) && virFileMakePath(devMountsSavePath[i]) = < 0) || - (S_ISREG(sb.st_mode) && virFileTouch(devMountsSavePath[i], sb.= st_mode) < 0)) { + (!S_ISDIR(sb.st_mode) && virFileTouch(devMountsSavePath[i], sb= .st_mode) < 0)) { virReportSystemError(errno, _("Failed to create %s"), devMountsSavePath[i]); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148347549264.12149203050046; Thu, 22 Jun 2017 09:19:07 -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 B82C0635C1; Thu, 22 Jun 2017 16:19:02 +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 665056FE48; Thu, 22 Jun 2017 16:19:02 +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 1D67F1853E2D; Thu, 22 Jun 2017 16:19:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIhGw023583 for ; Thu, 22 Jun 2017 12:18:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id F009060607; Thu, 22 Jun 2017 16:18:43 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C2686062A for ; Thu, 22 Jun 2017 16:18:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B82C0635C1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B82C0635C1 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:30 +0200 Message-Id: <409e430e6ecce542d13a43ea07f1ef36cbe5b524.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/8] qemu: Move preserved mount points path generation into a separate function 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.39]); Thu, 22 Jun 2017 16:19:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function is going to be used on other places, so instead of copying code we can just call the function. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 212717c80..286d60761 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7572,6 +7572,41 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, } =20 =20 +static char * +qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr cfg, + virDomainObjPtr vm, + const char *mount) +{ + char *path =3D NULL; + char *tmp; + const char *suffix =3D mount + strlen(DEVPREFIX); + size_t off; + + if (STREQ(mount, "/dev")) + suffix =3D "dev"; + + if (virAsprintf(&path, "%s/%s.%s", + cfg->stateDir, vm->def->name, suffix) < 0) + return NULL; + + /* Now consider that @mount is "/dev/blah/blah2". + * @suffix then points to "blah/blah2". However, caller + * expects all the @paths to be the same depth. The + * caller doesn't always do `mkdir -p` but sometimes bare + * `touch`. Therefore fix all the suffixes. */ + off =3D strlen(path) - strlen(suffix); + + tmp =3D path + off; + while (*tmp) { + if (*tmp =3D=3D '/') + *tmp =3D '.'; + tmp++; + } + + return path; +} + + /** * qemuDomainGetPreservedMounts: * @@ -7628,30 +7663,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr = cfg, goto error; =20 for (i =3D 0; i < nmounts; i++) { - char *tmp; - const char *suffix =3D mounts[i] + strlen(DEVPREFIX); - size_t off; - - if (STREQ(mounts[i], "/dev")) - suffix =3D "dev"; - - if (virAsprintf(&paths[i], "%s/%s.%s", - cfg->stateDir, vm->def->name, suffix) < 0) + if (!(paths[i] =3D qemuDomainGetPreservedMountPath(cfg, vm, mounts= [i]))) goto error; - - /* Now consider that mounts[i] is "/dev/blah/blah2". - * @suffix then points to "blah/blah2". However, caller - * expects all the @paths to be the same depth. The - * caller doesn't always do `mkdir -p` but sometimes bare - * `touch`. Therefore fix all the suffixes. */ - off =3D strlen(paths[i]) - strlen(suffix); - - tmp =3D paths[i] + off; - while (*tmp) { - if (*tmp =3D=3D '/') - *tmp =3D '.'; - tmp++; - } } =20 if (devPath) --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148549237181.84618389432114; Thu, 22 Jun 2017 09:22:29 -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 8C86DC0587DB; Thu, 22 Jun 2017 16:22:27 +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 67F115D96E; Thu, 22 Jun 2017 16:22:27 +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 C27704E98B; Thu, 22 Jun 2017 16:22:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIiNu023591 for ; Thu, 22 Jun 2017 12:18:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id D5C0760619; Thu, 22 Jun 2017 16:18:44 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 541C260607 for ; Thu, 22 Jun 2017 16:18:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C86DC0587DB Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8C86DC0587DB From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:31 +0200 Message-Id: <551b4e1405ec5b250e825e7c47aee7217a59b040.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/8] qemuDomainCreateDeviceRecursive: Fail on unsupported file type 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.32]); Thu, 22 Jun 2017 16:22:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, we silently assume that file we are creating in the namespace is either a link or a device (character or block one). This is not always the case. Therefore instead of doing something wrong, claim about unsupported file type. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 286d60761..e6fb041de 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7707,6 +7707,7 @@ qemuDomainCreateDeviceRecursive(const char *device, struct stat sb; int ret =3D -1; bool isLink =3D false; + bool isDev =3D false; bool create =3D false; #ifdef WITH_SELINUX char *tcon =3D NULL; @@ -7729,6 +7730,7 @@ qemuDomainCreateDeviceRecursive(const char *device, } =20 isLink =3D S_ISLNK(sb.st_mode); + isDev =3D S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); =20 /* Here, @device might be whatever path in the system. We * should create the path in the namespace iff it's "/dev" @@ -7828,7 +7830,7 @@ qemuDomainCreateDeviceRecursive(const char *device, if (qemuDomainCreateDeviceRecursive(target, data, allow_noent, ttl - 1) < 0) goto cleanup; - } else { + } else if (isDev) { if (create && mknod(devicePath, sb.st_mode, sb.st_rdev) < 0) { if (errno =3D=3D EEXIST) { @@ -7850,6 +7852,11 @@ qemuDomainCreateDeviceRecursive(const char *device, devicePath); goto cleanup; } + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("unsupported device type %s %o"), + device, (int) sb.st_mode); + goto cleanup; } =20 if (!create) { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148514545699.6755344737571; Thu, 22 Jun 2017 09:21:54 -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 CF3B730C458; Thu, 22 Jun 2017 16:21: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 AEEE05D967; Thu, 22 Jun 2017 16:21: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 5C3614E985; Thu, 22 Jun 2017 16:21:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIjhS023599 for ; Thu, 22 Jun 2017 12:18:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC8BE60608; Thu, 22 Jun 2017 16:18:45 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33ECE60607 for ; Thu, 22 Jun 2017 16:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF3B730C458 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CF3B730C458 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:32 +0200 Message-Id: <1011dda30471518d30fd261e0fa68bf53735d251.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] qemuDomainAttachDeviceMknodHelper: Fail on unsupported file type 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.29]); Thu, 22 Jun 2017 16:21:47 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, we silently assume that file we are creating in the namespace is either a link or a device (character or block one). This is not always the case. Therefore instead of doing something wrong, claim about unsupported file type. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e6fb041de..977b5c089 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8518,6 +8518,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, int ret =3D -1; bool delDevice =3D false; bool isLink =3D S_ISLNK(data->sb.st_mode); + bool isDev =3D S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode); =20 qemuSecurityPostFork(data->driver->securityManager); =20 @@ -8539,7 +8540,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, } else { delDevice =3D true; } - } else { + } else if (isDev) { VIR_DEBUG("Creating dev %s (%d,%d)", data->file, major(data->sb.st_rdev), minor(data->sb.st_r= dev)); if (mknod(data->file, data->sb.st_mode, data->sb.st_rdev) < 0) { @@ -8556,6 +8557,11 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUT= E_UNUSED, } else { delDevice =3D true; } + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("unsupported device type %s %o"), + data->file, (int) data->sb.st_mode); + goto cleanup; } =20 if (lchown(data->file, data->sb.st_uid, data->sb.st_gid) < 0) { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148516587777.5241661987047; Thu, 22 Jun 2017 09:21:56 -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 04D6A7D0E7; Thu, 22 Jun 2017 16:21:51 +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 D2FCF6FE5D; Thu, 22 Jun 2017 16:21:50 +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 816D51853E2D; Thu, 22 Jun 2017 16:21:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIk59023609 for ; Thu, 22 Jun 2017 12:18:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id B702660607; Thu, 22 Jun 2017 16:18:46 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34FE660624 for ; Thu, 22 Jun 2017 16:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 04D6A7D0E7 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 04D6A7D0E7 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:33 +0200 Message-Id: <2725fbe84c2ba7d5e74b31b572dbe1aae5f58108.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/8] qemuDomainCreateDeviceRecursive: Support file mount points 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]); Thu, 22 Jun 2017 16:21:51 +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=3D1462060 When building a qemu namespace we might be dealing with bare regular files. Files that live under /dev. For instance /dev/my_awesome_disk: # qemu-img create -f qcow2 /dev/my_awesome_disk 10M So far we were mknod()-ing them which is obviously wrong. We need to touch the file and bind mount it to the original: 1) touch /var/run/libvirt/qemu/fedora.dev/my_awesome_disk 2) mount --bind /dev/my_awesome_disk /var/run/libvirt/qemu/fedora.dev/my_aw= esome_disk Later, when the new /dev is built and replaces original /dev the file is going to live at expected location. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 977b5c089..6d7c218a2 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7708,6 +7708,7 @@ qemuDomainCreateDeviceRecursive(const char *device, int ret =3D -1; bool isLink =3D false; bool isDev =3D false; + bool isReg =3D false; bool create =3D false; #ifdef WITH_SELINUX char *tcon =3D NULL; @@ -7731,6 +7732,7 @@ qemuDomainCreateDeviceRecursive(const char *device, =20 isLink =3D S_ISLNK(sb.st_mode); isDev =3D S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); + isReg =3D S_ISREG(sb.st_mode); =20 /* Here, @device might be whatever path in the system. We * should create the path in the namespace iff it's "/dev" @@ -7842,16 +7844,12 @@ qemuDomainCreateDeviceRecursive(const char *device, } goto cleanup; } - - /* Set the file permissions again: mknod() is affected by the - * current umask, and as such might not have set them correctly */ + } else if (isReg) { if (create && - chmod(devicePath, sb.st_mode) < 0) { - virReportSystemError(errno, - _("Failed to set permissions for device %= s"), - devicePath); + virFileTouch(devicePath, sb.st_mode) < 0) goto cleanup; - } + /* Just create the file here so that code below sets + * proper owner and mode. Bind mount only after that. */ } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("unsupported device type %s %o"), @@ -7871,6 +7869,15 @@ qemuDomainCreateDeviceRecursive(const char *device, goto cleanup; } =20 + /* Symlinks don't have mode */ + if (!isLink && + chmod(devicePath, sb.st_mode) < 0) { + virReportSystemError(errno, + _("Failed to set permissions for device %s"), + devicePath); + goto cleanup; + } + /* Symlinks don't have ACLs. */ if (!isLink && virFileCopyACLs(device, devicePath) < 0 && @@ -7903,6 +7910,11 @@ qemuDomainCreateDeviceRecursive(const char *device, } #endif =20 + /* Finish mount process started earlier. */ + if (isReg && + virFileBindMountDevice(device, devicePath) < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_FREE(target); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148518099713.0312172605747; Thu, 22 Jun 2017 09:21:58 -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 44D756655; Thu, 22 Jun 2017 16:21:55 +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 0E6A26FE49; Thu, 22 Jun 2017 16:21:55 +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 ACC111853E30; Thu, 22 Jun 2017 16:21:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIpMl023632 for ; Thu, 22 Jun 2017 12:18:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02E2A60619; Thu, 22 Jun 2017 16:18:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7237960602 for ; Thu, 22 Jun 2017 16:18:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44D756655 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 44D756655 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:34 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] qemuDomainAttachDeviceMknodRecursive: Support file mount points 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.38]); Thu, 22 Jun 2017 16:21:56 +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=3D1462060 Just like in the previous commit, when attaching a file based device which has its source living under /dev (that is not a device rather than a regular file), calling mknod() is no help. We need to: 1) bind mount device to some temporary location 2) enter the namespace 3) move the mount point to desired place 4) umount it in the parent namespace from the temporary location At the same time, the check in qemuDomainNamespaceSetupDisk makes no longer sense. Therefore remove it. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 59 ++++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 6d7c218a2..51779c535 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8531,6 +8531,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, bool delDevice =3D false; bool isLink =3D S_ISLNK(data->sb.st_mode); bool isDev =3D S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode); + bool isReg =3D S_ISREG(data->sb.st_mode); =20 qemuSecurityPostFork(data->driver->securityManager); =20 @@ -8569,6 +8570,23 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUT= E_UNUSED, } else { delDevice =3D true; } + } else if (isReg) { + /* We are not cleaning up disks on virDomainDetachDevice + * because disk might be still in use by different disk + * as its backing chain. This might however clash here. + * Therefore do the cleanup here. */ + if (umount(data->file) < 0 && + errno !=3D ENOENT) { + virReportSystemError(errno, + _("Unable to umount %s"), + data->file); + goto cleanup; + } + if (virFileTouch(data->file, data->sb.st_mode) < 0) + goto cleanup; + delDevice =3D true; + /* Just create the file here so that code below sets + * proper owner and mode. Move the mount only after that. */ } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("unsupported device type %s %o"), @@ -8583,6 +8601,15 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUT= E_UNUSED, goto cleanup; } =20 + /* Symlinks don't have mode */ + if (!isLink && + chmod(data->file, data->sb.st_mode) < 0) { + virReportSystemError(errno, + _("Failed to set permissions for device %s"), + data->file); + goto cleanup; + } + /* Symlinks don't have ACLs. */ if (!isLink && virFileSetACLs(data->file, data->acl) < 0 && @@ -8606,6 +8633,11 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUT= E_UNUSED, } #endif =20 + /* Finish mount process started earlier. */ + if (isReg && + virFileMoveMount(data->target, data->file) < 0) + goto cleanup; + ret =3D 0; cleanup: if (ret < 0 && delDevice) @@ -8626,10 +8658,12 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverP= tr driver, size_t ndevMountsPath, unsigned int ttl) { + virQEMUDriverConfigPtr cfg =3D NULL; struct qemuDomainAttachDeviceMknodData data; int ret =3D -1; char *target =3D NULL; bool isLink; + bool isReg; =20 if (!ttl) { virReportSystemError(ELOOP, @@ -8651,8 +8685,18 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPt= r driver, } =20 isLink =3D S_ISLNK(data.sb.st_mode); + isReg =3D S_ISREG(data.sb.st_mode); =20 - if (isLink) { + if (isReg && STRPREFIX(file, DEVPREFIX)) { + cfg =3D virQEMUDriverGetConfig(driver); + if (!(target =3D qemuDomainGetPreservedMountPath(cfg, vm, file))) + goto cleanup; + + if (virFileBindMountDevice(file, target) < 0) + goto cleanup; + + data.target =3D target; + } else if (isLink) { if (virFileReadLink(file, &target) < 0) { virReportSystemError(errno, _("unable to resolve symlink %s"), @@ -8739,7 +8783,10 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPt= r driver, freecon(data.tcon); #endif virFileFreeACLs(&data.acl); + if (isReg && target) + umount(target); VIR_FREE(target); + virObjectUnref(cfg); return ret; } =20 @@ -8817,7 +8864,6 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver, char **devMountsPath =3D NULL; size_t ndevMountsPath =3D 0; virStorageSourcePtr next; - struct stat sb; int ret =3D -1; =20 if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) @@ -8836,15 +8882,6 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver, continue; } =20 - if (stat(next->path, &sb) < 0) { - virReportSystemError(errno, - _("Unable to access %s"), next->path); - goto cleanup; - } - - if (!S_ISBLK(sb.st_mode)) - continue; - if (qemuDomainAttachDeviceMknod(driver, vm, next->path, --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:30:17 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.zoho.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 1498148524149834.999837010634; Thu, 22 Jun 2017 09:22:04 -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 8C206C0005B8; Thu, 22 Jun 2017 16:21:58 +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 5E00E5D967; Thu, 22 Jun 2017 16:21: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 131071853E32; Thu, 22 Jun 2017 16:21:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MGIq58023642 for ; Thu, 22 Jun 2017 12:18:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB58360608; Thu, 22 Jun 2017 16:18:52 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36D0E60607 for ; Thu, 22 Jun 2017 16:18:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C206C0005B8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8C206C0005B8 From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 18:18:35 +0200 Message-Id: <4ee26afa9c6476a9b0f02c65dbacbae81a1a8331.1498147980.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/8] qemu ns: Create chardev backends more frequently 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.32]); Thu, 22 Jun 2017 16:21:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, the only type of chardev that we create the backend for in the namespace is type=3D'dev'. This is not enough, other backends might have files under /dev too. For instance channels might have a unix socket under /dev (well, bind mounted under /dev from a different place). Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- src/qemu/qemu_domain.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 51779c535..65eec26dd 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7732,7 +7732,7 @@ qemuDomainCreateDeviceRecursive(const char *device, =20 isLink =3D S_ISLNK(sb.st_mode); isDev =3D S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); - isReg =3D S_ISREG(sb.st_mode); + isReg =3D S_ISREG(sb.st_mode) || S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.s= t_mode); =20 /* Here, @device might be whatever path in the system. We * should create the path in the namespace iff it's "/dev" @@ -8129,11 +8129,17 @@ qemuDomainSetupChardev(virDomainDefPtr def ATTRIBUT= E_UNUSED, void *opaque) { const struct qemuDomainCreateDeviceData *data =3D opaque; + const char *path =3D NULL; =20 - if (dev->source->type !=3D VIR_DOMAIN_CHR_TYPE_DEV) + if (!(path =3D virDomainChrSourceDefPath(dev->source))) return 0; =20 - return qemuDomainCreateDevice(dev->source->data.file.path, data, false= ); + /* Socket created by qemu. It doesn't exist upfront. */ + if (dev->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX && + dev->source->data.nix.listen) + return 0; + + return qemuDomainCreateDevice(path, data, true); } =20 =20 @@ -8531,7 +8537,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, bool delDevice =3D false; bool isLink =3D S_ISLNK(data->sb.st_mode); bool isDev =3D S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode); - bool isReg =3D S_ISREG(data->sb.st_mode); + bool isReg =3D S_ISREG(data->sb.st_mode) || S_ISFIFO(data->sb.st_mode)= || S_ISSOCK(data->sb.st_mode); =20 qemuSecurityPostFork(data->driver->securityManager); =20 @@ -8576,7 +8582,7 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE= _UNUSED, * as its backing chain. This might however clash here. * Therefore do the cleanup here. */ if (umount(data->file) < 0 && - errno !=3D ENOENT) { + errno !=3D ENOENT && errno !=3D EINVAL) { virReportSystemError(errno, _("Unable to umount %s"), data->file); @@ -8685,7 +8691,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr= driver, } =20 isLink =3D S_ISLNK(data.sb.st_mode); - isReg =3D S_ISREG(data.sb.st_mode); + isReg =3D S_ISREG(data.sb.st_mode) || S_ISFIFO(data.sb.st_mode) || S_I= SSOCK(data.sb.st_mode); =20 if (isReg && STRPREFIX(file, DEVPREFIX)) { cfg =3D virQEMUDriverGetConfig(driver); @@ -9077,10 +9083,13 @@ qemuDomainNamespaceSetupChardev(virQEMUDriverPtr dr= iver, if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; =20 - if (chr->source->type !=3D VIR_DOMAIN_CHR_TYPE_DEV) + if (!(path =3D virDomainChrSourceDefPath(chr->source))) return 0; =20 - path =3D chr->source->data.file.path; + /* Socket created by qemu. It doesn't exist upfront. */ + if (chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX && + chr->source->data.nix.listen) + return 0; =20 cfg =3D virQEMUDriverGetConfig(driver); if (qemuDomainGetPreservedMounts(cfg, vm, --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list