From patchwork Thu Mar 18 16:35:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 48078 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 90770B7D16 for ; Fri, 19 Mar 2010 04:20:53 +1100 (EST) Received: from localhost ([127.0.0.1]:36391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsJOs-00077y-KC for incoming@patchwork.ozlabs.org; Thu, 18 Mar 2010 13:20:50 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NsIgd-0001P9-CG for qemu-devel@nongnu.org; Thu, 18 Mar 2010 12:35:07 -0400 Received: from [199.232.76.173] (port=40380 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NsIgc-0001Ob-Ok for qemu-devel@nongnu.org; Thu, 18 Mar 2010 12:35:06 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NsIgZ-0005TS-Un for qemu-devel@nongnu.org; Thu, 18 Mar 2010 12:35:06 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:56586) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NsIgZ-0005TI-F2 for qemu-devel@nongnu.org; Thu, 18 Mar 2010 12:35:03 -0400 Received: from blackfin.pond.sub.org (pD9E3ACC8.dip.t-dialin.net [217.227.172.200]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 36CC22DD2FB for ; Thu, 18 Mar 2010 17:35:02 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id AFAC629; Thu, 18 Mar 2010 17:35:01 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 18 Mar 2010 17:35:01 +0100 Message-Id: <1268930101-28934-2-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1268929996-28763-1-git-send-email-armbru@redhat.com> References: <1268929996-28763-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 11/11] monitor: New commands netdev_add, netdev_del 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 Monitor commands to go with -netdev. Signed-off-by: Markus Armbruster --- 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 d290b4b..31087bd 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -914,6 +914,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",