[libvirt-users] About the change of a VM's vcpu count in runtime?

Hi, We know that there is a command "setvcpus" in virsh used to "change number of virtual CPUs", now we just have the need to change vcpu count dynamically for a running VM, so I tried this command (the vcpu count is 2 in the VM xml file), below is the result: virsh # setvcpus 3 --count 4 error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: 4 > 2 virsh # setvcpus 3 --count 1 error: Operation not supported: qemu didn't unplug the vCPUs properly So I tried another way: log into the running VM, and "echo 0 > /sys/devices/system/cpu/cpu1/online", after that I can find only one processor in the vm through '/proc/cpuinfo', but in virsh, the vcpuinfo still shows: virsh # vcpuinfo 3 VCPU: 0 CPU: 0 State: running CPU time: 13.5s CPU Affinity: yyyy VCPU: 1 CPU: 1 State: running CPU time: 6.9s CPU Affinity: yyyy So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically? BRs, Dennis

On 05/28/2013 01:24 AM, Dennis Chen wrote:
Hi,
We know that there is a command "setvcpus" in virsh used to "change number of virtual CPUs", now we just have the need to change vcpu count dynamically for a running VM, so I tried this command (the vcpu count is 2 in the VM xml file), below is the result:
virsh # setvcpus 3 --count 4 error: invalid argument: requested vcpus is greater than max allowable vcpus for the domain: 4 > 2
Correct - you can't exceed the maximum number of vcpus that you told qemu on its initial command line. Worse, qemu hasn't supported cpu hotplug or hot-unplug for quite some time (qemu 1.5 added partial support for hotplug, but still left hot-unplug unimplemented; qemu 1.5 also added support for guest-agent unplug, but we have not yet wired that up in libvirt).
virsh # setvcpus 3 --count 1 error: Operation not supported: qemu didn't unplug the vCPUs properly
Alas, until qemu actually implements vcpu hot-unplug, this will fail for you (it works for xen:// URI though).
So I tried another way: log into the running VM, and "echo 0 > /sys/devices/system/cpu/cpu1/online", after that I can find only one processor in the vm through '/proc/cpuinfo', but in virsh, the vcpuinfo still shows:
That's not hot-unplug from qemu's perspective. That's just disabling the use of the cpu from within the guest (and in fact, that's what the new qemu 1.5 guest agent commands do, where we are still working on how best to wire that up into libvirt).
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically?
Wait for newer qemu and libvirt, or else pitch in and help write patches. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 05/28/2013 02:24 PM, Eric Blake wrote:
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically?
Wait for newer qemu and libvirt, or else pitch in and help write patches.
You might not have to wait that long - if you could help test these patches, it would be appreciated: https://www.redhat.com/archives/libvir-list/2013-May/msg01857.html -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

OK, thanks Eric! We'll test these patches and give the update then... BRs, Dennis -----Original Message----- From: Eric Blake [mailto:eblake@redhat.com] Sent: 2013年5月29日 4:28 Cc: Dennis Chen; libvirt-users@redhat.com Subject: Re: [libvirt-users] About the change of a VM's vcpu count in runtime? On 05/28/2013 02:24 PM, Eric Blake wrote:
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically?
Wait for newer qemu and libvirt, or else pitch in and help write patches.
You might not have to wait that long - if you could help test these patches, it would be appreciated: https://www.redhat.com/archives/libvir-list/2013-May/msg01857.html -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 05/29/2013 04:28 AM, Eric Blake wrote:
On 05/28/2013 02:24 PM, Eric Blake wrote:
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically? Wait for newer qemu and libvirt, or else pitch in and help write patches. You might not have to wait that long - if you could help test these patches, it would be appreciated:
https://www.redhat.com/archives/libvir-list/2013-May/msg01857.html
Hi, After apply the patch, I've made a test. The testing environment as: virsh # version Compiled against library: libvirt 1.0.5 Using library: libvirt 1.0.5 Using API: QEMU 1.0.5 Running hypervisor: QEMU 1.5.0 The xml piece of the vm domain: <channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/> <target type='virtio' name='org.qemu.guest_agent.0'/> </channel> the network connection between the vm and host is ok. Also I installed the qemu-guest-agent in the guest os: [root@localhost ~]#rpm -qa | grep qemu-guest qemu-guest-agent-0.12.1.2-2.355.el6.i686 An error happened when I try to offline a guest vcpu in virsh: virsh # setguestvcpu 8 1 --offline error: Guest agent is not responding: Guest agent not available for now Is there some step I missed before I invoke the 'setguestvcpu' command in virsh or I need to write a program to hot-plug/unplug the vcpu with the help of the new API introduced by this patch? Thanks! BRs, Dennis

