From patchwork Thu Jan 21 18:48:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 43446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4297DB7D2C for ; Fri, 22 Jan 2010 06:00:28 +1100 (EST) Received: from localhost ([127.0.0.1]:33643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY2Fn-0008RM-7U for incoming@patchwork.ozlabs.org; Thu, 21 Jan 2010 13:59:39 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NY25v-0006s5-0c for qemu-devel@nongnu.org; Thu, 21 Jan 2010 13:49:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NY25p-0006mC-Tl for qemu-devel@nongnu.org; Thu, 21 Jan 2010 13:49:25 -0500 Received: from [199.232.76.173] (port=59176 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NY25p-0006lg-5v for qemu-devel@nongnu.org; Thu, 21 Jan 2010 13:49:21 -0500 Received: from e31.co.us.ibm.com ([32.97.110.149]:57761) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NY25o-0000vx-F5 for qemu-devel@nongnu.org; Thu, 21 Jan 2010 13:49:20 -0500 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e31.co.us.ibm.com (8.14.3/8.13.1) with ESMTP id o0LIf9AY029435 for ; Thu, 21 Jan 2010 11:41:09 -0700 Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o0LIn3Hj125564 for ; Thu, 21 Jan 2010 11:49:04 -0700 Received: from d03av05.boulder.ibm.com (loopback [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o0LIn3ZN028984 for ; Thu, 21 Jan 2010 11:49:03 -0700 Received: from localhost.localdomain (sig-9-65-42-139.mts.ibm.com [9.65.42.139]) by d03av05.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o0LImvVt028674; Thu, 21 Jan 2010 11:49:02 -0700 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Thu, 21 Jan 2010 12:48:53 -0600 Message-Id: <1264099733-29666-5-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1264099733-29666-1-git-send-email-aliguori@us.ibm.com> References: <1264099733-29666-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: John Cooper , Anthony Liguori , Gerd Hoffman Subject: [Qemu-devel] [PATCH 4/4] Allow default network type to be overridden X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Introduce a default option to the network device which specifies that this is a default network device. This approach should generalize to any other device. The meaning of a default device is as follows: a default device is added to a machine IIF defaults aren't disable (via -default or -nodefaults) and a non-default device of this type hasn't been added. Signed-off-by: Anthony Liguori --- net.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 37 insertions(+), 5 deletions(-) diff --git a/net.c b/net.c index 6ef93e6..1aa3c77 100644 --- a/net.c +++ b/net.c @@ -833,6 +833,10 @@ static int net_init_nic(QemuOpts *opts, .name = "name", \ .type = QEMU_OPT_STRING, \ .help = "identifier for monitor commands", \ + }, { \ + .name = "default", \ + .type = QEMU_OPT_BOOL, \ + .help = "act as default network device", \ } typedef int (*net_client_init_func)(QemuOpts *opts, @@ -1056,6 +1060,15 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev) const char *type; int i; + /* Do not create default network devices if no defaults */ + if (!default_net) { + const char *opt = qemu_opt_get(opts, "default"); + + if (opt && strcmp(opt, "on") == 0) { + return 0; + } + } + type = qemu_opt_get(opts, "type"); if (!is_netdev) { @@ -1320,10 +1333,22 @@ static int net_init_netdev(QemuOpts *opts, void *dummy) int net_init_clients(void) { if (default_net) { - /* if no clients, we use a default config */ - qemu_opts_set(&qemu_net_opts, NULL, "type", "nic"); + QemuOpts *opts; + + opts = qemu_opts_create(&qemu_net_opts, NULL, 1); + if (opts == NULL) { + return -1; + } + qemu_opt_set(opts, "type", "nic"); + qemu_opt_set(opts, "default", "on"); + #ifdef CONFIG_SLIRP - qemu_opts_set(&qemu_net_opts, NULL, "type", "user"); + opts = qemu_opts_create(&qemu_net_opts, NULL, 1); + if (opts == NULL) { + return -1; + } + qemu_opt_set(opts, "type", "user"); + qemu_opt_set(opts, "default", "on"); #endif } @@ -1344,6 +1369,8 @@ int net_init_clients(void) int net_client_parse(QemuOptsList *opts_list, const char *optarg) { + QemuOpts *opts; + const char *opt; #if defined(CONFIG_SLIRP) int ret; if (net_slirp_parse_legacy(opts_list, optarg, &ret)) { @@ -1351,10 +1378,15 @@ int net_client_parse(QemuOptsList *opts_list, const char *optarg) } #endif - if (!qemu_opts_parse(opts_list, optarg, "type")) { + opts = qemu_opts_parse(opts_list, optarg, "type"); + if (opts == NULL) { return -1; } - default_net = 0; + opt = qemu_opt_get(opts, "default"); + if (!opt || strcmp(opt, "off") == 0) { + default_net = 0; + } + return 0; }