qemu: Ignore libvirt logs when reading QEMU error output

When QEMU fails to start, libvirt read its error output and reports it
back in an error message. However, when libvirtd is configured to log
debug messages, one would get the following unhelpful garbage:

    virsh # start cd
    error: Failed to start domain cd
    error: internal error process exited while connecting to monitor: \
      2013-04-22 14:24:54.214+0000: 2194219: debug : virFileClose:72 : \
      Closed fd 21
    2013-04-22 14:24:54.214+0000: 2194219: debug : virFileClose:72 : \
      Closed fd 27
    2013-04-22 14:24:54.215+0000: 2194219: debug : virFileClose:72 : \
      Closed fd 3
    2013-04-22 14:24:54.215+0000: 2194220: debug : virExec:602 : Run \
      hook 0x7feb8f600bf0 0x7feb86ef9300
    2013-04-22 14:24:54.215+0000: 2194220: debug : qemuProcessHook:2507 \
      : Obtaining domain lock
    2013-04-22 14:24:54.216+0000: 2194220: debug : \
      virDomainLockProcessStart:170 : plugin=0x7feb780261f0 \
      dom=0x7feb7802a360 paused=1 fd=0x7feb86ef8ec4
    2013-04-22 14:24:54.216+0000: 2194220: debug : \
      virDomainLockManagerNew:128 : plugin=0x7feb780261f0 \
      dom=0x7feb7802a360 withResources=1
    2013-04-22 14:24:54.216+0000: 2194220: debug : \
      virLockManagerPluginGetDriver:297 : plugin=0x7feb780261f0
    2013-04-22 14:24:54.216+0000: 2194220: debug : \
      virLockManagerNew:321 : driver=0x7feb8ef08640 type=0 nparams=5 \
      params=0x7feb86ef8d60 flags=0
    2013-04-22 14:24:54.216+000

instead of (the output with this patch applied):

    virsh # start cd
    error: Reconnected to the hypervisor
    error: Failed to start domain cd
    error: internal error process exited while connecting to monitor: \
      char device redirected to /dev/pts/33 (label charserial0)
    qemu-system-x86_64: -drive file=/home/vm/systemrescuecd-x86-1.2.0.\
      iso,if=none,id=drive-ide0-1-0,readonly=on,format=raw,cache=none: \
      could not open disk image /home/vm/systemrescuecd-x86-1.2.0.iso: \
      Permission denied
This commit is contained in:
Jiri Denemark 2013-04-22 18:20:21 +02:00
parent e4bdba8d7f
commit 6d1b3edc6e
1 changed files with 4 additions and 16 deletions

View File

@ -1665,21 +1665,6 @@ static void qemuProcessFreePtyPath(void *payload, const void *name ATTRIBUTE_UNU
VIR_FREE(payload);
}
static void
qemuProcessReadLogFD(int logfd, char *buf, int maxlen, int off)
{
int ret;
char *tmpbuf = buf + off;
ret = saferead(logfd, tmpbuf, maxlen - off - 1);
if (ret < 0) {
ret = 0;
}
tmpbuf[ret] = '\0';
}
static int
qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@ -1734,6 +1719,7 @@ cleanup:
virHashFree(paths);
if (pos != -1 && kill(vm->pid, 0) == -1 && errno == ESRCH) {
int len;
/* VM is dead, any other error raised in the interim is probably
* not as important as the qemu cmdline output */
if (virQEMUCapsUsedQMP(qemuCaps)) {
@ -1745,7 +1731,9 @@ cleanup:
goto closelog;
}
}
qemuProcessReadLogFD(logfd, buf, buf_size, strlen(buf));
len = strlen(buf);
qemuProcessReadLog(logfd, buf + len, buf_size - len - 1, 0);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("process exited while connecting to monitor: %s"),
buf);