[2/2] config: Add check_options helper

Submitted by Radostin Stoyanov on Jan. 6, 2019, 3:44 p.m.

Details

Message ID 20190106154427.11356-2-rstoyanov1@gmail.com
State Accepted
Series "Series without cover letter"
Headers show

Commit Message

Radostin Stoyanov Jan. 6, 2019, 3:44 p.m.
The purpose of this helper function is to perform actions common to
different interfaces, after all CRIU options have been parsed. This can
be used, for instance, to verify that a specific option was passed to
CRIU via CLI, RPC or config file.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
---
 criu/config.c             | 33 +++++++++++++++++++++++++++++++++
 criu/cr-service.c         |  5 +++--
 criu/crtools.c            | 25 +------------------------
 criu/include/cr_options.h |  1 +
 4 files changed, 38 insertions(+), 26 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/config.c b/criu/config.c
index f4fb39b86..b6ecbfb64 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -803,3 +803,36 @@  bad_arg:
 				long_opts[idx].name, optarg);
 	return 1;
 }
+
+int check_options()
+{
+	if (opts.tcp_established_ok)
+		pr_info("Will dump/restore TCP connections\n");
+	if (opts.tcp_skip_in_flight)
+		pr_info("Will skip in-flight TCP connections\n");
+	if (opts.tcp_close)
+		pr_info("Will drop all TCP connections on restore\n");
+	if (opts.link_remap_ok)
+		pr_info("Will allow link remaps on FS\n");
+	if (opts.weak_sysctls)
+		pr_info("Will skip non-existant sysctls on restore\n");
+
+	if (opts.deprecated_ok)
+		pr_info("Turn deprecated stuff ON\n");
+	else if (getenv("CRIU_DEPRECATED")) {
+		pr_info("Turn deprecated stuff ON via env\n");
+		opts.deprecated_ok = true;
+	}
+
+	if (!opts.restore_detach && opts.restore_sibling) {
+		pr_err("--restore-sibling only makes sense with --restore-detach\n");
+		return 1;
+	}
+
+	if (check_namespace_opts()) {
+		pr_err("Error: namespace flags conflict\n");
+		return 1;
+	}
+
+	return 0;
+}
diff --git a/criu/cr-service.c b/criu/cr-service.c
index 37cc6f7df..231a37f30 100644
--- a/criu/cr-service.c
+++ b/criu/cr-service.c
@@ -639,8 +639,6 @@  static int setup_opts_from_req(int sk, CriuOpts *req)
 	if (req->orphan_pts_master)
 		opts.orphan_pts_master = true;
 
-	if (check_namespace_opts())
-		goto err;
 
 	/* Evaluate additional configuration file a second time to overwrite
 	 * all RPC settings. */
@@ -650,7 +648,10 @@  static int setup_opts_from_req(int sk, CriuOpts *req)
 		if (i)
 			goto err;
 	}
+
 	log_set_loglevel(opts.log_level);
+	if (check_options())
+		goto err;
 
 	return 0;
 
diff --git a/criu/crtools.c b/criu/crtools.c
index c8b9ab19c..1ca30c74f 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -112,31 +112,8 @@  int main(int argc, char *argv[], char *envp[])
 		return cr_service_work(atoi(argv[2]));
 	}
 
-	if (opts.deprecated_ok)
-		pr_msg("Turn deprecated stuff ON\n");
-	if (opts.tcp_skip_in_flight)
-		pr_msg("Will skip in-flight TCP connections\n");
-	if (opts.tcp_established_ok)
-		pr_info("Will dump TCP connections\n");
-	if (opts.link_remap_ok)
-		pr_info("Will allow link remaps on FS\n");
-	if (opts.weak_sysctls)
-		pr_msg("Will skip non-existant sysctls on restore\n");
-
-	if (getenv("CRIU_DEPRECATED")) {
-		pr_msg("Turn deprecated stuff ON via env\n");
-		opts.deprecated_ok = true;
-	}
-
-	if (check_namespace_opts()) {
-		pr_msg("Error: namespace flags conflict\n");
+	if (check_options())
 		return 1;
-	}
-
-	if (!opts.restore_detach && opts.restore_sibling) {
-		pr_msg("--restore-sibling only makes sense with --restore-detach\n");
-		return 1;
-	}
 
 	if (opts.imgs_dir == NULL)
 		SET_CHAR_OPTS(imgs_dir, ".");
diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
index 4e8879cf6..8ddbf2341 100644
--- a/criu/include/cr_options.h
+++ b/criu/include/cr_options.h
@@ -145,6 +145,7 @@  extern struct cr_options opts;
 char *rpc_cfg_file;
 
 extern int parse_options(int argc, char **argv, bool *usage_error, bool *has_exec_cmd, int state);
+extern int check_options();
 extern void init_opts();
 
 #endif /* __CR_OPTIONS_H__ */

Comments

Andrei Vagin Jan. 13, 2019, 6:29 a.m.
Adrian, could you review this patch?

