[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[libvirt] [PATCH] Sanitize qemu monitor output
- From: Cole Robinson <crobinso redhat com>
- To: libvir-list redhat com
- Subject: [libvirt] [PATCH] Sanitize qemu monitor output
- Date: Mon, 01 Dec 2008 17:36:34 -0500
The attached patch cleans up output we read from the qemu monitor. This
is a simplified form of a patch I posted awhile ago. From the patch:
/* The monitor doesn't dump clean output after we have written to
* it. Every character we write dumps a bunch of useless stuff,
* so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
* Try to throw away everything before the first full command
* occurence, and inbetween the command and the newline starting
* the response
*/
This extra output makes our qemu log files _huge_ if doing things like
polling disk/net stats, and prevents us from returning any useful error
message printed from the monitor (say for media/disk eject, disk/net
stats, etc).
I've been running with this patch for a while and haven't hit any issues.
Thanks,
Cole
src/qemu_driver.c | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 0130d61..f60ccf4 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -1107,7 +1107,7 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED,
const char *cmd,
char **reply) {
int size = 0;
- char *buf = NULL;
+ char *buf = NULL, *commptr = NULL;
size_t cmdlen = strlen(cmd);
if (safewrite(vm->monitor, cmd, cmdlen) != cmdlen)
@@ -1145,7 +1145,25 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED,
/* Look for QEMU prompt to indicate completion */
if (buf && ((tmp = strstr(buf, "\n(qemu) ")) != NULL)) {
- tmp[0] = '\0';
+ /* Preserve the newline */
+ tmp[1] = '\0';
+
+ /* The monitor doesn't dump clean output after we have written to
+ * it. Every character we write dumps a bunch of useless stuff,
+ * so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
+ * Try to throw away everything before the first full command
+ * occurence, and inbetween the command and the newline starting
+ * the response
+ */
+ if ((commptr = strstr(buf, cmd))) {
+ char *dupptr = strchr(commptr, '\n');
+ if (dupptr) {
+ char *tmpbuf = strdup(dupptr);
+ VIR_FREE(buf);
+ buf = strdup(tmpbuf);
+ }
+ }
+
break;
}
pollagain:
@@ -2596,7 +2614,7 @@ static int qemudDomainChangeEjectableMedia(virDomainPtr dom,
if (qemudMonitorCommand(driver, vm, cmd, &reply) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("cannot change cdrom media"));
+ "%s", _("could not change cdrom media"));
VIR_FREE(cmd);
return -1;
}
@@ -2607,7 +2625,7 @@ static int qemudDomainChangeEjectableMedia(virDomainPtr dom,
DEBUG ("ejectable media change reply: %s", reply);
if (strstr(reply, "\ndevice ")) {
qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("changing cdrom media failed"));
+ _("changing cdrom media failed: %s"), reply);
VIR_FREE(reply);
VIR_FREE(cmd);
return -1;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]