Skip to contentSkip to conversation

exec-migration: handle EINTR in popen_get_buffer()

PATCH In review Uri Lublin 3 participants 7 messages Jun 8, 2009 – Jun 9, 2009

lore
Share & tools
lore

Uri Lublin

author
#0 lore raw

PATCH 1/1 exec-migration: handle EINTR in popen_get_buffer()

Sometimes, upon interrupt, fread returns with no data, and the (incoming exec) migration fails.

Fix by retrying on such a case.

---
 savevm.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
savevm.c +8 -1
index 248aea3..df2486d 100644
@@ -215,7 +215,14 @@ static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s
 static int popen_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
     QEMUFilePopen *s = opaque;
-    return fread(buf, 1, size, s->popen_file);
+    FILE *fp = s->popen_file;
+    int bytes;
+
+    do {
+        clearerr(fp);
+        bytes = fread(buf, 1, size, fp);
+    } while ((bytes == 0) && ferror(fp) && (errno == EINTR));
+    return bytes;
 }
 
 static int popen_close(void *opaque)
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 4 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and
the (incoming exec) migration fails.

Fix by retrying on such a case.

Maybe a better solution would be to introduce qemu_{f,}{read,write}, which handle EINTR and partial reads/writes.

author
#2 lore raw
Quoted 10 lines · Blue Swirl
Quoted 4 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and
the (incoming exec) migration fails.

Fix by retrying on such a case.

Maybe a better solution would be to introduce qemu_{f,}{read,write}, which handle EINTR and partial reads/writes.

The migration code does not care about partial reads/writes (at this level). Data is read /written to/from a buffer. When needed/available we retry.

I can introduce qemu_{f,}{read,write} which only takes care of EINTR (by retrying) but the caller would have to handle partial reads/writes (and EAGAIN). Would that be helpful ?

Thanks,
Uri.

#3 lore raw
Quoted 16 lines · Uri Lublin
Quoted 13 lines · Blue Swirl
Quoted 5 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and
the (incoming exec) migration fails.

Fix by retrying on such a case.

Maybe a better solution would be to introduce qemu_{f,}{read,write}, which handle EINTR and partial reads/writes.

Quoted 7 lines

The migration code does not care about partial reads/writes (at this
level). Data is read /written to/from a buffer. When needed/available we retry.

I can introduce qemu_{f,}{read,write} which only takes care of EINTR (by
retrying) but the caller would have to handle partial reads/writes (and EAGAIN). Would that be helpful ?

Would we really need two functions, one with partial read/write and EAGAIN handling and one with only EINTR? There's fread_targphys which handles partial reads/writes, but not EINTR/EAGAIN, otherwise in many {f]{read,write} use cases there is no handling for any of these.

#4 lore raw
In reply to Uri Lublin
Quoted 15 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and the (incoming exec) migration fails.

Fix by retrying on such a case.

---
 savevm.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
savevm.c +0 -0
index 248aea3..df2486d 100644

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 222

Quoted 9 lines
savevm.c +5 -1
@@ -215,7 +215,14 @@ static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s
 static int popen_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
     QEMUFilePopen *s = opaque;
-    return fread(buf, 1, size, s->popen_file);
+    FILE *fp = s->popen_file;
+    int bytes;
+
+    do {
+        clearerr(fp);

Would it make sense to only clearerr on EINTR - if we intend to retry?

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 224

Quoted 2 lines
savevm.c +2 -0
+        bytes = fread(buf, 1, size, fp);
+    } while ((bytes == 0) && ferror(fp) && (errno == EINTR));

This does nothing about partial reads (bytes != 0) I think it's intentional because the user actually retries partial reads. Right?

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 228

Quoted 4 lines
savevm.c +1 -0
+    return bytes;
 }
 
 static int popen_close(void *opaque)

Looking at qemu_fill_buffer, it seems that it is enough to set bytes to -EAGAIN. User will then retry. Correct?

Signature · 1 line
MST
#5 lore raw
Quoted 36 lines · Michael S. Tsirkin
Quoted 15 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and the (incoming exec) migration fails.

Fix by retrying on such a case.

---
 savevm.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
savevm.c +0 -0
index 248aea3..df2486d 100644

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 222

Quoted 9 lines
savevm.c +5 -1
@@ -215,7 +215,14 @@ static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s
 static int popen_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
 {
     QEMUFilePopen *s = opaque;
-    return fread(buf, 1, size, s->popen_file);
+    FILE *fp = s->popen_file;
+    int bytes;
+
+    do {
+        clearerr(fp);

Would it make sense to only clearerr on EINTR - if we intend to retry?

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 224

Quoted 2 lines
savevm.c +2 -0
+        bytes = fread(buf, 1, size, fp);
+    } while ((bytes == 0) && ferror(fp) && (errno == EINTR));

This does nothing about partial reads (bytes != 0) I think it's intentional because the user actually retries partial reads. Right?

Quoted 7 lines

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 228

Quoted 4 lines
savevm.c +1 -0
+    return bytes;
 }
 
 static int popen_close(void *opaque)

Looking at qemu_fill_buffer, it seems that it is enough to set bytes to -EAGAIN. User will then retry. Correct?

Looking at the code some more, at least qemu_get_byte really seems to expect a reliable read underneath, so it won't work. Generally the fact that qemu_get_byte returns 0 on error seems broken to me maybe we could fix that and then have a single loop retrying reads. But that's for another patch.

Signature · 1 line
MST
author
#6 lore raw
In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · Uri Lublin

Sometimes, upon interrupt, fread returns with no data, and the (incoming exec) migration fails.

Fix by retrying on such a case.

---
  savevm.c |    9 ++++++++-
  1 files changed, 8 insertions(+), 1 deletions(-)
Quoted 16 lines
Quoted 5 lines
savevm.c +0 -0
index 248aea3..df2486d 100644

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 222

Quoted 9 lines
savevm.c +5 -1
@@ -215,7 +215,14 @@ static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s
  static int popen_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
  {
      QEMUFilePopen *s = opaque;
-    return fread(buf, 1, size, s->popen_file);
+    FILE *fp = s->popen_file;
+    int bytes;
+
+    do {
+        clearerr(fp);

Would it make sense to only clearerr on EINTR - if we intend to retry?

I am not sure we should be worried about calling clearerr. I guess we can clearerr only upon ferror()!=0.

Quoted 8 lines

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 224

Quoted 3 lines
savevm.c +2 -0
+        bytes = fread(buf, 1, size, fp);
+    } while ((bytes == 0)&&  ferror(fp)&&  (errno == EINTR));

This does nothing about partial reads (bytes != 0) I think it's intentional because the user actually retries partial reads. Right?

It is intentional. The caller takes care of partial reads (lazily calling fill_buffer when needed).

Quoted 9 lines

savevm.c static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int s · line 228

Quoted 5 lines
savevm.c +1 -0
+    return bytes;
  }
 
  static int popen_close(void *opaque)

Looking at qemu_fill_buffer, it seems that it is enough to set bytes to -EAGAIN. User will then retry. Correct?

Currently qemu_fill_buffer does not retry (nor its callers).

Thanks for the review,
Uri.