kvm tools: Allow the user to pass a FD to use as a TAP device
PATCH 1/1 kvm tools: Allow the user to pass a FD to use as a TAP device
This allows users to pass a pre-configured fd to use for the network interface.
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3
--- tools/kvm/builtin-run.c | 2 ++ tools/kvm/include/kvm/virtio-net.h | 1 + tools/kvm/virtio/net.c | 6 ++++++ 3 files changed, 9 insertions(+), 0 deletions(-)
tools/kvm/builtin-run.c +2 -0
@@ -220,6 +220,8 @@ static int set_net_param(struct virtio_net_params *p, const char *param, p->host_ip =strdup (val); }else if (strcmp (param,"vhost" ) ==0 ) { p->vhost =atoi (val); + }else if (strcmp (param,"fd" ) ==0 ) { + p->fd =atoi (val); }return 0 ;
tools/kvm/include/kvm/virtio-net.h +1 -0
@@ -12,6 +12,7 @@ struct virtio_net_params {struct kvm *kvm;int mode;int vhost; +int fd; };void virtio_net__init (const struct virtio_net_params *params);
tools/kvm/virtio/net.c +6 -0
@@ -178,6 +178,12 @@ static bool virtio_net__tap_init(const struct virtio_net_params *params,struct sockaddr_in sin = {0 };struct ifreq ifr; +/* Did the user already gave us the FD? */ +if (params->fd) { + ndev->tap_fd = params->fd; +return 1 ; + } + ndev->tap_fd =open ("/dev/net/tun" ,O_RDWR );if (ndev->tap_fd <0 ) {pr_warning ("Unable to open /dev/net/tun" );
Signature · 1 line
1.7.8
Quoted 9 lines · Sasha Levin
This allows users to pass a pre-configured fd to use for the network interface.
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3Cc Daniel P. Berrange <[email protected]>Cc Osier Yang <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Daniel, Osier, I assume this is useful for libvirt?
Quoted 4 lines · Pekka Enberg
Quoted 3 lines · Sasha Levin
This allows users to pass a pre-configured fd to use for the network interface.
Quoted 8 lines
Quoted 6 lines
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3Cc Daniel P. Berrange <[email protected]>Cc Osier Yang <[email protected]>Signed-off-by Sasha Levin <[email protected]>Daniel, Osier, I assume this is useful for libvirt?
Yes, this works.
I don't know if kvmtool supports the VNET_HDR extension yet, but if it does, then we can make libvirt pass in a pre-opened FD for that too.
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Pekka Enberg
AppliedQuoted 8 lines · Daniel P. Berrange
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
This allows users to pass a pre-configured fd to use for the network interface.
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Cc Daniel P. Berrange <[email protected]>Cc Osier Yang <[email protected]>Signed-off-by Sasha Levin <[email protected]>Daniel, Osier, I assume this is useful for libvirt?
Yes, this works.
Applied, thanks!
Quoted 15 lines · Pekka Enberg
Quoted 13 lines · Daniel P. Berrange
Quoted 12 lines · Pekka Enberg
Quoted 9 lines · Sasha Levin
This allows users to pass a pre-configured fd to use for the network interface.
For example:
kvm run -n mode=tap,fd=3 3<>/dev/net/tap3Cc Daniel P. Berrange <[email protected]>Cc Osier Yang <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Daniel, Osier, I assume this is useful for libvirt?
Yes, this works.
Applied, thanks!
/me late to see the news. :)
I'm going to update the codes to support that.
Regards,
Osier