From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:41718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHyCe-00046f-Ma for qemu-devel@nongnu.org; Tue, 19 Mar 2013 11:11:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHyCa-0004Rq-3l for qemu-devel@nongnu.org; Tue, 19 Mar 2013 11:11:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHyCZ-0004Rl-S3 for qemu-devel@nongnu.org; Tue, 19 Mar 2013 11:11:48 -0400 Message-ID: <5148802E.9070100@redhat.com> Date: Tue, 19 Mar 2013 16:11:42 +0100 From: Gerd Hoffmann MIME-Version: 1.0 References: <1363701863-13004-1-git-send-email-kraxel@redhat.com> <514879F1.4010302@redhat.com> In-Reply-To: <514879F1.4010302@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] fix monitor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laszlo Ersek Cc: amit.shah@redhat.com, Luiz Capitulino , qemu-devel@nongnu.org, anthony@codemonkey.ws, Markus Armbruster On 03/19/13 15:45, Laszlo Ersek wrote: > On 03/19/13 15:04, Gerd Hoffmann wrote: >> chardev flow control broke monitor, fix it by adding watch support. >> >> Signed-off-by: Gerd Hoffmann >> --- >> v2: fix tyops > > Well played, Sir :) > >> --- >> monitor.c | 23 +++++++++++++++++++++-- >> 1 file changed, 21 insertions(+), 2 deletions(-) >> >> diff --git a/monitor.c b/monitor.c >> index 112e920..74807f9 100644 >> --- a/monitor.c >> +++ b/monitor.c >> @@ -261,11 +261,30 @@ int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, >> } >> } >> >> +static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond, >> + void *opaque) >> +{ >> + monitor_flush(opaque); >> + return FALSE; >> +} >> + >> void monitor_flush(Monitor *mon) >> { >> + int rc; >> + >> if (mon && mon->outbuf_index != 0 && !mon->mux_out) { >> - qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index); >> - mon->outbuf_index = 0; >> + rc = qemu_chr_fe_write(mon->chr, mon->outbuf, mon->outbuf_index); >> + if (rc == mon->outbuf_index) { >> + /* all flushed */ >> + mon->outbuf_index = 0; >> + return; >> + } >> + if (rc > 0) { >> + /* partial write */ >> + memmove(mon->outbuf, mon->outbuf + rc, mon->outbuf_index - rc); >> + mon->outbuf_index -= rc; >> + } >> + qemu_chr_fe_add_watch(mon->chr, G_IO_OUT, monitor_unblocked, mon); >> } >> } >> >> > > Looks good to me. > > Should we maybe forego (re)installing the (new) watch when rc<0? > (Especially because on a persistent error the fd might immediately > report writability.) Yes, it is probably wise to check for errno == EAGAIN (assuming qemu_chr_fe_write makes sure errno it set to something sensible on error). cheers, Gerd