lost and found ( for me ? )

Ubuntu 14.04 KVM : how to offline/online vCPU cores on virtual machines

Here is how to online/offline vCPU via virsh qemu-comamnd

assume you already set up qemu-guest-agent.

KV host : Ubuntu14.04
VM : CentOS 6.6

on the KVM host
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-get-vcpus"}'
{"return":[{"online":true,"can-offline":false,"logical-id":0},{"online":true,"can-offline":true,"logical-id":1},{"online":true,"can-offline":true,"logical-id":2},{"online":true,"can-offline":true,"logical-id":3},{"online":true,"can-offline":true,"logical-id":4},{"online":true,"can-offline":true,"logical-id":5},{"online":true,"can-offline":true,"logical-id":6},{"online":true,"can-offline":true,"logical-id":7}]}

offline logical-id 5
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-set-vcpus", "arguments" : { "vcpus" : [{"online":false,
"can-offline":false,"logical-id":5}]}}'
{"retur2n":1}

VM’s log ( dmesg )
CPU 5 is now offline

online logical id 5 again.
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-set-vcpus", "arguments" : { "vcpus" : [{"online":true,"
can-offline":false,"logical-id":5}]}}'
{"return":1}

VM’s log
Booting Node 0 Processor 5 APIC 0x5
kvm-clock: cpu 5, msr 0:28356841, secondary cpu clock
kvm-stealtime: cpu 5, msr 2834e880

offline multiple cores at one time.
virsh # qemu-agent-command centos6-vm1 '{"execute":"guest-set-vcpus", "arguments" : { "vcpus" : [{"online":false,"can-offline":false,"logical-id":5},{"online":false,"can-offline":false,"logical-id":6}]}}'
{"return":2}

Ubuntu 14.04 : qemu-guest-agent

Here are trial and error logs when setting up qemu-guest-agent.

KVM host : Ubuntu 14.04
Guest VMs : CentOS 6.6

KVM host
# uname –r
3.13.0-37-generic

# kvm --version
QEMU emulator version 2.0.0 (Debian 2.0.0+dfsg-2ubuntu1.7), Copyright (c) 2003-2008 Fabrice Bellard

install qemu-guest-agent on the VM.
# yum install qemu-guest-agent

# /etc/init.d/qemu-ga start

# /etc/init.d/qemu-ga status
qemu-ga is stopped

can not start qemu-ga.

reboot the VM.

# reboot

# /etc/init.d/qemu-ga status
qemu-ga is stopped

nnn, still can not start qemu-agent.


I forgot adding a channel for qemu-agent.

add following lines to the VM’s xml file.
<channel type='unix'>
     <source mode='bind' path='/var/lib/libvirt/qemu/centos6-vm.agent'/>
     <target type='virtio' name='org.qemu.guest_agent.0'/>
     <alias name='channel1'/>
     <address type='virtio-serial' controller='0' bus='0' port='2'/>
   </channel>

Here is an output of diff of VM’s xml file.
# diff /etc/libvirt/qemu/centos6-vm.xml /etc/libvirt/qemu/centos6-vm.xml.org
42,44d41
<     <controller type='virtio-serial' index='0'>
<       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
<     </controller>
57,61d53
<     <channel type='unix'>
<       <source mode='bind' path='/var/lib/libvirt/qemu/centos6-vm.agent'/>
<       <target type='virtio' name='org.qemu.guest_agent.0'/>
<       <address type='virtio-serial' controller='0' bus='0' port='2'/>
<     </channel>

Okay, qemu-ga is running on the VM.
# /etc/init.d/qemu-ga status
qemu-ga (pid  1086) is running...

on the KVM host
virsh # qemu-agent-command centos6-vm '{"execute":"guest-network-get-interfaces"}'
{"return":[{"name":"lo","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"127.0.0.1","prefix":8}],"hardware-address":"00:00:00:00:00:00"},{"name":"eth0","ip-addresses":[{"ip-address-type":"ipv4","ip-address":"192.168.122.53","prefix":24}],"hardware-address":"MAC address"}]}

I was able to get information via qemu-agent-command.