This is the bare minimum code required to allow libvirt to connect
to an externally launched QEMU instance, reverse engineering the
XML configuration from the command line args.
$ qemu-kvm -cdrom ~/demo.iso \
-monitor unix:/tmp/demo,server,nowait \
-name foo \
-uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea &
$ QEMUPID=$$
$ virsh qemu-attach $QEMUPID
Domain foo attached to pid 10079
$ ./tools/virsh dumpxml foo
<domain type='kvm' id='3'>
<name>foo</name>
<uuid>cece4f9f-dff0-575d-0e8e-01fe380f12ea</uuid>
<memory>65536</memory>
<currentMemory>65536</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc-0.14'>hvm</type>
</os>
<features>
<acpi/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
<disk type='file' device='cdrom'>
<source file='/home/berrange/demo.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1'
unit='0'/>
</disk>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x1'/>
</controller>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='5901' autoport='no'/>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x03' function='0x0'/>
</memballoon>
</devices>
</domain>
The biggest problem is that our ARGV-> XML convertor does not know
about the -device syntax people often now use.
There is also some robustness work to be done the QEMU driver in
general, to remove some assumptions that no longer hold true. For
example in our domain shutdown code, there are bits of cleanup
we should skip because we will not have done the corresponding
setup in the first place.
We also need to verify what happens with all the various APIs
particularly device hotplug, to ensure there are no bad results.
That said, even as it is, this functionality will be quite
useful for QEMU developers