[CRIU] [PATCH] bfd: bread: read in a loop when running with --remote
Mike Rapoport
rppt at linux.vnet.ibm.com
Sat Jul 1 18:41:11 MSK 2017
From: Omri Kramer <omri.kramer at gmail.com>
When the --remote option is used, the file descriptor used in bread is a
socket and read from it may return after only part of the data is received.
Keep looping until all the data is received when --remote option is on.
Signed-off-by: Omri Kramer <omri.kramer at gmail.com>
Signed-off-by: Lior Fisch <fischlior at gmail.com>
Reviewed-by: Mike Rapoprot <rppt at linux.vnet.ibm.com>
---
criu/bfd.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/criu/bfd.c b/criu/bfd.c
index 8269ab1..c03bc88 100644
--- a/criu/bfd.c
+++ b/criu/bfd.c
@@ -298,9 +298,29 @@ int bread(struct bfd *bfd, void *buf, int size)
{
struct xbuf *b = &bfd->b;
int more = 1, filled = 0;
+ int ret;
+ size_t curr;
- if (!bfd_buffered(bfd))
- return read(bfd->fd, buf, size);
+ if (!bfd_buffered(bfd)) {
+ if(!opts.remote)
+ return read(bfd->fd, buf, size);
+
+ /*
+ * With '--remote' bfd->fd is a socket and we may get
+ * partial reads here. Keep reading until all the data
+ * is received from the socket
+ */
+ while (1) {
+ ret = read(bfd->fd, buf + curr, size - curr);
+ if (ret < 0) {
+ pr_perror("Can't read from buffer\n");
+ return -1;
+ }
+
+ curr += ret;
+ if (curr == size || ret == 0)
+ return curr;
+ }
while (more > 0) {
int chunk;
--
2.7.4
More information about the CRIU
mailing list