Patchwork [1/3] do not loop on an incomplete io_thread_fd read

login
register
mail settings
Submitter Paolo Bonzini
Date Feb. 2, 2010, 7:33 p.m.
Message ID <1265139191-13568-2-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/44302/
State New
Headers show

Comments

Paolo Bonzini - Feb. 2, 2010, 7:33 p.m.
No need to loop if less than a full buffer is read, the next
read would return EAGAIN.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 vl.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Anthony Liguori - Feb. 10, 2010, 6:32 p.m.
On 02/02/2010 01:33 PM, Paolo Bonzini wrote:
> No need to loop if less than a full buffer is read, the next
> read would return EAGAIN.
>
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
>    

Applied all.  Thanks.

Regards,

Anthony Liguori
> ---
>   vl.c |    4 ++--
>   1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/vl.c b/vl.c
> index 6f1e1ab..46c1118 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3210,12 +3210,12 @@ static void qemu_event_read(void *opaque)
>   {
>       int fd = (unsigned long)opaque;
>       ssize_t len;
> +    char buffer[512];
>
>       /* Drain the notify pipe */
>       do {
> -        char buffer[512];
>           len = read(fd, buffer, sizeof(buffer));
> -    } while ((len == -1&&  errno == EINTR) || len>  0);
> +    } while ((len == -1&&  errno == EINTR) || len == sizeof(buffer));
>   }
>
>   static int qemu_event_init(void)
>

Patch

diff --git a/vl.c b/vl.c
index 6f1e1ab..46c1118 100644
--- a/vl.c
+++ b/vl.c
@@ -3210,12 +3210,12 @@  static void qemu_event_read(void *opaque)
 {
     int fd = (unsigned long)opaque;
     ssize_t len;
+    char buffer[512];
 
     /* Drain the notify pipe */
     do {
-        char buffer[512];
         len = read(fd, buffer, sizeof(buffer));
-    } while ((len == -1 && errno == EINTR) || len > 0);
+    } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
 }
 
 static int qemu_event_init(void)