[libvirt] [PATCH v2 4/8] Qemu Monitor API entry point.

Chris Lalancette clalance at redhat.com
Wed Apr 28 20:20:49 UTC 2010


Add the library entry point for the new virDomainQemuMonitorCommand()
entry point.  Because this is not part of the "normal" libvirt API,
it gets it's own header file, library file, and will eventually
get it's own over-the-wire protocol later in the series.

Changes since v1:
 - Go back to using the virDriver table for qemuDomainMonitorCommand, due to
   linking issues
 - Added versioning information to the libvirt-qemu.so

Signed-off-by: Chris Lalancette <clalance at redhat.com>
---
 include/libvirt/Makefile.am    |    1 +
 include/libvirt/libvirt-qemu.h |   30 ++++++++++++
 src/Makefile.am                |    8 +++-
 src/driver.h                   |    6 +++
 src/esx/esx_driver.c           |    1 +
 src/libvirt-qemu.c             |   97 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_private.syms       |    2 +
 src/libvirt_public.syms        |    5 ++-
 src/lxc/lxc_driver.c           |    1 +
 src/opennebula/one_driver.c    |    1 +
 src/openvz/openvz_driver.c     |    1 +
 src/phyp/phyp_driver.c         |    1 +
 src/qemu/qemu_driver.c         |    1 +
 src/remote/remote_driver.c     |    1 +
 src/test/test_driver.c         |    1 +
 src/uml/uml_driver.c           |    1 +
 src/vbox/vbox_tmpl.c           |    1 +
 src/xen/xen_driver.c           |    1 +
 src/xenapi/xenapi_driver.c     |    1 +
 19 files changed, 159 insertions(+), 2 deletions(-)
 create mode 100644 include/libvirt/libvirt-qemu.h
 create mode 100644 src/libvirt-qemu.c

diff --git a/include/libvirt/Makefile.am b/include/libvirt/Makefile.am
index 8589dc5..b2c2b76 100644
--- a/include/libvirt/Makefile.am
+++ b/include/libvirt/Makefile.am
@@ -3,6 +3,7 @@
 virincdir = $(includedir)/libvirt
 
 virinc_HEADERS = libvirt.h		\
+		 libvirt-qemu.h		\
 		 virterror.h
 
 install-exec-hook:
diff --git a/include/libvirt/libvirt-qemu.h b/include/libvirt/libvirt-qemu.h
new file mode 100644
index 0000000..1170196
--- /dev/null
+++ b/include/libvirt/libvirt-qemu.h
@@ -0,0 +1,30 @@
+/* -*- c -*-
+ * libvirt_qemu.h:
+ * Summary: qemu specific interfaces
+ * Description: Provides the interfaces of the libvirt library to handle
+ *              qemu specific methods
+ *
+ * Copy:  Copyright (C) 2010 Red Hat, Inc.
+ *
+ * See COPYING.LIB for the License of this software
+ *
+ * Author: Chris Lalancette <clalance at redhat.com>
+ */
+
+#ifndef __VIR_QEMU_H__
+# define __VIR_QEMU_H__
+
+# include "libvirt.h"
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+int virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
+                                char **result, unsigned int flags);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif /* __VIR_QEMU_H__ */
diff --git a/src/Makefile.am b/src/Makefile.am
index d8466f0..c8ab15e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -32,7 +32,7 @@ if WITH_NETWORK
 UUID=$(shell uuidgen 2>/dev/null)
 endif
 
-lib_LTLIBRARIES = libvirt.la
+lib_LTLIBRARIES = libvirt.la libvirt-qemu.la
 
 moddir = $(libdir)/libvirt/drivers
 mod_LTLIBRARIES =
@@ -955,6 +955,12 @@ libvirt_test_la_LIBADD = $(libvirt_la_LIBADD)
 libvirt_test_la_LDFLAGS = $(test_LDFLAGS)
 libvirt_test_la_CFLAGS = $(COVERAGE_CFLAGS)
 
+libvirt_qemu_la_SOURCES = libvirt-qemu.c
+libvirt_qemu_la_LDFLAGS = $(VERSION_SCRIPT_FLAGS)$(LIBVIRT_SYMBOL_FILE) \
+                          -version-info $(LIBVIRT_VERSION_INFO) \
+                          $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS)
+libvirt_qemu_la_CFLAGS = $(COVERAGE_CFLAGS)
+libvirt_qemu_la_LIBADD = libvirt.la $(CYGWIN_EXTRA_LIBADD)
 
 libexec_PROGRAMS =
 
diff --git a/src/driver.h b/src/driver.h
index f8db9c1..dbf692a 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -448,6 +448,11 @@ typedef int
     (*virDrvDomainSnapshotDelete)(virDomainSnapshotPtr snapshot,
                                   unsigned int flags);
 
+typedef int
+    (*virDrvQemuDomainMonitorCommand)(virDomainPtr domain, const char *cmd,
+                                      char **result, unsigned int flags);
+
+
 
 /**
  * _virDriver:
@@ -558,6 +563,7 @@ struct _virDriver {
     virDrvDomainSnapshotCurrent domainSnapshotCurrent;
     virDrvDomainRevertToSnapshot domainRevertToSnapshot;
     virDrvDomainSnapshotDelete domainSnapshotDelete;
+    virDrvQemuDomainMonitorCommand qemuDomainMonitorCommand;
 };
 
 typedef int
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index c0c3195..b31a453 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3809,6 +3809,7 @@ static virDriver esxDriver = {
     esxDomainSnapshotCurrent,        /* domainSnapshotCurrent */
     esxDomainRevertToSnapshot,       /* domainRevertToSnapshot */
     esxDomainSnapshotDelete,         /* domainSnapshotDelete */
