From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: John Cooper <john.cooper@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Gerd Hoffman <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 4/4] Allow default network type to be overridden
Date: Thu, 21 Jan 2010 12:48:53 -0600 [thread overview]
Message-ID: <1264099733-29666-5-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1264099733-29666-1-git-send-email-aliguori@us.ibm.com>
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 <aliguori@us.ibm.com>
---
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;
}
--
1.6.5.2
next prev parent reply other threads:[~2010-01-21 18:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-21 18:48 [Qemu-devel] [PATCH 0/4] Introduce global config and default devices Anthony Liguori
2010-01-21 18:48 ` [Qemu-devel] [PATCH 1/4] Support --confdir in configure to specify path to configuration files Anthony Liguori
2010-01-22 12:43 ` [Qemu-devel] " Paolo Bonzini
2010-01-22 14:39 ` Anthony Liguori
2010-01-21 18:48 ` [Qemu-devel] [PATCH 2/4] Load global config files by default Anthony Liguori
2010-01-22 10:33 ` [Qemu-devel] " Gerd Hoffmann
2010-01-21 18:48 ` [Qemu-devel] [PATCH 3/4] Add -defaults option to allow default devices to be overridden Anthony Liguori
2010-01-22 10:15 ` Markus Armbruster
2010-01-22 15:45 ` Anthony Liguori
2010-01-21 18:48 ` Anthony Liguori [this message]
2010-01-22 11:00 ` [Qemu-devel] Re: [PATCH 4/4] Allow default network type " Gerd Hoffmann
2010-01-22 14:44 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264099733-29666-5-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=john.cooper@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).