Hi Laine,
You mentioned:
But again, already-existing tap devices can't be used for interface type='bridge' or type='network' (which also connects the tap to a bridge).
Would you agree with this assessment?
Best regards,
Xuda Zhang
On 2/4/25 11:04 PM, Xuda Zhang wrote:
> Could you help confirm the exact behavior in this case? Specifically:
>
> 1. If a target tap device already exists, does libvirt modify the MAC
> address instead of recreating the device?
Sorry, I needed to qualify that detail a bit (and actually I probably
shouldn't have even brought it up, since it doesn't apply to tap devices
used to connect to a bridge device) - *only for
"<interface type='ethernet' managed='no'>" * an already-existing tap
device can be specified in the XML (with <target dev='blah'/>).
type='ethernet' is used for tap devices that aren't connected to any
bridge (all communication with the guest must then be *routed* by the
host at the IP level, rather than being bridged).
And a detail that I misremembered - when libvirt uses a pre-existing tap
device, it assumes that the creator of the tap already set the MAC
appropriately, so it doesn't modify it.
But again, already-existing tap devices can't be used for interface
type='bridge' or type='network' (which also connects the tap to a bridge).
> 2. Under what circumstances does libvirt destroy and recreate the tap
> device instead of modifying its attributes?
Another detail that I've forgotten over the long time since I last
looked at this code. libvirt doesn't explicitly delete the tap device,
it just closes the device. In the case of tap devices that libvirt
itself created, they are automatically deleted when they are closed.
In the case of pre-existing tap devices (which again doesn't apply in
your use case), 1) libvirt assumes that the creator of the pre-existing
device has already set the MAC address to something appropriate, so it
doesn't attempt to change it, and 2) again libvirt won't explicitly
delete the tap device. If it was created as a persistent device, then
closing it doesn't cause it to be auto-deleted, but if the original
creator of the tap device didn't create it as persistent, and no other
process has an open handle for the device, then again closing the device
will auto-delete it.
But again, for your use case (where the tap is connected to a bridge)
the creator of the tap device is always libvirt, and so it will always
be auto-deleted when libvirt closes the final handle it has open on the
device.
> Looking forward to your insights!
>
> Best regards,
> Xuda Zhang