-
Notifications
You must be signed in to change notification settings - Fork 617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support criu-image-streamer through RPC #2536
base: criu-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,19 +54,17 @@ | |
flush_early_log_buffer(STDERR_FILENO); | ||
} | ||
|
||
static int image_dir_mode(char *argv[], int optind) | ||
int image_dir_mode() | ||
{ | ||
switch (opts.mode) { | ||
case CR_DUMP: | ||
/* fallthrough */ | ||
case CR_CPUINFO_DUMP: | ||
/* fallthrough */ | ||
case CR_PRE_DUMP: | ||
return O_DUMP; | ||
case CR_RESTORE: | ||
return O_RSTR; | ||
case CR_CPUINFO: | ||
if (!strcmp(argv[optind + 1], "dump")) | ||
return O_DUMP; | ||
/* fallthrough */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to describe these changes in your commit message? |
||
default: | ||
return -1; | ||
} | ||
|
@@ -76,7 +74,7 @@ | |
return -1; | ||
} | ||
|
||
static int parse_criu_mode(char *mode) | ||
static int parse_criu_mode(char *mode, char *subcommand) | ||
{ | ||
if (!strcmp(mode, "dump")) | ||
opts.mode = CR_DUMP; | ||
|
@@ -96,8 +94,12 @@ | |
opts.mode = CR_SWRK; | ||
else if (!strcmp(mode, "dedup")) | ||
opts.mode = CR_DEDUP; | ||
else if (!strcmp(mode, "cpuinfo")) | ||
opts.mode = CR_CPUINFO; | ||
else if (!strcmp(mode, "cpuinfo") && subcommand == NULL) | ||
return -2; | ||
else if (!strcmp(mode, "cpuinfo") && !strcmp(subcommand, "dump")) | ||
opts.mode = CR_CPUINFO_DUMP; | ||
else if (!strcmp(mode, "cpuinfo") && !strcmp(subcommand, "check")) | ||
opts.mode = CR_CPUINFO_CHECK; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to separate the changes for cpuinfo and opts.stream in different commits: |
||
else if (!strcmp(mode, "exec")) | ||
opts.mode = CR_EXEC_DEPRECATED; | ||
else if (!strcmp(mode, "show")) | ||
|
@@ -115,6 +117,7 @@ | |
bool has_exec_cmd = false; | ||
bool has_sub_command; | ||
int state = PARSING_GLOBAL_CONF; | ||
char* subcommand; | ||
Check warning on line 120 in criu/crtools.c GitHub Actions / build
|
||
|
||
BUILD_BUG_ON(CTL_32 != SYSCTL_TYPE__CTL_32); | ||
BUILD_BUG_ON(__CTL_STR != SYSCTL_TYPE__CTL_STR); | ||
|
@@ -165,9 +168,15 @@ | |
return 1; | ||
} | ||
|
||
if (parse_criu_mode(argv[optind])) { | ||
has_sub_command = (argc - optind) > 1; | ||
subcommand = has_sub_command ? argv[optind + 1] : NULL; | ||
ret = parse_criu_mode(argv[optind], subcommand); | ||
if (ret == -1) { | ||
pr_err("unknown command: %s\n", argv[optind]); | ||
goto usage; | ||
} else if (ret == -2) { | ||
pr_err("cpuinfo requires an action: dump or check\n"); | ||
goto usage; | ||
} | ||
/* | ||
* util_init initializes criu_run_id and compel_run_id so that sockets | ||
|
@@ -200,8 +209,6 @@ | |
if (opts.work_dir == NULL) | ||
SET_CHAR_OPTS(work_dir, opts.imgs_dir); | ||
|
||
has_sub_command = (argc - optind) > 1; | ||
|
||
if (has_exec_cmd) { | ||
if (!has_sub_command) { | ||
pr_err("--exec-cmd requires a command\n"); | ||
|
@@ -225,23 +232,20 @@ | |
opts.exec_cmd[argc - optind - 1] = NULL; | ||
} else { | ||
/* No subcommands except for cpuinfo and restore --exec-cmd */ | ||
if (opts.mode != CR_CPUINFO && has_sub_command) { | ||
if (opts.mode != CR_CPUINFO_DUMP && opts.mode != CR_CPUINFO_CHECK && has_sub_command) { | ||
pr_err("excessive parameter%s for command %s\n", (argc - optind) > 2 ? "s" : "", argv[optind]); | ||
goto usage; | ||
} else if (opts.mode == CR_CPUINFO && !has_sub_command) { | ||
pr_err("cpuinfo requires an action: dump or check\n"); | ||
goto usage; | ||
} | ||
} | ||
|
||
if (opts.stream && image_dir_mode(argv, optind) == -1) { | ||
if (opts.stream && image_dir_mode() == -1) { | ||
pr_err("--stream cannot be used with the %s command\n", argv[optind]); | ||
goto usage; | ||
} | ||
|
||
/* We must not open imgs dir, if service is called */ | ||
if (opts.mode != CR_SERVICE) { | ||
ret = open_image_dir(opts.imgs_dir, image_dir_mode(argv, optind)); | ||
ret = open_image_dir(opts.imgs_dir, image_dir_mode()); | ||
if (ret < 0) { | ||
pr_err("Couldn't open image dir %s\n", opts.imgs_dir); | ||
return 1; | ||
|
@@ -335,16 +339,10 @@ | |
if (opts.mode == CR_DEDUP) | ||
return cr_dedup() != 0; | ||
|
||
if (opts.mode == CR_CPUINFO) { | ||
if (!argv[optind + 1]) { | ||
pr_err("cpuinfo requires an action: dump or check\n"); | ||
goto usage; | ||
} | ||
if (!strcmp(argv[optind + 1], "dump")) | ||
return cpuinfo_dump(); | ||
else if (!strcmp(argv[optind + 1], "check")) | ||
return cpuinfo_check(); | ||
} | ||
if (opts.mode == CR_CPUINFO_DUMP) | ||
return cpuinfo_dump(); | ||
if (opts.mode == CR_CPUINFO_CHECK) | ||
return cpuinfo_check(); | ||
|
||
if (opts.mode == CR_EXEC_DEPRECATED) { | ||
pr_err("The \"exec\" action is deprecated by the Compel library.\n"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we change
opts.mode
here?