Hide Forgot
Description of problem: qemu-attach will fail with 'JSON monitor is required' the 1st time and hang when execute the 2nd time Version-Release number of selected component (if applicable): libvirt-2.0.0-10.el7.x86_64 How reproducible: 100% Steps to Reproduce: 1. # qemu-img create /var/lib/libvirt/images/foo.img 1G 2. # /usr/libexec/qemu-kvm -cdrom /var/lib/libvirt/images/foo.img -monitor unix:/tmp/demo,server,nowait -name foo -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea & [1] 7044 # VNC server running on '::1;5900' 3.qemu-attach failed # virsh qemu-attach 7044 error: Failed to attach to pid 7044 error: Operation not supported: JSON monitor is required # virsh list --all Id Name State ---------------------------------------------------- ===> not connected 4. Run the qemu-attach command the 2nd time, it will hang. On another terminal, you will found the vm is already connected with "shut off" state # virsh qemu-attach 7044 ===> it will hang # virsh list Id Name State ---------------------------------------------------- 4 foo shut off # ps -aux | grep qemu-kvm root 7044 18.4 0.5 591372 39536 pts/1 Sl 12:34 0:12 /usr/libexec/qemu-kvm -cdrom /var/lib/libvirt/images/foo.img -monitor unix:/tmp/demo,server,nowait -name foo -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea 5. Run the qemu-attach the 3rd time, it says the domain is already active # virsh qemu-attach 7044 error: Failed to attach to pid 7044 error: Requested operation is not valid: domain 'foo' is already active Actual results: qemu-attach will fail with 'Json monitor required' when executed the 1st time and hang when executed the 2nd time. Expected results: The qemu-attach should not hang. Additional info: Downgrade to libvirt-2.0.0-6.el7.x86_64 on the same host, it works well. # virsh qemu-attach 6636 Domain foo attached to pid 6636
"JSON monitor is required" originates from my recent VCPU patches, which incorrectly require the JSON monitor in case of attaching to a qemu process. Libvirt then doesn't properly clean up.
commit 2c739866df5a820b2db280b36cd8b6fe00cfba58 Author: Peter Krempa <pkrempa> Date: Mon Oct 3 13:11:47 2016 +0200 qemu: attach: Close monitor socket on connection failure If attaching to a qemu process fails after opening the monitor socket libvirt does not clean up the monitor. As the monitor also holds a reference to the domain object the qemu attach API basically leaks it. QEMU also does not interact on a second monitor connection and thus a further attempt to attach to it would lock up. Prevent libvirt from leaking the monitor by explicitly closing it. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1378401 commit 62135ff692044a0a7cac5ee91f2cb42463550052 Author: Peter Krempa <pkrempa> Date: Fri Sep 30 12:45:59 2016 +0200 qemu: Don't strictly require JSON monitor for vCPU detection Attaching to a existing qemu process allows to get us into a situation when qemu is new enough to have JSON monitor and new vCPU hotplug but the json monitor is not used. The vCPU detection code would require it though. This broke attaching to qemu processes. Make the condition less strict and just skip the vCPU hotplug detection if JSON monitor is not available. Resolves one of the symptoms in: https://bugzilla.redhat.com/show_bug.cgi?id=1378401
Test passed with version libvirt-2.5.0-1.el7.x86_64 & qemu-kvm-rhev-2.6.0-28.el7.x86-64. 1. # qemu-img create /var/lib/libvirt/images/foo.img 1G 2. # /usr/libexec/qemu-kvm -cdrom /var/lib/libvirt/images/foo.img -monitor unix:/tmp/demo,server,nowait -name foo VNC server running on '::1;5900' 3.qemu-attach succeeded. # virsh qemu-attach 5975 Domain foo attached to pid 5975 4. virsh list Id Name State ---------------------------- 1 foo running
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHEA-2017:1846