Start and connect to QEMU so QMP commands can be performed. Isolates code for starting QEMU and establishing Monitor connections from code for obtaining capabilities so that arbitrary QMP commands can be exchanged with QEMU. --- src/qemu/qemu_capabilities.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index afce3eb2b7..097985cbe7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4303,6 +4303,65 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPCommandPtr cmd, } +/* Start and connect to QEMU so QMP commands can be performed. + */ +static virQEMUCapsInitQMPCommandPtr +virQEMUCapsSpinUpQemu(const char *exec, + const char *libDir, uid_t runUid, gid_t runGid, + bool forceTCG) +{ + virQEMUCapsInitQMPCommandPtr cmd = NULL; + virQEMUCapsInitQMPCommandPtr rtn_cmd = NULL; + char *binary = NULL; + + if (exec) { + if (VIR_STRDUP(binary, exec) < 0) + goto cleanup; + } else { + /* Check for existence of base emulator, or alternate base + * which can be used with magic cpu choice + */ + virArch arch = virArchFromHost(); + binary = virQEMUCapsFindBinaryForArch(arch, arch); + } + + VIR_DEBUG("binary=%s", binary); + + /* Make sure the binary we are about to try exec'ing exists. + * Technically we could catch the exec() failure, but that's + * in a sub-process so it's hard to feed back a useful error. + */ + if (!virFileIsExecutable(binary)) { + virReportSystemError(errno, _("QEMU binary %s is not executable"), + binary); + goto cleanup; + } + + if (!(cmd = virQEMUCapsInitQMPCommandNew(binary, libDir, + runUid, runGid, NULL))) + goto cleanup; + + if ((virQEMUCapsInitQMPCommandRun(cmd, forceTCG)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Error starting QEMU")); + goto cleanup; + } + + if (!(cmd->mon)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Error connecting to QEMU")); + goto cleanup; + } + + VIR_STEAL_PTR(rtn_cmd, cmd); + + cleanup: + virQEMUCapsInitQMPCommandFree(cmd); + VIR_FREE(binary); + + return rtn_cmd; +} + + static int virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, const char *libDir, -- 2.14.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list