From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v2 11/11] monitor: New commands netdev_add, netdev_del
Date: Mon, 22 Mar 2010 10:48:53 +0100 [thread overview]
Message-ID: <1269251333-20821-12-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1269251333-20821-1-git-send-email-armbru@redhat.com>
Monitor commands to go with -netdev.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
net.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
net.h | 2 +
qemu-monitor.hx | 30 ++++++++++++++++++++++++++++
3 files changed, 88 insertions(+), 1 deletions(-)
diff --git a/net.c b/net.c
index 1f3c39c..80e9025 100644
--- a/net.c
+++ b/net.c
@@ -1122,7 +1122,7 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
}
qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
- "a network backend type");
+ "a network client type");
return -1;
}
@@ -1186,6 +1186,61 @@ void net_host_device_remove(Monitor *mon, const QDict *qdict)
qemu_del_vlan_client(vc);
}
+/**
+ * do_netdev_add(): Add a host network device
+ *
+ * Argument qdict contains
+ * - "type": the device type, "tap", "user", ...
+ * - "id": the device's ID (must be unique)
+ * - device options
+ *
+ * Example:
+ *
+ * { "type": "user", "id": "netdev1", "hostname": "a-guest" }
+ */
+int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+ QemuOpts *opts;
+ int res;
+
+ opts = qemu_opts_from_qdict(&qemu_netdev_opts, qdict);
+ if (!opts) {
+ return -1;
+ }
+
+ res = net_client_init(mon, opts, 1);
+ qemu_opts_del(opts);
+ return res;
+}
+
+/**
+ * do_netdev_del(): Delete a host network device
+ *
+ * Argument qdict contains
+ * - "id": the device's ID
+ *
+ * Example:
+ *
+ * { "id": "netdev1" }
+ */
+int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+ const char *id = qdict_get_str(qdict, "id");
+ VLANClientState *vc;
+
+ vc = qemu_find_netdev(id);
+ if (!vc || vc->info->type == NET_CLIENT_TYPE_NIC) {
+ qerror_report(QERR_DEVICE_NOT_FOUND, id);
+ return -1;
+ }
+ if (vc->peer) {
+ qerror_report(QERR_DEVICE_IN_USE, id);
+ return -1;
+ }
+ qemu_del_vlan_client(vc);
+ return 0;
+}
+
void net_set_boot_mask(int net_boot_mask)
{
int i;
diff --git a/net.h b/net.h
index 16f19c5..ce9e2c6 100644
--- a/net.h
+++ b/net.h
@@ -166,6 +166,8 @@ void net_cleanup(void);
void net_set_boot_mask(int boot_mask);
void net_host_device_add(Monitor *mon, const QDict *qdict);
void net_host_device_remove(Monitor *mon, const QDict *qdict);
+int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index 5308f36..ff5f099 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -913,6 +913,36 @@ STEXI
Remove host VLAN client.
ETEXI
+ {
+ .name = "netdev_add",
+ .args_type = "netdev:O",
+ .params = "[user|tap|socket],id=str[,prop=value][,...]",
+ .help = "add host network device",
+ .user_print = monitor_user_noop,
+ .mhandler.cmd_new = do_netdev_add,
+ },
+
+STEXI
+@item netdev_add
+@findex netdev_add
+Add host network device.
+ETEXI
+
+ {
+ .name = "netdev_del",
+ .args_type = "id:s",
+ .params = "id",
+ .help = "remove host network device",
+ .user_print = monitor_user_noop,
+ .mhandler.cmd_new = do_netdev_del,
+ },
+
+STEXI
+@item netdev_del
+@findex netdev_del
+Remove host network device.
+ETEXI
+
#ifdef CONFIG_SLIRP
{
.name = "hostfwd_add",
--
1.6.6.1
next prev parent reply other threads:[~2010-03-22 9:49 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-22 9:48 [Qemu-devel] [PATCH v2 00/11] monitor: New commands netdev_add, netdev_del Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 01/11] error: Put error definitions back in alphabetical order Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 02/11] error: New QERR_DUPLICATE_ID Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 03/11] error: Convert qemu_opts_create() to QError Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 04/11] error: New QERR_INVALID_PARAMETER_VALUE Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 05/11] error: Convert qemu_opts_set() to QError Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 06/11] error: Drop extra messages after qemu_opts_set() and qemu_opts_parse() Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 07/11] error: Use QERR_INVALID_PARAMETER_VALUE instead of QERR_INVALID_PARAMETER Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 08/11] error: Convert qemu_opts_validate() to QError Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 09/11] error: Convert net_client_init() " Markus Armbruster
2010-03-22 9:48 ` [Qemu-devel] [PATCH v2 10/11] error: New QERR_DEVICE_IN_USE Markus Armbruster
2010-03-22 9:48 ` Markus Armbruster [this message]
2010-03-23 22:06 ` [Qemu-devel] Re: [PATCH v2 11/11] monitor: New commands netdev_add, netdev_del Luiz Capitulino
2010-03-25 15:52 ` Markus Armbruster
2010-03-22 10:20 ` [Qemu-devel] Re: [PATCH v2 00/11] " Markus Armbruster
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=1269251333-20821-12-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=lcapitulino@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).