[libvirt] [PATCH] libvirt: virsh: Kill all uses of __FUNCTION__ in error messages
by Noella Ashu
The error output of snapshot-revert should be more friendly. There is no
need to show up virDomainRevertToSnapshot to user. virError already includes
__FUNCTION__ information in a separate member of the struct, so repeating
it in the message is redundant and leads to situations where higher level
code ends up reporting the lower level name We correctly converted the
error output making it more succinct and user-friendly.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1086726
---
src/libvirt-domain-snapshot.c | 30 +++----
src/libvirt-domain.c | 201 ++++++++++++++++++------------------------
2 files changed, 96 insertions(+), 135 deletions(-)
diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c
index 9feb669..ac858ba 100644
--- a/src/libvirt-domain-snapshot.c
+++ b/src/libvirt-domain-snapshot.c
@@ -222,26 +222,20 @@ virDomainSnapshotCreateXML(virDomainPtr domain,
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT) &&
!(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) {
- virReportInvalidArg(flags,
- _("use of 'current' flag in %s requires "
- "'redefine' flag"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("use of 'current' flag in requires 'redefine' flag"));
goto error;
}
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE) &&
(flags & VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA)) {
- virReportInvalidArg(flags,
- _("'redefine' and 'no metadata' flags in %s are "
- "mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("'redefine' and 'no metadata' flags in are mutually exclusive"));
goto error;
}
if ((flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE) &&
(flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) {
- virReportInvalidArg(flags,
- _("'redefine' and 'halt' flags in %s are mutually "
- "exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("'redefine' and 'halt' flags are mutually exclusive"));
goto error;
}
@@ -1084,10 +1078,8 @@ virDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if ((flags & VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING) &&
(flags & VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
- virReportInvalidArg(flags,
- _("running and paused flags in %s are mutually "
- "exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("running and paused flags are mutually exclusive"));
goto error;
}
@@ -1146,10 +1138,8 @@ virDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
if ((flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) &&
(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
- virReportInvalidArg(flags,
- _("children and children_only flags in %s are "
- "mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("children and children_only flags are mutually exclusive"));
goto error;
}
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 4a45b9e..78b7a93 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -385,9 +385,7 @@ virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
virCheckNonNullArgGoto(uuidstr, error);
if (virUUIDParse(uuidstr, uuid) < 0) {
- virReportInvalidArg(uuidstr,
- _("uuidstr in %s must be a valid UUID"),
- __FUNCTION__);
+ virReportInvalidArg(uuidstr, "%s", _("Invalid UUID"));
goto error;
}
@@ -1440,9 +1438,9 @@ virDomainScreenshot(virDomainPtr domain,
virCheckReadOnlyGoto(domain->conn->flags, error);
if (domain->conn != stream->conn) {
- virReportInvalidArg(stream,
- _("stream in %s must match connection of domain '%s'"),
- __FUNCTION__, domain->name);
+ virReportInvalidArg(stream, "%s",
+ _("stream must match connection of domain '%s'"),
+ domain->name);
goto error;
}
@@ -2179,10 +2177,8 @@ virDomainGetMemoryParameters(virDomainPtr domain,
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' are mutually exclusive"));
goto error;
}
conn = domain->conn;
@@ -2423,10 +2419,8 @@ virDomainGetBlkioParameters(virDomainPtr domain,
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' are mutually exclusive"));
goto error;
}
conn = domain->conn;
@@ -3343,9 +3337,8 @@ virDomainMigratePeer2PeerFull(virDomainPtr domain,
if (!(tempuri = virURIParse(dconnuri)))
return -1;
if (!tempuri->server || STRPREFIX(tempuri->server, "localhost")) {
- virReportInvalidArg(dconnuri,
- _("unable to parse server from dconnuri in %s"),
- __FUNCTION__);
+ virReportInvalidArg(dconnuri, "%s",
+ _("unable to parse server from dconnuri"));
virURIFree(tempuri);
return -1;
}
@@ -3580,10 +3573,9 @@ virDomainMigrate(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
- _("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'shared disk' and 'shared incremental'"
+ " are mutually exclusive"));
goto error;
}
@@ -3809,10 +3801,9 @@ virDomainMigrate2(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
+ virReportInvalidArg(flags, "%s",
_("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ "are mutually exclusive"));
goto error;
}
@@ -3989,10 +3980,9 @@ virDomainMigrate3(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
+ virReportInvalidArg(flags, "%s",
_("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ "are mutually exclusive"));
goto error;
}
if (flags & VIR_MIGRATE_PEER2PEER) {
@@ -4212,10 +4202,9 @@ virDomainMigrateToURI(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
+ virReportInvalidArg(flags, "%s",
_("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ "are mutually exclusive"));
goto error;
}
@@ -4372,10 +4361,9 @@ virDomainMigrateToURI2(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
+ virReportInvalidArg(flags, "%s",
_("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ "are mutually exclusive"));
goto error;
}
@@ -4481,10 +4469,9 @@ virDomainMigrateToURI3(virDomainPtr domain,
if (flags & VIR_MIGRATE_NON_SHARED_DISK &&
flags & VIR_MIGRATE_NON_SHARED_INC) {
- virReportInvalidArg(flags,
+ virReportInvalidArg(flags, "%s",
_("flags 'shared disk' and 'shared incremental' "
- "in %s are mutually exclusive"),
- __FUNCTION__);
+ "are mutually exclusive"));
goto error;
}
@@ -4791,9 +4778,8 @@ virDomainMigratePrepareTunnel(virConnectPtr conn,
virCheckReadOnlyGoto(conn->flags, error);
if (conn != st->conn) {
- virReportInvalidArg(conn,
- _("conn in %s must match stream connection"),
- __FUNCTION__);
+ virReportInvalidArg(conn, "%s",
+ _("conn must match stream connection"));
goto error;
}
@@ -4937,9 +4923,8 @@ virDomainMigratePrepareTunnel3(virConnectPtr conn,
virCheckReadOnlyGoto(conn->flags, error);
if (conn != st->conn) {
- virReportInvalidArg(conn,
- _("conn in %s must match stream connection"),
- __FUNCTION__);
+ virReportInvalidArg(conn, "%s",
+ _("conn must match stream connection"));
goto error;
}
@@ -5221,8 +5206,7 @@ virDomainMigratePrepareTunnel3Params(virConnectPtr conn,
if (conn != st->conn) {
virReportInvalidArg(conn,
- _("conn in %s must match stream connection"),
- __FUNCTION__);
+ _("conn must match stream connection"));
goto error;
}
@@ -5529,10 +5513,9 @@ virDomainGetSchedulerParametersFlags(virDomainPtr domain,
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' in "
+ "are mutually exclusive"));
goto error;
}
conn = domain->conn;
@@ -5709,9 +5692,9 @@ virDomainBlockStats(virDomainPtr dom, const char *disk,
virCheckNonNullArgGoto(disk, error);
virCheckNonNullArgGoto(stats, error);
if (size > sizeof(stats2)) {
- virReportInvalidArg(size,
- _("size in %s must not exceed %zu"),
- __FUNCTION__, sizeof(stats2));
+ virReportInvalidArg(size, "%s",
+ _("size must not exceed %zu"),
+ sizeof(stats2));
goto error;
}
conn = dom->conn;
@@ -5850,9 +5833,9 @@ virDomainInterfaceStats(virDomainPtr dom, const char *path,
virCheckNonNullArgGoto(path, error);
virCheckNonNullArgGoto(stats, error);
if (size > sizeof(stats2)) {
- virReportInvalidArg(size,
- _("size in %s must not exceed %zu"),
- __FUNCTION__, sizeof(stats2));
+ virReportInvalidArg(size, "%s",
+ _("size must not exceed %zu"),
+ sizeof(stats2));
goto error;
}
@@ -6297,10 +6280,9 @@ virDomainMemoryPeek(virDomainPtr dom,
/* Exactly one of these two flags must be set. */
if (!(flags & VIR_MEMORY_VIRTUAL) == !(flags & VIR_MEMORY_PHYSICAL)) {
- virReportInvalidArg(flags,
- _("flags in %s must include VIR_MEMORY_VIRTUAL or "
- "VIR_MEMORY_PHYSICAL"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags must include VIR_MEMORY_VIRTUAL or "
+ "VIR_MEMORY_PHYSICAL"));
goto error;
}
@@ -7144,9 +7126,9 @@ virDomainSendKey(virDomainPtr domain,
virCheckPositiveArgGoto(nkeycodes, error);
if (nkeycodes > VIR_DOMAIN_SEND_KEY_MAX_KEYS) {
- virReportInvalidArg(nkeycodes,
- _("nkeycodes in %s must be <= %d"),
- __FUNCTION__, VIR_DOMAIN_SEND_KEY_MAX_KEYS);
+ virReportInvalidArg(nkeycodes, "%s",
+ _("nkeycodes must be <= %d"),
+ VIR_DOMAIN_SEND_KEY_MAX_KEYS);
goto error;
}
@@ -7344,8 +7326,8 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
flags & VIR_DOMAIN_VCPU_MAXIMUM) {
virReportInvalidArg(flags,
_("flags 'VIR_DOMAIN_VCPU_MAXIMUM' and "
- "'VIR_DOMAIN_VCPU_GUEST' in '%s' are mutually "
- "exclusive"), __FUNCTION__);
+ "'VIR_DOMAIN_VCPU_GUEST' in are mutually "
+ "exclusive"));
goto error;
}
@@ -7419,10 +7401,9 @@ virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
@@ -7626,9 +7607,8 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int ncpumaps,
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
@@ -7756,9 +7736,8 @@ virDomainGetEmulatorPinInfo(virDomainPtr domain, unsigned char *cpumap,
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
conn = domain->conn;
@@ -7925,10 +7904,9 @@ virDomainGetIOThreadInfo(virDomainPtr dom,
/* At most one of these two flags should be set. */
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
@@ -8181,10 +8159,9 @@ virDomainSetMetadata(virDomainPtr domain,
switch (type) {
case VIR_DOMAIN_METADATA_TITLE:
if (metadata && strchr(metadata, '\n')) {
- virReportInvalidArg(metadata,
- _("metadata title in %s can't contain "
- "newlines"),
- __FUNCTION__);
+ virReportInvalidArg(metadata, "%s",
+ _("metadata title can't contain "
+ "newlines"));
goto error;
}
/* fallthrough */
@@ -8259,10 +8236,9 @@ virDomainGetMetadata(virDomainPtr domain,
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
- virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
@@ -9199,18 +9175,18 @@ virConnectDomainEventRegisterAny(virConnectPtr conn,
if (dom) {
virCheckDomainGoto(dom, error);
if (dom->conn != conn) {
- virReportInvalidArg(dom,
- _("domain '%s' in %s must match connection"),
- dom->name, __FUNCTION__);
+ virReportInvalidArg(dom, "%s",
+ _("domain '%s' must match connection"),
+ dom->name);
goto error;
}
}
virCheckNonNullArgGoto(cb, error);
virCheckNonNegativeArgGoto(eventID, error);
if (eventID >= VIR_DOMAIN_EVENT_ID_LAST) {
- virReportInvalidArg(eventID,
- _("eventID in %s must be less than %d"),
- __FUNCTION__, VIR_DOMAIN_EVENT_ID_LAST);
+ virReportInvalidArg(eventID, "%s",
+ _("eventID must be less than %d"),
+ VIR_DOMAIN_EVENT_ID_LAST);
goto error;
}
@@ -9311,9 +9287,8 @@ virDomainManagedSave(virDomainPtr dom, unsigned int flags)
if ((flags & VIR_DOMAIN_SAVE_RUNNING) && (flags & VIR_DOMAIN_SAVE_PAUSED)) {
virReportInvalidArg(flags,
- _("running and paused flags in %s are mutually "
- "exclusive"),
- __FUNCTION__);
+ _("running and paused flags are mutually "
+ "exclusive"));
goto error;
}
@@ -9466,9 +9441,9 @@ virDomainOpenConsole(virDomainPtr dom,
virCheckReadOnlyGoto(conn->flags, error);
if (conn != st->conn) {
- virReportInvalidArg(st,
- _("stream in %s must match connection of domain '%s'"),
- __FUNCTION__, dom->name);
+ virReportInvalidArg(st, "%s",
+ _("stream must match connection of domain '%s'"),
+ dom->name);
goto error;
}
@@ -9531,8 +9506,8 @@ virDomainOpenChannel(virDomainPtr dom,
if (conn != st->conn) {
virReportInvalidArg(st,
- _("stream in %s must match connection of domain '%s'"),
- __FUNCTION__, dom->name);
+ _("stream must match connection of domain '%s'"),
+ dom->name);
goto error;
}
@@ -9955,9 +9930,8 @@ virDomainBlockRebase(virDomainPtr dom, const char *disk,
VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT |
VIR_DOMAIN_BLOCK_REBASE_COPY_RAW |
VIR_DOMAIN_BLOCK_REBASE_COPY_DEV)) {
- virReportInvalidArg(flags,
- _("use of flags in %s requires a copy job"),
- __FUNCTION__);
+ virReportInvalidArg(flags, "%s",
+ _("use of flags requires a copy job"));
goto error;
}
@@ -10276,9 +10250,9 @@ virDomainOpenGraphics(virDomainPtr dom,
}
if (!S_ISSOCK(sb.st_mode)) {
- virReportInvalidArg(fd,
- _("fd %d in %s must be a socket"),
- fd, __FUNCTION__);
+ virReportInvalidArg(fd, "%s",
+ _("fd %d must be a socket"),
+ fd);
goto error;
}
@@ -10490,9 +10464,8 @@ virDomainGetBlockIoTune(virDomainPtr dom,
if ((flags & VIR_DOMAIN_AFFECT_LIVE) &&
(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
virReportInvalidArg(flags,
- _("flags 'affect live' and 'affect config' in %s "
- "are mutually exclusive"),
- __FUNCTION__);
+ _("flags 'affect live' and 'affect config' "
+ "are mutually exclusive"));
goto error;
}
conn = dom->conn;
@@ -10615,8 +10588,7 @@ virDomainGetCPUStats(virDomainPtr domain,
if (start_cpu == -1) {
if (ncpus != 1) {
virReportInvalidArg(start_cpu,
- _("ncpus in %s must be 1 when start_cpu is -1"),
- __FUNCTION__);
+ _("ncpus must be 1 when start_cpu is -1"));
goto error;
}
} else {
@@ -11284,9 +11256,8 @@ virDomainListGetStats(virDomainPtr *doms,
virCheckNonNullArgGoto(retStats, cleanup);
if (!*doms) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("doms array must contain at least one domain in %s"),
- __FUNCTION__);
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("doms array must contain at least one domain"));
goto cleanup;
}
@@ -11304,9 +11275,9 @@ virDomainListGetStats(virDomainPtr *doms,
virCheckDomainGoto(dom, cleanup);
if (dom->conn != conn) {
- virReportError(VIR_ERR_INVALID_ARG,
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
_("domains in 'doms' array must belong to a "
- "single connection in %s"), __FUNCTION__);
+ "single connection"));
goto cleanup;
}
--
2.1.0
9 years, 8 months
[libvirt] [PATCH] virsh: fix domifaddr no output in quiet mode
by Luyao Huang
All of print function use vshPrintExtra in cmdDomIfAddr, this will
make domifaddr no output in quiet mode, after this patch, quiet mode
output will be:
# virsh -q domifaddr test3 --source agent
lo 00:00:00:00:00:00 ipv4 127.0.0.1/8
- - ipv6 ::1/128
ens8 52:54:00:1a:cb:3f ipv6 fe80::5054:ff:fe1a:cb3f/64
virbr0 52:54:00:db:51:e7 ipv4 192.168.122.1/24
virbr0-nic 52:54:00:db:51:e7 N/A N/A
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
tools/virsh-domain-monitor.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 6951db2..9686531 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2278,9 +2278,9 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
/* When the interface has no IP address */
if (!iface->naddrs) {
- vshPrintExtra(ctl, " %-10s %-17s %-12s %s\n",
- iface->name,
- iface->hwaddr ? iface->hwaddr : "N/A", "N/A", "N/A");
+ vshPrint(ctl, " %-10s %-17s %-12s %s\n",
+ iface->name,
+ iface->hwaddr ? iface->hwaddr : "N/A", "N/A", "N/A");
continue;
}
@@ -2313,12 +2313,12 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
/* Don't repeat interface name */
if (full || !j)
- vshPrintExtra(ctl, " %-10s %-17s %s\n",
- iface->name,
- iface->hwaddr ? iface->hwaddr : "", ip_addr_str);
+ vshPrint(ctl, " %-10s %-17s %s\n",
+ iface->name,
+ iface->hwaddr ? iface->hwaddr : "", ip_addr_str);
else
- vshPrintExtra(ctl, " %-10s %-17s %s\n",
- "-", "-", ip_addr_str);
+ vshPrint(ctl, " %-10s %-17s %s\n",
+ "-", "-", ip_addr_str);
virBufferFreeAndReset(&buf);
VIR_FREE(ip_addr_str);
--
1.8.3.1
9 years, 8 months
[libvirt] [PATCH 0/2] esx: Make esxNodeGetFreeMemory always use ESX host.
by Dawid Zamirski
This patch is intended to make ESX driver behave more consistently.
When calling virNodeGetFreeMemory, it would return the free bytes
from a cluster when using vpx connection or ESX host when using esx
connection. However, virGetNodeInfo always returns info from ESX
host (specifying ESX host is mandatory, even for vpx connections)
so to make this consitent, these patches make virNodeGetFreeMemory
always return info from the ESX host.
Dawid Zamirski (2):
esx: add esxVI_GetInt
esx: esxNodeGetFreeMemory return info from host.
src/esx/esx_driver.c | 53 ++++++++++++++++++--------------------------------
src/esx/esx_vi.c | 32 ++++++++++++++++++++++++++++++
src/esx/esx_vi.h | 3 +++
src/esx/esx_vi_types.c | 3 +++
src/esx/esx_vi_types.h | 1 +
5 files changed, 58 insertions(+), 34 deletions(-)
--
2.1.0
9 years, 8 months
[libvirt] qemu: migration: continuously sending and receiving ARP packets guest mistakenly thinks there's another guest with the same IP.
by zhang bo
Problem Description:
Live-migrate a guest, which has a tap device and continuously sends and receives ARP packets, it would mistakenly think there's another guest with the same IP, immedially after migration.
The steps to reproduce the problem:
1 define and start a domain with its network configured as:
<interface type='bridge'>
<mac address='52:54:00:7d:b0:af'/>
<source bridge='br0'/>
<virtualport type='openvswitch'>
<parameters interfaceid='e4ad3dbb-7808-4175-83ee-ee0cba1c5456'/>
</virtualport>
<model type='virtio'/>
<driver name='vhost' queues='4'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
2 The guest sends ARP packets continuously: arping -I ethX xx.xx.xx.xx(self_ip)
3 Meanwhile, the guest also receives ARP packets continuously: tcpdump -i ethX arp host xx.xx.xx.xx(self_ip) -entttt
4 After migrateion, at the dest side, the guest gets a lot of ARP packets which came from the source-side guest(which was stored while it's suspended.).
For example:
2015-03-27 16:45:56.695166 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695197 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695205 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695214 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695244 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695256 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695264 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695291 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695324 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695337 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695344 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
2015-03-27 16:45:56.695364 52:54:00:7d:b0:af > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 60: arp who-has 9.61.108.208 (ff:ff:ff:ff:ff:ff) tell 9.61.108.208
5 These packets will confuse my process. It may think that there is another VM has the same IP with itself.
Reasons for the problem:
The tap device will get up as soon as it's created(in virNetDevTapCreateInBridgePort), before the cpus got un-paused.
So, it kept receiving data before the guest starts to run, please note that the data are sent from the source side.
As soon as the guest get running, it parses the data stored before, and thinks they were from other guest with the same IP, which is in fact the guest from the source side.
There was a patch "network: Bring netdevs online later", it move the virNetDevSetOnline() of network device
just before start VM's vcpu. But in the Laine Stump replay mail say "It turns out, though, that regular tap
devices which will be connected to a bridge should be ifup'ed and attached to the bridge as soon as possible,
so that the forwarding delay timer of the bridge can start to count down."
I agree with Laine Stump's idea that it's not a perfect solution to start the tap device right before running vcpu.
so, here comes the question:
what can we do to insure our guests not receive itself's ARP packets from src side during migrateion?
9 years, 8 months
[libvirt] [PATCH] conf: Change virStoragePoolSaveConfig prototype s/configDir/configFile
by Erik Skultety
Just a minor change which might be a little confusing for someone
looking only at the API.
---
Pushed as trivial.
src/conf/storage_conf.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index edcdaed..da378b7 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -373,7 +373,7 @@ virStoragePoolObjAssignDef(virStoragePoolObjListPtr pools,
int virStoragePoolSaveState(const char *stateFile,
virStoragePoolDefPtr def);
-int virStoragePoolSaveConfig(const char *configDir,
+int virStoragePoolSaveConfig(const char *configFile,
virStoragePoolDefPtr def);
int virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
virStoragePoolObjPtr pool,
--
1.9.3
9 years, 8 months
[libvirt] [PATCH V3] libxl: fix dom0 balloon logic
by Jim Fehlig
Recent testing on large memory systems revealed a bug in the Xen xl
tool's freemem() function. When autoballooning is enabled, freemem()
is used to ensure enough memory is available to start a domain,
ballooning dom0 if necessary. When ballooning large amounts of memory
from dom0, freemem() would exceed its self-imposed wait time and
return an error. Meanwhile, dom0 continued to balloon. Starting the
domain later, after sufficient memory was ballooned from dom0, would
succeed. The libvirt implementation in libxlDomainFreeMem() suffers
the same bug since it is modeled after freemem().
In the end, the best place to fix the bug on the Xen side was to
slightly change the behavior of libxl_wait_for_memory_target().
Instead of failing after caller-provided wait_sec, the function now
blocks as long as dom0 memory ballooning is progressing. It will return
failure only when more memory is needed to reach the target and wait_sec
have expired with no progress being made. See xen.git commit fd3aa246.
There was a dicussion on how this would affect other libxl apps like
libvirt
http://lists.xen.org/archives/html/xen-devel/2015-03/msg00739.html
If libvirt containing this patch was build against a Xen containing
the old libxl_wait_for_memory_target() behavior, libxlDomainFreeMem()
will fail after 30 sec and domain creation will be terminated.
Without this patch and with old libxl_wait_for_memory_target() behavior,
libxlDomainFreeMem() does not succeed after 30 sec, but returns success
anyway. Domain creation continues resulting in all sorts of fun stuff
like cpu soft lockups in the guest OS. It was decided to properly fix
libxl_wait_for_memory_target(), and if anything improve the default
behavior of apps using the freemem reference impl in xl.
xl was patched to accommodate the change in libxl_wait_for_memory_target()
with xen.git commit 883b30a0. This patch does the same in the libxl
driver. While at it, I changed the logic to essentially match
freemem() in $xensrc/tools/libxl/xl_cmdimpl.c. It was a bit cleaner
IMO and will make it easier to spot future, potentially interesting
divergences.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
V3:
Remove unneeded local variable 'ret' in libxlDomainFreeMem.
src/libxl/libxl_domain.c | 49 ++++++++++++++++++++----------------------------
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index ce9e4d8..37b2b58 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -811,38 +811,33 @@ libxlDomainFreeMem(libxl_ctx *ctx, libxl_domain_config *d_config)
{
uint32_t needed_mem;
uint32_t free_mem;
- size_t i;
- int ret = -1;
int tries = 3;
int wait_secs = 10;
- if ((ret = libxl_domain_need_memory(ctx, &d_config->b_info,
- &needed_mem)) >= 0) {
- for (i = 0; i < tries; ++i) {
- if ((ret = libxl_get_free_memory(ctx, &free_mem)) < 0)
- break;
+ if (libxl_domain_need_memory(ctx, &d_config->b_info, &needed_mem) < 0)
+ goto error;
- if (free_mem >= needed_mem) {
- ret = 0;
- break;
- }
+ do {
+ if (libxl_get_free_memory(ctx, &free_mem) < 0)
+ goto error;
- if ((ret = libxl_set_memory_target(ctx, 0,
- free_mem - needed_mem,
- /* relative */ 1, 0)) < 0)
- break;
+ if (free_mem >= needed_mem)
+ return 0;
- ret = libxl_wait_for_free_memory(ctx, 0, needed_mem,
- wait_secs);
- if (ret == 0 || ret != ERROR_NOMEM)
- break;
+ if (libxl_set_memory_target(ctx, 0, free_mem - needed_mem,
+ /* relative */ 1, 0) < 0)
+ goto error;
- if ((ret = libxl_wait_for_memory_target(ctx, 0, 1)) < 0)
- break;
- }
- }
+ if (libxl_wait_for_memory_target(ctx, 0, wait_secs) < 0)
+ goto error;
- return ret;
+ tries--;
+ } while (tries > 0);
+
+ error:
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Failed to balloon domain0 memory"));
+ return -1;
}
static void
@@ -958,12 +953,8 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
cfg->ctx, &d_config) < 0)
goto endjob;
- if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("libxenlight failed to get free memory for domain '%s'"),
- d_config.c_info.name);
+ if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0)
goto endjob;
- }
if (virHostdevPrepareDomainDevices(hostdev_mgr, LIBXL_DRIVER_NAME,
vm->def, VIR_HOSTDEV_SP_PCI) < 0)
--
1.8.4.5
9 years, 8 months
[libvirt] [PATCH] virNetSocketNewConnectUNIX: Use flocks when spawning a daemon
by Michal Privoznik
https://bugzilla.redhat.com/show_bug.cgi?id=1200149
Even though we have a mutex mechanism so that two clients don't spawn
two daemons, it's not strong enough. It can happen that while one
client is spawning the daemon, the other one fails to connect.
Basically two possible errors can happen:
error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': Connection refused
or:
error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': No such file or directory
The problem in both cases is, the daemon is only starting up, while we
are trying to connect (and fail). We should postpone the connecting
phase until the daemon is started (by the other thread that is
spawning it). In order to do that, create a file lock 'libvirt-lock'
in the directory where session daemon would create its socket. So even
when called from multiple processes, spawning a daemon will serialize
on the file lock. So only the first to come will spawn the daemon.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/rpc/virnetsocket.c | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 6b019cc..8d8b6e0 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -545,8 +545,10 @@ int virNetSocketNewConnectUNIX(const char *path,
{
char *binname = NULL;
char *pidpath = NULL;
+ char *lockpath = NULL;
int fd, passfd = -1;
int pidfd = -1;
+ int lockfd = -1;
virSocketAddr localAddr;
virSocketAddr remoteAddr;
@@ -561,6 +563,22 @@ int virNetSocketNewConnectUNIX(const char *path,
return -1;
}
+ if (spawnDaemon) {
+ if (virPidFileConstructPath(false, NULL, "libvirt-lock", &lockpath) < 0)
+ goto error;
+
+ if ((lockfd = open(lockpath, O_RDWR | O_CREAT, 0600)) < 0 ||
+ virSetCloseExec(lockfd) < 0) {
+ virReportSystemError(errno, _("Unable to create lock '%s'"), lockpath);
+ goto error;
+ }
+
+ if (virFileLock(lockfd, false, 0, 1, true) < 0) {
+ virReportSystemError(errno, _("Unable to lock '%s'"), lockpath);
+ goto error;
+ }
+ }
+
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
virReportSystemError(errno, "%s", _("Failed to create socket"));
goto error;
@@ -595,17 +613,8 @@ int virNetSocketNewConnectUNIX(const char *path,
if (virPidFileConstructPath(false, NULL, binname, &pidpath) < 0)
goto error;
- pidfd = virPidFileAcquirePath(pidpath, false, getpid());
- if (pidfd < 0) {
- /*
- * This can happen in a very rare case of two clients spawning two
- * daemons at the same time, and the error in the logs that gets
- * reset here can be a clue to some future debugging.
- */
- virResetLastError();
- spawnDaemon = false;
- goto retry;
- }
+ if ((pidfd = virPidFileAcquirePath(pidpath, false, getpid())) < 0)
+ goto error;
if ((passfd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
virReportSystemError(errno, "%s", _("Failed to create socket"));
@@ -668,16 +677,17 @@ int virNetSocketNewConnectUNIX(const char *path,
goto error;
}
- /*
- * Do we need to eliminate the super-rare race here any more? It would
- * need incorporating the following VIR_FORCE_CLOSE() into a
- * virCommandHook inside a virNetSocketForkDaemon().
- */
VIR_FORCE_CLOSE(pidfd);
if (virNetSocketForkDaemon(binary, passfd) < 0)
goto error;
}
+ if (lockfd) {
+ unlink(lockpath);
+ VIR_FORCE_CLOSE(lockfd);
+ VIR_FREE(lockpath);
+ }
+
localAddr.len = sizeof(localAddr.data);
if (getsockname(fd, &localAddr.data.sa, &localAddr.len) < 0) {
virReportSystemError(errno, "%s", _("Unable to get local socket name"));
@@ -694,10 +704,14 @@ int virNetSocketNewConnectUNIX(const char *path,
error:
if (pidfd >= 0)
virPidFileDeletePath(pidpath);
+ if (lockfd)
+ unlink(lockpath);
VIR_FREE(pidpath);
+ VIR_FREE(lockpath);
VIR_FORCE_CLOSE(fd);
VIR_FORCE_CLOSE(passfd);
VIR_FORCE_CLOSE(pidfd);
+ VIR_FORCE_CLOSE(lockfd);
if (spawnDaemon)
unlink(path);
return -1;
--
2.0.5
9 years, 8 months
Re: [libvirt] [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model
by Eduardo Habkost
(CCing libvir-list and Jiri Denemark for libvirt-related discussion
about -cpu host/none, and live-migration safety expectations)
On Wed, Apr 01, 2015 at 06:31:23PM +0200, Michael Mueller wrote:
> On Wed, 1 Apr 2015 10:01:13 -0300
> Eduardo Habkost <ehabkost(a)redhat.com> wrote:
>
> > On Tue, Mar 31, 2015 at 10:09:09PM +0200, Michael Mueller wrote:
> > > On Tue, 31 Mar 2015 15:35:26 -0300
> > > Eduardo Habkost <ehabkost(a)redhat.com> wrote:
> > >
> > > > On Mon, Mar 30, 2015 at 04:28:24PM +0200, Michael Mueller wrote:
> > > > > This patch implements a new QMP request named 'query-cpu-model'.
> > > > > It returns the cpu model of cpu 0 and its backing accelerator.
> > > > >
> > > > > request:
> > > > > {"execute" : "query-cpu-model" }
> > > > >
> > > > > answer:
> > > > > {"return" : {"name": "2827-ga2", "accel": "kvm" }}
> > > > >
> > > > > Alias names are resolved to their respective machine type and GA names
> > > > > already during cpu instantiation. Thus, also a cpu model like 'host'
> > > > > which is implemented as alias will return its normalized cpu model name.
> > > > >
> > > > > Furthermore the patch implements the following function:
> > > > >
> > > > > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > > > >
> > > > > Signed-off-by: Michael Mueller <mimu(a)linux.vnet.ibm.com>
> > > > > ---
> > > > [...]
> > > > > +static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > > > > +{
> > > > > + return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > > > > +}
> > > >
> > > > How exactly is this information going to be used by clients? If getting
> > > > the correct type and ga values is important for them, maybe you could
> > > > add them as integer fields, instead of requiring clients to parse the
> > > > CPU model name?
> > >
> > > The consumer don't need to parse the name, it is just important for them to have
> > > distinctive names that correlate with the names returned by query-cpu-definitions.
> > > Once the name of an active guest is known, e.g. ("2827-ga2", "kvm") a potential
> > > migration target can be verified, i.e. its query-cpu-definitions answer for "kvm"
> > > has to contain "2827-ga2" with the attribute runnable set to true. With that mechanism
> > > also the largest common denominator can be calculated. That model will be used then.
> >
> > Understood. So the point is to really have a name that can be found at
> > query-cpu-definitions. Makes sense.
> >
> > (BTW, if you reused strdup_s390_cpu_name() inside
> > s390_cpu_compare_class_name() too, you would automatically ensure that
> > query-cpus, query-cpu-definitions and s390_cpu_class_by_name() will
> > always agree with each other).
>
> I have to verify but it seems to make sense from reading... I will do that if it works. :-)
>
> >
> > >
> > > I also changed the above mentioned routine to map the cpu model none case:
> > >
> > > static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > > {
> > > if (cpuid(cc->proc)) {
> > > return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > > } else {
> > > return g_strdup("none");
> > > }
> > > }
> >
> > What about:
> >
> > static const char *s390_cpu_name(S390CPUClass *cc)
> > {
> > return cc->model_name;
> > }
> >
> > And then you can just set cc->model_name=_name inside S390_PROC_DEF (and
> > set it to "none" inside s390_cpu_class_init()).
> >
>
> Wouldn't that store redundant information... but it would at least shift the work into the
> initialization phase and do the format just once per model.
To be honest, calculating the CPU model name on the fly with
strdup_s390_cpu_name() like you did above wouldn't be a problem to me.
I just wanted to avoid having the same CPU model name logic (and special
cases like "none") duplicated inside strdup_s390_cpu_name(),
S390_PROC_DEF, s390_cpu_class_by_name(), and maybe other places. Maybe
this duplication can be eliminated by simply reusing
strdup_s390_cpu_name() inside s390_cpu_compare_class_name().
>
> > I wonder if this class->model_name conversion could be made generic
> > inside the CPU class. We already have a CPU::class_by_name() method, so
> > it makes sense to have the opposite function too.
> >
> > (But I wouldn't mind making this s390-specific first, and converted
> > later to generic code if appropriate).
>
> ok
>
> >
> > >
> > > This implicitly will fail a comparison for cpu model ("none", "kvm") as that will
> > > never be part of the query-cpu-definitions answer.
> >
> > I am not sure I follow. If ("none", "kvm") is never in the list, is
> > "-cpu none -machine accel=kvm" always an invalid use case?
>
> Not directly invalid as "-cpu none" will be the same as omitting the -cpu option.
> KVM will setup the vcpu properties withou any QEMU control to whatever the hosting
> machine and the kvm kernel code offers. That will allow to run QEMU against a KVM
> version that is not aware of the s390 cpu model ioctls.
It looks like we have conflicting expectations about
query-cpu-definitions, it seems: on the one hand, if "-cpu none" is
valid I believe it should appear on the query-cpu-definitions return
value; on the other hand, it is not (always?) migration-safe, so just
comparing the source query-cpus data with the target
query-cpu-definitions data wouldn't be enough to ensure live-migration
safety.
On x86, we have a similar problem with "-cpu host", that changes
depending on the host hardware and host kernel. We solve this problem by
making libvirt code aware of the set of valid CPU models, and libvirt
has special cases for "-cpu host".
If you don't want to encode that knowledge in libvirt or other
management software for s390, it looks like you need something like a
"stable-abi-safe" field on CpuDefinitionInfo?
>
> >
> > (I don't understand completely the meaning of "-cpu none" yet. How does
> > the CPU look like for the guest in this case? Is it possible to
> > live-migrate when using -cpu none?)
>
> And yes, that does not make sense in a migration context. The answer on query-cpu-model
> (or query-cpus) will be ("none", "kvm") and that will never match a runnable model.
> The guest cpu will be derived from the hosting system and the kvm kernel as it is currently
> without the cpu model interface.
>
> I hope I made it better to understand now...
Yes, thanks!
--
Eduardo
9 years, 8 months