On Wed, Nov 26, 2014 at 01:13:57PM +0000, Zeeshan Ali (Khattak) wrote:
Add binding for virDomainOpenGraphicsFD. If virDomainOpenGraphicsFD
is
not available, it means we are dealing with older libvirt so we create
the socket pair ourselves if that is the case.
---
configure.ac | 4 ++
libvirt-gobject/libvirt-gobject-domain.c | 72 ++++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 4 ++
libvirt-gobject/libvirt-gobject.sym | 5 +++
4 files changed, 85 insertions(+)
diff --git a/configure.ac b/configure.ac
index 8cc3fca..bcb5cda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,10 @@ m4_if(m4_version_compare([2.61a.100],
LIBVIRT_GLIB_COMPILE_WARNINGS
PKG_CHECK_MODULES(LIBVIRT, libvirt >= $LIBVIRT_REQUIRED)
+# virDomainOpenGraphicsFD was introduced in libvirt 1.2.8
+AC_CHECK_LIB([virt],
+ [virDomainOpenGraphicsFD],
+ [AC_DEFINE([HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD], 1, [Have
virDomainOpenGraphicsFD?])])
enable_tests=no
PKG_CHECK_MODULES(GLIB2, glib-2.0 >= $GLIB2_TEST_REQUIRED,
[enable_tests=yes],
diff --git a/libvirt-gobject/libvirt-gobject-domain.c
b/libvirt-gobject/libvirt-gobject-domain.c
index 8df30d7..5a5189f 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -25,6 +25,9 @@
#include <libvirt/virterror.h>
#include <string.h>
+#ifndef HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD
+#include <sys/socket.h>
+#endif
#include "libvirt-glib/libvirt-glib.h"
#include "libvirt-gobject/libvirt-gobject.h"
@@ -1222,6 +1225,75 @@ cleanup:
}
/**
+ * gvir_domain_open_graphics_fd:
+ * @dom: the domain
+ * @idx: the graphics index
+ * @flags: extra flags, currently unused
+ *
+ * This will create a socket pair connected to the graphics backend of @dom. One
+ * end of the socket will be returned on success, and the other end is handed to
+ * the hypervisor. If @dom has multiple graphics backends configured, then @idx
+ * will determine which one is opened, starting from @idx 0.
+ *
+ * Returns: An fd on success, -1 on failure.
+ *
+ * Since: 0.2.0
+ */
+int gvir_domain_open_graphics_fd(GVirDomain *dom,
+ guint idx,
+ unsigned int flags,
+ GError **err)
+{
+ GVirDomainPrivate *priv;
+ int ret = -1;
+#ifndef HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD
+ int pair[2];
+#endif
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), -1);
+ g_return_val_if_fail(err == NULL || *err == NULL, -1);
+
+ priv = dom->priv;
+
+#ifdef HAVE_VIR_DOMAIN_OPEN_GRAPHICS_FD
+ ret = virDomainOpenGraphicsFD(priv->handle, idx, flags);
+ if (ret <= 0) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to open graphics");
+ goto end;
+ }
+
+#else
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) < 0) {
+ g_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Failed to create socket pair");
+ goto end;
+ }
+
+ if (virDomainOpenGraphics(priv->handle, idx, pair[0], flags) < 0) {
+ virErrorPtr vir_err;
+
+ vir_err = virGetLastError();
The 3 lines above can be removed. ACK with that fixed.
Christophe
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to open graphics");
+ close(pair[0]);
+ close(pair[1]);
+
+ goto end;
+ }
+ close(pair[0]);
+ ret = pair[1];
+
+#endif
+
+end:
+ return ret;
+}
+
+/**
* gvir_domain_suspend:
* @dom: the domain to suspend
* @err: Place-holder for possible errors
diff --git a/libvirt-gobject/libvirt-gobject-domain.h
b/libvirt-gobject/libvirt-gobject-domain.h
index 47ed784..4fe381e 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -332,6 +332,10 @@ gboolean gvir_domain_open_graphics(GVirDomain *dom,
int fd,
unsigned int flags,
GError **err);
+int gvir_domain_open_graphics_fd(GVirDomain *dom,
+ guint idx,
+ unsigned int flags,
+ GError **err);
gboolean gvir_domain_suspend (GVirDomain *dom,
GError **err);
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index d18769b..927cad9 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -260,4 +260,9 @@ LIBVIRT_GOBJECT_0.1.9 {
gvir_stream_io_condition_get_type;
} LIBVIRT_GOBJECT_0.1.5;
+LIBVIRT_GOBJECT_0.2.0 {
+ global:
+ gvir_domain_open_graphics_fd;
+} LIBVIRT_GOBJECT_0.1.9;
+
# .... define new API here using predicted next version number ....
--
2.1.0
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list