qemu: Build smartcard command line more wisely

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

Similarly to b133fac356 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@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Michal Privoznik 2018-03-23 14:24:14 +01:00
parent 1706bef617
commit 42900ec622
4 changed files with 53 additions and 2 deletions

View File

@ -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;

View File

@ -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 \

View File

@ -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'/>

View File

@ -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,