[libvirt] [PATCH 06/10] Qemu Monitor API entry point.

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

 



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.

Signed-off-by: Chris Lalancette <clalance@xxxxxxxxxx>
---
 include/libvirt/Makefile.am    |    1 +
 include/libvirt/libvirt-qemu.h |   30 ++++++++++++++
 src/Makefile.am                |    8 +++-
 src/libvirt-qemu.c             |   88 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 126 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..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@xxxxxxxxxx>
+ */
+
+#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 66dc349..c57a7b8 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 =
@@ -947,6 +947,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 = $(CYGWIN_EXTRA_LDFLAGS) $(MINGW_EXTRA_LDFLAGS)
+libvirt_qemu_la_CFLAGS = $(COVERAGE_CFLAGS)
+libvirt_qemu_la_LIBADD = libvirt_util.la libvirt_driver_qemu.la \
+			libvirt_driver_remote.la $(CYGWIN_EXTRA_LIBADD) \
+			../gnulib/lib/libgnu.la
 
 libexec_PROGRAMS =
 
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
new file mode 100644
index 0000000..e6a4cc4
--- /dev/null
+++ b/src/libvirt-qemu.c
@@ -0,0 +1,88 @@
+#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;
+    }
+
+    virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(conn);
+    return -1;
+}
-- 
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]