-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCheckpointRestore.cpp
135 lines (105 loc) · 2.8 KB
/
CheckpointRestore.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "CheckpointRestore.hpp"
#include <criu.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <jni.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>
JNIEXPORT void JNICALL Java_CheckpointRestore_CheckTheWorldNative(JNIEnv *env, jobject obj) {
int init_result = criu_init_opts();
if (init_result < 0) {
perror("Can't init opts");
}
int result = criu_check();
if (result == 0) {
printf("Criu Check success\n");
} else {
printf("Criu Check failed with error: %d: %s\n", result, strerror(result));
}
return;
}
JNIEXPORT void JNICALL Java_CheckpointRestore_SaveTheWorldNative (JNIEnv * env, jobject jobj, jstring jstr) {
const char * path = env->GetStringUTFChars(jstr, NULL);
struct stat st = {0};
if (stat(path, &st) == -1) {
mkdir(path, 0700);
}
int fd = open(path, O_DIRECTORY);
printf("\npath = %s\n",path);
if (fd < 0) {
perror("Can't open images dir");
}
int init_result = criu_init_opts();
if (init_result < 0) {
perror("Can't init opts");
}
criu_set_images_dir_fd(fd);
criu_set_shell_job(true);
criu_set_log_level(4);
criu_set_log_file((char *) "save.log");
criu_set_leave_running(true);
criu_set_ext_unix_sk(true);
int ret = criu_dump();
if (ret >= 0) {
printf("Successful dump\n");
} else {
printf("Error from dump %d\n", ret);
perror("Dump Error");
}
}
/*
* Class: CheckpointRestore
* Method: RestoreTheWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_CheckpointRestore_RestoreTheWorldNative
(JNIEnv * env, jobject jobj, jstring jstr) {
const char * path = env->GetStringUTFChars(jstr, NULL);
int fd = open(path, O_DIRECTORY);
if (fd < 0) {
perror("Can't open images dir");
}
int init_result = criu_init_opts();
if (init_result < 0) {
perror("Can't init opts");
}
printf("RestoreTheWorld: file = %s fd = %d\n", path, fd);
criu_set_shell_job(true);
criu_set_images_dir_fd(fd);
criu_set_log_file((char *) "javarestore.log");
criu_set_log_level(4);
int pid = criu_restore_child();
if (pid < 0) {
perror("Criu Restore Bad Pid \n");
} else {
int status = 0;
int result = waitpid(pid, &status, 0);
if (result < 0) {
printf("pid = %d status = %d result = %d\n", pid, status, result);
perror("Can't wait rchild");
}
}
}
/*
* Class: CheckpointRestore
* Method: MigrateTheWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_CheckpointRestore_MigrateTheWorld
(JNIEnv *, jobject);
/*
* Class: CheckpointRestore
* Method: SaveTheWorldIncremental
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_CheckpointRestore_SaveTheWorldIncremental
(JNIEnv *, jobject);