[libvirt-users] sttic vnet device for guest

On 28.10.2016 11:09, Anton Gorlov wrote:
Can i assign static vnet* device for some guests?
What do you mean? vnet* devices are created by libvirt when a domain is being started (or on device hotplug). In general, unless all devices would be statically allocated, it would be impossible to guarantee certain vnet name. However, what you can do is to create the device yourself and then just tell libvirt to use it: <interface type='bridge'> <source bridge='vnetX'/> </interface> But most likely, the problem you are trying to solve looks for a different solution. If you need the device name in order to set up some environment (e.g. apply some FW rules on the device), we have network hooks and domain hooks - user defined scripts that are run by libvirt on various events (e.g. domain startup, device hotplug, etc.). You should consider those. Michal

28.10.2016 23:32, Michal Privoznik пишет: On my host node i using system created bridge. example brctl show br1 bridge name bridge id STP enabled interfaces br1 8000.0025907925d3 no eth1 vnet0 vnet2 vnet3 vnetN - guest net adapter, It added to bridge at guest's node started. bridge defined as == <network> <name>internal</name> <forward mode="bridge"/> <bridge name="br1"/> </network> == But in guest config xml vnet[0-3] nod defined === <interface type='network'> <mac address='52:54:00:b3:b0:47'/> <source network='internal'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ===
Can i assign static vnet* device for some guests? What do you mean? vnet* devices are created by libvirt when a domain is being started (or on device hotplug). In general, unless all devices would be statically allocated, it would be impossible to guarantee certain vnet name.
However, what you can do is to create the device yourself and then just tell libvirt to use it:
<interface type='bridge'> <source bridge='vnetX'/> </interface>
But most likely, the problem you are trying to solve looks for a different solution. If you need the device name in order to set up some environment (e.g. apply some FW rules on the device), we have network hooks and domain hooks - user defined scripts that are run by libvirt on various events (e.g. domain startup, device hotplug, etc.). You should consider those.
Michal

On 28.10.2016 14:17, Anton Gorlov wrote:
28.10.2016 23:32, Michal Privoznik пишет:
On my host node i using system created bridge. example
brctl show br1 bridge name bridge id STP enabled interfaces br1 8000.0025907925d3 no eth1 vnet0 vnet2 vnet3
vnetN - guest net adapter, It added to bridge at guest's node started.
bridge defined as == <network> <name>internal</name> <forward mode="bridge"/> <bridge name="br1"/> </network> ==
But in guest config xml vnet[0-3] nod defined === <interface type='network'> <mac address='52:54:00:b3:b0:47'/> <source network='internal'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> ===
Sure. As I said - it is allocated at domain start up phase. Because that's when we know what's the next free device (or name that we can use for the device). If you start the domain, with your configuration libvirt will create vnetX and plug it into br1. Essentially, target device is runtime information, thus not present in config XML. Michal

