From nobody Fri May 3 16:48:46 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.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 1500553818319567.217154727319; Thu, 20 Jul 2017 05:30:18 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 661B47CE1C; Thu, 20 Jul 2017 12:30:15 +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 1BA357E8F0; Thu, 20 Jul 2017 12:30:15 +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 AF3B73FAE0; Thu, 20 Jul 2017 12:30:14 +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 v6KCU81r007003 for ; Thu, 20 Jul 2017 08:30:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 685F280920; Thu, 20 Jul 2017 12:30:08 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87E6080929; Thu, 20 Jul 2017 12:30:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 661B47CE1C Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.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 661B47CE1C From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:29:58 +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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 1/6] qemu: command: Rename and move qemuNetworkDriveGetPort 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Jul 2017 12:30:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move it to virstring.c and improve it to parse and validate ports. New name is virStringParsePort. --- src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 18 +----------------- src/util/virstring.c | 37 +++++++++++++++++++++++++++++++++++++ src/util/virstring.h | 4 ++++ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 187b12b32..f0c2c8446 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2656,6 +2656,7 @@ virStringListJoin; virStringListLength; virStringListRemove; virStringMatch; +virStringParsePort; virStringReplace; virStringSearch; virStringSortCompare; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6ac26af3e..be23796df 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -491,22 +491,6 @@ qemuSafeSerialParamValue(const char *value) } -static int -qemuNetworkDriveGetPort(const char *port) -{ - int ret =3D 0; - - if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse port number '%s'"), - port); - return -1; - } - - return ret; -} - - /** * qemuBuildSecretInfoProps: * @secinfo: pointer to the secret info object @@ -825,7 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, goto cleanup; if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { - if ((uri->port =3D qemuNetworkDriveGetPort(src->hosts->port)) < 0) + if (virStringParsePort(src->hosts->port, &uri->port) < 0) goto cleanup; if (VIR_STRDUP(uri->scheme, diff --git a/src/util/virstring.c b/src/util/virstring.c index 9b54bd6fb..fe61a3516 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1344,3 +1344,40 @@ void virStringTrimOptionalNewline(char *str) if (*tmp =3D=3D '\n') *tmp =3D '\0'; } + + +/** + * virStringParsePort: + * @str: port number to parse + * @port: pointer to parse port into + * + * Parses a string representation of a network port and validates it. Retu= rns + * 0 on success and -1 on error. + */ +int +virStringParsePort(const char *str, + int *port) +{ + unsigned int p =3D 0; + + *port =3D 0; + + if (!str) + return 0; + + if (virStrToLong_uip(str, NULL, 10, &p) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("failed to parse port number '%s'"), str); + return -1; + } + + if (p > 65535) { + virReportError(VIR_ERR_INVALID_ARG, + _("port '%s' out of range"), str); + return -1; + } + + *port =3D p; + + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 5eaaaea0a..e562bf514 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -296,4 +296,8 @@ char *virStringEncodeBase64(const uint8_t *buf, size_t = buflen); void virStringTrimOptionalNewline(char *str); +int virStringParsePort(const char *str, + int *port) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; + #endif /* __VIR_STRING_H__ */ --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:48:46 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.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 1500553821224706.499609405741; Thu, 20 Jul 2017 05:30:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E24368E3E6; Thu, 20 Jul 2017 12:30:19 +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 ACCD082701; Thu, 20 Jul 2017 12:30:19 +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 4790B1853E31; Thu, 20 Jul 2017 12:30:19 +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 v6KCUAUC007011 for ; Thu, 20 Jul 2017 08:30:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 693D27FEBB; Thu, 20 Jul 2017 12:30:10 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id D630280924; Thu, 20 Jul 2017 12:30:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E24368E3E6 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 E24368E3E6 From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:29:59 +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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 2/6] util: uri: Convert port number to unsigned integer 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 12:30:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Negative ports don't make sense so use a unsigned integer. --- src/util/virstring.c | 2 +- src/util/virstring.h | 2 +- src/util/viruri.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index fe61a3516..69e0fd173 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1356,7 +1356,7 @@ void virStringTrimOptionalNewline(char *str) */ int virStringParsePort(const char *str, - int *port) + unsigned int *port) { unsigned int p =3D 0; diff --git a/src/util/virstring.h b/src/util/virstring.h index e562bf514..ff5f0148d 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -297,7 +297,7 @@ char *virStringEncodeBase64(const uint8_t *buf, size_t = buflen); void virStringTrimOptionalNewline(char *str); int virStringParsePort(const char *str, - int *port) + unsigned int *port) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; #endif /* __VIR_STRING_H__ */ diff --git a/src/util/viruri.h b/src/util/viruri.h index 1e53abb0b..7850c38c2 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -42,7 +42,7 @@ struct _virURI { char *scheme; /* the URI scheme */ char *server; /* the server part */ char *user; /* the user part */ - int port; /* the port number */ + unsigned int port; /* the port number */ char *path; /* the path string */ char *query; /* the query string */ char *fragment; /* the fragment string */ --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:48:46 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.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 1500553819719938.8305238780214; Thu, 20 Jul 2017 05:30:19 -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 F03C72F86D3; Thu, 20 Jul 2017 12:30:15 +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 CE4C17F6B0; Thu, 20 Jul 2017 12:30:15 +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 64F121853E31; Thu, 20 Jul 2017 12:30:15 +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 v6KCUD0S007024 for ; Thu, 20 Jul 2017 08:30:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6412B176BB; Thu, 20 Jul 2017 12:30:13 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D6AD80922; Thu, 20 Jul 2017 12:30:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F03C72F86D3 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 F03C72F86D3 From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:30:00 +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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 3/6] qemu: command: Remove condition to use default sheepdog port 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, 20 Jul 2017 12:30:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since we now set the default ports when parsing disks, it's not necessary to have default port numbers encoded in the command line generator. --- src/qemu/qemu_command.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index be23796df..810578840 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -938,8 +938,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, goto cleanup; } else if (src->nhosts =3D=3D 1) { if (virAsprintf(&ret, "sheepdog:%s:%s:%s", - src->hosts->name, - src->hosts->port ? src->hosts->port : "700= 0", + src->hosts->name, src->hosts->port, src->path) < 0) goto cleanup; } else { --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:48:46 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.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 1500553829760241.42441014384258; Thu, 20 Jul 2017 05:30:29 -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 57A762FFC2C; Thu, 20 Jul 2017 12:30: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 258527C1C6; Thu, 20 Jul 2017 12:30: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 9CAC23FAE2; Thu, 20 Jul 2017 12:30:26 +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 v6KCUPnN007039 for ; Thu, 20 Jul 2017 08:30:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 904E9176BB; Thu, 20 Jul 2017 12:30:25 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AFBD80924; Thu, 20 Jul 2017 12:30:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57A762FFC2C 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 57A762FFC2C From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:30:01 +0200 Message-Id: <3a1170f1fef3e45d705b26933c14ba212e99e5aa.1500553294.git.pkrempa@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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 4/6] util: storage: fill in default ports when parsing backing chain 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.29]); Thu, 20 Jul 2017 12:30:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to when parsing XML we need to fill in default ports for the backing chain. This was missed in commit 5bda835466a8050625dd8bb10566e --- src/util/virstoragefile.c | 3 +++ tests/virstoragetest.c | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 2d0ff7812..bc1b616d4 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3340,6 +3340,9 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) if (rc < 0) goto error; + + if (virStorageSourceNetworkAssignDefaultPorts(ret) < 0) + goto error; } return ret; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 5352500b7..d83db78f5 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1349,7 +1349,7 @@ mymain(void) TEST_BACKING_PARSE("://", NULL); TEST_BACKING_PARSE("http://example.com/file", "\n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("rbd:testshare:id=3Dasdf:mon_host=3Dexample.com", "\n" @@ -1385,14 +1385,14 @@ mymain(void) TEST_BACKING_PARSE("json:{\"file.driver\":\"http\", " "\"file.url\":\"http://example.com/file\"}", "\n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file\":{ \"driver\":\"http\"," "\"url\":\"http://example.com/file= \"" "}" "}", "\n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file.driver\":\"ftp\", " "\"file.url\":\"http://example.com/file\"}", @@ -1400,7 +1400,7 @@ mymain(void) TEST_BACKING_PARSE("json:{\"file.driver\":\"gluster\", " "\"file.filename\":\"gluster://example.com/vo= l/file\"}", "\n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"gluster\"," "\"volume\":\"testvol\"," @@ -1421,7 +1421,7 @@ mymain(void) "\n" " \n" " \n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file.driver\":\"gluster\"," "\"file.volume\":\"testvol\"," @@ -1441,7 +1441,7 @@ mymain(void) "\n" " \n" " \n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"nbd\"," "\"path\":\"/path/to/socket\"" @@ -1552,7 +1552,7 @@ mymain(void) "}" "}", "\n" - " \n" + " \n" "\n"); TEST_BACKING_PARSE("json:{\"file\":{\"driver\":\"iscsi\"," "\"transport\":\"tcp\"," --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:48:46 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.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 1500553832389933.5312115243986; Thu, 20 Jul 2017 05:30:32 -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 074B08E3DF; Thu, 20 Jul 2017 12:30:30 +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 CAE4019EE4; Thu, 20 Jul 2017 12:30:29 +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 7E28F1853E31; Thu, 20 Jul 2017 12:30:29 +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 v6KCURRa007044 for ; Thu, 20 Jul 2017 08:30:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id F23A280920; Thu, 20 Jul 2017 12:30:26 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08D6F176BB; Thu, 20 Jul 2017 12:30:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 074B08E3DF Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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 074B08E3DF From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:30:02 +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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 5/6] conf: domain: Split up virDomainStorageHostParse and rename it 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.25]); Thu, 20 Jul 2017 12:30:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Split out parsing of one host into a separate function and add a new function to loop through all the host XML nodes. This change removes multiple levels of nesting due to the old XML parsing approach used. --- src/conf/domain_conf.c | 117 +++++++++++++++++++++++++++------------------= ---- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9320794de..a3fd7195a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6429,71 +6429,61 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, return ret; } + static int -virDomainStorageHostParse(xmlNodePtr node, - virStorageNetHostDefPtr *hosts, - size_t *nhosts) +virDomainStorageNetworkParseHost(xmlNodePtr hostnode, + virStorageNetHostDefPtr *hosts, + size_t *nhosts) { int ret =3D -1; - xmlNodePtr child; char *transport =3D NULL; virStorageNetHostDef host; memset(&host, 0, sizeof(host)); + host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - child =3D node->children; - while (child !=3D NULL) { - if (child->type =3D=3D XML_ELEMENT_NODE && - xmlStrEqual(child->name, BAD_CAST "host")) { - - host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; - - /* transport can be tcp (default), unix or rdma. */ - if ((transport =3D virXMLPropString(child, "transport"))) { - host.transport =3D virStorageNetHostTransportTypeFromStrin= g(transport); - if (host.transport < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown protocol transport type '%s'= "), - transport); - goto cleanup; - } - } + /* transport can be tcp (default), unix or rdma. */ + if ((transport =3D virXMLPropString(hostnode, "transport"))) { + host.transport =3D virStorageNetHostTransportTypeFromString(transp= ort); + if (host.transport < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown protocol transport type '%s'"), + transport); + goto cleanup; + } + } - host.socket =3D virXMLPropString(child, "socket"); + host.socket =3D virXMLPropString(hostnode, "socket"); - if (host.transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket =3D=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing socket for unix transport")); - goto cleanup; - } + if (host.transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host.socket =3D=3D NULL) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing socket for unix transport")); + goto cleanup; + } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && - host.socket !=3D NULL) { - virReportError(VIR_ERR_XML_ERROR, - _("transport '%s' does not support " - "socket attribute"), - transport); - goto cleanup; - } + if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX && + host.socket !=3D NULL) { + virReportError(VIR_ERR_XML_ERROR, + _("transport '%s' does not support " + "socket attribute"), + transport); + goto cleanup; + } - VIR_FREE(transport); + if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { + if (!(host.name =3D virXMLPropString(hostnode, "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing name for host")); + goto cleanup; + } - if (host.transport !=3D VIR_STORAGE_NET_HOST_TRANS_UNIX) { - if (!(host.name =3D virXMLPropString(child, "name"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing name for host")); - goto cleanup; - } + host.port =3D virXMLPropString(hostnode, "port"); + } - host.port =3D virXMLPropString(child, "port"); - } + if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) + goto cleanup; - if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) - goto cleanup; - } - child =3D child->next; - } ret =3D 0; cleanup: @@ -6502,6 +6492,27 @@ virDomainStorageHostParse(xmlNodePtr node, return ret; } + +static int +virDomainStorageNetworkParseHosts(xmlNodePtr node, + virStorageNetHostDefPtr *hosts, + size_t *nhosts) +{ + xmlNodePtr child; + + for (child =3D node->children; child; child =3D child->next) { + if (child->type =3D=3D XML_ELEMENT_NODE && + xmlStrEqual(child->name, BAD_CAST "host")) { + + if (virDomainStorageNetworkParseHost(child, hosts, nhosts) < 0) + return -1; + } + } + + return 0; +} + + static int virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr sc= sisrc) @@ -6609,8 +6620,8 @@ virDomainHostdevSubsysSCSIiSCSIDefParseXML(xmlNodePtr= sourcenode, goto cleanup; } - if (virDomainStorageHostParse(sourcenode, &iscsisrc->hosts, - &iscsisrc->nhosts) < 0) + if (virDomainStorageNetworkParseHosts(sourcenode, &iscsisrc->hosts, + &iscsisrc->nhosts) < 0) goto cleanup; if (iscsisrc->nhosts < 1) { @@ -7879,7 +7890,7 @@ virDomainDiskSourceParse(xmlNodePtr node, /* config file currently only works with remote disks */ src->configFile =3D virXPathString("string(./config/@file)", ctxt); - if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0) + if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nho= sts) < 0) goto cleanup; if (virStorageSourceNetworkAssignDefaultPorts(src) < 0) --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 16:48:46 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.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 1500553832544373.562635078413; Thu, 20 Jul 2017 05:30:32 -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 19903336F1E; Thu, 20 Jul 2017 12:30:30 +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 D09347C1C8; Thu, 20 Jul 2017 12:30:29 +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 819483FAE3; Thu, 20 Jul 2017 12:30:29 +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 v6KCUSAc007054 for ; Thu, 20 Jul 2017 08:30:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C0A9176BB; Thu, 20 Jul 2017 12:30:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CEE980921; Thu, 20 Jul 2017 12:30:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 19903336F1E 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 19903336F1E From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 14:30:03 +0200 Message-Id: <8a02bc1bd2db9a9bcfa50bfec40eb0c5b7d27a8d.1500553294.git.pkrempa@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 Cc: Michal Privoznik , Peter Krempa Subject: [libvirt] [PATCH v2 6/6] virStorageNetHostDef: Turn @port into integer 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]); Thu, 20 Jul 2017 12:30:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently, @port is type of string. Well, that's overkill and waste of memory. Port is always an integer. Use it as such. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 20 +++++++--- src/libxl/libxl_conf.c | 2 +- src/qemu/qemu_block.c | 7 +++- src/qemu/qemu_command.c | 11 +++--- src/qemu/qemu_parse_command.c | 13 +++---- src/storage/storage_backend_gluster.c | 17 ++------- src/storage/storage_driver.c | 7 +--- src/util/virstoragefile.c | 69 ++++++++++++++-----------------= ---- src/util/virstoragefile.h | 4 +- src/xenconfig/xen_xl.c | 2 +- 10 files changed, 68 insertions(+), 84 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a3fd7195a..7ba6804ac 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6437,6 +6437,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, { int ret =3D -1; char *transport =3D NULL; + char *port =3D NULL; virStorageNetHostDef host; memset(&host, 0, sizeof(host)); @@ -6478,7 +6479,10 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, goto cleanup; } - host.port =3D virXMLPropString(hostnode, "port"); + if ((port =3D virXMLPropString(hostnode, "port"))) { + if (virStringParsePort(port, &host.port) < 0) + goto cleanup; + } } if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) @@ -6489,6 +6493,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, cleanup: virStorageNetHostDefClear(&host); VIR_FREE(transport); + VIR_FREE(port); return ret; } @@ -7893,8 +7898,8 @@ virDomainDiskSourceParse(xmlNodePtr node, if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nho= sts) < 0) goto cleanup; - if (virStorageSourceNetworkAssignDefaultPorts(src) < 0) - goto cleanup; + virStorageSourceNetworkAssignDefaultPorts(src); + break; case VIR_STORAGE_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) @@ -14920,7 +14925,7 @@ virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostd= evDefPtr first, &second->source.subsys.u.scsi.u.iscsi; if (STREQ(first_iscsisrc->hosts[0].name, second_iscsisrc->hosts[0].nam= e) && - STREQ(first_iscsisrc->hosts[0].port, second_iscsisrc->hosts[0].por= t) && + first_iscsisrc->hosts[0].port =3D=3D second_iscsisrc->hosts[0].por= t && STREQ(first_iscsisrc->path, second_iscsisrc->path)) return 1; return 0; @@ -21419,7 +21424,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf, for (n =3D 0; n < src->nhosts; n++) { virBufferAddLit(buf, "hosts[n].name); - virBufferEscapeString(buf, " port=3D'%s'", src->hosts[n].port); + + if (src->hosts[n].port) + virBufferAsprintf(buf, " port=3D'%u'", src->hosts[n].port); if (src->hosts[n].transport) virBufferAsprintf(buf, " transport=3D'%s'", @@ -22266,7 +22273,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, if (scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE= _ISCSI) { virBufferAddLit(buf, "hosts[0].= name); - virBufferEscapeString(buf, " port=3D'%s'", iscsisrc->hosts[0].= port); + if (iscsisrc->hosts[0].port) + virBufferAsprintf(buf, " port=3D'%u'", iscsisrc->hosts[0].= port); virBufferAddLit(buf, "/>\n"); } else { virBufferAsprintf(buf, "\n", diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index a85bc71d2..4416a09dd 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -706,7 +706,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src, virBufferAsprintf(&buf, "%s", src->hosts[i].name); if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port); + virBufferAsprintf(&buf, "\\:%u", src->hosts[i].port); } } diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 93124c5ba..22de70657 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -447,6 +447,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, virJSONValuePtr ret =3D NULL; virStorageNetHostDefPtr host; const char *transport; + char *port =3D NULL; size_t i; if (!(servers =3D virJSONValueNewArray())) @@ -462,10 +463,13 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(vir= StorageSourcePtr src, else transport =3D "inet"; + if (virAsprintf(&port, "%u", host->port) < 0) + goto cleanup; + if (virJSONValueObjectCreate(&server, "s:type", transport, "s:host", host->name, - "s:port", host->port, + "s:port", port, NULL) < 0) goto cleanup; break; @@ -497,6 +501,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, cleanup: virJSONValueFree(servers); virJSONValueFree(server); + VIR_FREE(port); return ret; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 810578840..065217013 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -809,8 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, goto cleanup; if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { - if (virStringParsePort(src->hosts->port, &uri->port) < 0) - goto cleanup; + uri->port =3D src->hosts->port; if (VIR_STRDUP(uri->scheme, virStorageNetProtocolTypeToString(src->protocol)) <= 0) @@ -881,8 +880,8 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, switch (src->hosts->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: - virBufferStrcat(&buf, src->hosts->name, ":", - src->hosts->port, NULL); + virBufferAsprintf(&buf, "%s:%u", + src->hosts->name, src->hosts->port); break; case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -937,7 +936,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, if (virAsprintf(&ret, "sheepdog:%s", src->path) < 0) goto cleanup; } else if (src->nhosts =3D=3D 1) { - if (virAsprintf(&ret, "sheepdog:%s:%s:%s", + if (virAsprintf(&ret, "sheepdog:%s:%u:%s", src->hosts->name, src->hosts->port, src->path) < 0) goto cleanup; @@ -979,7 +978,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, virBufferAsprintf(&buf, "%s", src->hosts[i].name); if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\:%s", src->hosts[i].por= t); + virBufferAsprintf(&buf, "\\:%u", src->hosts[i].por= t); } } diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index af9063c02..15ed5c9e6 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -92,8 +92,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPt= r uri, if (VIR_STRDUP(def->src->hosts->name, uri->server) < 0) goto error; - if (virAsprintf(&def->src->hosts->port, "%d", uri->port) < 0) - goto error; + def->src->hosts->port =3D uri->port; } else { def->src->hosts->name =3D NULL; def->src->hosts->port =3D 0; @@ -240,7 +239,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) if (src) *src++ =3D '\0'; - if (VIR_STRDUP(h->port, port) < 0) + if (virStringParsePort(port, &h->port) < 0) goto error; } @@ -730,7 +729,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, goto error; def->src->nhosts =3D 1; def->src->hosts->name =3D def->src->path; - if (VIR_STRDUP(def->src->hosts->port, port) < 0) + if (virStringParsePort(port, &def->src->hosts->por= t) < 0) goto error; def->src->hosts->transport =3D VIR_STORAGE_NET_HOS= T_TRANS_TCP; def->src->hosts->socket =3D NULL; @@ -2005,7 +2004,7 @@ qemuParseCommandLine(virCapsPtr caps, goto error; disk->src->nhosts =3D 1; disk->src->hosts->name =3D disk->src->path; - if (VIR_STRDUP(disk->src->hosts->port, port) < 0) + if (virStringParsePort(port, &disk->src->hosts->po= rt) < 0) goto error; if (VIR_STRDUP(disk->src->path, vdi) < 0) goto error; @@ -2541,12 +2540,12 @@ qemuParseCommandLine(virCapsPtr caps, port =3D strchr(token, ':'); if (port) { *port++ =3D '\0'; - if (VIR_STRDUP(port, port) < 0) { + if (virStringParsePort(port, + &first_rbd_disk->src->hosts[first_r= bd_disk->src->nhosts].port) < 0) { VIR_FREE(hosts); goto error; } } - first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].port = =3D port; if (VIR_STRDUP(first_rbd_disk->src->hosts[first_rbd_disk->src-= >nhosts].name, token) < 0) { VIR_FREE(hosts); diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_ba= ckend_gluster.c index add8d34bf..92038c131 100644 --- a/src/storage/storage_backend_gluster.c +++ b/src/storage/storage_backend_gluster.c @@ -575,9 +575,8 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr = src) { virStorageFileBackendGlusterPrivPtr priv =3D src->drv->priv; - VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%s/%s%= s)", - src, src->hosts->name, src->hosts->port ? src->hosts->port := "0", - src->volume, src->path); + VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%u/%s%= s)", + src, src->hosts->name, src->hosts->port, src->volume, src->p= ath); if (priv->vol) glfs_fini(priv->vol); @@ -599,15 +598,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileB= ackendGlusterPrivPtr priv, case VIR_STORAGE_NET_HOST_TRANS_RDMA: case VIR_STORAGE_NET_HOST_TRANS_TCP: hoststr =3D host->name; - - if (host->port && - virStrToLong_i(host->port, NULL, 10, &port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse port number '%s'"), - host->port); - return -1; - } - + port =3D host->port; break; case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -828,7 +819,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStor= ageSourcePtr src) priv))) return NULL; - ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%s/%s/%s", + ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%u/%s/%s", src->hosts->name, src->hosts->port, src->volume, diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 18d630319..d3e81794d 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -2781,11 +2781,8 @@ virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr= def, if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name)= < 0) goto cleanup; - if (virAsprintf(&def->src->hosts[0].port, "%d", - pooldef->source.hosts[0].port ? - pooldef->source.hosts[0].port : - 3260) < 0) - goto cleanup; + def->src->hosts[0].port =3D pooldef->source.hosts[0].port ? + pooldef->source.hosts[0].port : 3260; /* iscsi volume has name like "unit:0:0:1" */ if (!(tokens =3D virStringSplit(def->src->srcpool->volume, ":", 0))) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index bc1b616d4..0add4c146 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1689,7 +1689,6 @@ virStorageNetHostDefClear(virStorageNetHostDefPtr def) return; VIR_FREE(def->name); - VIR_FREE(def->port); VIR_FREE(def->socket); } @@ -1736,13 +1735,11 @@ virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefPtr dst =3D &ret[i]; dst->transport =3D src->transport; + dst->port =3D src->port; if (VIR_STRDUP(dst->name, src->name) < 0) goto error; - if (VIR_STRDUP(dst->port, src->port) < 0) - goto error; - if (VIR_STRDUP(dst->socket, src->socket) < 0) goto error; } @@ -2430,10 +2427,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr = src, tmp[0] =3D '\0'; } - if (uri->port > 0) { - if (virAsprintf(&src->hosts->port, "%d", uri->port) < 0) - goto cleanup; - } + src->hosts->port =3D uri->port; if (VIR_STRDUP(src->hosts->name, uri->server) < 0) goto cleanup; @@ -2470,7 +2464,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, if (port) { *port =3D '\0'; port +=3D skip; - if (VIR_STRDUP(src->hosts[src->nhosts - 1].port, port) < 0) + if (virStringParsePort(port, &src->hosts[src->nhosts - 1].port) < = 0) goto error; } @@ -2488,7 +2482,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, return 0; error: - VIR_FREE(src->hosts[src->nhosts-1].port); VIR_FREE(src->hosts[src->nhosts-1].name); return -1; } @@ -2649,7 +2642,7 @@ virStorageSourceParseNBDColonString(const char *nbdst= r, goto cleanup; } - if (VIR_STRDUP(src->hosts->port, backing[2]) < 0) + if (virStringParsePort(backing[2], &src->hosts->port) < 0) goto cleanup; } @@ -2825,7 +2818,7 @@ virStorageSourceParseBackingJSONInetSocketAddress(vir= StorageNetHostDefPtr host, host->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; if (VIR_STRDUP(host->name, hostname) < 0 || - VIR_STRDUP(host->port, port) < 0) + virStringParsePort(port, &host->port) < 0) return -1; return 0; @@ -2985,12 +2978,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSour= cePtr src, goto cleanup; if ((port =3D strchr(src->hosts->name, ':'))) { - if (VIR_STRDUP(src->hosts->port, port + 1) < 0) + if (virStringParsePort(port + 1, &src->hosts->port) < 0) goto cleanup; - if (strlen(src->hosts->port) =3D=3D 0) - VIR_FREE(src->hosts->port); - *port =3D '\0'; } @@ -3050,7 +3040,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourceP= tr src, if (VIR_STRDUP(src->hosts[0].name, host) < 0) return -1; - if (VIR_STRDUP(src->hosts[0].port, port) < 0) + if (virStringParsePort(port, &src->hosts[0].port) < 0) return -1; } } @@ -3136,8 +3126,9 @@ virStorageSourceParseBackingJSONSSH(virStorageSourceP= tr src, return -1; } else { src->hosts[0].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + if (VIR_STRDUP(src->hosts[0].name, host) < 0 || - VIR_STRDUP(src->hosts[0].port, port) < 0) + virStringParsePort(port, &src->hosts[0].port) < 0) return -1; } @@ -3341,8 +3332,7 @@ virStorageSourceNewFromBackingAbsolute(const char *pa= th) if (rc < 0) goto error; - if (virStorageSourceNetworkAssignDefaultPorts(ret) < 0) - goto error; + virStorageSourceNetworkAssignDefaultPorts(ret); } return ret; @@ -3964,66 +3954,61 @@ virStorageSourceFindByNodeName(virStorageSourcePtr = top, } -static const char * +static unsigned int virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol) { switch (protocol) { case VIR_STORAGE_NET_PROTOCOL_HTTP: - return "80"; + return 80; case VIR_STORAGE_NET_PROTOCOL_HTTPS: - return "443"; + return 443; case VIR_STORAGE_NET_PROTOCOL_FTP: - return "21"; + return 21; case VIR_STORAGE_NET_PROTOCOL_FTPS: - return "990"; + return 990; case VIR_STORAGE_NET_PROTOCOL_TFTP: - return "69"; + return 69; case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: - return "7000"; + return 7000; case VIR_STORAGE_NET_PROTOCOL_NBD: - return "10809"; + return 10809; case VIR_STORAGE_NET_PROTOCOL_SSH: - return "22"; + return 22; case VIR_STORAGE_NET_PROTOCOL_ISCSI: - return "3260"; + return 3260; case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - return "24007"; + return 24007; case VIR_STORAGE_NET_PROTOCOL_RBD: /* we don't provide a default for RBD */ - return NULL; + return 0; case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_NONE: - return NULL; + return 0; } - return NULL; + return 0; } -int +void virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) { size_t i; for (i =3D 0; i < src->nhosts; i++) { if (src->hosts[i].transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP = && - src->hosts[i].port =3D=3D NULL) { - if (VIR_STRDUP(src->hosts[i].port, - virStorageSourceNetworkDefaultPort(src->protoco= l)) < 0) - return -1; - } + src->hosts[i].port =3D=3D 0) + src->hosts[i].port =3D virStorageSourceNetworkDefaultPort(src-= >protocol); } - - return 0; } diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 98992e04a..d1e8ffe07 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -155,7 +155,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostD= ef; typedef virStorageNetHostDef *virStorageNetHostDefPtr; struct _virStorageNetHostDef { char *name; - char *port; + unsigned int port; int transport; /* virStorageNetHostTransport */ char *socket; /* path to unix socket */ }; @@ -406,7 +406,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top, unsigned int *index) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int +void virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) ATTRIBUTE_NONNULL(1); diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index cac440cd4..7d8995933 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -1057,7 +1057,7 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src) virBufferAsprintf(&buf, "%s", src->hosts[i].name); if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\\\:%s", src->hosts[i].port); + virBufferAsprintf(&buf, "\\\\:%u", src->hosts[i].port); } } --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list