Libvirt utilizza l'agente guest Qemu in esecuzione all'interno di una VM. Questo post elaborerà il modo in cui l'agente Qemu funge da canale di comunicazione tra l'host KVM e l'ospite.
Protocollo di comunicazione
Il protocollo di comunicazione utilizzato per recuperare informazioni dal sistema operativo VM o inviare comandi al sistema operativo guest è Qemu Machine Protocol (QMP). QMP è un protocollo basato su JSON.
Ad esempio, libvirt utilizza l'agente guest per recuperare i dettagli del filesystem dal guest. Per verificare se l'agente ospite funziona:
# virsh qemu-agent-command >vm_name> '{"execute": "guest-info"}'
Ad esempio:
# virsh qemu-agent-command TestVM '{"execute": "guest-get-host-name"}' --pretty Please enter your authentication name: vdsm@ovirt Please enter your password: { "return": { "host-name": "<VM FQDN>" }
# virsh qemu-agent-command TestVM '{"execute": "guest-get-osinfo"}' --pretty Please enter your authentication name: vdsm@ovirt Please enter your password: { "return": { "name": "Oracle Linux Server", "kernel-release": "4.14.35-1902.300.11.el7uek.x86_64", "version": "7.8", "variant": "Server", "pretty-name": "Oracle Linux Server 7.8", "version-id": "7.8", "variant-id": "server", "kernel-version": "#2 SMP Tue Mar 17 17:11:47 PDT 2020", "machine": "x86_64", "id": "ol" } }
Metodo di comunicazione
La comunicazione tra l'agente ospite e l'host avviene tramite il canale virtio-serial e isa-serial org.qemu.guest_agen.0.
– Da VM guest, ecco il processo qemu.guest_agent:
# ps auxwww |grep guest root 811 0.0 0.0 44232 4572 ? Ss Feb22 0:51 /usr/bin/qemu-ga --method=virtio-serial --path=/dev/virtio -ports/org.qemu.guest_agent.0 --blacklist=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest-file-seek ,guest-file-flush,guest-exec,guest-exec-status -F/etc/qemu-ga/fsfreeze-hook
– Dall'host, verrà creato anche un file socket corrispondente in /var/lib/libvirt/qemu/channels/
# file /var/lib/libvirt/qemu/channels/56f42910-82d1-4e14-b4a4-646d220567c7.org.ovirt.hosted-engine-setup.0 /var/lib/libvirt/qemu/channels/56f42910-82d1-4e14-b4a4-646d220567c7.org.ovirt.hosted-engine-setup.0: socket
# virsh -r dumpxml TestVM |grep guest_agent <source mode='bind' path='/var/lib/libvirt/qemu/channels/56f42910-82d1-4e14-b4a4-646d220567c7.org.qemu.guest_agent.0'/> <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
Se la comunicazione è corretta, il socket UNIX ha una connessione 'ESTAB':
# ss |grep guest_agent u_str ESTAB 0 0 /var/lib/libvirt/qemu/channels/56f42910-82d1-4e14-b4a4-646d220567c7.org.qemu.guest_agent.0 82797274 * 82971852 u_str ESTAB 0 0 /var/lib/libvirt/qemu/channels/9c798303-1c30-4965-b447-e1c12588db14.org.qemu.guest_agent.0 82944156 * 82971680
Intervallo di comunicazione
Per impostazione predefinita, VDSM interroga l'agente guest QEMU (qemu-ga) ogni 5 minuti per recuperare le informazioni. Se l'agente guest QEMU non è in esecuzione e risponde entro 5 minuti, libvirtd segnalerà l'errore come "L'agente guest non risponde:l'agente guest QEMU non è connesso"
Altri
È disponibile anche la sottorete di QMP denominata 'hmp. "qemu-monitor-command" ha la capacità di scambiare informazioni in formato "hmp" tramite le opzioni -hmp. Per verificare lo stato della porta seriale virtio collegata all'ovirt-guest-agent:
# virsh qemu-monitor-command --hmp <Virtual Machine Name Here> 'info qtree'
Ad esempio:
# virsh qemu-monitor-command --hmp TestVM 'info qtree' Please enter your authentication name: vdsm@ovirt Please enter your password: dev: virtserialport, id "channel1" chardev = "charchannel1" nr = 2 (0x2) name = "org.qemu.guest_agent.0" port 2, guest on, host on, throttle off