On Sun, Jan 06, 2019 at 03:44:27PM +0000, Radostin Stoyanov wrote:
> The purpose of this helper function is to perform actions common to
> different interfaces, after all CRIU options have been parsed. This can
> be used, for instance, to verify that a specific option was passed to
> CRIU via CLI, RPC or config file.
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>  criu/config.c             | 33 +++++++++++++++++++++++++++++++++
>  criu/cr-service.c         |  5 +++--
>  criu/crtools.c            | 25 +------------------------
>  criu/include/cr_options.h |  1 +
>  4 files changed, 38 insertions(+), 26 deletions(-)
> 
> diff --git a/criu/config.c b/criu/config.c
> index f4fb39b86..b6ecbfb64 100644
> --- a/criu/config.c
> +++ b/criu/config.c
> @@ -803,3 +803,36 @@ bad_arg:
>  				long_opts[idx].name, optarg);
>  	return 1;
>  }
> +
> +int check_options()
> +{
> +	if (opts.tcp_established_ok)
> +		pr_info("Will dump/restore TCP connections\n");
> +	if (opts.tcp_skip_in_flight)
> +		pr_info("Will skip in-flight TCP connections\n");
> +	if (opts.tcp_close)
> +		pr_info("Will drop all TCP connections on restore\n");
> +	if (opts.link_remap_ok)
> +		pr_info("Will allow link remaps on FS\n");
> +	if (opts.weak_sysctls)
> +		pr_info("Will skip non-existant sysctls on restore\n");
> +
> +	if (opts.deprecated_ok)
> +		pr_info("Turn deprecated stuff ON\n");
> +	else if (getenv("CRIU_DEPRECATED")) {
> +		pr_info("Turn deprecated stuff ON via env\n");
> +		opts.deprecated_ok = true;
> +	}
> +
> +	if (!opts.restore_detach && opts.restore_sibling) {
> +		pr_err("--restore-sibling only makes sense with --restore-detach\n");
> +		return 1;
> +	}
> +
> +	if (check_namespace_opts()) {
> +		pr_err("Error: namespace flags conflict\n");
> +		return 1;
> +	}
> +
> +	return 0;
> +}
> diff --git a/criu/cr-service.c b/criu/cr-service.c
> index 37cc6f7df..231a37f30 100644
> --- a/criu/cr-service.c
> +++ b/criu/cr-service.c
> @@ -639,8 +639,6 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  	if (req->orphan_pts_master)
>  		opts.orphan_pts_master = true;
>  
> -	if (check_namespace_opts())
> -		goto err;
>  
>  	/* Evaluate additional configuration file a second time to overwrite
>  	 * all RPC settings. */
> @@ -650,7 +648,10 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  		if (i)
>  			goto err;
>  	}
> +
>  	log_set_loglevel(opts.log_level);
> +	if (check_options())
> +		goto err;
>  
>  	return 0;
>  
> diff --git a/criu/crtools.c b/criu/crtools.c
> index c8b9ab19c..1ca30c74f 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -112,31 +112,8 @@ int main(int argc, char *argv[], char *envp[])
>  		return cr_service_work(atoi(argv[2]));
>  	}
>  
> -	if (opts.deprecated_ok)
> -		pr_msg("Turn deprecated stuff ON\n");
> -	if (opts.tcp_skip_in_flight)
> -		pr_msg("Will skip in-flight TCP connections\n");
> -	if (opts.tcp_established_ok)
> -		pr_info("Will dump TCP connections\n");
> -	if (opts.link_remap_ok)
> -		pr_info("Will allow link remaps on FS\n");
> -	if (opts.weak_sysctls)
> -		pr_msg("Will skip non-existant sysctls on restore\n");
> -
> -	if (getenv("CRIU_DEPRECATED")) {
> -		pr_msg("Turn deprecated stuff ON via env\n");
> -		opts.deprecated_ok = true;
> -	}
> -
> -	if (check_namespace_opts()) {
> -		pr_msg("Error: namespace flags conflict\n");
> +	if (check_options())
>  		return 1;
> -	}
> -
> -	if (!opts.restore_detach && opts.restore_sibling) {
> -		pr_msg("--restore-sibling only makes sense with --restore-detach\n");
> -		return 1;
> -	}
>  
>  	if (opts.imgs_dir == NULL)
>  		SET_CHAR_OPTS(imgs_dir, ".");
> diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
> index 4e8879cf6..8ddbf2341 100644
> --- a/criu/include/cr_options.h
> +++ b/criu/include/cr_options.h
> @@ -145,6 +145,7 @@ extern struct cr_options opts;
>  char *rpc_cfg_file;
>  
>  extern int parse_options(int argc, char **argv, bool *usage_error, bool *has_exec_cmd, int state);
> +extern int check_options();
>  extern void init_opts();
>  
>  #endif /* __CR_OPTIONS_H__ */
> -- 
> 2.20.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
Adrian Reber Jan. 14, 2019, 6:43 a.m.
Makes sense. Good catch to include check_options() into cr-service.c

