exec-migration: handle EINTR in popen_get_buffer()
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
@@ -215,7 +215,14 @@ static int popen_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int sstatic 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
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.
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.
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.
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.
Signed-off-by Uri Lublin <[email protected]>--- savevm.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)savevm.c +0
-0
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 sstatic 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
Michael S. Tsirkin
Acked-byQuoted 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.
Signed-off-by Uri Lublin <[email protected]>--- savevm.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)savevm.c +0
-0savevm.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 sstatic 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
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.
Signed-off-by Uri Lublin<[email protected]>--- savevm.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
Quoted 16 lines
Quoted 5 lines
savevm.c +0
-0savevm.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 sstatic 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.