[CRIU] [PATCH 3/5] restorer: do page-size reads in a while loop

Adrian Reber adrian at lisas.de
Tue Aug 21 11:20:47 EDT 2012


When reading pages-*.img over a network socket using read() and size
PAGE_SIZE it might not always be possible to read the complete
PAGE_SIZE in one read(). Therefore read in while loop until PAGE_SIZE
has actually been read.

Signed-off-by: Adrian Reber <adrian at lisas.de>
---
 restorer.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/restorer.c b/restorer.c
index 95a7922..48011cb 100644
--- a/restorer.c
+++ b/restorer.c
@@ -343,6 +343,7 @@ long __export_restore_task(struct task_restore_core_args *args)
 	 * Read page contents.
 	 */
 	while (1) {
+		long i = 0;
 		ret = sys_read(args->fd_pages, &va, sizeof(va));
 		if (!ret)
 			break;
@@ -353,11 +354,14 @@ long __export_restore_task(struct task_restore_core_args *args)
 			goto core_restore_end;
 		}
 
-		ret = sys_read(args->fd_pages, (void *)va, PAGE_SIZE);
-		if (ret != PAGE_SIZE) {
-			write_num_n(__LINE__);
-			write_num_n(ret);
-			goto core_restore_end;
+		while (i != PAGE_SIZE) {
+			ret = sys_read(args->fd_pages, (void *)va, PAGE_SIZE - i);
+			if (ret < 0) {
+				write_num_n(__LINE__);
+				write_num_n(ret);
+				goto core_restore_end;
+			}
+			i += ret;
 		}
 	}
 
-- 
1.7.6.5



More information about the CRIU mailing list