[CRIU] [PATCH 1/5]v2 deduplication: add separate function for punch to use on restore

Tikhomirov Pavel snorcht at gmail.com
Wed Feb 19 06:56:30 PST 2014


Signed-off-by: Tikhomirov Pavel <snorcht at gmail.com>
---
 cr-dedup.c          | 26 ++++++++++++++++++--------
 include/page-read.h |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/cr-dedup.c b/cr-dedup.c
index 80ebb53..097892d 100644
--- a/cr-dedup.c
+++ b/cr-dedup.c
@@ -101,6 +101,19 @@ exit:
 	return 0;
 }
 
+int punch_hole(int fd, unsigned long off, unsigned long len)
+{
+	int ret;
+	pr_debug("Punch!/%lu/%lu/\n", off, len);
+	ret = fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
+			off, len);
+	if (ret != 0) {
+		pr_perror("Error punching hole");
+		return -1;
+	}
+	return 0;
+}
+
 int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
 {
 	unsigned long off;
@@ -133,14 +146,11 @@ int dedup_one_iovec(struct page_read *pr, struct iovec *iov)
 		piov_end = (unsigned long)piov.iov_base + piov.iov_len;
 		off_real = lseek(pr->fd_pg, 0, SEEK_CUR);
 		if (!pr->pe->in_parent) {
-			pr_debug("Punch!/%lu/%lu/\n", off_real, min(piov_end, iov_end) - off);
-			ret = fallocate(pr->fd_pg, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
-					off_real, min(piov_end, iov_end) - off);
-			if (ret != 0) {
-				pr_perror("Error punching hole : %d", errno);
-				return -1;
-			}
-		}
+			ret = punch_hole(pr->fd_pg, off_real, min(piov_end, iov_end) - off);
+			if (ret == -1)
+				return ret;
+		} else
+			pr_debug("Dedup is on inparent PE\n");
 		prp = pr->parent;
 		if (prp) {
 			/* recursively */
diff --git a/include/page-read.h b/include/page-read.h
index 4d70471..2df3ec8 100644
--- a/include/page-read.h
+++ b/include/page-read.h
@@ -73,4 +73,5 @@ extern void pagemap2iovec(PagemapEntry *pe, struct iovec *iov);
 extern int seek_pagemap_page(struct page_read *pr, unsigned long vaddr, bool warn);
 
 extern int dedup_one_iovec(struct page_read *pr, struct iovec *iov);
+extern int punch_hole(int fd, unsigned long off, unsigned long len);
 #endif /* __CR_PAGE_READ_H__ */
-- 
1.8.3.2



More information about the CRIU mailing list