[CRIU] [PATCH 3/4] deduplication: Compare predump files, old from "predump" directory

Tikhomirov Pavel snorcht at gmail.com
Wed Oct 9 07:06:27 PDT 2013


Signed-off-by: Tikhomirov Pavel <snorcht at gmail.com>
---
 cr-dedup.c          |  128 +++++++++++++++++++++++++++++++++++++++++++++++++++
 include/page-read.h |    2 +
 page-read.c         |   28 +++++++++--
 3 files changed, 155 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 cr-dedup.c
 mode change 100644 => 100755 include/page-read.h
 mode change 100644 => 100755 page-read.c

diff --git a/cr-dedup.c b/cr-dedup.c
old mode 100644
new mode 100755
index aa3c8a2..645f435
--- a/cr-dedup.c
+++ b/cr-dedup.c
@@ -9,9 +9,137 @@
 #include <string.h>
 
 #include "crtools.h"
+#include "page-read.h"
+#include "restorer.h"
 #include "cr-dedup.h"
 
 int cr_dedup(pid_t pid)
 {
+	DIR * dirp;
+	int ret, predump_fd = -1;
+	struct page_read pr, pr2;
+	unsigned long va, i, off;
+	struct iovec iov, iov2;
+
+	ret = open_page_read(pid, &pr);
+	if (ret)
+		return -1;
+	
+	dirp = opendir("parent");
+	if (dirp == NULL) {
+		ret = -1;
+		goto exit;
+	}
+
+	predump_fd = dirfd(dirp);
+	if (predump_fd == -1) {
+		ret = -1;
+		goto exit;
+	}
+
+	ret = open_page_read_dedup(predump_fd, pid, &pr2);
+	if (ret)
+		goto exit;
+
+	ret = pr.get_pagemap(&pr, &iov);
+	if (ret <= 0)
+		goto exit;
+
+	ret = pr2.get_pagemap(&pr2, &iov2);
+	if (ret <= 0)
+		goto exit;
+
+	off = 0;
+	while (1) {
+		unsigned long nr;
+		if (iov.iov_base != iov2.iov_base) {
+			pr_info("Pagemaps not equal\n");
+
+			if (iov.iov_base < iov2.iov_base){
+				lseek(pr.fd_pg, iov.iov_len, SEEK_CUR);
+				off += pr.pe->nr_pages;
+
+				ret = pr.get_pagemap(&pr, &iov);
+				if (ret <= 0)
+					break;
+			} else {
+				lseek(pr2.fd_pg, iov2.iov_len, SEEK_CUR);
+
+				ret = pr2.get_pagemap(&pr2, &iov2);
+				if (ret <= 0)
+					break;
+			}
+			continue;
+		}
+
+		if (iov.iov_len < iov2.iov_len) {
+			va = (unsigned long)iov.iov_base;
+			nr = pr.pe->nr_pages;
+		} else {
+			va = (unsigned long)iov2.iov_base;
+			nr = pr2.pe->nr_pages;
+		}
+
+		for (i = 0; i < nr; i++) {
+			unsigned char buf[PAGE_SIZE];
+			unsigned char buf2[PAGE_SIZE];
+			
+			ret = pr.read_page(&pr, va, buf);
+			if (ret < 0) {
+				pr_err("Can't read page");
+				goto exit;
+			}
+
+			ret = pr2.read_page(&pr2, va, buf2);
+			if (ret < 0) {
+				pr_err("Can't read page");
+				goto exit;
+			}
+
+			if (memcmp(buf, buf2, PAGE_SIZE) != 0) {
+				pr_info("Pages Not Equal : %lu\n", va);
+			} else {
+
+			}
+			
+			off++;
+			va += PAGE_SIZE;
+		}
+
+		if (nr < pr.pe->nr_pages) {	
+			lseek(pr.fd_pg, (pr.pe->nr_pages - nr)* PAGE_SIZE, SEEK_CUR);
+			off += pr.pe->nr_pages - nr;
+		}
+
+		if (nr < pr2.pe->nr_pages) {	
+			lseek(pr2.fd_pg, (pr2.pe->nr_pages - nr)* PAGE_SIZE, SEEK_CUR);
+		}
+
+		ret = pr.get_pagemap(&pr, &iov);
+		if (ret <= 0)
+			break;
+
+		ret = pr2.get_pagemap(&pr2, &iov2);
+		if (ret <= 0)
+			break;
+	}
+exit:
+	pr_info("Dedup test END\n");
+
+	pr.close(&pr);
+	pr2.close(&pr2);
+
+	if (dirp) {	
+		ret = closedir(dirp);
+		if (ret == -1)
+			return ret;
+	}
+
+	if (predump_fd >= 0) {
+		ret = close(predump_fd);
+		if (ret == -1)
+			return ret;
+	}
+
 	return 0;
 }
