Skip to contentSkip to conversation

migrate.c: migrate_fd_put_buffer: Do not busyloop: stop writing if EWOULDBLOCK

PATCH In review Uri Lublin 3 participants 4 messages May 19, 2009 – May 23, 2009

lore
Share & tools
lore

Uri Lublin

author
#0 lore raw

PATCH 1/1 migrate.c: migrate_fd_put_buffer: Do not busyloop: stop writing if EWOULDBLOCK

The migration code is non-blocking, designed for live migration.

Practically migrate_fd_put_buffer busy-loops trying to write, as on many machines EWOULDBLOCK==EAGAIN (look in include/asm-generic/errno.h).

---
 migration.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
migration.c +1 -1
index 859d945..ca397fa 100644
@@ -176,7 +176,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
 
     do {
         ret = s->write(s, data, size);
-    } while (ret == -1 && ((s->get_error(s)) == EINTR || (s->get_error(s)) == EWOULDBLOCK));
+    } while (ret == -1 && ((s->get_error(s)) == EINTR));
 
     if (ret == -1)
         ret = -(s->get_error(s));
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 16 lines · Uri Lublin

The migration code is non-blocking, designed for live migration.

Practically migrate_fd_put_buffer busy-loops trying to write, as on many machines EWOULDBLOCK==EAGAIN (look in include/asm-generic/errno.h).

---
 migration.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
migration.c +0 -0
index 859d945..ca397fa 100644

migration.c ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size) · line 182

Quoted 8 lines
migration.c +1 -1
@@ -176,7 +176,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
 
     do {
         ret = s->write(s, data, size);
-    } while (ret == -1 && ((s->get_error(s)) == EINTR || (s->get_error(s)) == EWOULDBLOCK));
+    } while (ret == -1 && ((s->get_error(s)) == EINTR));
 
     if (ret == -1)
         ret = -(s->get_error(s));

There is additional stuff that needs to test EWOULDBLOCK in further locations in the code. Otherwise migration will fail.

commit 2d875410cb168fa728dcde96885a3e4ddfd0bb58

Author: Dor Laor <[email protected]>
Date:   Thu May 21 12:29:39 2009 +0300

The migration code is non-blocking, designed for live migration.

Practically migrate_fd_put_buffer busy-loops trying to write, as on many machines EWOULDBLOCK==EAGAIN (look in
include/asm-generic/errno.h).

Based on Uri Lublin's patch.

qemu/buffered_file.c +2 -2
index be5baea..34cde6e 100644
@@ -86,7 +86,7 @@ static void buffered_flush(QEMUFileBuffered *s)
 
        ret = s->put_buffer(s->opaque, s->buffer + offset,
                            s->buffer_size - offset);
-        if (ret == -EAGAIN) {
+        if (ret == -EAGAIN || ret == -EWOULDBLOCK) {
            dprintf("backend not ready, freezing\n");
            s->freeze_output = 1;
            break;
@@ -132,7 +132,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in
        }
 
        ret = s->put_buffer(s->opaque, buf + offset, size - offset);
-        if (ret == -EAGAIN) {
+        if (ret == -EAGAIN || ret ==-EWOULDBLOCK) {
            dprintf("backend not ready, freezing\n");
            s->freeze_output = 1;
            break;
qemu/migration.c +1 -1
index 85757c5..8846eee 100644
@@ -174,7 +174,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
    if (ret == -1)
        ret = -(s->get_error(s));
 
-    if (ret == -EAGAIN)
+    if (ret == -EAGAIN || ret == -EWOULDBLOCK)
        qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
 
    return ret;
#2 lore raw
Quoted 34 lines · Dor Laor
Quoted 23 lines · Uri Lublin

The migration code is non-blocking, designed for live migration.

Practically migrate_fd_put_buffer busy-loops trying to write, as on many machines EWOULDBLOCK==EAGAIN (look in include/asm-generic/errno.h).

---
 migration.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
migration.c +1 -1
index 859d945..ca397fa 100644
@@ -176,7 +176,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const 
 void *data, size_t size)
 
     do {
         ret = s->write(s, data, size);
-    } while (ret == -1 && ((s->get_error(s)) == EINTR || 
 (s->get_error(s)) == EWOULDBLOCK));
+    } while (ret == -1 && ((s->get_error(s)) == EINTR));
 
Quoted 3 lines
     if (ret == -1)
         ret = -(s->get_error(s));

There is additional stuff that needs to test EWOULDBLOCK in further locations in the code. Otherwise migration will fail.

commit 2d875410cb168fa728dcde96885a3e4ddfd0bb58

Author: Dor Laor <[email protected]>
Date:   Thu May 21 12:29:39 2009 +0300
Quoted 6 lines

The migration code is non-blocking, designed for live migration.
Practically migrate_fd_put_buffer busy-loops trying to write, as
on many machines EWOULDBLOCK==EAGAIN (look in
include/asm-generic/errno.h).
Based on Uri Lublin's patch.

This is whitespace damaged, presumably from copy/paste, can you resend?

Signature · 3 lines
Regards,

Anthony Liguori
#3 lore raw
Quoted 3 lines · Anthony Liguori

This is whitespace damaged, presumably from copy/paste, can you resend?

Here is a better one.

Quoted 1 line

From 2d875410cb168fa728dcde96885a3e4ddfd0bb58 Mon Sep 17 00:00:00 2001

From: Dor Laor <[email protected]>
Date: Thu, 21 May 2009 12:29:39 +0300
Subject: [PATCH] The migration code is non-blocking, designed for live migration.

Practically migrate_fd_put_buffer busy-loops trying to write, as on many machines EWOULDBLOCK==EAGAIN (look in include/asm-generic/errno.h).

Based on Uri Lublin's patch.

---
 qemu/buffered_file.c |    4 ++--
 qemu/migration.c     |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
qemu/buffered_file.c +2 -2
index be5baea..34cde6e 100644
@@ -86,7 +86,7 @@ static void buffered_flush(QEMUFileBuffered *s)
 
         ret = s->put_buffer(s->opaque, s->buffer + offset,
                             s->buffer_size - offset);
-        if (ret == -EAGAIN) {
+        if (ret == -EAGAIN || ret == -EWOULDBLOCK) {
             dprintf("backend not ready, freezing\n");
             s->freeze_output = 1;
             break;
@@ -132,7 +132,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in
         }
 
         ret = s->put_buffer(s->opaque, buf + offset, size - offset);
-        if (ret == -EAGAIN) {
+        if (ret == -EAGAIN || ret ==-EWOULDBLOCK) {
             dprintf("backend not ready, freezing\n");
             s->freeze_output = 1;
             break;
qemu/migration.c +1 -1
index 85757c5..8846eee 100644
@@ -174,7 +174,7 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
     if (ret == -1)
         ret = -(s->get_error(s));
 
-    if (ret == -EAGAIN)
+    if (ret == -EAGAIN || ret == -EWOULDBLOCK)
         qemu_set_fd_handler2(s->fd, NULL, NULL, migrate_fd_put_notify, s);
 
     return ret;
Signature · 1 line
1.5.6.6