Decouple netdev from nic
cover Decouple netdev from nic
Virtualization management layers would like to decouple host network device (netdev) creation/deletion/setup from guest network adapters.
This would allow to independently:
- provision VMs with NIC(s)
- create and manage network devices on the host
First discussed here:
http://lists.gnu.org/archive/html/qemu-devel/2011-10/msg03614.html
Explicit plug/unplug of a backend netdev device to a VM NIC at runtime would be needed. This patch introduces a command "netdev_set" to attach a netdev device to a guest nic. This allows the following use cases:
1) qemu can start with detached nic and backend netdevs E.g. at boot time nic0 and netdev are not connected:
-netdev type=tap,id=netdev0 -device virtio-net-pci,id=nic0
Warning: netdev guest0 has no peer
Warning: nic net0 has no peer
The following sequence would connect backend device netdev0 to nic nic0
(qemu) set_link nic0 off
(qemu) netdev_set nic0 netdev0
(qemu) set_link nic0 up
Setting the link up/down is done separately with the existing set_link command, but could be added to the semantics of the new command if desired.
2) change of backend netdev at runtime.
E.g. at boot time, nic0 is connected to netdev netdev0:
-netdev type=tap,id=netdev0 -device virtio-net-pci,netdev=netdev0,id=nic0
The following sequence would change the backend device for nic0 to netdev1:
(qemu) set_link nic0 off
(qemu) netdev_del netdevnic0
(qemu) netdev_add id=netdev1,type=tap
(qemu) netdev_set nic0 netdev1
(qemu) set_link nic0 up
(netdev_del will currently call the link_status_changed callback for the guest
device it is attached to, so afaict the first step "set_link off" for the guest device is not strictly needed in this example)
- is this feature of interest upstream? If yes, what's the desired way to implement it in qom? Is there a legitimate way to change a qdev property after a device has been initialized? The netdev property of a guest nic is set at nic initialization time - if we attach a new backend device, how can we update the netdev property?
- A link property for a nic device (link=up/down) which denotes initial status of a nic can also be implemented (not yet in this patch). This way a nic could be initialized with disabled carrier at the command line using link=down.
thoughts, comments welcome.
series is based on
http://repo.or.cz/w/qemu/qmp-unstable.git/qmp-wip/qapi-commands-conv/netdev-add/v2
and can be found here:
https://github.com/vliaskov/qemu-kvm/commits/netdev-decouple
Vasilis Liaskovitis (2):
Implement netdev_set command
virtio-net: re-initialize tap device for new netdev
hmp-commands.hx | 14 +++++++++++++ hmp.c | 10 +++++++++ hmp.h | 1 + hw/virtio-net.c | 30 +++++++++++++++++++++++++++ net.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net.h | 1 + qapi-schema.json | 16 ++++++++++++++ qmp-commands.hx | 25 +++++++++++++++++++++++ 8 files changed, 155 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.9
RFC PATCH 1/2 Implement netdev_set command
This command can be used to attach a host backend network device (netdev) to a guest nic. Syntax is:netdev_set nicid netdevid
This patch adds qmp and hmp support for the command.
--- hmp-commands.hx | 14 +++++++++++++ hmp.c | 10 +++++++++ hmp.h | 1 + net.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ net.h | 1 + qapi-schema.json | 16 ++++++++++++++ qmp-commands.hx | 25 +++++++++++++++++++++++ 7 files changed, 125 insertions(+), 0 deletions(-)
hmp-commands.hx +14 -0
@@ -1032,6 +1032,20 @@ STEXI Remove host network device. ETEXI + { + .name = "netdev_set", + .args_type = "nicid:s,netdevid:s", + .params = "nicid netdevid", + .help = "attach host network device to nic", + .mhandler.cmd = hmp_netdev_set, + }, + +STEXI +@item netdev_del +@findex netdev_del +Attach host network device to nic. +ETEXI + #ifdef CONFIG_SLIRP { .name = "hostfwd_add",
hmp.c +10 -0
@@ -973,3 +973,13 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)qmp_netdev_del (id, &err);hmp_handle_error (mon, &err); } + +void hmp_netdev_set (Monitor *mon,const QDict *qdict) +{ +const char *nicid =qdict_get_str (qdict,"nicid" ); +const char *netdevid =qdict_get_str (qdict,"netdevid" ); +Error *err =NULL ; + +qmp_netdev_set (nicid, netdevid, &err); +hmp_handle_error (mon, &err); +}
hmp.h +1 -0
@@ -63,5 +63,6 @@ void hmp_migrate(Monitor *mon, const QDict *qdict);void hmp_device_del (Monitor *mon,const QDict *qdict);void hmp_netdev_add (Monitor *mon,const QDict *qdict);void hmp_netdev_del (Monitor *mon,const QDict *qdict); +void hmp_netdev_set (Monitor *mon,const QDict *qdict);#endif
net.c +58 -0
70 lines not on this page · raw message
net.h +1 -0
@@ -90,6 +90,7 @@ struct VLANState {VLANState *qemu_find_vlan (int id,int allocate);VLANClientState *qemu_find_netdev (const char *id); +VLANClientState *qemu_find_nic (const char *id); VLANClientState *qemu_new_net_client(NetClientInfo *info, VLANState *vlan, VLANClientState *peer,
qapi-schema.json +16 -0
@@ -1765,3 +1765,19 @@ # Since: 0.14.0 ## { 'command': 'netdev_del', 'data': {'id': 'str'} } + +## +# @netdev_set: +# +# Attach a network backend to a network device. +# +# @id: the name of the network device to attach to +# @netdev: the name of the network backend to attach +# +# Returns: Nothing on success +# If @id is not a valid network device, DeviceNotFound +# If @netdev is not a valid network backend, DeviceNotFound +# +# Since: 0.14.0 +## +{ 'command': 'netdev_set', 'data': {'nicid': 'str', 'netdevid': 'str'} }
qmp-commands.hx +25 -0
@@ -657,6 +657,31 @@ Example: EQMP { + .name = "netdev_set", + .args_type = "nicid:s,netdevid:s", + .mhandler.cmd_new = qmp_marshal_input_netdev_set, + }, + +SQMP +netdev_set +---------- + +Attach host network device to guest nic. + +Arguments: + +- "nicid": the nic device's ID, must be unique (json-string) +- "netdevid": the host network device's ID, must be unique (json-string) + +Example: + +-> { "execute": "netdev_set", "arguments": { "nicid": "nic1", "netdevid": "netdev1" } } +<- { "return": {} } + + +EQMP + + { .name = "block_resize", .args_type = "device:B,size:o", .mhandler.cmd_new = qmp_marshal_input_block_resize,
Signature · 1 line
1.7.9
RFC PATCH 2/2 virtio-net: re-initialize tap device for new netdev
In reply to Vasilis LiaskovitisWhen a nic's backend netdev device is changed, the tap device needs to be re-initialized for vnet_hdr and offload features. Also, vhost will have to be re-initialized. This is currently implemented in the virtio set_status callback function.
--- hw/virtio-net.c | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-)
hw/virtio-net.c +30 -0
@@ -63,6 +63,7 @@ typedef struct VirtIONet } mac_table;uint32_t *vlans;DeviceState *qdev; +VLANClientState *old_peer; } VirtIONet;/* TODO
@@ -137,10 +138,38 @@ static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) } } +static int peer_has_vnet_hdr (VirtIONet *n); +static void virtio_net_set_status (struct VirtIODevice *vdev,uint8_t status) {VirtIONet *n =to_virtio_net (vdev); +uint32_t features; + +/* re-initialize backend netdev if it is has been changed */ +if (n->old_peer != n->nic->nc.peer) { + features = vdev->guest_features; + +if (peer_has_vnet_hdr (n)) +tap_using_vnet_hdr (n->nic->nc.peer,1 ); + +if (n->has_vnet_hdr) { +tap_set_offload (n->nic->nc.peer, + (features >>VIRTIO_NET_F_GUEST_CSUM ) &1 , + (features >>VIRTIO_NET_F_GUEST_TSO4 ) &1 , + (features >>VIRTIO_NET_F_GUEST_TSO6 ) &1 , + (features >>VIRTIO_NET_F_GUEST_ECN ) &1 , + (features >>VIRTIO_NET_F_GUEST_UFO ) &1 ); + } +if ((n->nic->nc.peer->info->type ==NET_CLIENT_TYPE_TAP ) && +tap_get_vhost_net (n->nic->nc.peer)) { +vhost_net_ack_features (tap_get_vhost_net (n->nic->nc.peer), features); + } +/* vhost will have to be restarted */ +if (n->vhost_started) + n->vhost_started =0 ; + n->old_peer = n->nic->nc.peer; + }virtio_net_vhost_status (n, status);if (!n->tx_waiting) {
@@ -1044,6 +1073,7 @@ VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf, n->vlans =g_malloc0 (MAX_VLAN >>3 ); n->qdev = dev; + n->old_peer = conf->peer;register_savevm (dev,"virtio-net" ,-1 ,VIRTIO_NET_VM_VERSION , virtio_net_save, virtio_net_load, n);
Signature · 1 line
1.7.9