[CRIU] [PATCH 1/4] fi: Skeleton for fault-injection ability
Pavel Emelyanov
xemul at parallels.com
Thu Sep 24 08:07:47 PDT 2015
This patch(set) is inspired by similar from Andrey Vagin sent
sime time earlier.
The major idea is to artificially fail criu dump or restore at
specific places and let zdtm tests check whether failed dump
or restore resulted in anything bad.
This particular patch introduces the ability to tell criu "fail
at X point". Each point is specified with a integer constant
and with the next patches there will appear places over the
code checking for specific fail code being set and failing.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
Makefile.crtools | 1 +
crtools.c | 4 ++++
fault-injection.c | 22 ++++++++++++++++++++++
include/fault-injection.h | 17 +++++++++++++++++
4 files changed, 44 insertions(+)
create mode 100644 fault-injection.c
create mode 100644 include/fault-injection.h
diff --git a/Makefile.crtools b/Makefile.crtools
index 80f704f..e67f72f 100644
--- a/Makefile.crtools
+++ b/Makefile.crtools
@@ -74,6 +74,7 @@ obj-y += plugin.o
obj-y += cr-errno.o
obj-y += pie/pie-relocs.o
obj-y += seize.o
+obj-y += fault-injection.o
ifneq ($(MAKECMDGOALS),clean)
incdeps := y
diff --git a/crtools.c b/crtools.c
index ea8b889..d3812a1 100644
--- a/crtools.c
+++ b/crtools.c
@@ -40,6 +40,7 @@
#include "action-scripts.h"
#include "security.h"
#include "irmap.h"
+#include "fault-injection.h"
#include "setproctitle.h"
@@ -257,6 +258,9 @@ int main(int argc, char *argv[], char *envp[])
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
+ if (fault_injection_init())
+ return 1;
+
cr_pb_init();
if (restrict_uid(getuid(), getgid()))
return 1;
diff --git a/fault-injection.c b/fault-injection.c
new file mode 100644
index 0000000..f239fd9
--- /dev/null
+++ b/fault-injection.c
@@ -0,0 +1,22 @@
+#include <stdlib.h>
+#include "fault-injection.h"
+
+enum faults fi_strategy;
+
+int fault_injection_init()
+{
+ char *val;
+ int strat;
+
+ val = getenv("CRIU_FAULT");
+ if (val == NULL)
+ return 0;
+
+ strat = atoi(val);
+
+ if (strat <= 0 || strat >= FI_MAX)
+ return -1;
+
+ fi_strategy = strat;
+ return 0;
+}
diff --git a/include/fault-injection.h b/include/fault-injection.h
new file mode 100644
index 0000000..97531e6
--- /dev/null
+++ b/include/fault-injection.h
@@ -0,0 +1,17 @@
+#ifndef __CR_FAULT_INJECTION_H__
+#define __CR_FAULT_INJECTION_H__
+#include <stdbool.h>
+
+enum faults {
+ FI_NONE = 0,
+ FI_MAX,
+};
+
+extern enum faults fi_strategy;
+extern int fault_injection_init(void);
+
+static inline bool fault_injected(enum faults f)
+{
+ return fi_strategy == f;
+}
+#endif
--
1.9.3
More information about the CRIU
mailing list