WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [Qemu-devel] [PATCH 2/2] open ptys in non-blocking mode.

To: Kevin Wolf <kwolf@xxxxxxx>
Subject: [Xen-devel] Re: [Qemu-devel] [PATCH 2/2] open ptys in non-blocking mode.
From: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Date: Fri, 18 Jul 2008 11:10:01 +0200
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, qemu-devel@xxxxxxxxxx
Delivery-date: Fri, 18 Jul 2008 02:10:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <4880574C.1020703@xxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <1215605958-22623-1-git-send-email-kraxel@xxxxxxxxxx> <1215605958-22623-2-git-send-email-kraxel@xxxxxxxxxx> <4880574C.1020703@xxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.14 (X11/20080501)
Kevin Wolf wrote:
> [Crossposting to xen-devel]
> 
> Ian, we need something like this for qemu-xen (or ioemu-remote or
> whatever it's called now). Currently you must attach to the console of a
> domain, otherwise it won't boot up and keep hanging in a blocking write
> because the buffer is full.
> 
> The old ioemu had a hack in unix_write (doing a select before the write)
> which you didn't merge into qemu-xen. In fact, I noticed that you even
> removed that function entirely and I'm wondering why.

For completeness:  You also need the attached patch for unix_write,
otherwise you'll end up with qemu burning cpu cycles.  If you can't
write to a non-blocking file handle the write will instantly return with
-EAGAIN.  Calling it again of course doesn't change the result, so
better don't do that ...

-- 
http://kraxel.fedorapeople.org/xenner/
>From d9454802fa2105bc399518eebfa1e1415ff07143 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@xxxxxxxxxx>
Date: Wed, 9 Jul 2008 09:41:31 +0200
Subject: [PATCH 02/12] unix_write: don't block on non-blocking file handles.


Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
---
 vl.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index c8db579..2e2d883 100644
--- a/vl.c
+++ b/vl.c
@@ -2116,14 +2116,24 @@ void socket_set_nonblock(int fd)
 
 static int unix_write(int fd, const uint8_t *buf, int len1)
 {
+    int nonblock = fcntl(fd, F_GETFL) & O_NONBLOCK;
     int ret, len;
 
     len = len1;
     while (len > 0) {
         ret = write(fd, buf, len);
         if (ret < 0) {
-            if (errno != EINTR && errno != EAGAIN)
+            if (errno == EINTR) {
+               continue;
+           } else if (errno == EAGAIN) {
+               if (!nonblock)
+                   continue;
+               if (len1 != len)
+                   break; /* partial write, return written bytes */
+               return -1;
+           } else {
                 return -1;
+           }
         } else if (ret == 0) {
             break;
         } else {
-- 
1.5.4.1

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel