mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-02 07:15:31 +00:00
cr: Preparations for snapshot
1. Directory with images may have a "parent" symlink pointing to the place where the previous snapshot is 2. Each pagemap will have "in_parent" bit, which means, that the pages for this pagemap entry are not in the respective page.img but in parent 3. New --leave-running option to use with --snapshot not to kill tasks after snapshot Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
16
crtools.c
16
crtools.c
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
|
|||||||
int log_inited = 0;
|
int log_inited = 0;
|
||||||
int log_level = 0;
|
int log_level = 0;
|
||||||
|
|
||||||
static const char short_opts[] = "dsf:t:p:hcD:o:n:vxVr:jl";
|
static const char short_opts[] = "dsRf:t:p:hcD:o:n:vxVr:jl";
|
||||||
|
|
||||||
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
|
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
|
||||||
|
|
||||||
@@ -90,6 +90,7 @@ int main(int argc, char *argv[])
|
|||||||
{ "tree", required_argument, 0, 't' },
|
{ "tree", required_argument, 0, 't' },
|
||||||
{ "pid", required_argument, 0, 'p' },
|
{ "pid", required_argument, 0, 'p' },
|
||||||
{ "leave-stopped", no_argument, 0, 's' },
|
{ "leave-stopped", no_argument, 0, 's' },
|
||||||
|
{ "leave-running", no_argument, 0, 'R' },
|
||||||
{ "restore-detached", no_argument, 0, 'd' },
|
{ "restore-detached", no_argument, 0, 'd' },
|
||||||
{ "contents", no_argument, 0, 'c' },
|
{ "contents", no_argument, 0, 'c' },
|
||||||
{ "file", required_argument, 0, 'f' },
|
{ "file", required_argument, 0, 'f' },
|
||||||
@@ -113,6 +114,7 @@ int main(int argc, char *argv[])
|
|||||||
{ "page-server", no_argument, 0, 50},
|
{ "page-server", no_argument, 0, 50},
|
||||||
{ "address", required_argument, 0, 51},
|
{ "address", required_argument, 0, 51},
|
||||||
{ "port", required_argument, 0, 52},
|
{ "port", required_argument, 0, 52},
|
||||||
|
{ "snapshot", optional_argument, 0, 53},
|
||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,6 +126,9 @@ int main(int argc, char *argv[])
|
|||||||
case 's':
|
case 's':
|
||||||
opts.final_state = TASK_STOPPED;
|
opts.final_state = TASK_STOPPED;
|
||||||
break;
|
break;
|
||||||
|
case 'R':
|
||||||
|
opts.final_state = TASK_ALIVE;
|
||||||
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
opts.ext_unix_sk = true;
|
opts.ext_unix_sk = true;
|
||||||
break;
|
break;
|
||||||
@@ -256,6 +261,10 @@ int main(int argc, char *argv[])
|
|||||||
case 'l':
|
case 'l':
|
||||||
opts.handle_file_locks = true;
|
opts.handle_file_locks = true;
|
||||||
break;
|
break;
|
||||||
|
case 53:
|
||||||
|
opts.mem_snapshot = true;
|
||||||
|
opts.snap_parent = optarg;
|
||||||
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
pr_msg("Version: %s\n", version);
|
pr_msg("Version: %s\n", version);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -275,6 +284,9 @@ int main(int argc, char *argv[])
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.mem_snapshot)
|
||||||
|
pr_info("Will do snapshot from %s\n", opts.snap_parent);
|
||||||
|
|
||||||
ret = open_image_dir();
|
ret = open_image_dir();
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
pr_perror("can't open currect directory");
|
pr_perror("can't open currect directory");
|
||||||
@@ -355,8 +367,10 @@ usage:
|
|||||||
pr_msg(" -t|--tree checkpoint/restore the whole process tree identified by pid\n");
|
pr_msg(" -t|--tree checkpoint/restore the whole process tree identified by pid\n");
|
||||||
pr_msg(" -d|--restore-detached detach after restore\n");
|
pr_msg(" -d|--restore-detached detach after restore\n");
|
||||||
pr_msg(" -s|--leave-stopped leave tasks in stopped state after checkpoint instead of killing them\n");
|
pr_msg(" -s|--leave-stopped leave tasks in stopped state after checkpoint instead of killing them\n");
|
||||||
|
pr_msg(" -R|--leave-running leave tasks in running state after checkpoint\n");
|
||||||
pr_msg(" -D|--images-dir directory where to put images to\n");
|
pr_msg(" -D|--images-dir directory where to put images to\n");
|
||||||
pr_msg(" --pidfile [FILE] write a pid of a root task in this file\n");
|
pr_msg(" --pidfile [FILE] write a pid of a root task in this file\n");
|
||||||
|
pr_msg(" --snapshot <[DIR]> create snapshot (relative to DIR images if given)\n");
|
||||||
|
|
||||||
pr_msg("\n* Special resources support:\n");
|
pr_msg("\n* Special resources support:\n");
|
||||||
pr_msg(" -x|--%s allow external unix connections\n", USK_EXT_PARAM);
|
pr_msg(" -x|--%s allow external unix connections\n", USK_EXT_PARAM);
|
||||||
|
22
image.c
22
image.c
@@ -325,7 +325,29 @@ int open_image_dir(void)
|
|||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
if (opts.snap_parent) {
|
||||||
|
ret = symlink(opts.snap_parent, CR_PARENT_LINK);
|
||||||
|
if (ret < 0) {
|
||||||
|
pr_perror("Can't link parent snapshot.");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(CR_PARENT_LINK, O_RDONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
pr_perror("Can't open parent snapshot.");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = install_service_fd(PARENT_FD_OFF, fd);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
err:
|
||||||
|
close_image_dir();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void close_image_dir(void)
|
void close_image_dir(void)
|
||||||
|
@@ -117,6 +117,8 @@ struct cr_options {
|
|||||||
struct list_head scripts;
|
struct list_head scripts;
|
||||||
bool use_page_server;
|
bool use_page_server;
|
||||||
struct sockaddr_in ps_addr;
|
struct sockaddr_in ps_addr;
|
||||||
|
bool mem_snapshot;
|
||||||
|
char *snap_parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct cr_options opts;
|
extern struct cr_options opts;
|
||||||
@@ -131,10 +133,13 @@ enum sfd_type {
|
|||||||
PROC_FD_OFF,
|
PROC_FD_OFF,
|
||||||
CTL_TTY_OFF,
|
CTL_TTY_OFF,
|
||||||
SELF_STDIN_OFF,
|
SELF_STDIN_OFF,
|
||||||
|
PARENT_FD_OFF,
|
||||||
|
|
||||||
SERVICE_FD_MAX
|
SERVICE_FD_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define CR_PARENT_LINK "parent"
|
||||||
|
|
||||||
extern int clone_service_fd(int id);
|
extern int clone_service_fd(int id);
|
||||||
extern int init_service_fd(void);
|
extern int init_service_fd(void);
|
||||||
extern int get_service_fd(enum sfd_type type);
|
extern int get_service_fd(enum sfd_type type);
|
||||||
|
@@ -5,4 +5,5 @@ message pagemap_head {
|
|||||||
message pagemap_entry {
|
message pagemap_entry {
|
||||||
required uint64 vaddr = 1;
|
required uint64 vaddr = 1;
|
||||||
required uint32 nr_pages = 2;
|
required uint32 nr_pages = 2;
|
||||||
|
optional bool in_parent = 3;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user