From patchwork Wed May 26 21:31:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 53664 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 53DD9B7D16 for ; Thu, 27 May 2010 07:51:52 +1000 (EST) Received: from localhost ([127.0.0.1]:55102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHOVx-0007JQ-MU for incoming@patchwork.ozlabs.org; Wed, 26 May 2010 17:51:49 -0400 Received: from [140.186.70.92] (port=43706 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHODJ-0001KC-4h for qemu-devel@nongnu.org; Wed, 26 May 2010 17:32:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHODH-0000Ec-Rc for qemu-devel@nongnu.org; Wed, 26 May 2010 17:32:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63909) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHODH-0000ET-L7 for qemu-devel@nongnu.org; Wed, 26 May 2010 17:32:31 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4QLWTl9017132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 May 2010 17:32:29 -0400 Received: from virtlab9.virt.bos.redhat.com (virtlab9.virt.bos.redhat.com [10.16.72.29]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4QLWSrA014983; Wed, 26 May 2010 17:32:28 -0400 From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 26 May 2010 17:31:50 -0400 Message-ID: <20100526213030.9332.60231.stgit@virtlab9.virt.bos.redhat.com> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: alex.williamson@redhat.com Subject: [Qemu-devel] [PATCH] move net_handle_fd_param() into a common utility function 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 Move to monitor.c:monitor_handle_fd_param() as a common helper. Signed-off-by: Alex Williamson --- I'd like to use this for the proposed device assignment configfd parameter since there's nothing net specific about it. monitor.c | 17 +++++++++++++++++ monitor.h | 1 + net.c | 17 ----------------- net.h | 2 -- net/socket.c | 3 ++- net/tap.c | 5 +++-- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/monitor.c b/monitor.c index ad50f12..b7bf991 100644 --- a/monitor.c +++ b/monitor.c @@ -2496,6 +2496,23 @@ int monitor_get_fd(Monitor *mon, const char *fdname) return -1; } +int monitor_handle_fd_param(Monitor *mon, const char *param) +{ + if (!qemu_isdigit(param[0])) { + int fd; + + fd = monitor_get_fd(mon, param); + if (fd == -1) { + error_report("No file descriptor named %s found", param); + return -1; + } + + return fd; + } else { + return strtol(param, NULL, 0); + } +} + static const mon_cmd_t mon_cmds[] = { #include "qemu-monitor.h" { NULL, NULL, }, diff --git a/monitor.h b/monitor.h index ea15469..354c968 100644 --- a/monitor.h +++ b/monitor.h @@ -44,6 +44,7 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, void *opaque); int monitor_get_fd(Monitor *mon, const char *fdname); +int monitor_handle_fd_param(Monitor *mon, const char *param); void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap); void monitor_printf(Monitor *mon, const char *fmt, ...) diff --git a/net.c b/net.c index 378edfc..af4ffaf 100644 --- a/net.c +++ b/net.c @@ -737,23 +737,6 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models, return -1; } -int net_handle_fd_param(Monitor *mon, const char *param) -{ - if (!qemu_isdigit(param[0])) { - int fd; - - fd = monitor_get_fd(mon, param); - if (fd == -1) { - error_report("No file descriptor named %s found", param); - return -1; - } - - return fd; - } else { - return strtol(param, NULL, 0); - } -} - static int net_init_nic(QemuOpts *opts, Monitor *mon, const char *name, diff --git a/net.h b/net.h index b83f615..20b4840 100644 --- a/net.h +++ b/net.h @@ -177,6 +177,4 @@ int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data); void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); -int net_handle_fd_param(Monitor *mon, const char *param); - #endif diff --git a/net/socket.c b/net/socket.c index 1c4e153..89ccf1d 100644 --- a/net/socket.c +++ b/net/socket.c @@ -31,6 +31,7 @@ #include "qemu-error.h" #include "qemu-option.h" #include "qemu_socket.h" +#include "monitor.h" typedef struct NetSocketState { VLANClientState nc; @@ -510,7 +511,7 @@ int net_init_socket(QemuOpts *opts, return -1; } - fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd")); + fd = monitor_handle_fd_param(mon, qemu_opt_get(opts, "fd")); if (fd == -1) { return -1; } diff --git a/net/tap.c b/net/tap.c index 0147dab..645cc16 100644 --- a/net/tap.c +++ b/net/tap.c @@ -39,6 +39,7 @@ #include "qemu-char.h" #include "qemu-common.h" #include "qemu-error.h" +#include "monitor.h" #include "net/tap-linux.h" @@ -413,7 +414,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan return -1; } - fd = net_handle_fd_param(mon, qemu_opt_get(opts, "fd")); + fd = monitor_handle_fd_param(mon, qemu_opt_get(opts, "fd")); if (fd == -1) { return -1; } @@ -468,7 +469,7 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) { int vhostfd, r; if (qemu_opt_get(opts, "vhostfd")) { - r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd")); + r = monitor_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd")); if (r == -1) { return -1; }