[libvirt] [RFC PATCH 1/5] Qemu Monitor API entry point.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>
---
 include/libvirt/Makefile.am    |    1 +
 include/libvirt/libvirt_qemu.h |   30 ++++++++++++
 src/Makefile.am                |   11 ++++-
 src/driver.h                   |    5 ++
 src/esx/esx_driver.c           |    1 +
 src/internal.h                 |    1 +
 src/libvirt_qemu.c             |   96 ++++++++++++++++++++++++++++++++++++++++
 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 +
 18 files changed, 155 insertions(+), 1 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..ac5f32c 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..7d78a7f
--- /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@xxxxxxxxxx>
+ */
+
+#ifndef __VIR_QEMU_H__
+#define __VIR_QEMU_H__
+
+#include "libvirt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int virQemuMonitorCommand(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 d54e6d0..c01c94e 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 =
@@ -945,6 +945,15 @@ 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 util/threads.c util/threads.h \
+                               util/threads-pthread.h                   \
+                               util/threads-win32.h                     \
+                               util/virterror.c                         \
+                               util/virterror_internal.h
+
+libvirt_qemu_la_LDFLAGS = $(libvirt_la_LDFALGS)
+libvirt_qemu_la_CFLAGS = $(COVERAGE_CFLAGS)
+
 
 libexec_PROGRAMS =
 
diff --git a/src/driver.h b/src/driver.h
index f8db9c1..651653d 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -448,6 +448,10 @@ typedef int
     (*virDrvDomainSnapshotDelete)(virDomainSnapshotPtr snapshot,
                                   unsigned int flags);
 
+typedef int
+    (*virDrvQemuMonitorCommand)(virDomainPtr domain, const char *cmd,
+                                char **result, unsigned int flags);
+
 
 /**
  * _virDriver:
@@ -558,6 +562,7 @@ struct _virDriver {
     virDrvDomainSnapshotCurrent domainSnapshotCurrent;
     virDrvDomainRevertToSnapshot domainRevertToSnapshot;
     virDrvDomainSnapshotDelete domainSnapshotDelete;
+    virDrvQemuMonitorCommand qemuMonitorCommand;
 };
 
 typedef int
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 4ed9890..c7ae015 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -3810,6 +3810,7 @@ static virDriver esxDriver = {
     esxDomainSnapshotCurrent,        /* domainSnapshotCurrent */
     esxDomainRevertToSnapshot,       /* domainRevertToSnapshot */
     esxDomainSnapshotDelete,         /* domainSnapshotDelete */
+    NULL,                            /* qemuMonitorCommand */
 };
 
 
diff --git a/src/internal.h b/src/internal.h
index 2e73210..57dc660 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -22,6 +22,7 @@
 # include "gettext.h"
 
 # include "libvirt/libvirt.h"
+# include "libvirt/libvirt_qemu.h"
 # include "libvirt/virterror.h"
 
 # include "libvirt_internal.h"
diff --git a/src/libvirt_qemu.c b/src/libvirt_qemu.c
new file mode 100644
index 0000000..9c72fe2
--- /dev/null
+++ b/src/libvirt_qemu.c
@@ -0,0 +1,96 @@
+#include <config.h>
+
+#include "virterror_internal.h"
+#include "logging.h"
+#include "datatypes.h"
+#include "driver.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
+virQemuMonitorCommand(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->qemuMonitorCommand) {
+        int ret;
+        ret = conn->driver->qemuMonitorCommand(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/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 2851a2a..002eae9 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, /* qemuMonitorCommand */
 };
 
 static virStateDriver lxcStateDriver = {
diff --git a/src/opennebula/one_driver.c b/src/opennebula/one_driver.c
index cdd61eb..8a7ee30 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, /* qemuMonitorCommand */
 };
 
 static virStateDriver oneStateDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 95c4236..1bb6a9a 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, /* qemuMonitorCommand */
 };
 
 int openvzRegister(void) {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index f4d817e..45d3653 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, /* qemuMonitorCommand */
 };
 
 int
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index df1d435..74b200b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11346,6 +11346,7 @@ static virDriver qemuDriver = {
     qemuDomainSnapshotCurrent, /* domainSnapshotCurrent */
     qemuDomainRevertToSnapshot, /* domainRevertToSnapshot */
     qemuDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuMonitorCommand */
 };
 
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 751c354..408d18d 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -10134,6 +10134,7 @@ static virDriver remote_driver = {
     remoteDomainSnapshotCurrent, /* domainSnapshotCurrent */
     remoteDomainRevertToSnapshot, /* domainRevertToSnapshot */
     remoteDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuMonitorCommand */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4ea0279..f85c1d0 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, /* qemuMonitorCommand */
 };
 
 static virNetworkDriver testNetworkDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index a251e89..09d94c8 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, /* qemuMonitorCommand */
 };
 
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index a07cf8e..ab0a13e 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -8185,6 +8185,7 @@ virDriver NAME(Driver) = {
     vboxDomainSnapshotCurrent, /* domainSnapshotCurrent */
     vboxDomainRevertToSnapshot, /* domainRevertToSnapshot */
     vboxDomainSnapshotDelete, /* domainSnapshotDelete */
+    NULL, /* qemuMonitorCommand */
 };
 
 virNetworkDriver NAME(NetworkDriver) = {
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 5ab169d..51e6698 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1992,6 +1992,7 @@ static virDriver xenUnifiedDriver = {
     NULL, /* domainSnapshotCurrent */
     NULL, /* domainRevertToSnapshot */
     NULL, /* domainSnapshotDelete */
+    NULL, /* qemuMonitorCommand */
 };
 
 /**
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 75796d6..4c8650d 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, /* qemuMonitorCommand */
 };
 
 /**
-- 
1.6.6.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]