From patchwork Tue Jun 15 17:53:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 55767 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 8DFF2B7DBD for ; Wed, 16 Jun 2010 04:01:45 +1000 (EST) Received: from localhost ([127.0.0.1]:43464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOaSE-0007u0-Nl for incoming@patchwork.ozlabs.org; Tue, 15 Jun 2010 14:01:42 -0400 Received: from [140.186.70.92] (port=45536 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OOaQE-0007rA-MI for qemu-devel@nongnu.org; Tue, 15 Jun 2010 13:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OOaQC-0007pu-Ci for qemu-devel@nongnu.org; Tue, 15 Jun 2010 13:59:38 -0400 Received: from sh.osrg.net ([192.16.179.4]:48892) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OOaQB-0007ol-RU for qemu-devel@nongnu.org; Tue, 15 Jun 2010 13:59:36 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o5FHxUcY000897; Wed, 16 Jun 2010 02:59:30 +0900 Received: from localhost (dfs1401.osrg.net [10.68.14.1]) by fs.osrg.net (Postfix) with ESMTP id 307B33E02F8; Wed, 16 Jun 2010 02:59:30 +0900 (JST) From: MORITA Kazutaka To: kwolf@redhat.com Date: Wed, 16 Jun 2010 02:53:41 +0900 Message-Id: <1276624421-23999-3-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1276624421-23999-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> References: <1276624421-23999-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 103 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Wed, 16 Jun 2010 02:59:31 +0900 (JST) X-Virus-Scanned: clamav-milter 0.96.1 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel@nongnu.org, morita.kazutaka@lab.ntt.co.jp Subject: [Qemu-devel] [PATCH 2/2] qemu-io: check registered fds in command_loop() 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 Some block drivers use an aio handler and do I/O completion routines in it. However, the handler is not invoked if we only do aio_read/write, because registered fds are not checked at all. This patch registers a command processing function as a fd handler to STDIO, and calls qemu_aio_wait() in command_loop(). Any other handlers can be invoked when user input is idle. Signed-off-by: MORITA Kazutaka --- cmd.c | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 39 insertions(+), 14 deletions(-) diff --git a/cmd.c b/cmd.c index 460df92..2b66e24 100644 --- a/cmd.c +++ b/cmd.c @@ -24,6 +24,7 @@ #include #include "cmd.h" +#include "qemu-aio.h" #define _(x) x /* not gettext support yet */ @@ -149,6 +150,37 @@ add_args_command( args_func = af; } +static char *get_prompt(void); + +static void do_command(void *opaque) +{ + int c; + int *done = opaque; + char *input; + char **v; + const cmdinfo_t *ct; + + if ((input = fetchline()) == NULL) { + *done = 1; + return; + } + v = breakline(input, &c); + if (c) { + ct = find_command(v[0]); + if (ct) + *done = command(ct, c, v); + else + fprintf(stderr, _("command \"%s\" not found\n"), + v[0]); + } + doneline(input, v); + + if (*done == 0) { + printf("%s", get_prompt()); + fflush(stdout); + } +} + void command_loop(void) { @@ -186,20 +218,15 @@ command_loop(void) free(cmdline); return; } + + printf("%s", get_prompt()); + fflush(stdout); + + qemu_aio_set_fd_handler(STDIN_FILENO, do_command, NULL, NULL, NULL, &done); while (!done) { - if ((input = fetchline()) == NULL) - break; - v = breakline(input, &c); - if (c) { - ct = find_command(v[0]); - if (ct) - done = command(ct, c, v); - else - fprintf(stderr, _("command \"%s\" not found\n"), - v[0]); - } - doneline(input, v); + qemu_aio_wait(); } + qemu_aio_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL, NULL, NULL); } /* from libxcmd/input.c */ @@ -270,8 +297,6 @@ fetchline(void) if (!line) return NULL; - printf("%s", get_prompt()); - fflush(stdout); again: if (!fgets(line, MAXREADLINESZ, stdin)) { if (errno == EINTR)