Add hello to the public libvirt API

This is the fourth post in the series “HOWTO: Add libvirt support for a qemu command”

Although we have defined a top-level libvirt API, as yet there is no entry point implemented. In this patch, we create the entry point which does some basic sanity checking and dispatches the call down to a driver to perform the real work. Make this entry point visible by updating the version script. Find the patch here.

diff --git a/src/libvirt.c b/src/libvirt.c
index e46c18b..774ab3c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -13355,3 +13355,46 @@ error:
     return -1;
+ * virDomainHello:
+ * @dom: pointer to the domain object
+ * @params: pointer to a virHelloParams object
+ *
+ * Returns: A pleasant greeting.
+ */
+char *
+virDomainHello(virDomainPtr dom,
+               virHelloParamsPtr params)
+    virConnectPtr conn;
+    char *ret = NULL;
+    VIR_DOMAIN_DEBUG(dom, "params=%p", params);
+    if (params == NULL) {
+        virLibDomainError (VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+    virResetLastError();
+    if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
+        virLibDomainError (VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        goto error;
+    }
+    conn = dom->conn;
+    if (conn->driver->domainHello) {
+        ret = conn->driver->domainHello (dom, params);
+        if (ret == NULL) {
+            goto error;
+        }
+        return ret;
+    } else {
+        virLibDomainError (VIR_ERR_NO_SUPPORT, __FUNCTION__);
+    }
+    virDispatchError(dom->conn);
+    return NULL;

Shown above is the entry point. If you look at src/libvirt.c you will notice a lot of functions that look similar to this one. This is mostly boiler-plate code that: checks for obvious problems with parameters (like NULL pointers where they are not allowed), checks for a valid connection and valid domain, and dispatches the call down to the driver associated with this connection. If the driver does not support the operation a suitable error is returned.

diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 5caab4c..379ee6c 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -434,4 +434,9 @@ LIBVIRT_0.9.0 {
 } LIBVIRT_0.8.8;
+LIBVIRT_0.8.7 {
+    global:
+        virDomainHello;
+} LIBVIRT_0.8.6;
 # .... define new API here using predicted next version number ....

All public symbols in libvirt must be declared in the version script in the section corresponding to the release in which the symbol first became available.

Up next… Implement the qemu version of hello

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 Uncategorized. Bookmark the permalink.

1 Response to Add hello to the public libvirt API

  1. Dusty says:

    Hi Adam,

    I like the concentration on virtualization that your blog has. I notice you haven’t made any new posts in a while. Any chance of making any new contributions?


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s