On 06/01/2013 03:16 PM, Dennis Chen wrote:
On 05/29/2013 04:28 AM, Eric Blake wrote:
On 05/28/2013 02:24 PM, Eric Blake wrote:
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically? Wait for newer qemu and libvirt, or else pitch in and help write patches. You might not have to wait that long - if you could help test these patches, it would be appreciated:
https://www.redhat.com/archives/libvir-list/2013-May/msg01857.html
Hi,
After apply the patch, I've made a test. The testing environment as:
virsh # version Compiled against library: libvirt 1.0.5 Using library: libvirt 1.0.5 Using API: QEMU 1.0.5 Running hypervisor: QEMU 1.5.0
The xml piece of the vm domain: <channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/> <target type='virtio' name='org.qemu.guest_agent.0'/> </channel>
the network connection between the vm and host is ok.
Also I installed the qemu-guest-agent in the guest os: [root@localhost ~]#rpm -qa | grep qemu-guest qemu-guest-agent-0.12.1.2-2.355.el6.i686
An error happened when I try to offline a guest vcpu in virsh: virsh # setguestvcpu 8 1 --offline error: Guest agent is not responding: Guest agent not available for now
Is there some step I missed before I invoke the 'setguestvcpu' command in virsh or I need to write a program to hot-plug/unplug the vcpu with the help of the new API introduced by this patch? Thanks!
BRs, Dennis
update after investigation, I need to start up the 'qemu-guest-agent' daemon in the guest (https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/...): [root@localhost ~]#qemu-ga After that, I tried the command again: virsh # setguestvcpu 8 1 --offline error: internal error unable to execute QEMU agent command 'guest-set-vcpus': The command guest-set-vcpus has not been found I think the communication between monitor and guest is ok, because below command is OK: virsh # shutdown 8 --mode agent Domain 8 is being shutdown VM shutdown after this command. Also, I double checked the src/qemu/qemu_agent.c, and I can find the 2 functions: qemuAgentGetVCPUs() and qemuAgentSetVCPUs() Another, virsh # qemu-agent-command 9 '{"execute":"cpu-add","arguments":{"id":2}}' {"error":{"class":"CommandNotFound","desc":"The command cpu-add has not been found","data":{"name":"cpu-add"}}} Seems the guest agent can't find vcpu hot-plug/unplug command, the qemu I am using is 1.5.0, does it need some patches to handle this or something I still missed? BRs, Dennis

On 06/01/2013 06:49 PM, Dennis Chen wrote:
On 06/01/2013 03:16 PM, Dennis Chen wrote:
On 05/29/2013 04:28 AM, Eric Blake wrote:
On 05/28/2013 02:24 PM, Eric Blake wrote:
So the question is: is there any method I can't find yet to change the vcpu count of a running vm dynamically? Wait for newer qemu and libvirt, or else pitch in and help write patches. You might not have to wait that long - if you could help test these patches, it would be appreciated:
https://www.redhat.com/archives/libvir-list/2013-May/msg01857.html
Hi,
After apply the patch, I've made a test. The testing environment as:
virsh # version Compiled against library: libvirt 1.0.5 Using library: libvirt 1.0.5 Using API: QEMU 1.0.5 Running hypervisor: QEMU 1.5.0
The xml piece of the vm domain: <channel type='unix'> <source mode='bind' path='/var/lib/libvirt/qemu/f16x86_64.agent'/> <target type='virtio' name='org.qemu.guest_agent.0'/> </channel>
the network connection between the vm and host is ok.
Also I installed the qemu-guest-agent in the guest os: [root@localhost ~]#rpm -qa | grep qemu-guest qemu-guest-agent-0.12.1.2-2.355.el6.i686
An error happened when I try to offline a guest vcpu in virsh: virsh # setguestvcpu 8 1 --offline error: Guest agent is not responding: Guest agent not available for now
Is there some step I missed before I invoke the 'setguestvcpu' command in virsh or I need to write a program to hot-plug/unplug the vcpu with the help of the new API introduced by this patch? Thanks!
BRs, Dennis
update after investigation, I need to start up the 'qemu-guest-agent' daemon in the guest (https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/...): [root@localhost ~]#qemu-ga
After that, I tried the command again: virsh # setguestvcpu 8 1 --offline error: internal error unable to execute QEMU agent command 'guest-set-vcpus': The command guest-set-vcpus has not been found
I think the communication between monitor and guest is ok, because below command is OK: virsh # shutdown 8 --mode agent Domain 8 is being shutdown
VM shutdown after this command. Also, I double checked the src/qemu/qemu_agent.c, and I can find the 2 functions: qemuAgentGetVCPUs() and qemuAgentSetVCPUs()
Another, virsh # qemu-agent-command 9 '{"execute":"cpu-add","arguments":{"id":2}}' {"error":{"class":"CommandNotFound","desc":"The command cpu-add has not been found","data":{"name":"cpu-add"}}}
Seems the guest agent can't find vcpu hot-plug/unplug command, the qemu I am using is 1.5.0, does it need some patches to handle this or something I still missed?
hmm, I forget to upgrade the qemu-ga in guest os from 1.0 to 1.5.0. So I did that, the latest update -- The internal error doesn't show for "setguestvcpu 10 1 --offline" cmd, it's ok to offline the logic cpu id 1 when I checked it within the guest. But seems the output of "vcpuinfo/vcpucount" is not changed accordingly, e.g: virsh # vcpuinfo 10 VCPU: 0 CPU: 1 State: running .. VCPU: 1 CPU: 3 State: running ... both are running (actually the vcpu 1 is offline). plus, virsh # vcpumap 10 --offline --agent CPU map: -y but virsh # vcpumap 10 --offline CPU map: -- Last, in the qmp-commands.txt of qemu-1.5.0 and also mentioned in the patch [8/11]: "This patch implements support for the "cpu-add" QMP command that plugs CPUs into a live guest. The "cpu-add" command was introduced in QEMU 1.5" but in my environment, virsh # qemu-agent-command 10 '{"execute":"cpu-add","arguments":{"id":2}}' {"error":{"class":"CommandNotFound","desc":"The command cpu-add has not been found"}} is "cpu-add" supported by qemu 1.5.0 now? or something I still missed? IMO, the "cpu-add" is used to hot-plug a vcpu into the guest, so if the vcpu count specified in a vm xml is, e.g., 4, I can hotplug a new vcpu (totally 5 then) into the guest during runtime, is that correct? BRs, Dennis
participants (3)
-
Dennis Chen
-
dennis chen
-
Eric Blake