mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
conf: fix formatting of smartcard devices
My commit 0c1d863
broke formatting of passthrough smartcard devices:
<smartcard mode='passthrough' type='spicevmc'/>
resulted in invalid XML:
<smartcard mode='passthrough'>
type='spicevmc'>
<address type='ccid' controller='0' slot='0'/>
</smartcard>
Split out chardev source formatting function into two -
one formatting the attributes and other formatting the subelements.
Reported-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
f536b0dd73
commit
b4f7793ce2
@ -22804,10 +22804,9 @@ virDomainNetDefFormat(virBufferPtr buf,
|
|||||||
/* Assumes that "<device" has already been generated, and starts
|
/* Assumes that "<device" has already been generated, and starts
|
||||||
* output at " type='type'>". */
|
* output at " type='type'>". */
|
||||||
static int
|
static int
|
||||||
virDomainChrSourceDefFormat(virBufferPtr buf,
|
virDomainChrAttrsDefFormat(virBufferPtr buf,
|
||||||
virDomainChrSourceDefPtr def,
|
virDomainChrSourceDefPtr def,
|
||||||
bool tty_compat,
|
bool tty_compat)
|
||||||
unsigned int flags)
|
|
||||||
{
|
{
|
||||||
const char *type = virDomainChrTypeToString(def->type);
|
const char *type = virDomainChrTypeToString(def->type);
|
||||||
|
|
||||||
@ -22823,7 +22822,14 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
|
|||||||
virBufferEscapeString(buf, " tty='%s'",
|
virBufferEscapeString(buf, " tty='%s'",
|
||||||
def->data.file.path);
|
def->data.file.path);
|
||||||
}
|
}
|
||||||
virBufferAddLit(buf, ">\n");
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
virDomainChrSourceDefFormat(virBufferPtr buf,
|
||||||
|
virDomainChrSourceDefPtr def,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
|
||||||
switch ((virDomainChrType)def->type) {
|
switch ((virDomainChrType)def->type) {
|
||||||
case VIR_DOMAIN_CHR_TYPE_NULL:
|
case VIR_DOMAIN_CHR_TYPE_NULL:
|
||||||
@ -22924,7 +22930,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
|
|||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddLit(buf, "/>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -22953,8 +22959,10 @@ virDomainChrDefFormat(virBufferPtr buf,
|
|||||||
def->source->type == VIR_DOMAIN_CHR_TYPE_PTY &&
|
def->source->type == VIR_DOMAIN_CHR_TYPE_PTY &&
|
||||||
!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
|
!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
|
||||||
def->source->data.file.path);
|
def->source->data.file.path);
|
||||||
if (virDomainChrSourceDefFormat(buf, def->source, tty_compat, flags) < 0)
|
if (virDomainChrAttrsDefFormat(buf, def->source, tty_compat) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virDomainChrSourceDefFormat(buf, def->source, flags);
|
||||||
|
|
||||||
/* Format <target> block */
|
/* Format <target> block */
|
||||||
switch (def->deviceType) {
|
switch (def->deviceType) {
|
||||||
@ -23067,9 +23075,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
|
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
|
||||||
if (virDomainChrSourceDefFormat(&childBuf, def->data.passthru, false,
|
virDomainChrSourceDefFormat(&childBuf, def->data.passthru, flags);
|
||||||
flags) < 0)
|
|
||||||
return -1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -23083,6 +23089,10 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<smartcard mode='%s'", mode);
|
virBufferAsprintf(buf, "<smartcard mode='%s'", mode);
|
||||||
|
if (def->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH &&
|
||||||
|
virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (virBufferUse(&childBuf)) {
|
if (virBufferUse(&childBuf)) {
|
||||||
virBufferAddLit(buf, ">\n");
|
virBufferAddLit(buf, ">\n");
|
||||||
virBufferAddBuffer(buf, &childBuf);
|
virBufferAddBuffer(buf, &childBuf);
|
||||||
@ -23390,10 +23400,11 @@ virDomainRNGDefFormat(virBufferPtr buf,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_RNG_BACKEND_EGD:
|
case VIR_DOMAIN_RNG_BACKEND_EGD:
|
||||||
virBufferAdjustIndent(buf, 2);
|
if (virDomainChrAttrsDefFormat(buf, def->source.chardev, false) < 0)
|
||||||
if (virDomainChrSourceDefFormat(buf, def->source.chardev,
|
|
||||||
false, flags) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
virDomainChrSourceDefFormat(buf, def->source.chardev, flags);
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</backend>\n");
|
virBufferAddLit(buf, "</backend>\n");
|
||||||
|
|
||||||
@ -24234,9 +24245,11 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
|
|||||||
bus = virDomainRedirdevBusTypeToString(def->bus);
|
bus = virDomainRedirdevBusTypeToString(def->bus);
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<redirdev bus='%s'", bus);
|
virBufferAsprintf(buf, "<redirdev bus='%s'", bus);
|
||||||
virBufferAdjustIndent(buf, 2);
|
if (virDomainChrAttrsDefFormat(buf, def->source, false) < 0)
|
||||||
if (virDomainChrSourceDefFormat(buf, def->source, false, flags) < 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
virBufferAddLit(buf, ">\n");
|
||||||
|
virBufferAdjustIndent(buf, 2);
|
||||||
|
virDomainChrSourceDefFormat(buf, def->source, flags);
|
||||||
virDomainDeviceInfoFormat(buf, &def->info,
|
virDomainDeviceInfoFormat(buf, &def->info,
|
||||||
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
|
flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-i686</emulator>
|
||||||
|
<controller type='ccid' index='0'/>
|
||||||
|
<controller type='usb' index='0'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||||
|
</controller>
|
||||||
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
|
<smartcard mode='host'>
|
||||||
|
<address type='ccid' controller='0' slot='0'/>
|
||||||
|
</smartcard>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<input type='keyboard' bus='ps2'/>
|
||||||
|
<memballoon model='virtio'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||||
|
</memballoon>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -0,0 +1,34 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-i686</emulator>
|
||||||
|
<controller type='usb' index='0'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||||
|
</controller>
|
||||||
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
|
<controller type='ccid' index='0'/>
|
||||||
|
<smartcard mode='host-certificates'>
|
||||||
|
<certificate>cert1</certificate>
|
||||||
|
<certificate>cert2</certificate>
|
||||||
|
<certificate>cert3</certificate>
|
||||||
|
<address type='ccid' controller='0' slot='0'/>
|
||||||
|
</smartcard>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<input type='keyboard' bus='ps2'/>
|
||||||
|
<memballoon model='virtio'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||||
|
</memballoon>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
31
tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-host.xml
Normal file
31
tests/qemuxml2xmloutdata/qemuxml2xmlout-smartcard-host.xml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-i686</emulator>
|
||||||
|
<controller type='usb' index='0'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||||
|
</controller>
|
||||||
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
|
<controller type='ccid' index='0'/>
|
||||||
|
<smartcard mode='host'>
|
||||||
|
<address type='ccid' controller='0' slot='0'/>
|
||||||
|
</smartcard>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<input type='keyboard' bus='ps2'/>
|
||||||
|
<memballoon model='virtio'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||||
|
</memballoon>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -0,0 +1,31 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-i686</emulator>
|
||||||
|
<controller type='usb' index='0'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||||
|
</controller>
|
||||||
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
|
<controller type='ccid' index='0'/>
|
||||||
|
<smartcard mode='passthrough' type='spicevmc'>
|
||||||
|
<address type='ccid' controller='0' slot='0'/>
|
||||||
|
</smartcard>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<input type='keyboard' bus='ps2'/>
|
||||||
|
<memballoon model='virtio'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||||
|
</memballoon>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -0,0 +1,33 @@
|
|||||||
|
<domain type='qemu'>
|
||||||
|
<name>QEMUGuest1</name>
|
||||||
|
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||||
|
<memory unit='KiB'>219136</memory>
|
||||||
|
<currentMemory unit='KiB'>219136</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='i686' machine='pc'>hvm</type>
|
||||||
|
<boot dev='hd'/>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<emulator>/usr/bin/qemu-system-i686</emulator>
|
||||||
|
<controller type='usb' index='0'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
|
||||||
|
</controller>
|
||||||
|
<controller type='pci' index='0' model='pci-root'/>
|
||||||
|
<controller type='ccid' index='0'/>
|
||||||
|
<smartcard mode='passthrough' type='tcp'>
|
||||||
|
<source mode='bind' host='127.0.0.1' service='2001'/>
|
||||||
|
<protocol type='raw'/>
|
||||||
|
<address type='ccid' controller='0' slot='0'/>
|
||||||
|
</smartcard>
|
||||||
|
<input type='mouse' bus='ps2'/>
|
||||||
|
<input type='keyboard' bus='ps2'/>
|
||||||
|
<memballoon model='virtio'>
|
||||||
|
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||||
|
</memballoon>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
@ -1199,6 +1199,12 @@ mymain(void)
|
|||||||
DO_TEST("cpu-check-default-partial", NONE);
|
DO_TEST("cpu-check-default-partial", NONE);
|
||||||
DO_TEST("cpu-check-default-partial2", NONE);
|
DO_TEST("cpu-check-default-partial2", NONE);
|
||||||
|
|
||||||
|
DO_TEST("smartcard-host", NONE);
|
||||||
|
DO_TEST("smartcard-host-certificates", NONE);
|
||||||
|
DO_TEST("smartcard-passthrough-tcp", NONE);
|
||||||
|
DO_TEST("smartcard-passthrough-spicevmc", NONE);
|
||||||
|
DO_TEST("smartcard-controller", NONE);
|
||||||
|
|
||||||
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
||||||
virFileDeleteTree(fakerootdir);
|
virFileDeleteTree(fakerootdir);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user