From nobody Fri May 16 10:55:06 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.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 1494517816220663.3388142560776; Thu, 11 May 2017 08:50:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80EA380046; Thu, 11 May 2017 15:50:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A7B678F1E; Thu, 11 May 2017 15:50:12 +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 003F95EC6A; Thu, 11 May 2017 15:50:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4BFo0I6011203 for ; Thu, 11 May 2017 11:50:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4AA3496550; Thu, 11 May 2017 15:50:00 +0000 (UTC) Received: from antique-work.brq.redhat.com (dhcp129-230.brq.redhat.com [10.34.129.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3FAD9654B for ; Thu, 11 May 2017 15:49:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80EA380046 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 80EA380046 From: Pavel Hrdina To: libvir-list@redhat.com Date: Thu, 11 May 2017 17:49:54 +0200 Message-Id: <0ee71710b84c066b3c04d6c6823a686e7923d436.1494517711.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] qemu: improve detection of UNIX path generated by libvirt 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 11 May 2017 15:50:14 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently we consider all UNIX paths with specific prefix as generated by libvirt, but that's a wrong assumption. Let's make the detection better by actually checking whether the whole path matches one of the paths that we generate or generated in the past. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1446980 Signed-off-by: Pavel Hrdina --- src/qemu/qemu_domain.c | 78 ++++++++++++++++++= +--- .../qemuxml2argv-channel-unix-gen-path1.xml | 17 +++++ .../qemuxml2argv-channel-unix-gen-path2.xml | 17 +++++ .../qemuxml2argv-channel-unix-gen-path3.xml | 17 +++++ .../qemuxml2argv-channel-unix-user-path.xml | 17 +++++ .../qemuxml2xmlout-channel-unix-gen-path1.xml | 32 +++++++++ .../qemuxml2xmlout-channel-unix-gen-path2.xml | 32 +++++++++ .../qemuxml2xmlout-channel-unix-gen-path3.xml | 32 +++++++++ .../qemuxml2xmlout-channel-unix-user-path.xml | 33 +++++++++ tests/qemuxml2xmltest.c | 5 ++ 10 files changed, 271 insertions(+), 9 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-pa= th1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-pa= th2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-pa= th3.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-channel-unix-user-p= ath.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-ge= n-path1.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-ge= n-path2.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-ge= n-path3.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-us= er-path.xml diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cc02c801e1..99bfd8f320 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3154,24 +3154,84 @@ qemuDomainDefaultNetModel(const virDomainDef *def, =20 =20 /* - * Clear auto generated unix socket path, i.e., the one which starts with = our - * channel directory. + * Clear auto generated unix socket paths: + * + * libvirt 1.2.18 and older: + * {cfg->channelTargetDir}/{dom-name}.{target-name} + * + * libvirt 1.2.19 - 1.3.2: + * {cfg->channelTargetDir}/domain-{dom-name}/{target-name} + * + * libvirt 1.3.3 and newer: + * {cfg->channelTargetDir}/domain-{dom-id}-{short-dom-name}/{target-na= me} + * + * The unix socket path was stored in config XML until libvirt 1.3.0. + * If someone specifies the same path as we generate, they shouldn't do it. + * + * This function clears the path for migration as well, so we need to clear + * the path event if we are not storing it in the XML. */ -static void +static int qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr, virQEMUDriverPtr driver) { virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + char *path; + char *prefix =3D NULL; + int prefixLen; + int ret =3D -1; + int rv; =20 - if (chr->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL && - chr->targetType =3D=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO && - chr->source->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX && - chr->source->data.nix.path && - STRPREFIX(chr->source->data.nix.path, cfg->channelTargetDir)) { - VIR_FREE(chr->source->data.nix.path); + if (chr->deviceType !=3D VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL || + chr->targetType !=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_VIRTIO || + chr->source->type !=3D VIR_DOMAIN_CHR_TYPE_UNIX || + !chr->source->data.nix.path) { + ret =3D 0; + goto cleanup; } =20 + if (!STRPREFIX(chr->source->data.nix.path, cfg->channelTargetDir)) { + ret =3D 0; + goto cleanup; + } + + path =3D chr->source->data.nix.path + strlen(cfg->channelTargetDir); + prefixLen =3D strlen(path) - strlen(chr->target.name); + + if (STRNEQ(path + prefixLen, chr->target.name)) { + ret =3D 0; + goto cleanup; + } + + if (!VIR_STRNDUP(prefix, path, prefixLen)) + goto cleanup; + + /* Now we've isolated the middle part of the path by removing the + * cfg->channelTargetDir part from the beginning and chr->target.name + * from the end. The middle part is the one that changed in the past + * and the only part that we need to try to match with. */ + +#define VIR_CLEAR_CHR_DEF_PATH(regex) = \ + if ((rv =3D virStringMatch(prefix, regex)) < 0) = \ + goto cleanup; = \ + = \ + if (rv =3D=3D 0) { = \ + VIR_FREE(chr->source->data.nix.path); = \ + ret =3D 0; = \ + goto cleanup; = \ + } + + VIR_CLEAR_CHR_DEF_PATH("^/[^/]+\\.$") + VIR_CLEAR_CHR_DEF_PATH("^/domain-[^/]+/$") + VIR_CLEAR_CHR_DEF_PATH("^/domain-[0-9]+-[^/]+/$") + +#undef VIR_CLEAR_CHR_DEF_PATH + + ret =3D 0; + cleanup: + VIR_FREE(prefix); virObjectUnref(cfg); + return ret; } =20 =20 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path1.xml= b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path1.xml new file mode 100644 index 0000000000..25c84e922b --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path1.xml @@ -0,0 +1,17 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path2.xml= b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path2.xml new file mode 100644 index 0000000000..2d7ca0ae77 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path2.xml @@ -0,0 +1,17 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path3.xml= b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path3.xml new file mode 100644 index 0000000000..20477016c9 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-gen-path3.xml @@ -0,0 +1,17 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-user-path.xml= b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-user-path.xml new file mode 100644 index 0000000000..45fdf08a66 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-channel-unix-user-path.xml @@ -0,0 +1,17 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path1= .xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path1.xml new file mode 100644 index 0000000000..aa2a3099d7 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path1.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + + +
+ + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path2= .xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path2.xml new file mode 100644 index 0000000000..aa2a3099d7 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path2.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + + +
+ + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path3= .xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path3.xml new file mode 100644 index 0000000000..aa2a3099d7 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-gen-path3.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + + +
+ + + +
+ + + + + + diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-user-path= .xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-user-path.xml new file mode 100644 index 0000000000..488212d761 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-channel-unix-user-path.xml @@ -0,0 +1,33 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + +
+ + + +
+ + + + +
+ + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 2dccde746e..044faf2a5d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -551,6 +551,11 @@ mymain(void) DO_TEST("channel-virtio", NONE); DO_TEST("channel-virtio-state", NONE); =20 + DO_TEST_FULL("channel-unix-gen-path1", WHEN_INACTIVE, GIC_NONE, NONE); + DO_TEST_FULL("channel-unix-gen-path2", WHEN_INACTIVE, GIC_NONE, NONE); + DO_TEST_FULL("channel-unix-gen-path3", WHEN_INACTIVE, GIC_NONE, NONE); + DO_TEST_FULL("channel-unix-user-path", WHEN_INACTIVE, GIC_NONE, NONE); + DO_TEST("hostdev-usb-address", NONE); DO_TEST("hostdev-pci-address", NONE); DO_TEST("hostdev-vfio", NONE); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list