Received: from eggs.gnu.org ([2001:4830:134:3::10]:33745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjrLj-0008WA-By for qemu-devel@nongnu.org; Tue, 13 Sep 2016 13:18:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjrLh-0005zY-Be for qemu-devel@nongnu.org; Tue, 13 Sep 2016 13:18:22 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjrLh-0005yT-5o for qemu-devel@nongnu.org; Tue, 13 Sep 2016 13:18:21 -0400 Received: by mail-wm0-f66.google.com with SMTP id b184so3338122wma.3 for ; Tue, 13 Sep 2016 10:18:21 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 13 Sep 2016 19:16:09 +0200 Message-Id: <1473786989-54823-39-git-send-email-pbonzini@redhat.com> In-Reply-To: <1473786989-54823-1-git-send-email-pbonzini@redhat.com> References: <1473786989-54823-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 38/58] sclpconsolelm: remove bogus check for -EAGAIN List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: "Daniel P. Berrange" The write_console_data() method in sclpconsole-lm.c checks whether the return value of qemu_chr_fe_write() has the value of -EAGAIN and if so then increments the buffer offset by the value of EAGAIN. Fortunately qemu_chr_fe_write() will never return EAGAIN directly, rather it returns -1 with errno set to EAGAIN, so this broken code path was not reachable. The behaviour on EAGAIN was stil bad though, causing the write_console_data() to busy_wait repeatedly calling qemu_chr_fe_write() with no sleep between iters. Just remove all this loop logic and replace with a call to qemu_chr_fe_write_all(). Acked-by: Cornelia Huck Signed-off-by: Daniel P. Berrange Message-Id: <1473170165-540-3-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini --- hw/char/sclpconsole-lm.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/hw/char/sclpconsole-lm.c b/hw/char/sclpconsole-lm.c index a22ad8d..dbe7531 100644 --- a/hw/char/sclpconsole-lm.c +++ b/hw/char/sclpconsole-lm.c @@ -191,9 +191,6 @@ static int read_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr, */ static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len) { - int ret = 0; - const uint8_t *buf_offset; - SCLPConsoleLM *scon = SCLPLM_CONSOLE(event); if (!scon->chr) { @@ -201,21 +198,9 @@ static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len) return len; } - buf_offset = buf; - while (len > 0) { - ret = qemu_chr_fe_write(scon->chr, buf, len); - if (ret == 0) { - /* a pty doesn't seem to be connected - no error */ - len = 0; - } else if (ret == -EAGAIN || (ret > 0 && ret < len)) { - len -= ret; - buf_offset += ret; - } else { - len = 0; - } - } - - return ret; + /* XXX this blocks entire thread. Rewrite to use + * qemu_chr_fe_write and background I/O callbacks */ + return qemu_chr_fe_write_all(scon->chr, buf, len); } static int process_mdb(SCLPEvent *event, MDBO *mdbo) -- 1.8.3.1