From: Sasha Levin Subject: [PATCH] kvm tools: Allow the user to pass a FD to use as a TAP device Date: Wed, 7 Dec 2011 11:37:53 +0200 Message-ID: <1323250673-6869-1-git-send-email-levinsasha928@gmail.com> Cc: mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com, kvm@vger.kernel.org, Sasha Levin , "Daniel P. Berrange" , Osier Yang To: penberg@kernel.org Return-path: Received: from mail-ee0-f46.google.com ([74.125.83.46]:45993 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751705Ab1LGJiz (ORCPT ); Wed, 7 Dec 2011 04:38:55 -0500 Received: by eekd41 with SMTP id d41so266192eek.19 for ; Wed, 07 Dec 2011 01:38:54 -0800 (PST) Sender: kvm-owner@vger.kernel.org List-ID: 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 Cc: Osier Yang Signed-off-by: Sasha Levin --- 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