Skip to contentSkip to conversation

kvm tools: Allow the user to pass a FD to use as a TAP device

PATCH Applied Sasha Levin 4 participants 5 messages Dec 7, 2011 – Dec 8, 2011 KVM

lore
Share & tools
lore
#0 lore raw

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
Cc Daniel P. Berrange <[email protected]>
Cc Osier Yang <[email protected]>
---
 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
index 9148d83..924ae80 100644
@@ -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
index dade8cb..a3219b6 100644
@@ -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
index 3fb5054..9b93c5d 100644
@@ -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
#2 lore raw
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/tap3

Cc Daniel P. Berrange <[email protected]>
Cc Osier Yang <[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 :|
Applied
#3 lore raw
Quoted 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]>

Daniel, Osier, I assume this is useful for libvirt?

Yes, this works.

Applied, thanks!

#4 lore raw
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/tap3
Cc Daniel P. Berrange <[email protected]>
Cc Osier Yang <[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