From patchwork Wed Sep 26 18:56:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 187178 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC63E2C0097 for ; Thu, 27 Sep 2012 04:56:38 +1000 (EST) Received: from localhost ([::1]:35555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGwmi-0002l7-VE for incoming@patchwork.ozlabs.org; Wed, 26 Sep 2012 14:56:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGwmT-0002ch-Tj for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGwmN-0006wq-9F for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:56:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGwmM-0006we-W5 for qemu-devel@nongnu.org; Wed, 26 Sep 2012 14:56:15 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8QIuAwT020317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 26 Sep 2012 14:56:10 -0400 Received: from localhost (ovpn-113-94.phx2.redhat.com [10.3.113.94]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8QIu9hS026465; Wed, 26 Sep 2012 14:56:09 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2012 15:56:52 -0300 Message-Id: <1348685813-29414-3-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1348685813-29414-1-git-send-email-lcapitulino@redhat.com> References: <1348685813-29414-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, jan.kiszka@siemens.com, armbru@redhat.com, d.hatayama@jp.fujitsu.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org fd_write_vmcore() will indefinitely spin for a non-blocking file-descriptor that would block. However, if the fd is non-blocking, how does it make sense to spin? Change this behavior to return an error instead. Note that this can only happen with an fd provided by a management application. The fd opened internally by dump-guest-memory is blocking. While there, also fix 'writen_size' variable name. Signed-off-by: Luiz Capitulino --- dump.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/dump.c b/dump.c index 2bf8d8d..81c3624 100644 --- a/dump.c +++ b/dump.c @@ -100,18 +100,11 @@ static void dump_error(DumpState *s, const char *reason) static int fd_write_vmcore(void *buf, size_t size, void *opaque) { DumpState *s = opaque; - int fd = s->fd; - size_t writen_size; + size_t written_size; - /* The fd may be passed from user, and it can be non-blocked */ - while (size) { - writen_size = qemu_write_full(fd, buf, size); - if (writen_size != size && errno != EAGAIN) { - return -1; - } - - buf += writen_size; - size -= writen_size; + written_size = qemu_write_full(s->fd, buf, size); + if (written_size != size) { + return -1; } return 0;