[libvirt] [PATCH 0/2] Fix a couple of resource leaks
by John Ferlan
Resource a couple Coverity found resource leaks
John Ferlan (2):
daemon: Don't conditionally free @origErr in daemonStreamEvent
tests: Free @fakerootdir in error path
daemon/stream.c | 2 +-
tests/qemumemlocktest.c | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
--
2.9.4
7 years, 5 months
[libvirt] [PATCH] nodedev: fix an improper comment
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)gmail.com>
Actually we use virConnectNodeDeviceEventGenericCallback.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)gmail.com>
---
include/libvirt/libvirt-nodedev.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-nodedev.h
index cd3f237..25e8724 100644
--- a/include/libvirt/libvirt-nodedev.h
+++ b/include/libvirt/libvirt-nodedev.h
@@ -142,7 +142,7 @@ int virNodeDeviceDestroy (virNodeDevicePtr dev);
*/
typedef enum {
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE = 0, /* virConnectNodeDeviceEventLifecycleCallback */
- VIR_NODE_DEVICE_EVENT_ID_UPDATE = 1, /* virConnectNodeDeviceEventUpdateCallback */
+ VIR_NODE_DEVICE_EVENT_ID_UPDATE = 1, /* virConnectNodeDeviceEventGenericCallback */
# ifdef VIR_ENUM_SENTINELS
VIR_NODE_DEVICE_EVENT_ID_LAST
--
2.7.4
7 years, 5 months
[libvirt] [PATCH] fix 1 << -1 at JOB_MASK macro
by xinhua.Cao
From: caoxinhua <caoxinhua(a)huawei.com>
when we start a vm, we call JOB_MASK(QEMU_JOB_NONE), then 1 << -1 will be execute. we fix it as return 0
---
src/libxl/libxl_domain.h | 2 +-
src/qemu/qemu_domain.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 3a3890b..dc40139 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -30,7 +30,7 @@
# include "libxl_conf.h"
# include "virchrdev.h"
-# define JOB_MASK(job) (1 << (job - 1))
+# define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1))
# define DEFAULT_JOB_MASK \
(JOB_MASK(LIBXL_JOB_DESTROY) | \
JOB_MASK(LIBXL_JOB_ABORT))
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 365b23c..6750215 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -51,7 +51,7 @@
# define QEMU_DOMAIN_MIG_BANDWIDTH_MAX (INT64_MAX / (1024 * 1024))
# endif
-# define JOB_MASK(job) (1 << (job - 1))
+# define JOB_MASK(job) (job == 0 ? 0 : 1 << (job - 1))
# define QEMU_JOB_DEFAULT_MASK \
(JOB_MASK(QEMU_JOB_QUERY) | \
JOB_MASK(QEMU_JOB_DESTROY) | \
--
2.8.3
7 years, 5 months
[libvirt] [PATCH v3 00/16] qemu: migration: show disks stats for nbd migration
by Nikolay Shirokovskiy
diff from v2:
============
1. Fix style issues.
2. Rework patch for fetching job info
(save logic to use temporary variable when drop vm lock)
3. Update disk stats when block jobs are canceled.
4. Adress a few more corner cases.
This patch series add disks stats to domain job info(stats) as
well as to migration completed event in case nbd scheme is used.
There is little nuisance with qcow2 disks (which is the main scenario
I guess) tied to the way qemu reports stats for this type of disks.
For example if we have 64G disk filled only to 1G then stats
start from 63G and will grow up to 64G on completion. The same way disk stats
will be reported by this patch.
I guess the better way to express the situation is to say we have 64G 'total',
and have 'processed' field grow from 0G to 1G, like in case of memory
stats. [1] is the example of completed memory stats of empty guest
domain, which show difference between processed and total.
There can be a workaround like getting initial blockjob offset position
as a zero but is is rather ugly and racy and like uses undocumented
behaviour.
[1] memory migration stats example
Memory processed: 3.307 MiB
Memory remaining: 0.000 B
Memory total: 1.032 GiB
The above is applied to qemu 2.6 at least.
Patches that were explicitly ACKed in previous review
(up to style issues) marked with A.
Nikolay Shirokovskiy (16):
qemu: drop code for VIR_DOMAIN_JOB_BOUNDED and timeRemaining
A qemu: introduce qemu domain job status
A qemu: introduce QEMU_DOMAIN_JOB_STATUS_POSTCOPY
A qemu: drop QEMU_MIGRATION_COMPLETED_UPDATE_STATS
A qemu: drop excessive zero-out in qemuMigrationFetchJobStatus
qemu: refactor fetching migration stats
A qemu: simplify getting completed job stats
qemu: fail querying destination migration statistics always
qemu: start all async job with job status active
qemu: introduce migrating job status
qemu: always get job condition on getting job stats
qemu: migrate: show disks stats on job info requests
qemu: support getting disks stats during stopping block jobs
qemu: migation: resolve race on getting job info and stopping block jobs
qemu: migrate: copy disks stats to completed job
qemu: migration: don't expose incomplete job as complete
src/qemu/qemu_blockjob.c | 1 +
src/qemu/qemu_domain.c | 38 +++++--
src/qemu/qemu_domain.h | 16 ++-
src/qemu/qemu_driver.c | 95 ++++++++--------
src/qemu/qemu_migration.c | 236 ++++++++++++++++++++++++++-------------
src/qemu/qemu_migration.h | 15 ++-
src/qemu/qemu_migration_cookie.c | 7 +-
src/qemu/qemu_monitor.c | 5 +-
src/qemu/qemu_monitor.h | 4 +-
src/qemu/qemu_monitor_json.c | 4 +-
src/qemu/qemu_process.c | 10 +-
tests/qemumonitorjsontest.c | 1 +
12 files changed, 273 insertions(+), 159 deletions(-)
--
1.8.3.1
7 years, 5 months
[libvirt] [PATCH go-xml] Add support for DNS in network
by Thomas Hipp
Add support for DNS in network, and add test code.
Signed-off-by: Thomas Hipp <thipp(a)suse.de>
---
network.go | 39 ++++++++++++++++++++++++++++++++++
network_test.go | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 99 insertions(+), 5 deletions(-)
diff --git a/network.go b/network.go
index cc850a1..e0baa96 100644
--- a/network.go
+++ b/network.go
@@ -84,6 +84,44 @@ type NetworkRoute struct {
Gateway string `xml:"gateway,attr,omitempty"`
}
+type NetworkDNSForwarder struct {
+ Domain string `xml:"domain,attr,omitempty"`
+ Addr string `xml:"addr,attr,omitempty"`
+}
+
+type NetworkDNSTXT struct {
+ Name string `xml:"name,attr"`
+ Value string `xml:"value,attr"`
+}
+
+type NetworkDNSHostHostname struct {
+ Hostname string `xml:",chardata"`
+}
+
+type NetworkDNSHost struct {
+ IP string `xml:"ip,attr"`
+ Hostnames []NetworkDNSHostHostname `xml:"hostname"`
+}
+
+type NetworkDNSSRV struct {
+ Service string `xml:"service,attr"`
+ Protocol string `xml:"protocol,attr"`
+ Target string `xml:"target,attr,omitempty"`
+ Port uint `xml:"port,attr,omitempty"`
+ Priority uint `xml:"priority,attr,omitempty"`
+ Weight uint `xml:"weight,attr,omitempty"`
+ Domain string `xml:"domain,attr,omitempty"`
+}
+
+type NetworkDNS struct {
+ Enable string `xml:"enable,attr,omitempty"`
+ ForwardPlainNames string `xml:"forwardPlainNames,attr,omitempty"`
+ Forwarders []NetworkDNSForwarder `xml:"forwarder"`
+ TXTs []NetworkDNSTXT `xml:"txt"`
+ Host *NetworkDNSHost `xml:"host"`
+ SRVs []NetworkDNSSRV `xml:"srv"`
+}
+
type Network struct {
XMLName xml.Name `xml:"network"`
IPv6 string `xml:"ipv6,attr,omitempty"`
@@ -96,6 +134,7 @@ type Network struct {
Domain *NetworkDomain `xml:"domain"`
IPs []NetworkIP `xml:"ip"`
Routes []NetworkRoute `xml:"route"`
+ DNS *NetworkDNS `xml:"dns"`
}
func (s *Network) Unmarshal(doc string) error {
diff --git a/network_test.go b/network_test.go
index 5269398..2eb81ab 100644
--- a/network_test.go
+++ b/network_test.go
@@ -89,9 +89,9 @@ var networkTestData = []struct {
},
},
NetworkIP{
- Family: "ipv6",
- Address:"2001:db8:ca2:2::1",
- Prefix: "64",
+ Family: "ipv6",
+ Address: "2001:db8:ca2:2::1",
+ Prefix: "64",
DHCP: &NetworkDHCP{
Hosts: []NetworkDHCPHost{
NetworkDHCPHost{
@@ -99,13 +99,57 @@ var networkTestData = []struct {
Name: "paul",
},
NetworkDHCPHost{
- ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
- IP: "2001:db8:ca2:2:3::2",
+ ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
+ IP: "2001:db8:ca2:2:3::2",
},
},
},
},
},
+ DNS: &NetworkDNS{
+ Enable: "yes",
+ ForwardPlainNames: "no",
+ Forwarders: []NetworkDNSForwarder{
+ NetworkDNSForwarder{
+ Addr: "8.8.8.8",
+ },
+ NetworkDNSForwarder{
+ Domain: "example.com",
+ Addr: "8.8.4.4",
+ },
+ NetworkDNSForwarder{
+ Domain: "www.example.com",
+ },
+ },
+ TXTs: []NetworkDNSTXT{
+ NetworkDNSTXT{
+ Name: "example",
+ Value: "example value",
+ },
+ },
+ Host: &NetworkDNSHost{
+ IP: "192.168.122.2",
+ Hostnames: []NetworkDNSHostHostname{
+ NetworkDNSHostHostname{
+ Hostname: "myhost",
+ },
+ NetworkDNSHostHostname{
+ Hostname: "myhostalias",
+ },
+ },
+ },
+ SRVs: []NetworkDNSSRV{
+ NetworkDNSSRV{
+ Service: "name",
+ Protocol: "tcp",
+ Domain: "test-domain-name",
+ Target: ".",
+ Port: 1024,
+ Priority: 10,
+ Weight: 10,
+ },
+ },
+ },
},
Expected: []string{
`<network>`,
@@ -124,6 +168,17 @@ var networkTestData = []struct {
` <host id="0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66" ip="2001:db8:ca2:2:3::2"></host>`,
` </dhcp>`,
` </ip>`,
+ ` <dns enable="yes" forwardPlainNames="no">`,
+ ` <forwarder addr="8.8.8.8"></forwarder>`,
+ ` <forwarder domain="example.com" addr="8.8.4.4"></forwarder>`,
+ ` <forwarder domain="www.example.com"></forwarder>`,
+ ` <txt name="example" value="example value"></txt>`,
+ ` <host ip="192.168.122.2">`,
+ ` <hostname>myhost</hostname>`,
+ ` <hostname>myhostalias</hostname>`,
+ ` </host>`,
+ ` <srv service="name" protocol="tcp" target="." port="1024" priority="10" weight="10" domain="test-domain-name"></srv>`,
+ ` </dns>`,
`</network>`,
},
},
--
2.13.2
7 years, 5 months
[libvirt] [PATCH go-xml] Add support for NAT in network forward
by Thomas Hipp
Add support for NAT in network forward, and add test code.
Signed-off-by: Thomas Hipp <thipp(a)suse.de>
---
network.go | 20 ++++++++++++++++++--
network_test.go | 31 +++++++++++++++++++++++++------
2 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/network.go b/network.go
index cc850a1..3635ad2 100644
--- a/network.go
+++ b/network.go
@@ -41,9 +41,25 @@ type NetworkDomain struct {
LocalOnly string `xml:"localOnly,attr,omitempty"`
}
+type NetworkForwardNATAddress struct {
+ Start string `xml:"start,attr"`
+ End string `xml:"end,attr"`
+}
+
+type NetworkForwardNATPort struct {
+ Start uint `xml:"start,attr"`
+ End uint `xml:"end,attr"`
+}
+
+type NetworkForwardNAT struct {
+ Addresses []NetworkForwardNATAddress `xml:"address"`
+ Ports []NetworkForwardNATPort `xml:"port"`
+}
+
type NetworkForward struct {
- Mode string `xml:"mode,attr,omitempty"`
- Dev string `xml:"dev,attr,omitempty"`
+ Mode string `xml:"mode,attr,omitempty"`
+ Dev string `xml:"dev,attr,omitempty"`
+ NAT *NetworkForwardNAT `xml:"nat"`
}
type NetworkMAC struct {
diff --git a/network_test.go b/network_test.go
index 5269398..65f4d53 100644
--- a/network_test.go
+++ b/network_test.go
@@ -67,6 +67,20 @@ var networkTestData = []struct {
},
Forward: &NetworkForward{
Mode: "nat",
+ NAT: &NetworkForwardNAT{
+ Addresses: []NetworkForwardNATAddress{
+ NetworkForwardNATAddress{
+ Start: "1.2.3.4",
+ End: "1.2.3.10",
+ },
+ },
+ Ports: []NetworkForwardNATPort{
+ NetworkForwardNATPort{
+ Start: 500,
+ End: 1000,
+ },
+ },
+ },
},
IPs: []NetworkIP{
NetworkIP{
@@ -89,9 +103,9 @@ var networkTestData = []struct {
},
},
NetworkIP{
- Family: "ipv6",
- Address:"2001:db8:ca2:2::1",
- Prefix: "64",
+ Family: "ipv6",
+ Address: "2001:db8:ca2:2::1",
+ Prefix: "64",
DHCP: &NetworkDHCP{
Hosts: []NetworkDHCPHost{
NetworkDHCPHost{
@@ -99,8 +113,8 @@ var networkTestData = []struct {
Name: "paul",
},
NetworkDHCPHost{
- ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
- IP: "2001:db8:ca2:2:3::2",
+ ID: "0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66",
+ IP: "2001:db8:ca2:2:3::2",
},
},
},
@@ -111,7 +125,12 @@ var networkTestData = []struct {
`<network>`,
` <name>test</name>`,
` <bridge name="virbr0"></bridge>`,
- ` <forward mode="nat"></forward>`,
+ ` <forward mode="nat">`,
+ ` <nat>`,
+ ` <address start="1.2.3.4" end="1.2.3.10"></address>`,
+ ` <port start="500" end="1000"></port>`,
+ ` </nat>`,
+ ` </forward>`,
` <ip address="192.168.122.1" netmask="255.255.255.0">`,
` <dhcp>`,
` <range start="192.168.122.2" end="192.168.122.254"></range>`,
--
2.13.2
7 years, 5 months
[libvirt] [PATCH RESEND] qemu: shared disks with cache=directsync should be safe for migration
by Peng Hao
From: Hao Peng <peng.hao2(a)zte.com.cn>
At present shared disks can be migrated with either readonly or cache=none. But
cache=directsync should be safe for migration, because both cache=directsync and cache=none
don't use the host page cache, and cache=direct write through qemu block layer cache.
Signed-off-by: Peng Hao <peng.hao2(a)zte.com.cn>
Reviewed-by: Wang Yechao <wang.yechao255(a)zte.com.cn>
---
src/qemu/qemu_migration.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index c23fffe..9d509dd 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1160,11 +1160,12 @@ qemuMigrationIsSafe(virDomainDefPtr def,
const char *src = virDomainDiskGetSource(disk);
/* Our code elsewhere guarantees shared disks are either readonly (in
- * which case cache mode doesn't matter) or used with cache=none */
+ * which case cache mode doesn't matter) or used with cache=none or used with cache=directsync */
if (virStorageSourceIsEmpty(disk->src) ||
disk->src->readonly ||
disk->src->shared ||
- disk->cachemode == VIR_DOMAIN_DISK_CACHE_DISABLE)
+ disk->cachemode == VIR_DOMAIN_DISK_CACHE_DISABLE ||
+ disk->cachemode == VIR_DOMAIN_DISK_CACHE_DIRECTSYNC)
continue;
/* disks which are migrated by qemu are safe too */
@@ -1188,7 +1189,7 @@ qemuMigrationIsSafe(virDomainDefPtr def,
virReportError(VIR_ERR_MIGRATE_UNSAFE, "%s",
_("Migration may lead to data corruption if disks"
- " use cache != none"));
+ " use cache != none or cache != directsync"));
return false;
}
--
1.8.3.1
7 years, 5 months
[libvirt] [PATCH] security: Don't overwrite error of GetProcessLabel
by Cole Robinson
Security impls of this function already raise errors, don't
overwrite them.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/lxc/lxc_driver.c | 6 ++----
src/qemu/qemu_driver.c | 7 +------
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 652e9cba0..088d3d20f 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1348,11 +1348,9 @@ static int lxcDomainGetSecurityLabel(virDomainPtr dom, virSecurityLabelPtr secla
}
if (virSecurityManagerGetProcessLabel(driver->securityManager,
- vm->def, priv->initpid, seclabel) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to get security label"));
+ vm->def, priv->initpid,
+ seclabel) < 0)
goto cleanup;
- }
}
ret = 0;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8d261b725..62d5b8dfe 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6111,11 +6111,8 @@ static int qemuDomainGetSecurityLabel(virDomainPtr dom, virSecurityLabelPtr secl
*/
if (virDomainObjIsActive(vm)) {
if (qemuSecurityGetProcessLabel(driver->securityManager,
- vm->def, vm->pid, seclabel) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to get security label"));
+ vm->def, vm->pid, seclabel) < 0)
goto cleanup;
- }
}
ret = 0;
@@ -6173,8 +6170,6 @@ static int qemuDomainGetSecurityLabelList(virDomainPtr dom,
for (i = 0; i < len; i++) {
if (qemuSecurityGetProcessLabel(mgrs[i], vm->def, vm->pid,
&(*seclabels)[i]) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("Failed to get security label"));
VIR_FREE(mgrs);
VIR_FREE(*seclabels);
goto cleanup;
--
2.13.3
7 years, 5 months
[libvirt] [PATCH 0/2] util: uri: use unsigned numbers for port
by Peter Krempa
Peter Krempa (2):
qemu: command: Remove qemuNetworkDriveGetPort
util: uri: Convert port number to unsigned integer
src/qemu/qemu_command.c | 22 +++++-----------------
src/util/viruri.h | 2 +-
2 files changed, 6 insertions(+), 18 deletions(-)
--
2.13.2
7 years, 5 months
[libvirt] [PATCH] virStorageNetHostDef: Turn @port into integer
by Michal Privoznik
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 <mprivozn(a)redhat.com>
---
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 = -1;
xmlNodePtr child;
char *transport = NULL;
+ char *port = NULL;
virStorageNetHostDef host;
memset(&host, 0, sizeof(host));
@@ -6486,7 +6487,15 @@ virDomainStorageHostParse(xmlNodePtr node,
goto cleanup;
}
- host.port = virXMLPropString(child, "port");
+ port = 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;
+ }
}
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;
}
@@ -7882,8 +7892,8 @@ virDomainDiskSourceParse(xmlNodePtr node,
if (virDomainStorageHostParse(node, &src->hosts, &src->nhosts) < 0)
goto cleanup;
- 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(virDomainHostdevDefPtr first,
&second->source.subsys.u.scsi.u.iscsi;
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))
return 1;
return 0;
@@ -21408,7 +21418,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr buf,
for (n = 0; n < src->nhosts; n++) {
virBufferAddLit(buf, "<host");
virBufferEscapeString(buf, " name='%s'", src->hosts[n].name);
- virBufferEscapeString(buf, " port='%s'", src->hosts[n].port);
+
+ if (src->hosts[n].port)
+ virBufferAsprintf(buf, " port='%d'", src->hosts[n].port);
if (src->hosts[n].transport)
virBufferAsprintf(buf, " transport='%s'",
@@ -22255,7 +22267,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
virBufferAddLit(buf, "<host");
virBufferEscapeString(buf, " name='%s'", iscsisrc->hosts[0].name);
- virBufferEscapeString(buf, " port='%s'", iscsisrc->hosts[0].port);
+ if (iscsisrc->hosts[0].port)
+ virBufferAsprintf(buf, " port='%d'", iscsisrc->hosts[0].port);
virBufferAddLit(buf, "/>\n");
} else {
virBufferAsprintf(buf, "<adapter name='%s'/>\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);
if (src->hosts[i].port)
- virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port);
+ virBufferAsprintf(&buf, "\\:%d", src->hosts[i].port);
}
}
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(virStorageSourcePtr 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)
}
-static int
-qemuNetworkDriveGetPort(const char *port)
-{
- int ret = 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;
if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
- if ((uri->port = qemuNetworkDriveGetPort(src->hosts->port)) < 0)
- goto cleanup;
+ uri->port = src->hosts->port;
if (VIR_STRDUP(uri->scheme,
virStorageNetProtocolTypeToString(src->protocol)) < 0)
@@ -897,8 +880,7 @@ 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:%d", src->hosts->name, src->hosts->port);
break;
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 == 1) {
- if (virAsprintf(&ret, "sheepdog:%s:%s:%s",
+ if (virAsprintf(&ret, "sheepdog:%s:%d:%s",
src->hosts->name,
- src->hosts->port ? src->hosts->port : "7000",
+ 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);
if (src->hosts[i].port)
- virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port);
+ virBufferAsprintf(&buf, "\\:%d", src->hosts[i].port);
}
}
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, virURIPtr 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 = uri->port;
} else {
def->src->hosts->name = NULL;
def->src->hosts->port = 0;
@@ -240,8 +239,13 @@ qemuParseNBDString(virDomainDiskDefPtr disk)
if (src)
*src++ = '\0';
- 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;
+ }
}
if (src && STRPREFIX(src, "exportname=")) {
@@ -730,8 +734,13 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
goto error;
def->src->nhosts = 1;
def->src->hosts->name = def->src->path;
- if (VIR_STRDUP(def->src->hosts->port, port) < 0)
+ if (virStrToLong_i(port, NULL, 10, &def->src->hosts->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 = VIR_STORAGE_NET_HOST_TRANS_TCP;
def->src->hosts->socket = NULL;
if (VIR_STRDUP(def->src->path, vdi) < 0)
@@ -2005,8 +2014,13 @@ qemuParseCommandLine(virCapsPtr caps,
goto error;
disk->src->nhosts = 1;
disk->src->hosts->name = disk->src->path;
- if (VIR_STRDUP(disk->src->hosts->port, port) < 0)
+ if (virStrToLong_i(port, NULL, 10, &disk->src->hosts->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 = strchr(token, ':');
if (port) {
+ int port_i;
*port++ = '\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].port = port_i;
}
- 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,
token) < 0) {
VIR_FREE(hosts);
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_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 = 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:%d/%s%s)",
+ src, src->hosts->name, src->hosts->port, src->volume, src->path);
if (priv->vol)
glfs_fini(priv->vol);
@@ -599,15 +598,7 @@ virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
case VIR_STORAGE_NET_HOST_TRANS_RDMA:
case VIR_STORAGE_NET_HOST_TRANS_TCP:
hoststr = 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 = host->port;
break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
@@ -828,7 +819,7 @@ virStorageFileBackendGlusterGetUniqueIdentifier(virStorageSourcePtr src)
priv)))
return NULL;
- 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;
- 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 = pooldef->source.hosts[0].port ?
+ pooldef->source.hosts[0].port : 3260;
/* iscsi volume has name like "unit:0:0:1" */
if (!(tokens = 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;
+ def->port = 0;
VIR_FREE(def->name);
- VIR_FREE(def->port);
VIR_FREE(def->socket);
}
@@ -1736,13 +1736,11 @@ virStorageNetHostDefCopy(size_t nhosts,
virStorageNetHostDefPtr dst = &ret[i];
dst->transport = src->transport;
+ dst->port = 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 +2428,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
tmp[0] = '\0';
}
- if (uri->port > 0) {
- if (virAsprintf(&src->hosts->port, "%d", uri->port) < 0)
- goto cleanup;
- }
+ if (uri->port > 0)
+ src->hosts->port = uri->port;
if (VIR_STRDUP(src->hosts->name, uri->server) < 0)
goto cleanup;
@@ -2470,8 +2466,14 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
if (port) {
*port = '\0';
port += 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;
+ }
}
parts = virStringSplit(hostport, "\\:", 0);
@@ -2488,7 +2490,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;
}
@@ -2638,7 +2639,7 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0)
goto cleanup;
- } else {
+ } else {
if (VIR_STRDUP(src->hosts->name, backing[1]) < 0)
goto cleanup;
@@ -2649,8 +2650,13 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
goto cleanup;
}
- 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;
+ }
}
if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
@@ -2824,8 +2830,16 @@ virStorageSourceParseBackingJSONInetSocketAddress(virStorageNetHostDefPtr host,
host->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
- 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;
return 0;
@@ -2985,11 +2999,12 @@ virStorageSourceParseBackingJSONiSCSI(virStorageSourcePtr src,
goto cleanup;
if ((port = strchr(src->hosts->name, ':'))) {
- if (VIR_STRDUP(src->hosts->port, port + 1) < 0)
- goto cleanup;
-
- if (strlen(src->hosts->port) == 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);
+ }
*port = '\0';
}
@@ -3050,8 +3065,14 @@ virStorageSourceParseBackingJSONNbd(virStorageSourcePtr src,
if (VIR_STRDUP(src->hosts[0].name, host) < 0)
return -1;
- 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;
+ }
}
}
@@ -3136,8 +3157,17 @@ virStorageSourceParseBackingJSONSSH(virStorageSourcePtr src,
return -1;
} else {
src->hosts[0].transport = 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;
}
@@ -3961,66 +3991,61 @@ virStorageSourceFindByNodeName(virStorageSourcePtr top,
}
-static const char *
+static 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 = 0; i < src->nhosts; i++) {
if (src->hosts[i].transport == VIR_STORAGE_NET_HOST_TRANS_TCP &&
- src->hosts[i].port == NULL) {
- if (VIR_STRDUP(src->hosts[i].port,
- virStorageSourceNetworkDefaultPort(src->protocol)) < 0)
- return -1;
- }
+ src->hosts[i].port == 0)
+ src->hosts[i].port = 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 virStorageNetHostDef;
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);
-int
+void
virStorageSourceNetworkAssignDefaultPorts(virStorageSourcePtr src)
ATTRIBUTE_NONNULL(1);
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);
if (src->hosts[i].port)
- virBufferAsprintf(&buf, "\\\\:%s", src->hosts[i].port);
+ virBufferAsprintf(&buf, "\\\\:%d", src->hosts[i].port);
}
}
--
2.13.0
7 years, 5 months