A good reference commit to see how to implement something like that is this commit adding usb-audio support:
commit e260a0e60a5abc48f27d09900ca3150130919d3fAuthor: Peter Krempa <pkrempa@redhat.com>Date: Thu Jul 24 17:32:31 2014 +0200 conf: Add USB sound card support and implement it for qemu
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related or that one is blocking others.
Learn more.
We're thinking of trying to write a patch for this but we have a few questions to clarify the issue. Mostly we wanted to know what was wrong with Guannan's previous attempt at patching this. Was it incorrect, incomplete, or otherwise lacking? We also were confused on how Peter's usb-audio commit actually addressed an issue. It seems like most of the changes were documentation and constant and only a few changes changed significant amounts of code. We understand that QEMU is the program actually handling the sound card, but how do Peter's changes actually hook up the sound card with QEMU? Would the changes needed for the usb-net device be the same as Peter's usb-audio changes except in different sections of each file, or would the changes need to be made elsewhere? We saw that Peter and Guannan both had changes to tests/qemuhelptest.c and src/qemu/qemu_capabilities.c (to name a few).
According to the discussion on the first patch, the usb-net model name duplicated the net part (which is already implied by the <interface> element) and usb is a bus, not a model of the device. A specific model name based on the device it tries to emulate was requested. I think what was lacking is the real-world requirement for this device.
Peter's changes included:
XML parser and formatter changes
XML schema change
documenting the element
QEMU capability addition
QEMU command line formatting
unit tests for QEMU command line formatting
The parsing and formatting only required adding it to the virDomainSoundModel enum, because we already parse and format the attribute for other models - see the virDomainSoundModelTypeFromString call in virDomainSoundDefParseXML.
Similarly, we already had code that checks QEMU's output for a list of supported devices and code that formats the QEMU command line, so only the code that would be different for this sound model was included. "QEMU capabilities" are our notes about what the currently used QEMU binary can do.
For the sound card, all the interaction we actually do with QEMU is that we put it on the command line when starting the domain (see the addition in tests/qemuxml2argvdata/qemuxml2argv-sound-device.args).
Unlike for sound cards, hotplugging network interfaces is supported by libvirt, so changes to qemu_hotplug.c might be needed too.
Note that tests/qemuhelptest.c no longer exists and tests/qemuxml2argvtest.c no longer requires you to manually list the capabilities and you can simply use DO_TEST_LATEST to use what the latest QEMU supports. Also, Peter's patches could have been split: 1+2+3 belong together, but 4 and 5+6 could have been separated.
For tests, you can just edit the code in src/ (and for xml2argvtest, the input XML file) and generate the output automatically, see: https://libvirt.org/advanced-tests.html