[CRIU] [PATCH v2] bfd: bread: read in a loop when running with --remote

Omri Kramer omri.kramer at gmail.com
Mon Jul 10 14:56:59 MSK 2017


When the --remote option is used, the file descriptor
used in bread is a socketand it may return after only
part of the data is read. Keep going 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>
---
 criu/bfd.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/criu/bfd.c b/criu/bfd.c
index 8269ab1..7c54d9b 100644
--- a/criu/bfd.c
+++ b/criu/bfd.c
@@ -15,6 +15,7 @@
 #include "util.h"
 #include "xmalloc.h"
 #include "page.h"
+#include "cr_options.h"
 
 #undef	LOG_PREFIX
 #define LOG_PREFIX "bfd: "
@@ -298,9 +299,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 = 0;
 
-	if (!bfd_buffered(bfd))
-		return read(bfd->fd, buf, size);
+	if (!bfd_buffered(bfd)) {
+		if(!opts.remote)
+			return read(bfd->fd, buf, size);
+		/*
+		 * Required to keep reading,
+		 * for succesfully Reading all the data
+		 * from the socket, when on remote option.
+		 */
+		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