On 10/28/2016 05:30 PM, Michal Privoznik wrote:
28.10.2016 23:32, Michal Privoznik пишет:
On my host node i using system created bridge. example
brctl show br1 bridge name bridge id STP enabled interfaces br1 8000.0025907925d3 no eth1 vnet0 vnet2 vnet3
vnetN - guest net adapter, It added to bridge at guest's node started.
bridge defined as == <network> <name>internal</name> <forward mode="bridge"/> <bridge name="br1"/> </network> ==
But in guest config xml vnet[0-3] nod defined === <interface type='network'> <mac address='52:54:00:b3:b0:47'/> <source network='internal'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> === Sure. As I said - it is allocated at domain start up phase. Because
On 28.10.2016 14:17, Anton Gorlov wrote: that's when we know what's the next free device (or name that we can use for the device). If you start the domain, with your configuration libvirt will create vnetX and plug it into br1. Essentially, target device is runtime information, thus not present in config XML.
... but *is* in the status xml (i.e. the output of "visrh dumpxml $domain" while the domain is running, and also the xml provided on stdin to the qemu and network hooks when they are called). (also, what Vincent said in his email - names with the prefix "vnet" are assumed to be "leftover" from a previous instance of the domain (for better or worse) an replaced with an autogenerated name. But if you supply a name that doesn't start with "vnet", it will be used).

31.10.2016 16:45, Laine Stump пишет:
... but *is* in the status xml (i.e. the output of "visrh dumpxml $domain" while the domain is running, and also the xml provided on stdin to the qemu and network hooks when they are called).
(also, what Vincent said in his email - names with the prefix "vnet" are assumed to be "leftover" from a previous instance of the domain (for better or worse) an replaced with an autogenerated name. But if you supply a name that doesn't start with "vnet", it will be used).
Hmm. What right way to manualy create my vnet device (example privnet0) and apply it device for guest?

❦ 3 novembre 2016 20:43 +0300, Anton Gorlov <stalker@altlinux.ru> :
... but *is* in the status xml (i.e. the output of "visrh dumpxml $domain" while the domain is running, and also the xml provided on stdin to the qemu and network hooks when they are called).
(also, what Vincent said in his email - names with the prefix "vnet" are assumed to be "leftover" from a previous instance of the domain (for better or worse) an replaced with an autogenerated name. But if you supply a name that doesn't start with "vnet", it will be used).
Hmm. What right way to manualy create my vnet device (example privnet0) and apply it device for guest?
You can create it with tunctl. -- For a light heart lives long. -- Shakespeare, "Love's Labour's Lost"

03.11.2016 21:49, Vincent Bernat пишет:
... but *is* in the status xml (i.e. the output of "visrh dumpxml $domain" while the domain is running, and also the xml provided on stdin to the qemu and network hooks when they are called). (also, what Vincent said in his email - names with the prefix "vnet" are assumed to be "leftover" from a previous instance of the domain (for better or worse) an replaced with an autogenerated name. But if you supply a name that doesn't start with "vnet", it will be used). Hmm. What right way to manualy create my vnet device (example privnet0) and apply it device for guest? You can create it with tunctl.
create device by command ip tuntap add dev privnet0 mode tap one_queue vnet_hdr set it in guest xml by <interface type='network'> <mac address='52:54:00:e8:6d:19'/> <source network='testnet'/> <target dev='privnet0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> testnet is <network> <name>testnet</name> <uuid>f31d8d1b-9ff4-8bf7-d8b6-e6bd8759a2f1</uuid> <forward mode='bridge'/> <bridge name='br0' /> </network> guest start, privnet0 added to bridge br0 and set up. work fine. after guest is shutdown privnet0 is not removed from bridge br0 and guest not started after. What is wrong?

What i doing wrong? 03.11.2016 22:49, Anton Gorlov пишет:
create device by command ip tuntap add dev privnet0 mode tap one_queue vnet_hdr
set it in guest xml by
<interface type='network'> <mac address='52:54:00:e8:6d:19'/> <source network='testnet'/> <target dev='privnet0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
testnet is
<network> <name>testnet</name> <uuid>f31d8d1b-9ff4-8bf7-d8b6-e6bd8759a2f1</uuid> <forward mode='bridge'/> <bridge name='br0' /> </network>
guest start, privnet0 added to bridge br0 and set up. work fine. after guest is shutdown privnet0 is not removed from bridge br0 and guest not started after. What is wrong?

❦ 28 octobre 2016 14:32 -0700, Michal Privoznik <mprivozn@redhat.com> :
vnet* devices are created by libvirt when a domain is being started (or on device hotplug). In general, unless all devices would be statically allocated, it would be impossible to guarantee certain vnet name.
However, what you can do is to create the device yourself and then just tell libvirt to use it:
<interface type='bridge'> <source bridge='vnetX'/> </interface>
I think that libvirt will just dismiss the interface because of its prefix and creates another one itself. It would work with another prefix. -- Make sure your code "does nothing" gracefully. - The Elements of Programming Style (Kernighan & Plauger)
participants (4)
-
Anton Gorlov
-
Laine Stump
-
Michal Privoznik
-
Vincent Bernat