From patchwork Mon Jul 23 11:50:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 172648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 17C182C0361 for ; Mon, 23 Jul 2012 22:15:06 +1000 (EST) Received: from localhost ([::1]:60362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StHBf-0000OP-7d for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 07:52:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StHAL-0005Sn-EG for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:51:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StHAG-0000Vr-5n for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:51:09 -0400 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:36535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StHAF-0000VW-Qq for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:51:04 -0400 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Jul 2012 12:51:03 +0100 Received: from d06nrmr1806.portsmouth.uk.ibm.com (9.149.39.193) by e06smtp18.uk.ibm.com (192.168.101.148) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Jul 2012 12:51:01 +0100 Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6NBp0EY745634 for ; Mon, 23 Jul 2012 12:51:00 +0100 Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6NBp0f1008074 for ; Mon, 23 Jul 2012 05:51:00 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6NBp0CZ008060; Mon, 23 Jul 2012 05:51:00 -0600 From: Stefan Hajnoczi To: Anthony Liguori Date: Mon, 23 Jul 2012 12:50:42 +0100 Message-Id: <1343044244-28728-18-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343044244-28728-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1343044244-28728-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12072311-6892-0000-0000-0000028266E3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.114 Cc: Laszlo Ersek , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 17/19] convert net_init_tap() to NetClientOptions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laszlo Ersek Signed-off-by: Laszlo Ersek Signed-off-by: Stefan Hajnoczi --- net/tap-aix.c | 2 +- net/tap-bsd.c | 2 +- net/tap-haiku.c | 2 +- net/tap-linux.c | 9 +++-- net/tap-solaris.c | 2 +- net/tap-win32.c | 11 +++--- net/tap.c | 111 ++++++++++++++++++++++++++--------------------------- net/tap.h | 2 +- 8 files changed, 71 insertions(+), 70 deletions(-) diff --git a/net/tap-aix.c b/net/tap-aix.c index e19aaba..f27c177 100644 --- a/net/tap-aix.c +++ b/net/tap-aix.c @@ -31,7 +31,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required return -1; } -int tap_set_sndbuf(int fd, QemuOpts *opts) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { return 0; } diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 937a94b..a3b717d 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -117,7 +117,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required return fd; } -int tap_set_sndbuf(int fd, QemuOpts *opts) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { return 0; } diff --git a/net/tap-haiku.c b/net/tap-haiku.c index 91dda8e..34739d1 100644 --- a/net/tap-haiku.c +++ b/net/tap-haiku.c @@ -31,7 +31,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required return -1; } -int tap_set_sndbuf(int fd, QemuOpts *opts) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { return 0; } diff --git a/net/tap-linux.c b/net/tap-linux.c index 41d581b..c6521be 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -98,16 +98,19 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required */ #define TAP_DEFAULT_SNDBUF 0 -int tap_set_sndbuf(int fd, QemuOpts *opts) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { int sndbuf; - sndbuf = qemu_opt_get_size(opts, "sndbuf", TAP_DEFAULT_SNDBUF); + sndbuf = !tap->has_sndbuf ? TAP_DEFAULT_SNDBUF : + tap->sndbuf > INT_MAX ? INT_MAX : + tap->sndbuf; + if (!sndbuf) { sndbuf = INT_MAX; } - if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1 && qemu_opt_get(opts, "sndbuf")) { + if (ioctl(fd, TUNSETSNDBUF, &sndbuf) == -1 && tap->has_sndbuf) { error_report("TUNSETSNDBUF ioctl failed: %s", strerror(errno)); return -1; } diff --git a/net/tap-solaris.c b/net/tap-solaris.c index cf76463..5d6ac42 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -197,7 +197,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required return fd; } -int tap_set_sndbuf(int fd, QemuOpts *opts) +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { return 0; } diff --git a/net/tap-win32.c b/net/tap-win32.c index b738f45..b6099cd 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -699,19 +699,20 @@ static int tap_win32_init(VLANState *vlan, const char *model, return 0; } -int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, +int net_init_tap(QemuOpts *old_opts, const NetClientOptions *opts, const char *name, VLANState *vlan) { - const char *ifname; + const NetdevTapOptions *tap; - ifname = qemu_opt_get(opts, "ifname"); + assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP); + tap = opts->tap; - if (!ifname) { + if (!tap->has_ifname) { error_report("tap: no interface name"); return -1; } - if (tap_win32_init(vlan, "tap", name, ifname) == -1) { + if (tap_win32_init(vlan, "tap", name, tap->ifname) == -1) { return -1; } diff --git a/net/tap.c b/net/tap.c index 0fc856c..c5563c0 100644 --- a/net/tap.c +++ b/net/tap.c @@ -548,29 +548,32 @@ int net_init_bridge(QemuOpts *opts, const NetClientOptions *new_opts, return 0; } -static int net_tap_init(QemuOpts *opts, int *vnet_hdr) +static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, + const char *setup_script, char *ifname, + size_t ifname_sz) { int fd, vnet_hdr_required; - char ifname[128] = {0,}; - const char *setup_script; - if (qemu_opt_get(opts, "ifname")) { - pstrcpy(ifname, sizeof(ifname), qemu_opt_get(opts, "ifname")); + if (tap->has_ifname) { + pstrcpy(ifname, ifname_sz, tap->ifname); + } else { + assert(ifname_sz > 0); + ifname[0] = '\0'; } - *vnet_hdr = qemu_opt_get_bool(opts, "vnet_hdr", 1); - if (qemu_opt_get(opts, "vnet_hdr")) { + if (tap->has_vnet_hdr) { + *vnet_hdr = tap->vnet_hdr; vnet_hdr_required = *vnet_hdr; } else { + *vnet_hdr = 1; vnet_hdr_required = 0; } - TFR(fd = tap_open(ifname, sizeof(ifname), vnet_hdr, vnet_hdr_required)); + TFR(fd = tap_open(ifname, ifname_sz, vnet_hdr, vnet_hdr_required)); if (fd < 0) { return -1; } - setup_script = qemu_opt_get(opts, "script"); if (setup_script && setup_script[0] != '\0' && strcmp(setup_script, "no") != 0 && @@ -579,30 +582,34 @@ static int net_tap_init(QemuOpts *opts, int *vnet_hdr) return -1; } - qemu_opt_set(opts, "ifname", ifname); - return fd; } -int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, +int net_init_tap(QemuOpts *old_opts, const NetClientOptions *opts, const char *name, VLANState *vlan) { - TAPState *s; + const NetdevTapOptions *tap; + int fd, vnet_hdr = 0; const char *model; + TAPState *s; + + /* for the no-fd, no-helper case */ + const char *script = NULL; /* suppress wrong "uninit'd use" gcc warning */ + char ifname[128]; + + assert(opts->kind == NET_CLIENT_OPTIONS_KIND_TAP); + tap = opts->tap; - if (qemu_opt_get(opts, "fd")) { - if (qemu_opt_get(opts, "ifname") || - qemu_opt_get(opts, "script") || - qemu_opt_get(opts, "downscript") || - qemu_opt_get(opts, "vnet_hdr") || - qemu_opt_get(opts, "helper")) { + if (tap->has_fd) { + if (tap->has_ifname || tap->has_script || tap->has_downscript || + tap->has_vnet_hdr || tap->has_helper) { error_report("ifname=, script=, downscript=, vnet_hdr=, " "and helper= are invalid with fd="); return -1; } - fd = net_handle_fd_param(cur_mon, qemu_opt_get(opts, "fd")); + fd = net_handle_fd_param(cur_mon, tap->fd); if (fd == -1) { return -1; } @@ -613,18 +620,15 @@ int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, model = "tap"; - } else if (qemu_opt_get(opts, "helper")) { - if (qemu_opt_get(opts, "ifname") || - qemu_opt_get(opts, "script") || - qemu_opt_get(opts, "downscript") || - qemu_opt_get(opts, "vnet_hdr")) { + } else if (tap->has_helper) { + if (tap->has_ifname || tap->has_script || tap->has_downscript || + tap->has_vnet_hdr) { error_report("ifname=, script=, downscript=, and vnet_hdr= " "are invalid with helper="); return -1; } - fd = net_bridge_run_helper(qemu_opt_get(opts, "helper"), - DEFAULT_BRIDGE_INTERFACE); + fd = net_bridge_run_helper(tap->helper, DEFAULT_BRIDGE_INTERFACE); if (fd == -1) { return -1; } @@ -636,15 +640,8 @@ int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, model = "bridge"; } else { - if (!qemu_opt_get(opts, "script")) { - qemu_opt_set(opts, "script", DEFAULT_NETWORK_SCRIPT); - } - - if (!qemu_opt_get(opts, "downscript")) { - qemu_opt_set(opts, "downscript", DEFAULT_NETWORK_DOWN_SCRIPT); - } - - fd = net_tap_init(opts, &vnet_hdr); + script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT; + fd = net_tap_init(tap, &vnet_hdr, script, ifname, sizeof ifname); if (fd == -1) { return -1; } @@ -658,25 +655,24 @@ int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, return -1; } - if (tap_set_sndbuf(s->fd, opts) < 0) { + if (tap_set_sndbuf(s->fd, tap) < 0) { return -1; } - if (qemu_opt_get(opts, "fd")) { + if (tap->has_fd) { snprintf(s->nc.info_str, sizeof(s->nc.info_str), "fd=%d", fd); - } else if (qemu_opt_get(opts, "helper")) { - snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "helper=%s", qemu_opt_get(opts, "helper")); + } else if (tap->has_helper) { + snprintf(s->nc.info_str, sizeof(s->nc.info_str), "helper=%s", + tap->helper); } else { - const char *ifname, *script, *downscript; + const char *downscript; - ifname = qemu_opt_get(opts, "ifname"); - script = qemu_opt_get(opts, "script"); - downscript = qemu_opt_get(opts, "downscript"); + downscript = tap->has_downscript ? tap->downscript : + DEFAULT_NETWORK_DOWN_SCRIPT; snprintf(s->nc.info_str, sizeof(s->nc.info_str), - "ifname=%s,script=%s,downscript=%s", - ifname, script, downscript); + "ifname=%s,script=%s,downscript=%s", ifname, script, + downscript); if (strcmp(downscript, "no") != 0) { snprintf(s->down_script, sizeof(s->down_script), "%s", downscript); @@ -684,25 +680,26 @@ int net_init_tap(QemuOpts *opts, const NetClientOptions *new_opts, } } - if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd") || - qemu_opt_get_bool(opts, "vhostforce", false))) { - int vhostfd, r; - bool force = qemu_opt_get_bool(opts, "vhostforce", false); - if (qemu_opt_get(opts, "vhostfd")) { - r = net_handle_fd_param(cur_mon, qemu_opt_get(opts, "vhostfd")); - if (r == -1) { + if (tap->has_vhost ? tap->vhost : + tap->has_vhostfd || (tap->has_vhostforce && tap->vhostforce)) { + int vhostfd; + + if (tap->has_vhostfd) { + vhostfd = net_handle_fd_param(cur_mon, tap->vhostfd); + if (vhostfd == -1) { return -1; } - vhostfd = r; } else { vhostfd = -1; } - s->vhost_net = vhost_net_init(&s->nc, vhostfd, force); + + s->vhost_net = vhost_net_init(&s->nc, vhostfd, + tap->has_vhostforce && tap->vhostforce); if (!s->vhost_net) { error_report("vhost-net requested but could not be initialized"); return -1; } - } else if (qemu_opt_get(opts, "vhostfd")) { + } else if (tap->has_vhostfd) { error_report("vhostfd= is not valid without vhost"); return -1; } diff --git a/net/tap.h b/net/tap.h index 44e31ce..f092129 100644 --- a/net/tap.h +++ b/net/tap.h @@ -47,7 +47,7 @@ void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo); void tap_set_vnet_hdr_len(VLANClientState *vc, int len); -int tap_set_sndbuf(int fd, QemuOpts *opts); +int tap_set_sndbuf(int fd, const NetdevTapOptions *tap); int tap_probe_vnet_hdr(int fd); int tap_probe_vnet_hdr_len(int fd, int len); int tap_probe_has_ufo(int fd);