[libvirt] [libvirt-designer PATCHv2 8/9] Implement gvir_designer_domain_add_smartcard()

Christophe Fergeau cfergeau at redhat.com
Thu Apr 18 16:12:32 UTC 2013


This setups smartcard redirection to the guest.
I'm not yet fully sure what users could want to tweak there
(there are various ways of setting up the smartcard redirection),
so this code may need to be made more flexible.
The current code is also not checking whether the hypervisor
supports this kind of redirection or not.
---
 examples/virtxml.c                         |  2 ++
 libvirt-designer/libvirt-designer-domain.c | 36 ++++++++++++++++++++++++++++++
 libvirt-designer/libvirt-designer-domain.h |  1 +
 libvirt-designer/libvirt-designer.sym      |  1 +
 4 files changed, 40 insertions(+)

diff --git a/examples/virtxml.c b/examples/virtxml.c
index bd3bfb3..941c9a9 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -650,6 +650,8 @@ main(int argc, char *argv[])
         g_object_unref(gvir_designer_domain_add_usb_redir(domain, &error));
         CHECK_ERROR;
     }
+    g_object_unref(gvir_designer_domain_add_smartcard(domain, &error));
+    CHECK_ERROR;
 
     g_object_unref(gvir_designer_domain_add_sound(domain, &error));
     CHECK_ERROR;
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index e6db016..7aec002 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -698,6 +698,42 @@ gvir_designer_domain_add_usb_redir(GVirDesignerDomain *design, GError **error)
 }
 
 
+/**
+ * gvir_designer_domain_add_smartcard:
+ * @design: (transfer none): the domain designer instance
+ * @error: return location for a #GError, or NULL
+ *
+ * Add a new virtual smartcard reader to @design. This will allow to
+ * share a smartcard reader between the guest and the host.
+ *
+ * Returns: (transfer full): the pointer to the new smartcard device
+ */
+GVirConfigDomainSmartcard *
+gvir_designer_domain_add_smartcard(GVirDesignerDomain *design, GError **error)
+{
+    /* FIXME: check if OS/hypervisor support smartcard, might need
+     *        libosinfo improvements
+     */
+    GVirConfigDomainSmartcardPassthrough *smartcard;
+    GVirConfigDomainChardevSourceSpiceVmc *vmc;
+    GVirConfigDomainChardevSource *source;
+
+    g_return_val_if_fail(GVIR_DESIGNER_IS_DOMAIN(design), NULL);
+    g_return_val_if_fail(!error_is_set(error), NULL);
+
+    smartcard = gvir_config_domain_smartcard_passthrough_new();
+    vmc = gvir_config_domain_chardev_source_spicevmc_new();
+    source = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(vmc);
+    gvir_config_domain_smartcard_passthrough_set_source(smartcard, source);
+    g_object_unref(G_OBJECT(vmc));
+
+    gvir_config_domain_add_device(design->priv->config,
+                                  GVIR_CONFIG_DOMAIN_DEVICE(smartcard));
+
+    return GVIR_CONFIG_DOMAIN_SMARTCARD(smartcard);
+}
+
+
 static void gvir_designer_domain_add_power_management(GVirDesignerDomain *design)
 {
     GVirConfigDomainPowerManagement *pm;
diff --git a/libvirt-designer/libvirt-designer-domain.h b/libvirt-designer/libvirt-designer-domain.h
index 981fd2e..643e3bf 100644
--- a/libvirt-designer/libvirt-designer-domain.h
+++ b/libvirt-designer/libvirt-designer-domain.h
@@ -135,6 +135,7 @@ GVirConfigDomainInterface *gvir_designer_domain_add_interface_network(GVirDesign
 GVirConfigDomainGraphics *gvir_designer_domain_add_graphics(GVirDesignerDomain *design,
                                                             GVirDesignerDomainGraphics type,
                                                             GError **error);
+GVirConfigDomainSmartcard *gvir_designer_domain_add_smartcard(GVirDesignerDomain *design, GError **error);
 GVirConfigDomainSound *gvir_designer_domain_add_sound(GVirDesignerDomain *design, GError **error);
 GVirConfigDomainRedirdev *gvir_designer_domain_add_usb_redir(GVirDesignerDomain *design, GError **error);
 
diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
index 15faac1..91c70f4 100644
--- a/libvirt-designer/libvirt-designer.sym
+++ b/libvirt-designer/libvirt-designer.sym
@@ -22,6 +22,7 @@ LIBVIRT_DESIGNER_0.0.1 {
 	gvir_designer_domain_add_floppy_device;
 	gvir_designer_domain_add_graphics;
 	gvir_designer_domain_add_interface_network;
+	gvir_designer_domain_add_smartcard;
 	gvir_designer_domain_add_sound;
 	gvir_designer_domain_add_usb_redir;
 
-- 
1.8.1.4




More information about the libvir-list mailing list