+    NULL,                            /* qemuDomainMonitorCommand */
 };
 
 
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
new file mode 100644
index 0000000..2d43e13
--- /dev/null
+++ b/src/libvirt-qemu.c
@@ -0,0 +1,97 @@
+#include <config.h>
+
+#include "virterror_internal.h"
+#include "logging.h"
+#include "datatypes.h"
+#include "libvirt/libvirt-qemu.h"
+
+/**
+ * virLibConnError:
+ * @conn: the connection if available
+ * @error: the error number
+ * @info: extra information string
+ *
+ * Handle an error at the connection level
+ */
+static void
+virLibConnError(virConnectPtr conn, virErrorNumber error, const char *info)
+{
+    const char *errmsg;
+
+    if (error == VIR_ERR_OK)
+        return;
+
+    errmsg = virErrorMsg(error, info);
+    virRaiseError(conn, NULL, NULL, VIR_FROM_NONE, error, VIR_ERR_ERROR,
+                  errmsg, info, NULL, 0, 0, errmsg, info);
+}
+
+/**
+ * virLibDomainError:
+ * @domain: the domain if available
+ * @error: the error number
+ * @info: extra information string
+ *
+ * Handle an error at the connection level
+ */
+static void
+virLibDomainError(virDomainPtr domain, virErrorNumber error,
+                  const char *info)
+{
+    virConnectPtr conn = NULL;
+    const char *errmsg;
+
+    if (error == VIR_ERR_OK)
+        return;
+
+    errmsg = virErrorMsg(error, info);
+    if (error != VIR_ERR_INVALID_DOMAIN) {
+        conn = domain->conn;
+    }
+    virRaiseError(conn, domain, NULL, VIR_FROM_DOM, error, VIR_ERR_ERROR,
+                  errmsg, info, NULL, 0, 0, errmsg, info);
+}
+
+int
+virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
+                            char **result, unsigned int flags)
+{
+    virConnectPtr conn;
+
+    DEBUG("domain=%p, cmd=%s, result=%p, flags=%u", domain, cmd, result, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    conn = domain->conn;
+
+    if (result == NULL) {
+        virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(domain, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (conn->driver->qemuDomainMonitorCommand) {
+        int ret;
+        ret = conn->driver->qemuDomainMonitorCommand(domain, cmd, result,
+                                                     flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 746327d..9f46b15 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -13,6 +13,7 @@ virBufferContentAndReset;
 virBufferError;
 virBufferURIEncodeString;
 virBufferFreeAndReset;
+virBufferStrcat;
 
 
 # caps.h
@@ -706,6 +707,7 @@ virReportSystemErrorFull;
 virReportOOMErrorFull;
 virStrerror;
 virSetError;
+virDispatchError;
 
 
 # xml.h
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index b4db904..22d53f9 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -393,5 +393,8 @@ LIBVIRT_0.8.0 {
         virDomainSnapshotFree;
 } LIBVIRT_0.7.7;
 
-
+LIBVIRT_0.8.1 {
+    global:
+        virDomainQemuMonitorCommand;
+} LIBVIRT_0.8.0;
 # .... define new API here using predicted next version number ....
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 2851a2a..f9bc625 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2550,6 +2550,7 @@ static virDriver lxcDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 static virStateDriver lxcStateDriver = {
diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c
index cdd61eb..0ed1fa7 100644
--- a/src/opennebula/one_driver.c
+++ b/src/opennebula/one_driver.c
@@ -804,6 +804,7 @@ static virDriver oneDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 static virStateDriver oneStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 47004d6..47b5657 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1558,6 +1558,7 @@ static virDriver openvzDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index f4d817e..f764a16 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1663,6 +1663,7 @@ virDriver phypDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 int
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 23a1e1d..c720103 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11647,6 +11647,7 @@ static virDriver qemuDriver = {
     qemuDomainSnapshotCurrent, /* domainSnapshotCurrent */
     qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */
     qemuDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 1917f26..a2079ee 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -10177,6 +10177,7 @@ static virDriver remote_driver = {
     remoteDomainSnapshotCurrent, /* domainSnapshotCurrent */
     remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
     remoteDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4ea0279..74b1ea3 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5313,6 +5313,7 @@ static virDriver testDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index a251e89..e7f9c57 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1944,6 +1944,7 @@ static virDriver umlDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f564213..19de29e 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8207,6 +8207,7 @@ virDriver NAME(Driver) = {
     vboxDomainSnapshotCurrent, /* domainSnapshotCurrent */
     vboxDomainRevertToSnapshot, /* domainRevertToSnapshot */
     vboxDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 virNetworkDriver NAME(NetworkDriver) = {
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index b6dcf8d..a48990e 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1994,6 +1994,7 @@ static virDriver xenUnifiedDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 /**
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 75796d6..e5841dd 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1795,6 +1795,7 @@ static virDriver xenapiDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuDomainMonitorCommand */
 };
 
 /**
-- 
1.6.6.1




More information about the libvir-list mailing list