Received: from eggs.gnu.org ([208.118.235.92]:40195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGR1G-0001MP-Kv for qemu-devel@nongnu.org; Tue, 25 Sep 2012 05:01:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGR1A-000671-Cx for qemu-devel@nongnu.org; Tue, 25 Sep 2012 05:01:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18666) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGR1A-00066i-4w for qemu-devel@nongnu.org; Tue, 25 Sep 2012 05:01:24 -0400 From: Markus Armbruster References: <1348247243-12446-1-git-send-email-lcapitulino@redhat.com> <1348247243-12446-3-git-send-email-lcapitulino@redhat.com> <505FFD45.2050804@cn.fujitsu.com> <20120924103433.2afcbc0b@doriath.home> <5061691A.9040609@cn.fujitsu.com> Date: Tue, 25 Sep 2012 11:01:15 +0200 In-Reply-To: <5061691A.9040609@cn.fujitsu.com> (Wen Congyang's message of "Tue, 25 Sep 2012 16:19:38 +0800") Message-ID: <87txum5vdw.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/3] qmp: dump-guest-memory: don't spin if non-blocking fd would block List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wen Congyang Cc: jan.kiszka@siemens.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, d.hatayama@jp.fujitsu.com, Luiz Capitulino Wen Congyang writes: > At 09/24/2012 09:34 PM, Luiz Capitulino Wrote: >> On Mon, 24 Sep 2012 14:27:17 +0800 >> Wen Congyang wrote: >> >>> At 09/22/2012 01:07 AM, Luiz Capitulino Wrote: >>>> 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. >>>> >>>> Signed-off-by: Luiz Capitulino >>>> --- >>>> dump.c | 13 +++---------- >>>> 1 file changed, 3 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/dump.c b/dump.c >>>> index 2bf8d8d..5eea015 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; >>>> >>>> - /* 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) { >>> >>> Hmm, if the fd is a blocking fd, errno can't be EAGAIN. So the >>> function doesn't spin. What problems do you meet? >> >> The problem is with non-blocking fds, where spinning isn't correct, for >> two reasons: > > But, If the fd is non-blocking, errno can't be EAGAIN. So it doesn't spin. I'm afraid you're confused. http://pubs.opengroup.org/onlinepubs/009695399/functions/write.html [EAGAIN] The O_NONBLOCK flag is set for the file descriptor and the thread would be delayed in the write() operation.