From nobody Tue Apr 23 09:37:35 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 1494593886282303.50006207352965; Fri, 12 May 2017 05:58:06 -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 312E23DBD5; Fri, 12 May 2017 12:58:04 +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 911C57E49B; Fri, 12 May 2017 12:58:03 +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 4902D180BAF1; Fri, 12 May 2017 12:58:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4CCw0qp008213 for ; Fri, 12 May 2017 08:58:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 352A28B96F; Fri, 12 May 2017 12:58: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 B1AD08B96E for ; Fri, 12 May 2017 12:57:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 312E23DBD5 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 312E23DBD5 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 12 May 2017 14:57:54 +0200 Message-Id: <3a9dcb514f396434fc4f7e6d5447a48bbad6c2bd.1494593677.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/3] util: introduce virStringMatch 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.30]); Fri, 12 May 2017 12:58:05 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Simply tries to match the provided regex on a string and returns the result. Useful if caller don't care about the matched substring and want to just test if some pattern patches a string. Signed-off-by: Pavel Hrdina --- changes in v2: - virStringMatch returns bool instead of int src/libvirt_private.syms | 1 + src/util/virstring.c | 33 +++++++++++++++++++++++++++++++++ src/util/virstring.h | 3 +++ tests/virstringtest.c | 47 ++++++++++++++++++++++++++++++++++++++++++++= +++ 4 files changed, 84 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index afb9100c50..d32c6e7549 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2621,6 +2621,7 @@ virStringListHasString; virStringListJoin; virStringListLength; virStringListRemove; +virStringMatch; virStringReplace; virStringSearch; virStringSortCompare; diff --git a/src/util/virstring.c b/src/util/virstring.c index 335e773d78..c8d6b0ca02 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -979,6 +979,39 @@ virStringSearch(const char *str, } =20 /** + * virStringMatch: + * @str: string to match + * @regexp: POSIX Extended regular expression pattern used for matching + * + * Performs a POSIX extended regex match against a string. + * Returns true on match, false on error or no match. + */ +bool +virStringMatch(const char *str, + const char *regexp) +{ + regex_t re; + int rv; + + VIR_DEBUG("match '%s' for '%s'", str, regexp); + + if ((rv =3D regcomp(&re, regexp, REG_EXTENDED | REG_NOSUB)) !=3D 0) { + char error[100]; + regerror(rv, &re, error, sizeof(error)); + virReportError(VIR_ERR_INTERNAL_ERROR, + _("error while compiling regular expression '%s': %= s"), + regexp, error); + return false; + } + + rv =3D regexec(&re, str, 0, NULL, 0); + + regfree(&re); + + return rv =3D=3D 0; +} + +/** * virStringReplace: * @haystack: the source string to process * @oldneedle: the substring to locate diff --git a/src/util/virstring.h b/src/util/virstring.h index c545ca3f0d..0038a405b1 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -274,6 +274,9 @@ ssize_t virStringSearch(const char *str, char ***matches) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); =20 +bool virStringMatch(const char *str, + const char *regexp); + char *virStringReplace(const char *haystack, const char *oldneedle, const char *newneedle) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 96bc79f832..97c6e76dcb 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -480,6 +480,38 @@ testStringSearch(const void *opaque) } =20 =20 +struct stringMatchData { + const char *str; + const char *regexp; + bool expectMatch; +}; + +static int +testStringMatch(const void *opaque) +{ + const struct stringMatchData *data =3D opaque; + bool match; + + match =3D virStringMatch(data->str, data->regexp); + + if (data->expectMatch) { + if (!match) { + fprintf(stderr, "expected match for '%s' on '%s' but got no ma= tch\n", + data->regexp, data->str); + return -1; + } + } else { + if (match) { + fprintf(stderr, "expected no match for '%s' on '%s' but got ma= tch\n", + data->regexp, data->str); + return -1; + } + } + + return 0; +} + + struct stringReplaceData { const char *haystack; const char *oldneedle; @@ -803,6 +835,21 @@ mymain(void) const char *matches3[] =3D { "foo", "bar" }; TEST_SEARCH("1foo2bar3eek", "([a-z]+)", 2, 2, matches3, false); =20 +#define TEST_MATCH(s, r, m) = \ + do { = \ + struct stringMatchData data =3D { = \ + .str =3D s, = \ + .regexp =3D r, = \ + .expectMatch =3D m, = \ + }; = \ + if (virTestRun("virStringMatch " s, testStringMatch, &data) < 0) = \ + ret =3D -1; = \ + } while (0) + + TEST_MATCH("foo", "foo", true); + TEST_MATCH("foobar", "f[o]+", true); + TEST_MATCH("foobar", "^f[o]+$", false); + #define TEST_REPLACE(h, o, n, r) = \ do { = \ struct stringReplaceData data =3D { = \ --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 23 09:37:35 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 1494593885150706.8655598594808; Fri, 12 May 2017 05:58:05 -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 438C761986; Fri, 12 May 2017 12:58:03 +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 1B1A58EE40; Fri, 12 May 2017 12:58:03 +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 BE62D180BAF2; Fri, 12 May 2017 12:58:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4CCw1Lc008219 for ; Fri, 12 May 2017 08:58:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 059E28B96E; Fri, 12 May 2017 12:58:01 +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 82E968B972 for ; Fri, 12 May 2017 12:58:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 438C761986 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 438C761986 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 12 May 2017 14:57:55 +0200 Message-Id: <7154f734e0689c8bc6f6b778e86878768a8132c9.1494593677.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/3] util: introduce virBufferEscapeRegex 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.38]); Fri, 12 May 2017 12:58:04 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a helper to escape all possible meta-characters used for POSIX extended regular expressions. Signed-off-by: Pavel Hrdina --- new in v2 src/libvirt_private.syms | 1 + src/util/virbuffer.c | 19 +++++++++++++++++++ src/util/virbuffer.h | 3 +++ tests/virbuftest.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d32c6e7549..bbe283529b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1312,6 +1312,7 @@ virBufferCurrentContent; virBufferError; virBufferEscape; virBufferEscapeN; +virBufferEscapeRegex; virBufferEscapeSexpr; virBufferEscapeShell; virBufferEscapeString; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 80c8e289d4..f07b119c0f 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -556,6 +556,25 @@ virBufferEscapeSexpr(virBufferPtr buf, } =20 /** + * virBufferEscapeRegex: + * @buf: the buffer to append to + * @format: a printf like format string but with only one %s parameter + * @str: the string argument which needs to be escaped + * + * Do a formatted print with a single string to a buffer. The @str is + * escaped to avoid using POSIX extended regular expression meta-character= s. + * Escaping is not applied to characters specified in @format. Auto + * indentation may be applied. + */ +void +virBufferEscapeRegex(virBufferPtr buf, + const char *format, + const char *str) +{ + virBufferEscape(buf, '\\', "^$.|?*+()[]{}\\", format, str); +} + +/** * virBufferEscape: * @buf: the buffer to append to * @escape: the escape character to inject diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index d1b64ca3a3..7a7014aa70 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -88,6 +88,9 @@ void virBufferEscapeString(virBufferPtr buf, const char *= format, const char *str); void virBufferEscapeSexpr(virBufferPtr buf, const char *format, const char *str); +void virBufferEscapeRegex(virBufferPtr buf, + const char *format, + const char *str); void virBufferEscapeShell(virBufferPtr buf, const char *str); void virBufferURIEncodeString(virBufferPtr buf, const char *str); =20 diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 5905fee7d4..940e4c1c61 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -405,6 +405,35 @@ testBufEscapeN(const void *opaque) =20 =20 static int +testBufEscapeRegex(const void *opaque) +{ + const struct testBufAddStrData *data =3D opaque; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *actual; + int ret =3D -1; + + virBufferEscapeRegex(&buf, "%s", data->data); + + if (!(actual =3D virBufferContentAndReset(&buf))) { + VIR_TEST_DEBUG("testBufEscapeN: buf is empty"); + goto cleanup; + } + + if (STRNEQ_NULLABLE(actual, data->expect)) { + VIR_TEST_DEBUG("testBufEscapeN: Strings don't match:\n"); + virTestDifference(stderr, data->expect, actual); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_FREE(actual); + return ret; +} + + +static int testBufSetIndent(const void *opaque ATTRIBUTE_UNUSED) { virBuffer buf =3D VIR_BUFFER_INITIALIZER; @@ -492,6 +521,17 @@ mymain(void) DO_TEST_ESCAPEN("equal=3Descape", "equal\\=3Descape"); DO_TEST_ESCAPEN("comma,equal=3Descape", "comma,,equal\\=3Descape"); =20 +#define DO_TEST_ESCAPE_REGEX(data, expect) = \ + do { = \ + struct testBufAddStrData info =3D { data, expect }; = \ + if (virTestRun("Buf: EscapeRegex", testBufEscapeRegex, &info) < 0)= \ + ret =3D -1; = \ + } while (0) + + DO_TEST_ESCAPE_REGEX("noescape", "noescape"); + DO_TEST_ESCAPE_REGEX("^$.|?*+()[]{}\\", + "\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\]\\{\\}\\\\"); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue Apr 23 09:37:35 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 1494593890109127.26041303567592; Fri, 12 May 2017 05:58:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7184F6602; Fri, 12 May 2017 12:58:08 +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 4A15C5C89F; Fri, 12 May 2017 12:58:08 +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 F1A285ED67; Fri, 12 May 2017 12:58:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4CCw1Ls008228 for ; Fri, 12 May 2017 08:58:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id D271F8B96E; Fri, 12 May 2017 12:58:01 +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 5AEC78B971 for ; Fri, 12 May 2017 12:58:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7184F6602 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 7184F6602 From: Pavel Hrdina To: libvir-list@redhat.com Date: Fri, 12 May 2017 14:57:56 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 3/3] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 12 May 2017 12:58:09 +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. The UNIX path isn't stored in config XML since libvirt-1.3.0. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1446980 Signed-off-by: Pavel Hrdina --- changes in v2: - dropped the magic to split the path into 3 parts and use only one regexp to match the path src/qemu/qemu_domain.c | 51 ++++++++++++++++++= ---- .../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, 244 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..00e37d3428 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3154,24 +3154,57 @@ 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); + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + char *regexp =3D NULL; + int ret =3D -1; =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)) { + 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; + } + + virBufferEscapeRegex(&buf, "^%s", cfg->channelTargetDir); + virBufferAddLit(&buf, "/([^/]+\\.)|(domain-[^/]+/)"); + virBufferEscapeRegex(&buf, "%s$", chr->target.name); + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + regexp =3D virBufferContentAndReset(&buf); + + if (virStringMatch(chr->source->data.nix.path, regexp)) VIR_FREE(chr->source->data.nix.path); - } =20 + ret =3D 0; + cleanup: + VIR_FREE(regexp); 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.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list