QEMU Commandline arguments to lib-virt are not accepted – unable to save xml file

kvmqemuvirtual machine

I am trying to get audio working on a Win10 Guest running on a Ubuntu host following this guide https://blog.zerosector.io/2018/07/28/kvm-qemu-windows-10-gpu-passthrough/ .

GPU pass through works however I have issues with audio.
The section that describes how to get audio working requires command line arguments to be passed to the VM by editing the first line of the xml file and then adding these lines at the end:

<qemu:env name='QEMU_AUDIO_DRV' value='pa'/>
<qemu:env name='QEMU_PA_SAMPLES' value='8192'/>
<qemu:env name='QEMU_AUDIO_TIMER_PERIOD' value='99'/>
<qemu:env name='QEMU_PA_SERVER' value='/run/user/1000/pulse/native'/>

The issue that I am having is that when I get to the part where I edit my VM configuration with virsh edit win10 the changes are not saved and the following error occurs:

Failed. Try again? [y,n,i,f,?]: 
error: XML document failed to validate against schema: Unable to 
validate doc against /usr/share/libvirt/schemas/domain.rng
Element domain has extra content: env

I tried both f and i responses, but the xml file does not save and the audio still does not work in the VM.

Doing some research I found that modifying the first line of the xml file from

<domain type='kvm'> to 
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>

does not have an effect as that schema does not exist anymore (404s). Replacing it with the .rng alternative 'https://libvirt.org/schemas/domain.rng' does not work either.

My question is: How do I pass the required commandline arguments to the machine that already exists and is configured through virt-manager?

EDIT: I decided to try again and I managed to figure it out, thanks to Michael Hampton's reply. Check the answer below.

Best Answer

I decided to try again and I managed to figure it out, thanks to Michael Hamptons reply.

Turns out when you want to pass environment variables to the like I was trying to do, you must also include

<qemu:commandline>
...
</qemu:commandline>

before and after the environment variables. The final section of my xml file looks like this:

<qemu:commandline>    
<qemu:env name='QEMU_AUDIO_DRV' value='pa'/>
<qemu:env name='QEMU_PA_SAMPLES' value='8192'/>
<qemu:env name='QEMU_AUDIO_TIMER_PERIOD' value='99'/>
<qemu:env name='QEMU_PA_SERVER' value='/run/user/1000/pulse/native'/>
</qemu:commandline>
Related Question