[Devel] [RFC] criu: fault -- Add FI_HUGE_ANON_SHMEM_ID injection

Cyrill Gorcunov gorcunov at gmail.com
Thu Oct 19 18:25:06 MSK 2017


To verify that we can handle anon shared memory with
shmid more than 4 bytes long we have to wait until the
kernel gives us the id needed, which could take days/weeks.

In turn we can use our fault injection engine, just add

	export CRIU_FI_HUGE_ANON_SHMEM_ID_BASE=4294967295
	export CRIU_FAULT=132

into libvzctl scripts (/usr/libexec/libvzctl/scripts/vz-cpt)
and we add 0xffffffff into every shmid for anon shared memory

 | -rw-r--r-- 1 root root       22 Oct 19 18:20 pagemap-shmem-4295314050.img

so on dump the image will have a name like above.

Note: The patch is only to verify the former bug, adding arbitrary
numbers into shmid is not harmless, thus only valid for small containers
and should not be used for heavy ones.

https://jira.sw.ru/browse/PSBM-75112

Signed-off-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>
---
 criu/fault-injection.c         |  6 ++++++
 criu/include/fault-injection.h |  2 ++
 criu/proc_parse.c              | 14 +++++++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/criu/fault-injection.c b/criu/fault-injection.c
index f239fd9..68b0cb0 100644
--- a/criu/fault-injection.c
+++ b/criu/fault-injection.c
@@ -2,6 +2,7 @@
 #include "fault-injection.h"
 
 enum faults fi_strategy;
+unsigned long fi_huge_anon_shmem_id_base = 0xfffffffful;
 
 int fault_injection_init()
 {
@@ -17,6 +18,11 @@ int fault_injection_init()
 	if (strat <= 0 || strat >= FI_MAX)
 		return -1;
 
+	if (strat == FI_HUGE_ANON_SHMEM_ID) {
+		val = getenv("CRIU_FI_HUGE_ANON_SHMEM_ID_BASE");
+		fi_huge_anon_shmem_id_base = (unsigned long)atol(val);
+	}
+
 	fi_strategy = strat;
 	return 0;
 }
diff --git a/criu/include/fault-injection.h b/criu/include/fault-injection.h
index 46a5f71..30c104c 100644
--- a/criu/include/fault-injection.h
+++ b/criu/include/fault-injection.h
@@ -16,6 +16,7 @@ enum faults {
 	FI_NO_MEMFD = 129,
 	FI_NO_BREAKPOINTS = 130,
 	FI_PARTIAL_PAGES = 131,
+	FI_HUGE_ANON_SHMEM_ID = 132,
 	FI_MAX,
 };
 
@@ -38,6 +39,7 @@ extern enum faults fi_strategy;
 #define fault_injected(f)	__fault_injected(f, fi_strategy)
 
 extern int fault_injection_init(void);
+extern unsigned long fi_huge_anon_shmem_id_base;
 
 #else /* CR_NOGLIBC */
 
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index fcf9c81..26650b7 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -42,6 +42,7 @@
 #include "timerfd.h"
 #include "path.h"
 #include "fs-magic.h"
+#include "fault-injection.h"
 
 #include "protobuf.h"
 #include "images/fdinfo.pb-c.h"
@@ -295,8 +296,14 @@ static int vma_get_mapfile_user(const char *fname, struct vma_area *vma,
 		vma->e->status |= VMA_ANON_SHARED;
 		vma->e->shmid = vfi->ino;
 
-		if (!strncmp(fname, "/SYSV", 5))
+		if (!strncmp(fname, "/SYSV", 5)) {
 			vma->e->status |= VMA_AREA_SYSVIPC;
+		} else {
+			if (fault_injected(FI_HUGE_ANON_SHMEM_ID)) {
+				if (vma->e->shmid < fi_huge_anon_shmem_id_base)
+					vma->e->shmid += fi_huge_anon_shmem_id_base;
+			}
+		}
 
 		return 0;
 	}
@@ -583,6 +590,11 @@ static int handle_vma(pid_t pid, struct vma_area *vma_area,
 			if (!strncmp(file_path, "/SYSV", 5)) {
 				pr_info("path: %s\n", file_path);
 				vma_area->e->status |= VMA_AREA_SYSVIPC;
+			} else {
+				if (fault_injected(FI_HUGE_ANON_SHMEM_ID)) {
+					if (vma_area->e->shmid < fi_huge_anon_shmem_id_base)
+						vma_area->e->shmid += fi_huge_anon_shmem_id_base;
+				}
 			}
 		} else {
 			if (vma_area->e->flags & MAP_PRIVATE)
-- 
2.7.5



More information about the Devel mailing list