From 147a50b274c69d7de9f21cd29a488bc7a2ebeaee Mon Sep 17 00:00:00 2001 From: Liana Koleva <43767763+lianakoleva@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:23:26 +0000 Subject: [PATCH] Support criu-image-streamer through RPC Programs calling CRIU through RPC may want access to image streaming for faster data transfer. To use image streaming through RPC, (1) criu-image-streamer must be started by the calling program. (2) The RPC call must enable stream in `criu_opts`. Signed-off-by: Liana Koleva --- criu/cr-service.c | 27 ++++++++++++--------------- images/rpc.proto | 1 + 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/criu/cr-service.c b/criu/cr-service.c index b9d11ced22..0bde62b97b 100644 --- a/criu/cr-service.c +++ b/criu/cr-service.c @@ -285,7 +285,7 @@ int exec_rpc_query_external_files(char *name, int sk) static char images_dir[PATH_MAX]; -static int setup_opts_from_req(int sk, CriuOpts *req) +static int setup_opts_from_req(int sk, CriuOpts *req, int mode) { struct ucred ids; struct stat st; @@ -394,14 +394,10 @@ static int setup_opts_from_req(int sk, CriuOpts *req) if (req->parent_img) SET_CHAR_OPTS(img_parent, req->parent_img); - /* - * Image streaming is not supported with CRIU's service feature as - * the streamer must be started for each dump/restore operation. - * It is unclear how to do that with RPC, so we punt for now. - * This explains why we provide the argument mode=-1 instead of - * O_RSTR or O_DUMP. - */ - if (open_image_dir(images_dir_path, -1) < 0) { + if (req->stream) + opts.stream = true; + + if (open_image_dir(images_dir_path, mode) < 0) { pr_perror("Can't open images directory"); goto err; } @@ -810,7 +806,7 @@ static int dump_using_req(int sk, CriuOpts *req) bool self_dump = !req->pid; opts.mode = CR_DUMP; - if (setup_opts_from_req(sk, req)) + if (setup_opts_from_req(sk, req, O_DUMP)) goto exit; __setproctitle("dump --rpc -t %d -D %s", req->pid, images_dir); @@ -853,7 +849,7 @@ static int restore_using_req(int sk, CriuOpts *req) opts.restore_detach = true; opts.mode = CR_RESTORE; - if (setup_opts_from_req(sk, req)) + if (setup_opts_from_req(sk, req, O_RSTR)) goto exit; __setproctitle("restore --rpc -D %s", images_dir); @@ -905,7 +901,7 @@ static int check(int sk, CriuOpts *req) __setproctitle("check --rpc"); opts.mode = CR_CHECK; - if (setup_opts_from_req(sk, req)) + if (setup_opts_from_req(sk, req, -1)) exit(1); exit(!!cr_check()); @@ -937,7 +933,7 @@ static int pre_dump_using_req(int sk, CriuOpts *req, bool single) int ret = 1; opts.mode = CR_PRE_DUMP; - if (setup_opts_from_req(sk, req)) + if (setup_opts_from_req(sk, req, O_DUMP)) goto cout; __setproctitle("pre-dump --rpc -t %d -D %s", req->pid, images_dir); @@ -1015,7 +1011,7 @@ static int start_page_server_req(int sk, CriuOpts *req, bool daemon_mode) close(start_pipe[0]); opts.mode = CR_PAGE_SERVER; - if (setup_opts_from_req(sk, req)) + if (setup_opts_from_req(sk, req, -1)) goto out_ch; __setproctitle("page-server --rpc --address %s --port %hu", opts.addr, opts.port); @@ -1260,9 +1256,10 @@ static int handle_cpuinfo(int sk, CriuReq *msg) if (pid == 0) { int ret = 1; + int mode = (msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP) ? O_DUMP : -1; opts.mode = CR_CPUINFO; - if (setup_opts_from_req(sk, msg->opts)) + if (setup_opts_from_req(sk, msg->opts, mode)) goto cout; __setproctitle("cpuinfo %s --rpc -D %s", msg->type == CRIU_REQ_TYPE__CPUINFO_DUMP ? "dump" : "check", diff --git a/images/rpc.proto b/images/rpc.proto index 1a4722a9ce..42cc535bd5 100644 --- a/images/rpc.proto +++ b/images/rpc.proto @@ -145,6 +145,7 @@ message criu_opts { optional bool leave_stopped = 69; optional bool display_stats = 70; optional bool log_to_stderr = 71; + optional bool stream = 72; /* optional bool check_mounts = 128; */ }