[PATCH] qemu: Build smartcard command line more wisely

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

 



https://bugzilla.redhat.com/show_bug.cgi?id=1558317

Similarly to b133fac356324c3 we need to look up alias of CCID
controller when constructing smartcard command line instead of
relying on broken assumption it will always be 'ccid0'. After
user aliases it can be anything.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                  | 38 +++++++++++++++++++++++++++++++-
 tests/qemuxml2argvdata/user-aliases.args |  3 +++
 tests/qemuxml2argvdata/user-aliases.xml  | 11 +++++++++
 tests/qemuxml2argvtest.c                 |  3 ++-
 4 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a8afbd14fa..937a7d1b7b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8701,6 +8701,32 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
 }
 
 
+static const char *
+qemuBuildSmartcardFindCCIDController(const virDomainDef *def,
+                                     const virDomainSmartcardDef *smartcard)
+{
+    size_t i;
+
+    /* Should never happen. But doesn't hurt to check. */
+    if (smartcard->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID)
+        return NULL;
+
+    for (i = 0; i < def->ncontrollers; i++) {
+        const virDomainControllerDef *tmp = def->controllers[i];
+
+        if (tmp->type != VIR_DOMAIN_CONTROLLER_TYPE_CCID)
+            continue;
+
+        if (tmp->idx != smartcard->info.addr.ccid.controller)
+            continue;
+
+        return tmp->info.alias;
+    }
+
+    return NULL;
+}
+
+
 static int
 qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
                               virCommandPtr cmd,
@@ -8714,6 +8740,7 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
     char *devstr;
     virBuffer opt = VIR_BUFFER_INITIALIZER;
     const char *database;
+    const char *contAlias = NULL;
 
     if (!def->nsmartcards)
         return 0;
@@ -8811,8 +8838,17 @@ qemuBuildSmartcardCommandLine(virLogManagerPtr logManager,
         virBufferFreeAndReset(&opt);
         return -1;
     }
+
+    if (!(contAlias = qemuBuildSmartcardFindCCIDController(def,
+                                                           smartcard))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to find controller for %s"),
+                       smartcard->info.alias);
+        return -1;
+    }
+
     virCommandAddArg(cmd, "-device");
-    virBufferAsprintf(&opt, ",id=%s,bus=ccid0.0", smartcard->info.alias);
+    virBufferAsprintf(&opt, ",id=%s,bus=%s.0", smartcard->info.alias, contAlias);
     virCommandAddArgBuffer(cmd, &opt);
 
     return 0;
diff --git a/tests/qemuxml2argvdata/user-aliases.args b/tests/qemuxml2argvdata/user-aliases.args
index 4c9c951cef..ad93947104 100644
--- a/tests/qemuxml2argvdata/user-aliases.args
+++ b/tests/qemuxml2argvdata/user-aliases.args
@@ -31,6 +31,8 @@ server,nowait \
 -global PIIX4_PM.disable_s4=0 \
 -boot cd \
 -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x8 \
+-device usb-ccid,id=ua-myCCID,bus=ua-SomeWeirdController.0,port=1 \
+-device usb-ccid,id=ua-myCCID2,bus=ua-SomeWeirdController.0,port=2 \
 -usb \
 -drive file=/var/lib/libvirt/images/fd.img,format=raw,if=none,\
 id=drive-ua-myDisk1,cache=none \
@@ -55,6 +57,7 @@ bus=pci.0,addr=0x9 \
 -device rtl8139,vlan=2,id=ua-AndAlsoClientMode,mac=52:54:00:8c:b1:f8,bus=pci.0,\
 addr=0xa \
 -net socket,connect=127.0.0.1:1234,vlan=2,name=hostua-AndAlsoClientMode \
+-device ccid-card-emulated,backend=nss-emulated,id=smartcard0,bus=ua-myCCID.0 \
 -chardev pty,id=charserial0 \
 -device isa-serial,chardev=charserial0,id=serial0 \
 -chardev pty,id=charserial1 \
diff --git a/tests/qemuxml2argvdata/user-aliases.xml b/tests/qemuxml2argvdata/user-aliases.xml
index 52132a82d7..9ce123b477 100644
--- a/tests/qemuxml2argvdata/user-aliases.xml
+++ b/tests/qemuxml2argvdata/user-aliases.xml
@@ -85,6 +85,14 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
     </controller>
     <controller type='fdc' index='0'/>
+    <controller type='ccid' index='0'>
+      <alias name='ua-myCCID'/>
+      <address type='usb' bus='0' port='1'/>
+    </controller>
+    <controller type='ccid' index='1'>
+      <alias name='ua-myCCID2'/>
+      <address type='usb' bus='0' port='2'/>
+    </controller>
     <interface type='ethernet'>
       <mac address='52:54:00:d6:c0:0b'/>
       <model type='virtio'/>
@@ -109,6 +117,9 @@
       <alias name='ua-AndAlsoClientMode'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
     </interface>
+    <smartcard mode='host'>
+      <address type='ccid' controller='0' slot='0'/>
+    </smartcard>
     <serial type='pty'>
       <target type='isa-serial' port='0'>
         <model name='isa-serial'/>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 5ece3f0cc6..064fd3b767 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2995,7 +2995,8 @@ mymain(void)
             QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_PIIX_DISABLE_S3,
             QEMU_CAPS_PIIX_DISABLE_S4, QEMU_CAPS_VNC,
             QEMU_CAPS_DEVICE_ISA_SERIAL,
-            QEMU_CAPS_HDA_DUPLEX);
+            QEMU_CAPS_HDA_DUPLEX,
+            QEMU_CAPS_CCID_EMULATED);
     DO_TEST("user-aliases2", QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_ICH9_AHCI);
     DO_TEST("user-aliases-usb", QEMU_CAPS_KVM,
             QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4,
-- 
2.16.1

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

  Powered by Linux