If you are a qemu developer, one task you’ll inevitably do is add a new command to qemu. If you want your command to be usable by tools such as virt-manager, you will also need to add support for your command to libvirt. The first time I did this, I found the process quite daunting (due to the number of abstraction layers). In this series of posts, I will guide you through the process of supporting a fictitious
hello qemu command in libvirt.
Before writing any libvirt code, it is important to consider how your qemu command will be used by the libvirt API. Within the qemu/kvm virtualization software stack, libvirt operates at a higher level abstraction than qemu. While some libvirt APIs map directly to qemu monitor commands (ie.
cont), others involve more sophisticated operations within libvirt (ie. domain migration). This tutorial shows the steps to follow if your libvirt API function maps directly to a qemu command. For more complex situations, I would recommend asking for advice on the libvirt mailing list before spending too much time on an API that will need to be changed several times.
Show me the code:
For those of you who would like to follow along with the actual code, I have published my repositories for the qemu command itself and the libvirt support.
hello command is a “hello world” styled command with an option to receive your greeting in poorly-translated Spanish and an option to display it with exclamation. Consider the example qemu monitor session to see how this command works:
QEMU 0.14.0 monitor - type 'help' for more information (qemu) hello Hello world (qemu) hello -e Hello world! (qemu) hello -e spanish ¡Hola mundo! (qemu) hello spanish Hola mundo (qemu) hello -e czech hello: Invalid parameter 'lang'
In the first post of this series, I will walk through the qemu code I wrote to add support for the
hello command. The rest of the series will provide similar discussion of the libvirt implementation.
Libvirt is fundamentally a series abstraction layers so to implement the
hello command will be an exercise in implementing these layers. Each part is implemented as a separate patch against libvirt and each will be covered in its own post here:
- Define hello API function and data types
- Add hello to the public libvirt API
- Implement the qemu version of hello
- Add hello remote transport support
- Create hello virsh command
- Enable python bindings for hello
Up next… Hello World in Qemu