[libvirt] [PATCH libvirt-glib 1/2] Add binding for virDomainOpenConsole

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-domain.c | 48 ++++++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 6 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 55 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 7bfb0ae..331a533 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -589,3 +589,51 @@ end: virStreamFree(st); return mime; } + + +/** + * gvir_domain_open_console: + * @dom: (transfer none): the domain + * @devname: (transfer none)(allow-none): the device name + * @stream: (transfer none): stream to use as output + * @flags: extra flags, currently unused + * + * Open a text console for the domain @dom, connecting it to the + * stream @stream. If @devname is NULL, the default console will + * be opened, otherwise @devname can be used to specify a non-default + * console device. + * + * Returns: TRUE if the console was opened, FALSE otherwise. + */ +gboolean gvir_domain_open_console(GVirDomain *dom, + GVirStream *stream, + const gchar *devname, + guint flags, + GError **err) +{ + GVirDomainPrivate *priv; + virStreamPtr st = NULL; + gboolean ret = FALSE; + + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); + g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE); + + priv = dom->priv; + g_object_get(stream, "handle", &st, NULL); + + if (virDomainOpenConsole(priv->handle, + devname, + st, + flags) < 0) { + gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to open console"); + goto cleanup; + } + + ret = TRUE; +cleanup: + if (st != NULL) + virStreamFree(st); + return ret; +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index b9e39dd..3a4dd02 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -141,6 +141,12 @@ gchar *gvir_domain_screenshot(GVirDomain *dom, guint flags, GError **err); +gboolean gvir_domain_open_console(GVirDomain *dom, + GVirStream *stream, + const gchar *devname, + guint flags, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index d0444bd..caef28d 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -52,6 +52,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_domain_resume; gvir_domain_stop; gvir_domain_delete; + gvir_domain_open_console; gvir_domain_shutdown; gvir_domain_reboot; gvir_domain_get_config; -- 1.7.7.3

From: "Daniel P. Berrange" <berrange@redhat.com> --- libvirt-gobject/libvirt-gobject-domain.c | 41 ++++++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 6 ++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 331a533..677d64b 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -637,3 +637,44 @@ cleanup: virStreamFree(st); return ret; } + + +/** + * gvir_domain_open_graphics: + * @dom: the domain + * @idx: the graphics index + * @fd: pre-opened socket pair + * @flags: extra flags, currently unused + * + * Open a connection to the local graphics display, connecting it to the + * socket pair file descriptor passed in as @fd. + * + * Returns: TRUE if the graphics connection was opened, FALSE otherwise. + */ +gboolean gvir_domain_open_graphics(GVirDomain *dom, + guint idx, + int fd, + unsigned int flags, + GError **err) +{ + GVirDomainPrivate *priv; + gboolean ret = FALSE; + + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); + + priv = dom->priv; + + if (virDomainOpenGraphics(priv->handle, + idx, + fd, + flags) < 0) { + gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to open graphics"); + goto cleanup; + } + + ret = TRUE; +cleanup: + return ret; +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 3a4dd02..6fcec8d 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -147,6 +147,12 @@ gboolean gvir_domain_open_console(GVirDomain *dom, guint flags, GError **err); +gboolean gvir_domain_open_graphics(GVirDomain *dom, + guint idx, + int fd, + unsigned int flags, + GError **err); + G_END_DECLS #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */ -- 1.7.7.3

On Mon, Dec 12, 2011 at 04:04:45PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-domain.c | 41 ++++++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 6 ++++
No addition to the .sym file?
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 331a533..677d64b 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -637,3 +637,44 @@ cleanup: virStreamFree(st); return ret; } + + +/** + * gvir_domain_open_graphics: + * @dom: the domain + * @idx: the graphics index
idx refers to the index of the <graphics> device node we are interested in in the domain config? The API looks a bit complicated to me, but I'm not sure it's easy to come up with something nicer :-/ The rest looks good to me. Christophe
+ * @fd: pre-opened socket pair + * @flags: extra flags, currently unused + * + * Open a connection to the local graphics display, connecting it to the + * socket pair file descriptor passed in as @fd. + * + * Returns: TRUE if the graphics connection was opened, FALSE otherwise. + */ +gboolean gvir_domain_open_graphics(GVirDomain *dom, + guint idx, + int fd, + unsigned int flags, + GError **err) +{ + GVirDomainPrivate *priv; + gboolean ret = FALSE; + + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); + + priv = dom->priv; + + if (virDomainOpenGraphics(priv->handle, + idx, + fd, + flags) < 0) { + gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to open graphics"); + goto cleanup; + } + + ret = TRUE; +cleanup: + return ret; +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 3a4dd02..6fcec8d 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -147,6 +147,12 @@ gboolean gvir_domain_open_console(GVirDomain *dom, guint flags, GError **err);
+gboolean gvir_domain_open_graphics(GVirDomain *dom, + guint idx, + int fd, + unsigned int flags, + GError **err); + G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */ -- 1.7.7.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On Thu, Dec 15, 2011 at 05:59:31PM +0100, Christophe Fergeau wrote:
On Mon, Dec 12, 2011 at 04:04:45PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-domain.c | 41 ++++++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 6 ++++
No addition to the .sym file?
Opps, yeah, need that.
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 331a533..677d64b 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -637,3 +637,44 @@ cleanup: virStreamFree(st); return ret; } + + +/** + * gvir_domain_open_graphics: + * @dom: the domain + * @idx: the graphics index
idx refers to the index of the <graphics> device node we are interested in in the domain config? The API looks a bit complicated to me, but I'm not sure it's easy to come up with something nicer :-/
Yeah, there's not really much of an alternative Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Mon, Dec 12, 2011 at 04:04:44PM +0000, Daniel P. Berrange wrote:
From: "Daniel P. Berrange" <berrange@redhat.com>
--- libvirt-gobject/libvirt-gobject-domain.c | 48 ++++++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 6 ++++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index 7bfb0ae..331a533 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -589,3 +589,51 @@ end: virStreamFree(st); return mime; } + + +/** + * gvir_domain_open_console: + * @dom: (transfer none): the domain + * @devname: (transfer none)(allow-none): the device name + * @stream: (transfer none): stream to use as output + * @flags: extra flags, currently unused + * + * Open a text console for the domain @dom, connecting it to the + * stream @stream. If @devname is NULL, the default console will + * be opened, otherwise @devname can be used to specify a non-default + * console device. + * + * Returns: TRUE if the console was opened, FALSE otherwise. + */ +gboolean gvir_domain_open_console(GVirDomain *dom, + GVirStream *stream, + const gchar *devname, + guint flags, + GError **err) +{ + GVirDomainPrivate *priv; + virStreamPtr st = NULL; + gboolean ret = FALSE; + + g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); + g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE); + + priv = dom->priv; + g_object_get(stream, "handle", &st, NULL); + + if (virDomainOpenConsole(priv->handle, + devname, + st, + flags) < 0) { + gvir_set_error_literal(err, GVIR_DOMAIN_ERROR, + 0, + "Unable to open console"); + goto cleanup; + } + + ret = TRUE; +cleanup: + if (st != NULL) + virStreamFree(st);
I'd go with g_boxed_free I think, but that's just a small detail, ACK. Christophe
+ return ret; +} diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index b9e39dd..3a4dd02 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -141,6 +141,12 @@ gchar *gvir_domain_screenshot(GVirDomain *dom, guint flags, GError **err);
+gboolean gvir_domain_open_console(GVirDomain *dom, + GVirStream *stream, + const gchar *devname, + guint flags, + GError **err); + G_END_DECLS
#endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index d0444bd..caef28d 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -52,6 +52,7 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_domain_resume; gvir_domain_stop; gvir_domain_delete; + gvir_domain_open_console; gvir_domain_shutdown; gvir_domain_reboot; gvir_domain_get_config; -- 1.7.7.3
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (2)
-
Christophe Fergeau
-
Daniel P. Berrange