This basically covers the talking-to-monitor part of virQEMUCapsInitQMP. The patch itself has no real value, but it creates an entity to be tested in the next patches. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 144 ++++++++++++++++++++++++------------------- src/qemu/qemu_capabilities.h | 3 + 2 files changed, 83 insertions(+), 64 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d830e2a..b09f1a5 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2491,6 +2491,85 @@ cleanup: return ret; } +int +virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, + qemuMonitorPtr mon) +{ + int ret = -1; + int major, minor, micro; + char *package = NULL; + + /* @mon is supposed to be locked by callee */ + + if (qemuMonitorSetCapabilities(mon) < 0) { + virErrorPtr err = virGetLastError(); + VIR_DEBUG("Failed to set monitor capabilities %s", + err ? err->message : "<unknown problem>"); + ret = 0; + goto cleanup; + } + + if (qemuMonitorGetVersion(mon, + &major, &minor, µ, + &package) < 0) { + virErrorPtr err = virGetLastError(); + VIR_DEBUG("Failed to query monitor version %s", + err ? err->message : "<unknown problem>"); + ret = 0; + goto cleanup; + } + + VIR_DEBUG("Got version %d.%d.%d (%s)", + major, minor, micro, NULLSTR(package)); + + if (major < 1 || (major == 1 && minor < 2)) { + VIR_DEBUG("Not new enough for QMP capabilities detection"); + ret = 0; + goto cleanup; + } + + qemuCaps->version = major * 1000000 + minor * 1000 + micro; + qemuCaps->usedQMP = true; + + virQEMUCapsInitQMPBasic(qemuCaps); + + if (virQEMUCapsInitArchQMPBasic(qemuCaps, mon) < 0) + goto cleanup; + + /* USB option is supported v1.3.0 onwards */ + if (qemuCaps->version >= 1003000) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT); + + /* WebSockets were introduced between 1.3.0 and 1.3.1 */ + if (qemuCaps->version >= 1003001) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET); + + if (qemuCaps->version >= 1006000) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY); + + if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPObjects(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPKVMState(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPTPM(qemuCaps, mon) < 0) + goto cleanup; + if (virQEMUCapsProbeQMPCommandLine(qemuCaps, mon) < 0) + goto cleanup; + + ret = 0; +cleanup: + VIR_FREE(package); + return ret; +} + static int virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, const char *libDir, @@ -2500,8 +2579,6 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, int ret = -1; virCommandPtr cmd = NULL; qemuMonitorPtr mon = NULL; - int major, minor, micro; - char *package = NULL; int status = 0; virDomainChrSourceDef config; char *monarg = NULL; @@ -2581,67 +2658,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, virObjectLock(mon); - if (qemuMonitorSetCapabilities(mon) < 0) { - virErrorPtr err = virGetLastError(); - VIR_DEBUG("Failed to set monitor capabilities %s", - err ? err->message : "<unknown problem>"); - ret = 0; - goto cleanup; - } - - if (qemuMonitorGetVersion(mon, - &major, &minor, µ, - &package) < 0) { - virErrorPtr err = virGetLastError(); - VIR_DEBUG("Failed to query monitor version %s", - err ? err->message : "<unknown problem>"); - ret = 0; - goto cleanup; - } - - VIR_DEBUG("Got version %d.%d.%d (%s)", - major, minor, micro, NULLSTR(package)); - - if (major < 1 || (major == 1 && minor < 2)) { - VIR_DEBUG("Not new enough for QMP capabilities detection"); - ret = 0; - goto cleanup; - } - - qemuCaps->version = major * 1000000 + minor * 1000 + micro; - qemuCaps->usedQMP = true; - - virQEMUCapsInitQMPBasic(qemuCaps); - - if (virQEMUCapsInitArchQMPBasic(qemuCaps, mon) < 0) - goto cleanup; - - /* USB option is supported v1.3.0 onwards */ - if (qemuCaps->version >= 1003000) - virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT); - - /* WebSockets were introduced between 1.3.0 and 1.3.1 */ - if (qemuCaps->version >= 1003001) - virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET); - - if (qemuCaps->version >= 1006000) - virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VIDEO_PRIMARY); - - if (virQEMUCapsProbeQMPCommands(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPEvents(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPObjects(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPKVMState(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPTPM(qemuCaps, mon) < 0) - goto cleanup; - if (virQEMUCapsProbeQMPCommandLine(qemuCaps, mon) < 0) + if (virQEMUCapsInitQMPMonitor(qemuCaps, mon) < 0) goto cleanup; ret = 0; @@ -2654,7 +2671,6 @@ cleanup: virCommandFree(cmd); VIR_FREE(monarg); VIR_FREE(monpath); - VIR_FREE(package); if (pid != 0) { char ebuf[1024]; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index f3c8fa8..128f525 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -213,6 +213,9 @@ virQEMUCapsPtr virQEMUCapsNewForBinary(const char *binary, uid_t runUid, gid_t runGid); +int virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps, + qemuMonitorPtr mon); + int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon); -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list