From nobody Mon Apr 29 21:17:44 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 1500478000661377.81612717146743; Wed, 19 Jul 2017 08:26:40 -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 02457C04574D; Wed, 19 Jul 2017 15:26:36 +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 8C2BA79821; Wed, 19 Jul 2017 15:26:35 +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 10C731803B26; Wed, 19 Jul 2017 15:26:35 +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 v6JFQXIo000612 for ; Wed, 19 Jul 2017 11:26:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8100080F78; Wed, 19 Jul 2017 15:26:33 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 885E27F5FA; Wed, 19 Jul 2017 15:26:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 02457C04574D 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 02457C04574D From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 19 Jul 2017 17:26:27 +0200 Message-Id: <633f4999b1ec9a8a3c5a99394eb93bc191990ed1.1500477971.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com Subject: [libvirt] [PATCH] 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.32]); Wed, 19 Jul 2017 15:26:37 +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 | 25 ++++++-- src/libxl/libxl_conf.c | 2 +- src/qemu/qemu_block.c | 2 +- src/qemu/qemu_command.c | 28 ++------- src/qemu/qemu_parse_command.c | 33 +++++++--- src/storage/storage_backend_gluster.c | 17 ++--- src/storage/storage_driver.c | 7 +-- src/util/virstoragefile.c | 113 +++++++++++++++++++++---------= ---- src/util/virstoragefile.h | 4 +- src/xenconfig/xen_xl.c | 2 +- 10 files changed, 130 insertions(+), 103 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9320794de..e8fdaa36f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6437,6 +6437,7 @@ virDomainStorageHostParse(xmlNodePtr node, int ret =3D -1; xmlNodePtr child; char *transport =3D NULL; + char *port =3D NULL; virStorageNetHostDef host; =20 memset(&host, 0, sizeof(host)); @@ -6486,7 +6487,15 @@ virDomainStorageHostParse(xmlNodePtr node, goto cleanup; } =20 - host.port =3D virXMLPropString(child, "port"); + port =3D virXMLPropString(child, "port"); + if (port && + (virStrToLong_i(port, NULL, 10, &host.port) < 0 || + host.port < 0)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("failed to parse port number '%s'"), + port); + goto cleanup; + } } =20 if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) @@ -6499,6 +6508,7 @@ virDomainStorageHostParse(xmlNodePtr node, cleanup: virStorageNetHostDefClear(&host); VIR_FREE(transport); + VIR_FREE(port); return ret; } =20 @@ -7882,8 +7892,8 @@ virDomainDiskSourceParse(xmlNodePtr node, if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0) goto cleanup; =20 - if (virStorageSourceNetworkAssignDefaultPorts(src) < 0) - goto cleanup; + virStorageSourceNetworkAssignDefaultPorts(src); + break; case VIR_STORAGE_TYPE_VOLUME: if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) @@ -14909,7 +14919,7 @@ virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostd= evDefPtr first, &second->source.subsys.u.scsi.u.iscsi; =20 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; @@ -21408,7 +21418,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'%d'", src->hosts[n].port); =20 if (src->hosts[n].transport) virBufferAsprintf(buf, " transport=3D'%s'", @@ -22255,7 +22267,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'%d'", 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..1b20fb906 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); =20 if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port); + virBufferAsprintf(&buf, "\\:%d", src->hosts[i].port); } } =20 diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 93124c5ba..3d64528a8 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -465,7 +465,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virSt= orageSourcePtr src, if (virJSONValueObjectCreate(&server, "s:type", transport, "s:host", host->name, - "s:port", host->port, + "i:port", host->port, NULL) < 0) goto cleanup; break; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6ac26af3e..b4a99c651 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -491,22 +491,6 @@ qemuSafeSerialParamValue(const char *value) } =20 =20 -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,8 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, goto cleanup; =20 if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { - if ((uri->port =3D qemuNetworkDriveGetPort(src->hosts->port)) < 0) - goto cleanup; + uri->port =3D src->hosts->port; =20 if (VIR_STRDUP(uri->scheme, virStorageNetProtocolTypeToString(src->protocol)) <= 0) @@ -897,8 +880,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, =20 switch (src->hosts->transport) { case VIR_STORAGE_NET_HOST_TRANS_TCP: - virBufferStrcat(&buf, src->hosts->name, ":", - src->hosts->port, NULL); + virBufferAsprintf(&buf, "%s:%d", src->hosts->name, src= ->hosts->port); break; =20 case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -953,9 +935,9 @@ 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:%d:%s", src->hosts->name, - src->hosts->port ? src->hosts->port : "700= 0", + src->hosts->port ? src->hosts->port : 7000, src->path) < 0) goto cleanup; } else { @@ -996,7 +978,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, virBufferAsprintf(&buf, "%s", src->hosts[i].name); =20 if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\:%s", src->hosts[i].por= t); + virBufferAsprintf(&buf, "\\:%d", src->hosts[i].por= t); } } =20 diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index af9063c02..45d9c77d8 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; =20 - 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,8 +239,13 @@ qemuParseNBDString(virDomainDiskDefPtr disk) if (src) *src++ =3D '\0'; =20 - if (VIR_STRDUP(h->port, port) < 0) + if (virStrToLong_i(port, NULL, 10, &h->port) < 0 || + h->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); goto error; + } } =20 if (src && STRPREFIX(src, "exportname=3D")) { @@ -730,8 +734,13 @@ 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 (virStrToLong_i(port, NULL, 10, &def->src->host= s->port) < 0 || + def->src->hosts->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number = '%s'"), + port); goto error; + } def->src->hosts->transport =3D VIR_STORAGE_NET_HOS= T_TRANS_TCP; def->src->hosts->socket =3D NULL; if (VIR_STRDUP(def->src->path, vdi) < 0) @@ -2005,8 +2014,13 @@ 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 (virStrToLong_i(port, NULL, 10, &disk->src->hos= ts->port) < 0 || + disk->src->hosts->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number = '%s'"), + port); goto error; + } if (VIR_STRDUP(disk->src->path, vdi) < 0) goto error; } @@ -2540,13 +2554,18 @@ qemuParseCommandLine(virCapsPtr caps, } port =3D strchr(token, ':'); if (port) { + int port_i; *port++ =3D '\0'; - if (VIR_STRDUP(port, port) < 0) { + if (virStrToLong_i(port, NULL, 10, &port_i) < 0 || + port_i < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); VIR_FREE(hosts); goto error; } + first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].po= rt =3D port_i; } - 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..cc042982e 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; =20 - 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:%d/%s%= s)", + src, src->hosts->name, src->hosts->port, src->volume, src->p= ath); =20 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; =20 case VIR_STORAGE_NET_HOST_TRANS_UNIX: @@ -828,7 +819,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStor= ageSourcePtr src) priv))) return NULL; =20 - ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%s/%s/%s", + ignore_value(virAsprintf(&priv->canonpath, "gluster://%s:%d/%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; =20 - 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; =20 /* 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 2d0ff7812..bea4a42ad 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1688,8 +1688,8 @@ virStorageNetHostDefClear(virStorageNetHostDefPtr def) if (!def) return; =20 + def->port =3D 0; VIR_FREE(def->name); - VIR_FREE(def->port); VIR_FREE(def->socket); } =20 @@ -1736,13 +1736,11 @@ virStorageNetHostDefCopy(size_t nhosts, virStorageNetHostDefPtr dst =3D &ret[i]; =20 dst->transport =3D src->transport; + dst->port =3D src->port; =20 if (VIR_STRDUP(dst->name, src->name) < 0) goto error; =20 - if (VIR_STRDUP(dst->port, src->port) < 0) - goto error; - if (VIR_STRDUP(dst->socket, src->socket) < 0) goto error; } @@ -2430,10 +2428,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr = src, tmp[0] =3D '\0'; } =20 - if (uri->port > 0) { - if (virAsprintf(&src->hosts->port, "%d", uri->port) < 0) - goto cleanup; - } + if (uri->port > 0) + src->hosts->port =3D uri->port; =20 if (VIR_STRDUP(src->hosts->name, uri->server) < 0) goto cleanup; @@ -2470,8 +2466,14 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, if (port) { *port =3D '\0'; port +=3D skip; - if (VIR_STRDUP(src->hosts[src->nhosts - 1].port, port) < 0) + if (virStrToLong_i(port, NULL, 10, + &src->hosts[src->nhosts - 1].port) < 0 || + src->hosts[src->nhosts - 1].port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); goto error; + } } =20 parts =3D virStringSplit(hostport, "\\:", 0); @@ -2488,7 +2490,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, return 0; =20 error: - VIR_FREE(src->hosts[src->nhosts-1].port); VIR_FREE(src->hosts[src->nhosts-1].name); return -1; } @@ -2638,7 +2639,7 @@ virStorageSourceParseNBDColonString(const char *nbdst= r, if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0) goto cleanup; =20 - } else { + } else { if (VIR_STRDUP(src->hosts->name, backing[1]) < 0) goto cleanup; =20 @@ -2649,8 +2650,13 @@ virStorageSourceParseNBDColonString(const char *nbds= tr, goto cleanup; } =20 - if (VIR_STRDUP(src->hosts->port, backing[2]) < 0) + if (virStrToLong_i(backing[2], NULL, 10, &src->hosts->port) < 0 || + src->hosts->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + backing[2]); goto cleanup; + } } =20 if (backing[3] && STRPREFIX(backing[3], "exportname=3D")) { @@ -2824,8 +2830,16 @@ virStorageSourceParseBackingJSONInetSocketAddress(vi= rStorageNetHostDefPtr host, =20 host->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; =20 - if (VIR_STRDUP(host->name, hostname) < 0 || - VIR_STRDUP(host->port, port) < 0) + if (port && + (virStrToLong_i(port, NULL, 10, &host->port) < 0 || + host->port < 0)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); + return -1; + } + + if (VIR_STRDUP(host->name, hostname) < 0) return -1; =20 return 0; @@ -2985,11 +2999,12 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSou= rcePtr src, goto cleanup; =20 if ((port =3D strchr(src->hosts->name, ':'))) { - if (VIR_STRDUP(src->hosts->port, port + 1) < 0) - goto cleanup; - - if (strlen(src->hosts->port) =3D=3D 0) - VIR_FREE(src->hosts->port); + if (virStrToLong_i(port + 1, NULL, 10, &src->hosts->port) < 0 || + src->hosts->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port + 1); + } =20 *port =3D '\0'; } @@ -3050,8 +3065,14 @@ virStorageSourceParseBackingJSONNbd(virStorageSource= Ptr src, if (VIR_STRDUP(src->hosts[0].name, host) < 0) return -1; =20 - if (VIR_STRDUP(src->hosts[0].port, port) < 0) + if (port && + (virStrToLong_i(port, NULL, 10, &src->hosts[0].port) < 0 || + src->hosts[0].port < 0)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); return -1; + } } } =20 @@ -3136,8 +3157,17 @@ virStorageSourceParseBackingJSONSSH(virStorageSource= Ptr 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) + + if (port && + (virStrToLong_i(port, NULL, 10, &src->hosts[0].port) < 0 || + src->hosts[0].port < 0)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + port); + return -1; + } + + if (VIR_STRDUP(src->hosts[0].name, host) < 0) return -1; } =20 @@ -3961,66 +3991,61 @@ virStorageSourceFindByNodeName(virStorageSourcePtr = top, } =20 =20 -static const char * +static int virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol) { switch (protocol) { case VIR_STORAGE_NET_PROTOCOL_HTTP: - return "80"; + return 80; =20 case VIR_STORAGE_NET_PROTOCOL_HTTPS: - return "443"; + return 443; =20 case VIR_STORAGE_NET_PROTOCOL_FTP: - return "21"; + return 21; =20 case VIR_STORAGE_NET_PROTOCOL_FTPS: - return "990"; + return 990; =20 case VIR_STORAGE_NET_PROTOCOL_TFTP: - return "69"; + return 69; =20 case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: - return "7000"; + return 7000; =20 case VIR_STORAGE_NET_PROTOCOL_NBD: - return "10809"; + return 10809; =20 case VIR_STORAGE_NET_PROTOCOL_SSH: - return "22"; + return 22; =20 case VIR_STORAGE_NET_PROTOCOL_ISCSI: - return "3260"; + return 3260; =20 case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - return "24007"; + return 24007; =20 case VIR_STORAGE_NET_PROTOCOL_RBD: /* we don't provide a default for RBD */ - return NULL; + return 0; =20 case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_NONE: - return NULL; + return 0; } =20 - return NULL; + return 0; } =20 =20 -int +void virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) { size_t i; =20 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..934504806 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; + 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); =20 -int +void virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) ATTRIBUTE_NONNULL(1); =20 diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index cac440cd4..e21da5410 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); =20 if (src->hosts[i].port) - virBufferAsprintf(&buf, "\\\\:%s", src->hosts[i].port); + virBufferAsprintf(&buf, "\\\\:%d", src->hosts[i].port); } } =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list