Skip to content

Commit

Permalink
criu: Fault injection core
Browse files Browse the repository at this point in the history
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.

Two points are introduced -- early on dump, right after loading
the parasite and right after creation of the root task.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
xemul committed Oct 19, 2015
1 parent c405304 commit 68baf8e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile.crtools
Expand Up @@ -75,6 +75,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
obj-y += pie/util-fd.o
obj-y += pie/util.o

Expand Down
6 changes: 6 additions & 0 deletions cr-dump.c
Expand Up @@ -81,6 +81,7 @@
#include "lsm.h"
#include "seccomp.h"
#include "seize.h"
#include "fault-injection.h"

#include "asm/dump.h"

Expand Down Expand Up @@ -1195,6 +1196,11 @@ static int dump_one_task(struct pstree_item *item)
goto err;
}

if (fault_injected(FI_DUMP_EARLY)) {
pr_info("fault: CRIU sudden detach\n");
BUG();
}

if (root_ns_mask & CLONE_NEWPID && root_item == item) {
int pfd;

Expand Down
7 changes: 6 additions & 1 deletion cr-restore.c
Expand Up @@ -76,7 +76,7 @@
#include "security.h"
#include "lsm.h"
#include "seccomp.h"

#include "fault-injection.h"
#include "parasite-syscall.h"

#include "protobuf.h"
Expand Down Expand Up @@ -1531,6 +1531,11 @@ static int restore_task_with_children(void *_arg)
if (prepare_sigactions() < 0)
goto err_fini_mnt;

if (fault_injected(FI_RESTORE_ROOT_ONLY)) {
pr_info("fault: Restore root task failure!\n");
BUG();
}

if (create_children_and_session())
goto err_fini_mnt;

Expand Down
4 changes: 4 additions & 0 deletions crtools.c
Expand Up @@ -40,6 +40,7 @@
#include "action-scripts.h"
#include "security.h"
#include "irmap.h"
#include "fault-injection.h"

#include "setproctitle.h"

Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions 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;
}
19 changes: 19 additions & 0 deletions include/fault-injection.h
@@ -0,0 +1,19 @@
#ifndef __CR_FAULT_INJECTION_H__
#define __CR_FAULT_INJECTION_H__
#include <stdbool.h>

enum faults {
FI_NONE = 0,
FI_DUMP_EARLY,
FI_RESTORE_ROOT_ONLY,
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

0 comments on commit 68baf8e

Please sign in to comment.