示例#1
0
文件: 2.c 项目: one-eye-bob/OS2-Lab
void setCriuOptions(){
	//Reserved for the file descriptor
	int fd;

	//Open if "checkpoints" is a directory, or fail
	fd = open("checkpoints", O_DIRECTORY);

	//Check if open didn't fail
	if(fd == -1){
		perror("Error: open failed to open the 'checkpoints' directory.\n");
		//return -1;	
	}

	//Set up criu options
	int ret = criu_init_opts();
	if(ret == -1){
		perror("Error: criu_init_opts failed to inital the request options.\n");
	}

	//Set the images directory, where they will be stored
	criu_set_images_dir_fd(fd);

	//Specify the CRIU service socket
	criu_set_service_address("criu_service.socket");

	//Specify how to connnect to service socket
	criu_set_service_comm(CRIU_COMM_SK);
	
	//Make it to continue executing after dumping
	criu_set_leave_running(true);

	//Make it a shell job, since criu would be unable to dump otherwise
	criu_set_shell_job(true);
}
示例#2
0
文件: 1.c 项目: one-eye-bob/OS2-Lab
int main(){
	//Reserved for the file descriptor
	int fd;
	
	//Reserved to check the failures for the following functions
	int ret;
	
	//Create the "dump" directory if it doesn't exist, only owner has (full) access
	ret = mkdir("dump", 0700);
	if(ret == -1){
		perror("Error: Could not create dump folder.\n");
		return -1;
	}
	
	//Open if "dump" is a directory, or fail
	fd = open("dump", O_DIRECTORY);
	
	//Check if open didn't fail
	if(fd == -1){
		perror("Error: open failed to open the 'dump' directory.\n");
		return -1;	
	}
	
	//Preparation for CRIU:
	//Initial the request options
	ret = criu_init_opts();
	if(ret == -1){
		perror("Error: criu_init_opts failed to inital the request options.\n");
		return -1;
	}
	
	//Set the images directory, where they will be stored
	criu_set_images_dir_fd(fd);
	
	//Specify the CRIU service socket
	criu_set_service_address("criu_service.socket");
	
	//Specify how to connnect to service socket
	criu_set_service_comm(CRIU_COMM_SK);
	
	//To test whether the kernel support is up-to-dater
	ret = criu_check();
	if(ret < 0){
		perror("Error: criu_check failed.\n");
		return -1;
	}

	return 0;	
}
示例#3
0
int main(int argc, char **argv)
{
    int pid, ret, fd, p[2];

    printf("--- Start loop ---\n");
    pipe(p);
    pid = fork();
    if (pid < 0) {
        perror("Can't");
        return -1;
    }

    if (!pid) {
        printf("   `- loop: initializing\n");
        if (setsid() < 0)
            exit(1);
        if (signal(SIGUSR1, sh) == SIG_ERR)
            exit(1);

        close(0);
        close(1);
        close(2);
        close(p[0]);

        ret = SUCC_ECODE;
        write(p[1], &ret, sizeof(ret));
        close(p[1]);

        while (!stop)
            sleep(1);
        exit(SUCC_ECODE);
    }

    close(p[1]);

    /* Wait for kid to start */
    ret = -1;
    read(p[0], &ret, sizeof(ret));
    if (ret != SUCC_ECODE) {
        printf("Error starting loop\n");
        goto err;
    }

    /* Wait for pipe to get closed, then dump */
    read(p[0], &ret, 1);
    close(p[0]);

    printf("--- Dump loop ---\n");
    criu_init_opts();
    criu_set_service_address(argv[1]);
    criu_set_pid(pid);
    criu_set_log_file("dump.log");
    criu_set_log_level(4);
    fd = open(argv[2], O_DIRECTORY);
    criu_set_images_dir_fd(fd);

    ret = criu_dump();
    if (ret < 0) {
        what_err_ret_mean(ret);
        kill(pid, SIGKILL);
        goto err;
    }

    printf("   `- Dump succeeded\n");
    waitpid(pid, NULL, 0);

    printf("--- Restore loop ---\n");
    criu_init_opts();
    criu_set_log_level(4);
    criu_set_log_file("restore.log");
    criu_set_images_dir_fd(fd);

    pid = criu_restore_child();
    if (pid <= 0) {
        what_err_ret_mean(pid);
        return -1;
    }

    printf("   `- Restore returned pid %d\n", pid);
    kill(pid, SIGUSR1);
err:
    if (waitpid(pid, &ret, 0) < 0) {
        perror("   Can't wait kid");
        return -1;
    }

    return chk_exit(ret, SUCC_ECODE);
}
示例#4
0
int opal_crs_criu_checkpoint(pid_t pid, opal_crs_base_snapshot_t *base_snapshot,
                             opal_crs_base_ckpt_options_t *options,
                             opal_crs_state_type_t *state)
{
    int ret;
    int fd = 0;
    int oh = mca_crs_criu_component.super.output_handle;
    opal_crs_criu_snapshot_t *snapshot = NULL;
    char *dest = NULL;

    opal_output_verbose(10, oh, "crs:criu: checkpoint(%d, ---)", pid);

    snapshot = (opal_crs_criu_snapshot_t *)base_snapshot;
    snapshot->super.component_name = strdup(mca_crs_criu_component.super.base_version.mca_component_name);

    if (NULL == snapshot->super.metadata) {
        if (NULL == (snapshot->super.metadata = fopen(snapshot->super.metadata_filename, "a"))) {
            opal_output(oh, "crs:criu: checkpoint(): Error: Unable to open the file (%s)",
                        snapshot->super.metadata_filename);
            *state = OPAL_CRS_ERROR;
            goto cleanup;
        }
    }
    fprintf(snapshot->super.metadata, "%s%s\n", CRS_METADATA_COMP, snapshot->super.component_name);

    fclose(snapshot->super.metadata);
    snapshot->super.metadata = NULL;

    ret = criu_init_opts();

    if (ret < 0) {
        criu_error(ret, pid);
        *state = OPAL_CRS_ERROR;
        goto cleanup;
    }

    opal_output_verbose(10, oh, "crs:criu: criu_init_opts() returned %d", ret);

    dest = snapshot->super.snapshot_directory;
    opal_output_verbose(10, oh, "crs:criu: opening snapshot directory %s", dest);
    fd = open(dest, O_DIRECTORY);

    if (fd < 0) {
        *state = OPAL_CRS_ERROR;
        opal_output(oh, "crs:criu: checkpoint(): Error: Unable to open checkpoint "
                    "directory (%s) for pid (%d)", dest, pid);
        goto cleanup;
    }

    /* http://criu.org/C_API */
    criu_set_images_dir_fd(fd);
    criu_set_pid(pid);

    criu_set_log_file(mca_crs_criu_component.log_file);
    criu_set_log_level(mca_crs_criu_component.log_level);
    criu_set_tcp_established(mca_crs_criu_component.tcp_established);
    criu_set_shell_job(mca_crs_criu_component.shell_job);
    criu_set_ext_unix_sk(mca_crs_criu_component.ext_unix_sk);
    criu_set_leave_running(mca_crs_criu_component.leave_running);
    ret = criu_dump();

    if (ret < 0) {
        criu_error(ret, pid);
        *state = OPAL_CRS_ERROR;
        goto cleanup;
    }

    *state = OPAL_CRS_CONTINUE;

 cleanup:

    if (fd > 0) {
        close(fd);
    }

    if (OPAL_CRS_ERROR == *state) {
        return OPAL_ERROR;
    }
    return OPAL_SUCCESS;
}
示例#5
0
文件: test.c 项目: avagin/crtools
int main(int argc, char *argv[])
{
	int ret, fd;

	criu_set_service_address("criu_service.socket");

	puts("--- Check ---");
	ret = criu_check();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else
		puts("Success");

	puts("--- Dump loop ---");
	criu_init_opts();
	criu_set_pid(atoi(argv[1]));
	criu_set_log_file("dump.log");
	criu_set_log_level(4);
	fd = open("imgs_loop", O_DIRECTORY);
	criu_set_images_dir_fd(fd);

	ret = criu_dump();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else if (ret == 0)
		puts("Success");

	puts("--- Restore loop ---");
	criu_init_opts();
	criu_set_log_level(4);
	criu_set_log_file("restore.log");
	criu_set_images_dir_fd(fd);

	ret = criu_restore();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else if (ret > 0) {
		puts("Success");
		printf("pid %d\n", ret);
	}

	puts("--- Dump myself ---");
	criu_init_opts();
	criu_set_leave_running(true);
	criu_set_shell_job(true);
	criu_set_images_dir_fd(open("imgs_test", O_DIRECTORY));

	ret = criu_dump();
	if (ret < 0) {
		what_err_ret_mean(ret);
		return -1;
	} else {
		puts("Success");
		if (ret == 1)
			puts("Restored");
	}

	return 0;
}