diff --git a/include/page-read.h b/include/page-read.h
old mode 100644
new mode 100755
index b19ea69..95337d6
--- a/include/page-read.h
+++ b/include/page-read.h
@@ -66,4 +66,6 @@ struct page_read {
 };
 
 int open_page_read(int pid, struct page_read *);
+int open_page_read_dedup(int dfd, int pid, struct page_read *);
+int open_page_rw(int pid, struct page_read *);
 #endif
diff --git a/page-read.c b/page-read.c
old mode 100644
new mode 100755
index 78b1303..b845b9f
--- a/page-read.c
+++ b/page-read.c
@@ -181,13 +181,16 @@ err_cl:
 	return -1;
 }
 
-static int open_page_read_at(int dfd, int pid, struct page_read *pr)
+static int open_page_rw_at(int dfd, int pid, struct page_read *pr, int rw)
 {
 	pr->pe = NULL;
 
 	pr->fd = open_image_at(dfd, CR_FD_PAGEMAP, O_RSTR, (long)pid);
 	if (pr->fd < 0) {
-		pr->fd_pg = open_image_at(dfd, CR_FD_PAGES_OLD, O_RSTR, pid);
+		if (rw)
+			pr->fd_pg = open_image_at(dfd, CR_FD_PAGES_OLD, O_RDWR, pid);
+		else
+			pr->fd_pg = open_image_at(dfd, CR_FD_PAGES_OLD, O_RSTR, pid);
 		if (pr->fd_pg < 0)
 			return -1;
 
@@ -203,7 +206,10 @@ static int open_page_read_at(int dfd, int pid, struct page_read *pr)
 			return -1;
 		}
 
-		pr->fd_pg = open_pages_image_at(dfd, O_RSTR, pr->fd);
+		if (rw)
+			pr->fd_pg = open_pages_image_at(dfd, O_RDWR, pr->fd);
+		else
+			pr->fd_pg = open_pages_image_at(dfd, O_RSTR, pr->fd);
 		if (pr->fd_pg < 0) {
 			close_page_read(pr);
 			return -1;
@@ -223,7 +229,23 @@ static int open_page_read_at(int dfd, int pid, struct page_read *pr)
 	return 0;
 }
 
+static int open_page_read_at(int dfd, int pid, struct page_read *pr)
+{
+	return open_page_rw_at(dfd, pid, pr, 0);
+}
+
 int open_page_read(int pid, struct page_read *pr)
 {
 	return open_page_read_at(get_service_fd(IMG_FD_OFF), pid, pr);
 }
+
+int open_page_read_dedup(int dfd, int pid, struct page_read *pr)
+{
+	return open_page_read_at(dfd, pid, pr);
+}
+
+int open_page_rw(int pid, struct page_read *pr)
+{
+        return open_page_rw_at(get_service_fd(IMG_FD_OFF), pid, pr, 1);
+}
+
-- 
1.7.9.5



More information about the CRIU mailing list