HOWTO: Add libvirt support for a qemu command

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. pause and 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.

qemu: http://repo.or.cz/w/qemu/aglitke.git/shortlog/refs/heads/tutorial
libvirt: http://repo.or.cz/w/libvirt/aglitke.git/shortlog/refs/heads/tutorial

The command:

The 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'

The steps:

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:

  1. Define hello API function and data types
  2. Add hello to the public libvirt API
  3. Implement the qemu version of hello
  4. Add hello remote transport support
  5. Create hello virsh command
  6. Enable python bindings for hello

Up next… Hello World in Qemu

Advertisements

About aglitke

I am a software engineer working on Linux, open source software, and virtualization. I am proud to work at Red Hat on oVirt and Red Hat Virtualization with a focus on software defined storage. Other notable projects I have been involved in include: The Linux ppc64 architecture, Linux kernel crash dumps (kdump), Linux huge pages and libhugetlbfs, qemu, libvirt, and the Memory Overcommitment Manager.
This entry was posted in libvirt. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s