Acked-by: Adrian Reber <areber@redhat.com>

On Sun, Jan 06, 2019 at 03:44:27PM +0000, Radostin Stoyanov wrote:
> The purpose of this helper function is to perform actions common to
> different interfaces, after all CRIU options have been parsed. This can
> be used, for instance, to verify that a specific option was passed to
> CRIU via CLI, RPC or config file.
> 
> Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
> ---
>  criu/config.c             | 33 +++++++++++++++++++++++++++++++++
>  criu/cr-service.c         |  5 +++--
>  criu/crtools.c            | 25 +------------------------
>  criu/include/cr_options.h |  1 +
>  4 files changed, 38 insertions(+), 26 deletions(-)
> 
> diff --git a/criu/config.c b/criu/config.c
> index f4fb39b86..b6ecbfb64 100644
> --- a/criu/config.c
> +++ b/criu/config.c
> @@ -803,3 +803,36 @@ bad_arg:
>  				long_opts[idx].name, optarg);
>  	return 1;
>  }
> +
> +int check_options()
> +{
> +	if (opts.tcp_established_ok)
> +		pr_info("Will dump/restore TCP connections\n");
> +	if (opts.tcp_skip_in_flight)
> +		pr_info("Will skip in-flight TCP connections\n");
> +	if (opts.tcp_close)
> +		pr_info("Will drop all TCP connections on restore\n");
> +	if (opts.link_remap_ok)
> +		pr_info("Will allow link remaps on FS\n");
> +	if (opts.weak_sysctls)
> +		pr_info("Will skip non-existant sysctls on restore\n");
> +
> +	if (opts.deprecated_ok)
> +		pr_info("Turn deprecated stuff ON\n");
> +	else if (getenv("CRIU_DEPRECATED")) {
> +		pr_info("Turn deprecated stuff ON via env\n");
> +		opts.deprecated_ok = true;
> +	}
> +
> +	if (!opts.restore_detach && opts.restore_sibling) {
> +		pr_err("--restore-sibling only makes sense with --restore-detach\n");
> +		return 1;
> +	}
> +
> +	if (check_namespace_opts()) {
> +		pr_err("Error: namespace flags conflict\n");
> +		return 1;
> +	}
> +
> +	return 0;
> +}
> diff --git a/criu/cr-service.c b/criu/cr-service.c
> index 37cc6f7df..231a37f30 100644
> --- a/criu/cr-service.c
> +++ b/criu/cr-service.c
> @@ -639,8 +639,6 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  	if (req->orphan_pts_master)
>  		opts.orphan_pts_master = true;
>  
> -	if (check_namespace_opts())
> -		goto err;
>  
>  	/* Evaluate additional configuration file a second time to overwrite
>  	 * all RPC settings. */
> @@ -650,7 +648,10 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  		if (i)
>  			goto err;
>  	}
> +
>  	log_set_loglevel(opts.log_level);
> +	if (check_options())
> +		goto err;
>  
>  	return 0;
>  
> diff --git a/criu/crtools.c b/criu/crtools.c
> index c8b9ab19c..1ca30c74f 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -112,31 +112,8 @@ int main(int argc, char *argv[], char *envp[])
>  		return cr_service_work(atoi(argv[2]));
>  	}
>  
> -	if (opts.deprecated_ok)
> -		pr_msg("Turn deprecated stuff ON\n");
> -	if (opts.tcp_skip_in_flight)
> -		pr_msg("Will skip in-flight TCP connections\n");
> -	if (opts.tcp_established_ok)
> -		pr_info("Will dump TCP connections\n");
> -	if (opts.link_remap_ok)
> -		pr_info("Will allow link remaps on FS\n");
> -	if (opts.weak_sysctls)
> -		pr_msg("Will skip non-existant sysctls on restore\n");
> -
> -	if (getenv("CRIU_DEPRECATED")) {
> -		pr_msg("Turn deprecated stuff ON via env\n");
> -		opts.deprecated_ok = true;
> -	}
> -
> -	if (check_namespace_opts()) {
> -		pr_msg("Error: namespace flags conflict\n");
> +	if (check_options())
>  		return 1;
> -	}
> -
> -	if (!opts.restore_detach && opts.restore_sibling) {
> -		pr_msg("--restore-sibling only makes sense with --restore-detach\n");
> -		return 1;
> -	}
>  
>  	if (opts.imgs_dir == NULL)
>  		SET_CHAR_OPTS(imgs_dir, ".");
> diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
> index 4e8879cf6..8ddbf2341 100644
> --- a/criu/include/cr_options.h
> +++ b/criu/include/cr_options.h
> @@ -145,6 +145,7 @@ extern struct cr_options opts;
>  char *rpc_cfg_file;
>  
>  extern int parse_options(int argc, char **argv, bool *usage_error, bool *has_exec_cmd, int state);
> +extern int check_options();
>  extern void init_opts();
>  
>  #endif /* __CR_OPTIONS_H__ */
> -- 
> 2.20.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu