From patchwork Tue Mar 1 08:22:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 8462991 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E49F99F9A0 for ; Tue, 1 Mar 2016 08:23:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D5CA201F4 for ; Tue, 1 Mar 2016 08:23:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6004A201BB for ; Tue, 1 Mar 2016 08:23:20 +0000 (UTC) Received: from localhost ([::1]:41571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aafaR-0008AQ-Lw for patchwork-qemu-devel@patchwork.kernel.org; Tue, 01 Mar 2016 03:23:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aafaG-00089z-1y for qemu-devel@nongnu.org; Tue, 01 Mar 2016 03:23:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aafaC-0002V4-G7 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 03:23:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aafaC-0002Ut-96 for qemu-devel@nongnu.org; Tue, 01 Mar 2016 03:23:04 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id E19EF32E892 for ; Tue, 1 Mar 2016 08:23:03 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u218N28p027031; Tue, 1 Mar 2016 03:23:02 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id CD63B8087D; Tue, 1 Mar 2016 09:23:01 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 1 Mar 2016 09:22:56 +0100 Message-Id: <1456820580-19156-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1456820580-19156-1-git-send-email-kraxel@redhat.com> References: <1456820580-19156-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PULL 1/5] console: add & use qemu_console_lookup_by_device_name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have two places needing this, and a third one will come shortly. So factor things out into a helper function to reduce code duplication. Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrange Reviewed-by: Markus Armbruster --- include/ui/console.h | 2 ++ ui/console.c | 23 +++++++++++++++++++++++ ui/input.c | 15 ++++----------- ui/vnc.c | 15 ++++----------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 6631b96..f636971 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -378,6 +378,8 @@ void graphic_hw_gl_block(QemuConsole *con, bool block); QemuConsole *qemu_console_lookup_by_index(unsigned int index); QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head); +QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, + uint32_t head, Error **errp); bool qemu_console_is_visible(QemuConsole *con); bool qemu_console_is_graphic(QemuConsole *con); bool qemu_console_is_fixedsize(QemuConsole *con); diff --git a/ui/console.c b/ui/console.c index 7db0fd2..ae61382 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1790,6 +1790,29 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev, uint32_t head) return NULL; } +QemuConsole *qemu_console_lookup_by_device_name(const char *device_id, + uint32_t head, Error **errp) +{ + DeviceState *dev; + QemuConsole *con; + + dev = qdev_find_recursive(sysbus_get_default(), device_id); + if (dev == NULL) { + error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + "Device '%s' not found", device_id); + return NULL; + } + + con = qemu_console_lookup_by_device(dev, head); + if (con == NULL) { + error_setg(errp, "Device %s (head %d) is not bound to a QemuConsole", + device_id, head); + return NULL; + } + + return con; +} + bool qemu_console_is_visible(QemuConsole *con) { return (con == active_console) || (con->dcls > 0); diff --git a/ui/input.c b/ui/input.c index bdcb974..fce99ba 100644 --- a/ui/input.c +++ b/ui/input.c @@ -82,19 +82,12 @@ void qemu_input_handler_bind(QemuInputHandlerState *s, const char *device_id, int head, Error **errp) { - DeviceState *dev; QemuConsole *con; + Error *err = NULL; - dev = qdev_find_recursive(sysbus_get_default(), device_id); - if (dev == NULL) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, - "Device '%s' not found", device_id); - return; - } - - con = qemu_console_lookup_by_device(dev, head); - if (con == NULL) { - error_setg(errp, "Device %s is not bound to a QemuConsole", device_id); + con = qemu_console_lookup_by_device_name(device_id, head, &err); + if (err) { + error_propagate(errp, err); return; } diff --git a/ui/vnc.c b/ui/vnc.c index b6bbea5..f27df6d 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3732,19 +3732,12 @@ void vnc_display_open(const char *id, Error **errp) device_id = qemu_opt_get(opts, "display"); if (device_id) { - DeviceState *dev; int head = qemu_opt_get_number(opts, "head", 0); + Error *err = NULL; - dev = qdev_find_recursive(sysbus_get_default(), device_id); - if (dev == NULL) { - error_setg(errp, "Device '%s' not found", device_id); - goto fail; - } - - con = qemu_console_lookup_by_device(dev, head); - if (con == NULL) { - error_setg(errp, "Device %s is not bound to a QemuConsole", - device_id); + con = qemu_console_lookup_by_device_name(device_id, head, &err); + if (err) { + error_propagate(errp, err); goto fail; } } else {