kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device
@ 2011-12-07  9:37 Sasha Levin
  2011-12-07 16:28 ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Sasha Levin @ 2011-12-07  9:37 UTC (permalink / raw)
  To: penberg
  Cc: mingo, gorcunov, asias.hejun, kvm, Sasha Levin,
	Daniel P. Berrange, Osier Yang

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 <berrange@redhat.com>
Cc: Osier Yang <jyang@redhat.com>
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 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(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 9148d83..924ae80 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -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;
diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h
index dade8cb..a3219b6 100644
--- a/tools/kvm/include/kvm/virtio-net.h
+++ b/tools/kvm/include/kvm/virtio-net.h
@@ -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);
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 3fb5054..9b93c5d 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -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");
-- 
1.7.8


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device
  2011-12-07  9:37 [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device Sasha Levin
@ 2011-12-07 16:28 ` Pekka Enberg
  2011-12-07 16:38   ` Daniel P. Berrange
  0 siblings, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2011-12-07 16:28 UTC (permalink / raw)
  To: Sasha Levin
  Cc: mingo, gorcunov, asias.hejun, kvm, Daniel P. Berrange, Osier Yang

On Wed, Dec 7, 2011 at 11:37 AM, Sasha Levin <levinsasha928@gmail.com> wrote:
> 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 <berrange@redhat.com>
> Cc: Osier Yang <jyang@redhat.com>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device
  2011-12-07 16:28 ` Pekka Enberg
@ 2011-12-07 16:38   ` Daniel P. Berrange
  2011-12-07 17:24     ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel P. Berrange @ 2011-12-07 16:38 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, mingo, gorcunov, asias.hejun, kvm, Osier Yang

On Wed, Dec 07, 2011 at 06:28:12PM +0200, Pekka Enberg wrote:
> On Wed, Dec 7, 2011 at 11:37 AM, Sasha Levin <levinsasha928@gmail.com> wrote:
> > 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 <berrange@redhat.com>
> > Cc: Osier Yang <jyang@redhat.com>
> > Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> 
> 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
-- 
|: 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 :|

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device
  2011-12-07 16:38   ` Daniel P. Berrange
@ 2011-12-07 17:24     ` Pekka Enberg
  2011-12-08 15:32       ` Osier Yang
  0 siblings, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2011-12-07 17:24 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Sasha Levin, mingo, gorcunov, asias.hejun, kvm, Osier Yang

[-- Attachment #1: Type: TEXT/PLAIN, Size: 602 bytes --]

On Wed, 7 Dec 2011, Daniel P. Berrange wrote:

> On Wed, Dec 07, 2011 at 06:28:12PM +0200, Pekka Enberg wrote:
>> On Wed, Dec 7, 2011 at 11:37 AM, Sasha Levin <levinsasha928@gmail.com> wrote:
>>> 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 <berrange@redhat.com>
>>> Cc: Osier Yang <jyang@redhat.com>
>>> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>>
>> Daniel, Osier, I assume this is useful for libvirt?
>
> Yes, this works.

Applied, thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device
  2011-12-07 17:24     ` Pekka Enberg
@ 2011-12-08 15:32       ` Osier Yang
  0 siblings, 0 replies; 5+ messages in thread
From: Osier Yang @ 2011-12-08 15:32 UTC (permalink / raw)
  To: Pekka Enberg
  Cc: Daniel P. Berrange, Sasha Levin, mingo, gorcunov, asias.hejun,
	kvm

On 2011年12月08日 01:24, Pekka Enberg wrote:
> On Wed, 7 Dec 2011, Daniel P. Berrange wrote:
>
>> On Wed, Dec 07, 2011 at 06:28:12PM +0200, Pekka Enberg wrote:
>>> On Wed, Dec 7, 2011 at 11:37 AM, Sasha Levin
>>> <levinsasha928@gmail.com> wrote:
>>>> 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 <berrange@redhat.com>
>>>> Cc: Osier Yang <jyang@redhat.com>
>>>> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
>>>
>>> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-12-08 15:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-07  9:37 [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device Sasha Levin
2011-12-07 16:28 ` Pekka Enberg
2011-12-07 16:38   ` Daniel P. Berrange
2011-12-07 17:24     ` Pekka Enberg
2011-12-08 15:32       ` Osier Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).