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

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



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 c9dc36d..b56ce0d 100644
--- a/examples/virtxml.c
+++ b/examples/virtxml.c
@@ -577,6 +577,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;
 
     if (arch_str) {
         gvir_designer_domain_setup_container_full(domain, arch_str, &error);
diff --git a/libvirt-designer/libvirt-designer-domain.c b/libvirt-designer/libvirt-designer-domain.c
index 50d09c5..601cde5 100644
--- a/libvirt-designer/libvirt-designer-domain.c
+++ b/libvirt-designer/libvirt-designer-domain.c
@@ -700,6 +700,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 1c130c6..1102232 100644
--- a/libvirt-designer/libvirt-designer-domain.h
+++ b/libvirt-designer/libvirt-designer-domain.h
@@ -121,6 +121,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);
 GVirConfigDomainRedirdev *gvir_designer_domain_add_usb_redir(GVirDesignerDomain *design, GError **error);
 
 gboolean gvir_designer_domain_setup_resources(GVirDesignerDomain *design,
diff --git a/libvirt-designer/libvirt-designer.sym b/libvirt-designer/libvirt-designer.sym
index eec33b1..3441bec 100644
--- a/libvirt-designer/libvirt-designer.sym
+++ b/libvirt-designer/libvirt-designer.sym
@@ -18,6 +18,7 @@ LIBVIRT_DESIGNER_0.0.1 {
 	gvir_designer_domain_add_disk_device;
 	gvir_designer_domain_add_graphics;
 	gvir_designer_domain_add_interface_network;
+	gvir_designer_domain_add_smartcard;
 	gvir_designer_domain_add_usb_redir;
 
 	gvir_designer_domain_setup_resources;
-- 
1.8.1.4


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