提交 97ea8da1 编写于 作者: P Peter Krempa

virStorageNetHostDef: Turn @port into integer

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: NMichal Privoznik <mprivozn@redhat.com>
上级 a7828886
...@@ -6324,6 +6324,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, ...@@ -6324,6 +6324,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
{ {
int ret = -1; int ret = -1;
char *transport = NULL; char *transport = NULL;
char *port = NULL;
virStorageNetHostDef host; virStorageNetHostDef host;
memset(&host, 0, sizeof(host)); memset(&host, 0, sizeof(host));
...@@ -6365,7 +6366,10 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, ...@@ -6365,7 +6366,10 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
goto cleanup; goto cleanup;
} }
host.port = virXMLPropString(hostnode, "port"); if ((port = virXMLPropString(hostnode, "port"))) {
if (virStringParsePort(port, &host.port) < 0)
goto cleanup;
}
} }
if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0) if (VIR_APPEND_ELEMENT(*hosts, *nhosts, host) < 0)
...@@ -6376,6 +6380,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, ...@@ -6376,6 +6380,7 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode,
cleanup: cleanup:
virStorageNetHostDefClear(&host); virStorageNetHostDefClear(&host);
VIR_FREE(transport); VIR_FREE(transport);
VIR_FREE(port);
return ret; return ret;
} }
...@@ -7780,8 +7785,8 @@ virDomainDiskSourceParse(xmlNodePtr node, ...@@ -7780,8 +7785,8 @@ virDomainDiskSourceParse(xmlNodePtr node,
if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts) < 0) if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts) < 0)
goto cleanup; goto cleanup;
if (virStorageSourceNetworkAssignDefaultPorts(src) < 0) virStorageSourceNetworkAssignDefaultPorts(src);
goto cleanup;
break; break;
case VIR_STORAGE_TYPE_VOLUME: case VIR_STORAGE_TYPE_VOLUME:
if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0) if (virDomainDiskSourcePoolDefParse(node, &src->srcpool) < 0)
...@@ -14814,7 +14819,7 @@ virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostdevDefPtr first, ...@@ -14814,7 +14819,7 @@ virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostdevDefPtr first,
&second->source.subsys.u.scsi.u.iscsi; &second->source.subsys.u.scsi.u.iscsi;
if (STREQ(first_iscsisrc->hosts[0].name, second_iscsisrc->hosts[0].name) && if (STREQ(first_iscsisrc->hosts[0].name, second_iscsisrc->hosts[0].name) &&
STREQ(first_iscsisrc->hosts[0].port, second_iscsisrc->hosts[0].port) && first_iscsisrc->hosts[0].port == second_iscsisrc->hosts[0].port &&
STREQ(first_iscsisrc->path, second_iscsisrc->path)) STREQ(first_iscsisrc->path, second_iscsisrc->path))
return 1; return 1;
return 0; return 0;
...@@ -21313,7 +21318,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf, ...@@ -21313,7 +21318,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf,
for (n = 0; n < src->nhosts; n++) { for (n = 0; n < src->nhosts; n++) {
virBufferAddLit(buf, "<host"); virBufferAddLit(buf, "<host");
virBufferEscapeString(buf, " name='%s'", src->hosts[n].name); virBufferEscapeString(buf, " name='%s'", src->hosts[n].name);
virBufferEscapeString(buf, " port='%s'", src->hosts[n].port);
if (src->hosts[n].port)
virBufferAsprintf(buf, " port='%u'", src->hosts[n].port);
if (src->hosts[n].transport) if (src->hosts[n].transport)
virBufferAsprintf(buf, " transport='%s'", virBufferAsprintf(buf, " transport='%s'",
...@@ -22160,7 +22167,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, ...@@ -22160,7 +22167,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) { if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
virBufferAddLit(buf, "<host"); virBufferAddLit(buf, "<host");
virBufferEscapeString(buf, " name='%s'", iscsisrc->hosts[0].name); virBufferEscapeString(buf, " name='%s'", iscsisrc->hosts[0].name);
virBufferEscapeString(buf, " port='%s'", iscsisrc->hosts[0].port); if (iscsisrc->hosts[0].port)
virBufferAsprintf(buf, " port='%u'", iscsisrc->hosts[0].port);
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} else { } else {
virBufferAsprintf(buf, "<adapter name='%s'/>\n", virBufferAsprintf(buf, "<adapter name='%s'/>\n",
......
...@@ -706,7 +706,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src, ...@@ -706,7 +706,7 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src,
virBufferAsprintf(&buf, "%s", src->hosts[i].name); virBufferAsprintf(&buf, "%s", src->hosts[i].name);
if (src->hosts[i].port) if (src->hosts[i].port)
virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port); virBufferAsprintf(&buf, "\\:%u", src->hosts[i].port);
} }
} }
......
...@@ -447,6 +447,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src, ...@@ -447,6 +447,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
virJSONValuePtr ret = NULL; virJSONValuePtr ret = NULL;
virStorageNetHostDefPtr host; virStorageNetHostDefPtr host;
const char *transport; const char *transport;
char *port = NULL;
size_t i; size_t i;
if (!(servers = virJSONValueNewArray())) if (!(servers = virJSONValueNewArray()))
...@@ -462,10 +463,13 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src, ...@@ -462,10 +463,13 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
else else
transport = "inet"; transport = "inet";
if (virAsprintf(&port, "%u", host->port) < 0)
goto cleanup;
if (virJSONValueObjectCreate(&server, if (virJSONValueObjectCreate(&server,
"s:type", transport, "s:type", transport,
"s:host", host->name, "s:host", host->name,
"s:port", host->port, "s:port", port,
NULL) < 0) NULL) < 0)
goto cleanup; goto cleanup;
break; break;
...@@ -497,6 +501,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src, ...@@ -497,6 +501,7 @@ qemuBlockStorageSourceBuildHostsJSONSocketAddress(virStorageSourcePtr src,
cleanup: cleanup:
virJSONValueFree(servers); virJSONValueFree(servers);
virJSONValueFree(server); virJSONValueFree(server);
VIR_FREE(port);
return ret; return ret;
} }
......
...@@ -809,8 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, ...@@ -809,8 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
goto cleanup; goto cleanup;
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
if (virStringParsePort(src->hosts->port, &uri->port) < 0) uri->port = src->hosts->port;
goto cleanup;
if (VIR_STRDUP(uri->scheme, if (VIR_STRDUP(uri->scheme,
virStorageNetProtocolTypeToString(src->protocol)) < 0) virStorageNetProtocolTypeToString(src->protocol)) < 0)
...@@ -881,8 +880,8 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, ...@@ -881,8 +880,8 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
switch (src->hosts->transport) { switch (src->hosts->transport) {
case VIR_STORAGE_NET_HOST_TRANS_TCP: case VIR_STORAGE_NET_HOST_TRANS_TCP:
virBufferStrcat(&buf, src->hosts->name, ":", virBufferAsprintf(&buf, "%s:%u",
src->hosts->port, NULL); src->hosts->name, src->hosts->port);
break; break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX: case VIR_STORAGE_NET_HOST_TRANS_UNIX:
...@@ -937,7 +936,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, ...@@ -937,7 +936,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
if (virAsprintf(&ret, "sheepdog:%s", src->path) < 0) if (virAsprintf(&ret, "sheepdog:%s", src->path) < 0)
goto cleanup; goto cleanup;
} else if (src->nhosts == 1) { } else if (src->nhosts == 1) {
if (virAsprintf(&ret, "sheepdog:%s:%s:%s", if (virAsprintf(&ret, "sheepdog:%s:%u:%s",
src->hosts->name, src->hosts->port, src->hosts->name, src->hosts->port,
src->path) < 0) src->path) < 0)
goto cleanup; goto cleanup;
...@@ -979,7 +978,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, ...@@ -979,7 +978,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
virBufferAsprintf(&buf, "%s", src->hosts[i].name); virBufferAsprintf(&buf, "%s", src->hosts[i].name);
if (src->hosts[i].port) if (src->hosts[i].port)
virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port); virBufferAsprintf(&buf, "\\:%u", src->hosts[i].port);
} }
} }
......
...@@ -92,8 +92,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, ...@@ -92,8 +92,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri,
if (VIR_STRDUP(def->src->hosts->name, uri->server) < 0) if (VIR_STRDUP(def->src->hosts->name, uri->server) < 0)
goto error; goto error;
if (virAsprintf(&def->src->hosts->port, "%d", uri->port) < 0) def->src->hosts->port = uri->port;
goto error;
} else { } else {
def->src->hosts->name = NULL; def->src->hosts->name = NULL;
def->src->hosts->port = 0; def->src->hosts->port = 0;
...@@ -240,7 +239,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) ...@@ -240,7 +239,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
if (src) if (src)
*src++ = '\0'; *src++ = '\0';
if (VIR_STRDUP(h->port, port) < 0) if (virStringParsePort(port, &h->port) < 0)
goto error; goto error;
} }
...@@ -730,7 +729,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, ...@@ -730,7 +729,7 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
goto error; goto error;
def->src->nhosts = 1; def->src->nhosts = 1;
def->src->hosts->name = def->src->path; def->src->hosts->name = def->src->path;
if (VIR_STRDUP(def->src->hosts->port, port) < 0) if (virStringParsePort(port, &def->src->hosts->port) < 0)
goto error; goto error;
def->src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; def->src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
def->src->hosts->socket = NULL; def->src->hosts->socket = NULL;
...@@ -2005,7 +2004,7 @@ qemuParseCommandLine(virCapsPtr caps, ...@@ -2005,7 +2004,7 @@ qemuParseCommandLine(virCapsPtr caps,
goto error; goto error;
disk->src->nhosts = 1; disk->src->nhosts = 1;
disk->src->hosts->name = disk->src->path; disk->src->hosts->name = disk->src->path;
if (VIR_STRDUP(disk->src->hosts->port, port) < 0) if (virStringParsePort(port, &disk->src->hosts->port) < 0)
goto error; goto error;
if (VIR_STRDUP(disk->src->path, vdi) < 0) if (VIR_STRDUP(disk->src->path, vdi) < 0)
goto error; goto error;
...@@ -2541,12 +2540,12 @@ qemuParseCommandLine(virCapsPtr caps, ...@@ -2541,12 +2540,12 @@ qemuParseCommandLine(virCapsPtr caps,
port = strchr(token, ':'); port = strchr(token, ':');
if (port) { if (port) {
*port++ = '\0'; *port++ = '\0';
if (VIR_STRDUP(port, port) < 0) { if (virStringParsePort(port,
&first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].port) < 0) {
VIR_FREE(hosts); VIR_FREE(hosts);
goto error; goto error;
} }
} }
first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].port = port;
if (VIR_STRDUP(first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].name, if (VIR_STRDUP(first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].name,
token) < 0) { token) < 0) {
VIR_FREE(hosts); VIR_FREE(hosts);
......
...@@ -575,9 +575,8 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src) ...@@ -575,9 +575,8 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
{ {
virStorageFileBackendGlusterPrivPtr priv = src->drv->priv; virStorageFileBackendGlusterPrivPtr priv = src->drv->priv;
VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%s/%s%s)", VIR_DEBUG("deinitializing gluster storage file %p (gluster://%s:%u/%s%s)",
src, src->hosts->name, src->hosts->port ? src->hosts->port : "0", src, src->hosts->name, src->hosts->port, src->volume, src->path);
src->volume, src->path);
if (priv->vol) if (priv->vol)
glfs_fini(priv->vol); glfs_fini(priv->vol);
...@@ -599,15 +598,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv, ...@@ -599,15 +598,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
case VIR_STORAGE_NET_HOST_TRANS_RDMA: case VIR_STORAGE_NET_HOST_TRANS_RDMA:
case VIR_STORAGE_NET_HOST_TRANS_TCP: case VIR_STORAGE_NET_HOST_TRANS_TCP:
hoststr = host->name; hoststr = host->name;
port = host->port;
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;
}
break; break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX: case VIR_STORAGE_NET_HOST_TRANS_UNIX:
...@@ -828,7 +819,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src) ...@@ -828,7 +819,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
priv))) priv)))
return NULL; 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->name,
src->hosts->port, src->hosts->port,
src->volume, src->volume,
......
...@@ -2783,11 +2783,8 @@ virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def, ...@@ -2783,11 +2783,8 @@ virStorageAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name) < 0) if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name) < 0)
goto cleanup; goto cleanup;
if (virAsprintf(&def->src->hosts[0].port, "%d", def->src->hosts[0].port = pooldef->source.hosts[0].port ?
pooldef->source.hosts[0].port ? pooldef->source.hosts[0].port : 3260;
pooldef->source.hosts[0].port :
3260) < 0)
goto cleanup;
/* iscsi volume has name like "unit:0:0:1" */ /* iscsi volume has name like "unit:0:0:1" */
if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0)))
......
...@@ -1689,7 +1689,6 @@ virStorageNetHostDefClear(virStorageNetHostDefPtr def) ...@@ -1689,7 +1689,6 @@ virStorageNetHostDefClear(virStorageNetHostDefPtr def)
return; return;
VIR_FREE(def->name); VIR_FREE(def->name);
VIR_FREE(def->port);
VIR_FREE(def->socket); VIR_FREE(def->socket);
} }
...@@ -1736,13 +1735,11 @@ virStorageNetHostDefCopy(size_t nhosts, ...@@ -1736,13 +1735,11 @@ virStorageNetHostDefCopy(size_t nhosts,
virStorageNetHostDefPtr dst = &ret[i]; virStorageNetHostDefPtr dst = &ret[i];
dst->transport = src->transport; dst->transport = src->transport;
dst->port = src->port;
if (VIR_STRDUP(dst->name, src->name) < 0) if (VIR_STRDUP(dst->name, src->name) < 0)
goto error; goto error;
if (VIR_STRDUP(dst->port, src->port) < 0)
goto error;
if (VIR_STRDUP(dst->socket, src->socket) < 0) if (VIR_STRDUP(dst->socket, src->socket) < 0)
goto error; goto error;
} }
...@@ -2430,10 +2427,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src, ...@@ -2430,10 +2427,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
tmp[0] = '\0'; tmp[0] = '\0';
} }
if (uri->port > 0) { src->hosts->port = uri->port;
if (virAsprintf(&src->hosts->port, "%d", uri->port) < 0)
goto cleanup;
}
if (VIR_STRDUP(src->hosts->name, uri->server) < 0) if (VIR_STRDUP(src->hosts->name, uri->server) < 0)
goto cleanup; goto cleanup;
...@@ -2470,7 +2464,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, ...@@ -2470,7 +2464,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
if (port) { if (port) {
*port = '\0'; *port = '\0';
port += skip; port += skip;
if (VIR_STRDUP(src->hosts[src->nhosts - 1].port, port) < 0) if (virStringParsePort(port, &src->hosts[src->nhosts - 1].port) < 0)
goto error; goto error;
} }
...@@ -2488,7 +2482,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, ...@@ -2488,7 +2482,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
return 0; return 0;
error: error:
VIR_FREE(src->hosts[src->nhosts-1].port);
VIR_FREE(src->hosts[src->nhosts-1].name); VIR_FREE(src->hosts[src->nhosts-1].name);
return -1; return -1;
} }
...@@ -2649,7 +2642,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr, ...@@ -2649,7 +2642,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
goto cleanup; goto cleanup;
} }
if (VIR_STRDUP(src->hosts->port, backing[2]) < 0) if (virStringParsePort(backing[2], &src->hosts->port) < 0)
goto cleanup; goto cleanup;
} }
...@@ -2825,7 +2818,7 @@ virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host, ...@@ -2825,7 +2818,7 @@ virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
if (VIR_STRDUP(host->name, hostname) < 0 || if (VIR_STRDUP(host->name, hostname) < 0 ||
VIR_STRDUP(host->port, port) < 0) virStringParsePort(port, &host->port) < 0)
return -1; return -1;
return 0; return 0;
...@@ -2985,12 +2978,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src, ...@@ -2985,12 +2978,9 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
goto cleanup; goto cleanup;
if ((port = strchr(src->hosts->name, ':'))) { if ((port = strchr(src->hosts->name, ':'))) {
if (VIR_STRDUP(src->hosts->port, port + 1) < 0) if (virStringParsePort(port + 1, &src->hosts->port) < 0)
goto cleanup; goto cleanup;
if (strlen(src->hosts->port) == 0)
VIR_FREE(src->hosts->port);
*port = '\0'; *port = '\0';
} }
...@@ -3050,7 +3040,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src, ...@@ -3050,7 +3040,7 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
if (VIR_STRDUP(src->hosts[0].name, host) < 0) if (VIR_STRDUP(src->hosts[0].name, host) < 0)
return -1; return -1;
if (VIR_STRDUP(src->hosts[0].port, port) < 0) if (virStringParsePort(port, &src->hosts[0].port) < 0)
return -1; return -1;
} }
} }
...@@ -3136,8 +3126,9 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src, ...@@ -3136,8 +3126,9 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
return -1; return -1;
} else { } else {
src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
if (VIR_STRDUP(src->hosts[0].name, host) < 0 || 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; return -1;
} }
...@@ -3341,8 +3332,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path) ...@@ -3341,8 +3332,7 @@ virStorageSourceNewFromBackingAbsolute(const char *path)
if (rc < 0) if (rc < 0)
goto error; goto error;
if (virStorageSourceNetworkAssignDefaultPorts(ret) < 0) virStorageSourceNetworkAssignDefaultPorts(ret);
goto error;
} }
return ret; return ret;
...@@ -3964,66 +3954,61 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top, ...@@ -3964,66 +3954,61 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
} }
static const char * static unsigned int
virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol) virStorageSourceNetworkDefaultPort(virStorageNetProtocol protocol)
{ {
switch (protocol) { switch (protocol) {
case VIR_STORAGE_NET_PROTOCOL_HTTP: case VIR_STORAGE_NET_PROTOCOL_HTTP:
return "80"; return 80;
case VIR_STORAGE_NET_PROTOCOL_HTTPS: case VIR_STORAGE_NET_PROTOCOL_HTTPS:
return "443"; return 443;
case VIR_STORAGE_NET_PROTOCOL_FTP: case VIR_STORAGE_NET_PROTOCOL_FTP:
return "21"; return 21;
case VIR_STORAGE_NET_PROTOCOL_FTPS: case VIR_STORAGE_NET_PROTOCOL_FTPS:
return "990"; return 990;
case VIR_STORAGE_NET_PROTOCOL_TFTP: case VIR_STORAGE_NET_PROTOCOL_TFTP:
return "69"; return 69;
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
return "7000"; return 7000;
case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_NBD:
return "10809"; return 10809;
case VIR_STORAGE_NET_PROTOCOL_SSH: case VIR_STORAGE_NET_PROTOCOL_SSH:
return "22"; return 22;
case VIR_STORAGE_NET_PROTOCOL_ISCSI: case VIR_STORAGE_NET_PROTOCOL_ISCSI:
return "3260"; return 3260;
case VIR_STORAGE_NET_PROTOCOL_GLUSTER: case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
return "24007"; return 24007;
case VIR_STORAGE_NET_PROTOCOL_RBD: case VIR_STORAGE_NET_PROTOCOL_RBD:
/* we don't provide a default for RBD */ /* we don't provide a default for RBD */
return NULL; return 0;
case VIR_STORAGE_NET_PROTOCOL_LAST: case VIR_STORAGE_NET_PROTOCOL_LAST:
case VIR_STORAGE_NET_PROTOCOL_NONE: case VIR_STORAGE_NET_PROTOCOL_NONE:
return NULL; return 0;
} }
return NULL; return 0;
} }
int void
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
{ {
size_t i; size_t i;
for (i = 0; i < src->nhosts; i++) { for (i = 0; i < src->nhosts; i++) {
if (src->hosts[i].transport == VIR_STORAGE_NET_HOST_TRANS_TCP && if (src->hosts[i].transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
src->hosts[i].port == NULL) { src->hosts[i].port == 0)
if (VIR_STRDUP(src->hosts[i].port, src->hosts[i].port = virStorageSourceNetworkDefaultPort(src->protocol);
virStorageSourceNetworkDefaultPort(src->protocol)) < 0)
return -1;
}
} }
return 0;
} }
...@@ -155,7 +155,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostDef; ...@@ -155,7 +155,7 @@ typedef struct _virStorageNetHostDef virStorageNetHostDef;
typedef virStorageNetHostDef *virStorageNetHostDefPtr; typedef virStorageNetHostDef *virStorageNetHostDefPtr;
struct _virStorageNetHostDef { struct _virStorageNetHostDef {
char *name; char *name;
char *port; unsigned int port;
int transport; /* virStorageNetHostTransport */ int transport; /* virStorageNetHostTransport */
char *socket; /* path to unix socket */ char *socket; /* path to unix socket */
}; };
...@@ -406,7 +406,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top, ...@@ -406,7 +406,7 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
unsigned int *index) unsigned int *index)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int void
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src) virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
......
...@@ -1057,7 +1057,7 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src) ...@@ -1057,7 +1057,7 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src)
virBufferAsprintf(&buf, "%s", src->hosts[i].name); virBufferAsprintf(&buf, "%s", src->hosts[i].name);
if (src->hosts[i].port) if (src->hosts[i].port)
virBufferAsprintf(&buf, "\\\\:%s", src->hosts[i].port); virBufferAsprintf(&buf, "\\\\:%u", src->hosts[i].port);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册