[CRIU] [PATCH 4/5] deduplication: add punching holes in "parent"

Tikhomirov Pavel snorcht at gmail.com
Sun Oct 13 05:22:55 PDT 2013


punch where coresponding data was updated in curent snapshot

Signed-off-by: Tikhomirov Pavel <snorcht at gmail.com>
---
 cr-dedup.c         |   11 +++++++++++
 include/cr-dedup.h |    9 +++++++++
 2 files changed, 20 insertions(+)

diff --git a/cr-dedup.c b/cr-dedup.c
index 25a3129..b76b7fb 100644
--- a/cr-dedup.c
+++ b/cr-dedup.c
@@ -101,6 +101,17 @@ int _cr_dedup(int predump_fd, int pid)
 		i_len = (long)(min(iov.iov_base + iov.iov_len, iov2.iov_base + iov2.iov_len)
 			- max(iov.iov_base, iov2.iov_base));
 
+		if (i_len > 0 && !pr.pe->in_parent && !pr2.pe->in_parent) {
+			/* punch */
+			pr_info("Punch!/%lu/%lu/\n", off * PAGE_SIZE + i_off, i_len);
+
+			ret = fallocate(pr2.fd_pg, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off * PAGE_SIZE + i_off, i_len);
+			if (ret != 0) {
+				pr_err("Error fallocate : %d\n", errno);
+				goto exit;
+			}
+		}
+
 		if (iov.iov_base + iov.iov_len == iov2.iov_base + iov2.iov_len) {
 			ret = pr.get_pagemap(&pr, &iov);
 			if (ret <= 0)
diff --git a/include/cr-dedup.h b/include/cr-dedup.h
index 3840a12..54a5ec9 100644
--- a/include/cr-dedup.h
+++ b/include/cr-dedup.h
@@ -1,6 +1,15 @@
 #ifndef __CR_DEDUP_H__
 #define __CR_DEDUP_H__
 
+#define FALLOC_FL_KEEP_SIZE	0x01 /* default is extend size */
+#define FALLOC_FL_PUNCH_HOLE	0x02 /* de-allocates range */
+
+struct to_punch{
+	struct list_head list;
+	unsigned long off;
+	unsigned long nr_pages;
+};
+
 int cr_dedup(void);
 
 #endif
-- 
1.7.9.5



More information about the CRIU mailing list