From patchwork Mon Apr 5 20:33:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 49454 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 2F1AFB7D0C for ; Tue, 6 Apr 2010 08:00:44 +1000 (EST) Received: from localhost ([127.0.0.1]:52565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NytOk-0007rd-5z for incoming@patchwork.ozlabs.org; Mon, 05 Apr 2010 16:59:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nyt3N-0002Ga-MZ for qemu-devel@nongnu.org; Mon, 05 Apr 2010 16:37:49 -0400 Received: from [140.186.70.92] (port=49507 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nyt3I-0001Wn-1N for qemu-devel@nongnu.org; Mon, 05 Apr 2010 16:37:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nyt0P-0001dr-Pa for qemu-devel@nongnu.org; Mon, 05 Apr 2010 16:34:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29091) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nyt0P-0001di-FG for qemu-devel@nongnu.org; Mon, 05 Apr 2010 16:34:45 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o35KYiv1032462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Apr 2010 16:34:44 -0400 Received: from localhost (vpn-8-191.rdu.redhat.com [10.11.8.191]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o35KYgR8001601; Mon, 5 Apr 2010 16:34:43 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 5 Apr 2010 17:33:55 -0300 Message-Id: <1270499642-31543-15-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1270499642-31543-1-git-send-email-lcapitulino@redhat.com> References: <1270499642-31543-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Luiz Capitulino , qemu-devel@nongnu.org, Markus Armbruster Subject: [Qemu-devel] [PATCH 14/21] 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 From: Markus Armbruster Monitor commands to go with -netdev. Signed-off-by: Markus Armbruster Signed-off-by: Luiz Capitulino --- net.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ net.h | 2 ++ qemu-monitor.hx | 30 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 0 deletions(-) diff --git a/net.c b/net.c index 71c0828..9a95451 100644 --- a/net.c +++ b/net.c @@ -1194,6 +1194,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); + 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); + qemu_opts_del(qemu_opts_find(&qemu_netdev_opts, id)); + 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",