When qemuMonitorCloseFileHandle is called in error path, we need to
preserve the original error since a possible further error when running
closefd monitor command is not very useful to users.
---
src/qemu/qemu_monitor.c | 34 +++++++++++++++++++++++++---------
src/qemu/qemu_monitor.h | 3 ++-
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e593642..4c6c66f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1552,7 +1552,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
ret = qemuMonitorTextMigrate(mon, flags, "fd:migrate");
if (ret < 0) {
- if (qemuMonitorCloseFileHandle(mon, "migrate") < 0)
+ if (qemuMonitorCloseFileHandle(mon, "migrate", true) < 0)
VIR_WARN("failed to close migration handle");
}
@@ -1962,22 +1962,34 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
- const char *fdname)
+ const char *fdname,
+ bool preserveError)
{
- int ret;
+ int ret = -1;
+ virErrorPtr error = NULL;
+
VIR_DEBUG("mon=%p fdname=%s",
mon, fdname);
+ if (preserveError)
+ error = virSaveLastError();
+
if (!mon) {
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
_("monitor must not be NULL"));
- return -1;
+ goto cleanup;
}
if (mon->json)
ret = qemuMonitorJSONCloseFileHandle(mon, fdname);
else
ret = qemuMonitorTextCloseFileHandle(mon, fdname);
+
+cleanup:
+ if (error) {
+ virSetError(error);
+ virFreeError(error);
+ }
return ret;
}
@@ -2014,9 +2026,11 @@ int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
cleanup:
if (ret < 0) {
- if (tapfd >= 0 && qemuMonitorCloseFileHandle(mon, tapfd_name) < 0)
+ if (tapfd >= 0 &&
+ qemuMonitorCloseFileHandle(mon, tapfd_name, true) < 0)
VIR_WARN("failed to close device handle '%s'",
tapfd_name);
- if (vhostfd >= 0 && qemuMonitorCloseFileHandle(mon, vhostfd_name) <
0)
+ if (vhostfd >= 0 &&
+ qemuMonitorCloseFileHandle(mon, vhostfd_name, true) < 0)
VIR_WARN("failed to close device handle '%s'",
vhostfd_name);
}
@@ -2078,9 +2092,11 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
cleanup:
if (ret < 0) {
- if (tapfd >= 0 && qemuMonitorCloseFileHandle(mon, tapfd_name) < 0)
+ if (tapfd >= 0 &&
+ qemuMonitorCloseFileHandle(mon, tapfd_name, true) < 0)
VIR_WARN("failed to close device handle '%s'",
tapfd_name);
- if (vhostfd >= 0 && qemuMonitorCloseFileHandle(mon, vhostfd_name) <
0)
+ if (vhostfd >= 0 &&
+ qemuMonitorCloseFileHandle(mon, vhostfd_name, true) < 0)
VIR_WARN("failed to close device handle '%s'",
vhostfd_name);
}
@@ -2258,7 +2274,7 @@ int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
ret = qemuMonitorTextAddDevice(mon, devicestr);
if (ret < 0 && fd >= 0) {
- if (qemuMonitorCloseFileHandle(mon, fdname) < 0)
+ if (qemuMonitorCloseFileHandle(mon, fdname, true) < 0)
VIR_WARN("failed to close device handle '%s'", fdname);
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 893f3e9..71ee932 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -363,7 +363,8 @@ int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
int fd);
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
- const char *fdname);
+ const char *fdname,
+ bool preserveError);
/* XXX do we really want to hardcode 'netstr' as the
--
1.7.6