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