[RFC PATCHv2 5/5] WIP: smartcard: turn on qemu support

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

 



Still to go - add .args files to match .xml files in testsuite

* src/qemu/qemu_command.c (qemuBuildCommandLine): Emit smartcard
options.
(qemuAssignDeviceAliases): Assign an alias for smartcard passthrough.
* tests/qemuxml2argvtest.c (mymain): Three new tests.
* tests/qemuxml2argvdata/...arg: Three new files.
---

Well, as you can see, the tests/ part isn't done yet.

 src/qemu/qemu_command.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 205c303..d02241f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -604,6 +604,11 @@ qemuAssignDeviceAliases(virDomainDefPtr def, unsigned long long qemuCmdFlags)
         if (virAsprintf(&def->channels[i]->info.alias, "channel%d", i) < 0)
             goto no_memory;
     }
+    for (i = 0; i < def->nsmartcards ; i++) {
+        if (def->smartcards[i]->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH &&
+            virAsprintf(&def->smartcards[i]->info.alias, "smartcard%d", i) < 0)
+            goto no_memory;
+    }
     if (def->console) {
         if (virAsprintf(&def->console->info.alias, "console%d", i) < 0)
             goto no_memory;
@@ -3332,6 +3337,50 @@ qemuBuildCommandLine(virConnectPtr conn,
         }
     }

+    if (def->nsmartcards) {
+        /* Requires -chardev and -device usb-ccid */
+        if (!(qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) ||
+            !(qemuCmdFlags & QEMUD_CMD_FLAG_USB_CCID)) {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                            _("smartcard requires QEMU to support -usb-ccid"));
+            goto error;
+        }
+        virCommandAddArgList(cmd, "-device", "usb-ccid", NULL);
+    }
+    for (i = 0 ; i < def->nsmartcards ; i++) {
+        virDomainSmartcardDefPtr smartcard = def->smartcards[i];
+        char *devstr;
+        virBuffer smartcard_buf = VIR_BUFFER_INITIALIZER;
+        int j;
+
+        switch (smartcard->type) {
+        case VIR_DOMAIN_SMARTCARD_TYPE_HOST:
+            virCommandAddArgList(cmd, "-device", "ccid-card-emulated", NULL);
+            break;
+        case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES:
+            virCommandAddArg(cmd, "-device");
+            virBufferAddLit(&smartcard_buf,
+                            "ccid-card-emulated,backend=certificates");
+            for (j = 0; j < VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES; j++)
+                virBufferVSprintf(&smartcard_buf, ",cert%d=%s", j + 1,
+                                  smartcard->data.cert.file[j]);
+            virCommandAddArgBuffer(cmd, &smartcard_buf);
+            break;
+        case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
+            virCommandAddArg(cmd, "-chardev");
+            if (!(devstr = qemuBuildChrChardevStr(&smartcard->data.passthru,
+                                                  smartcard->info.alias)))
+                    goto error;
+            virCommandAddArg(cmd, devstr);
+            VIR_FREE(devstr);
+
+            virCommandAddArg(cmd, "-device");
+            virCommandAddArgFormat(cmd, "ccid-card-passthru,chardev=%s",
+                                   smartcard->info.alias);
+            break;
+        }
+    }
+
     if (!def->nserials) {
         /* If we have -device, then we set -nodefault already */
         if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE))
-- 
1.7.3.4

--
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]