agent: Update macro for e.g. String type

stack-only types are handled properly with the
parse_cmdline_param macro advancted types like
String couldn't be guarded by a guard function since
it passed the variable by value rather than reference.

Now we can have guard functions for the String type

parse_cmdline_param!(
    param,
    CGROUP_NO_V1,
    config.cgroup_no_v1,
    get_string_value,
    | no_v1 | no_v1 == "all"
);

Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
Zvonko Kaiser 2025-01-23 18:48:14 +00:00
parent aab9d36e47
commit 9162103f85

View File

@ -252,7 +252,7 @@ macro_rules! parse_cmdline_param {
($param:ident, $key:ident, $field:expr, $func:ident, $guard:expr) => { ($param:ident, $key:ident, $field:expr, $func:ident, $guard:expr) => {
if $param.starts_with(format!("{}=", $key).as_str()) { if $param.starts_with(format!("{}=", $key).as_str()) {
let val = $func($param)?; let val = $func($param)?;
if $guard(val) { if $guard(&val) {
$field = val; $field = val;
} }
continue; continue;
@ -477,7 +477,7 @@ impl AgentConfig {
HOTPLUG_TIMOUT_OPTION, HOTPLUG_TIMOUT_OPTION,
config.hotplug_timeout, config.hotplug_timeout,
get_timeout, get_timeout,
|hotplug_timeout: time::Duration| hotplug_timeout.as_secs() > 0 |hotplug_timeout: &time::Duration| hotplug_timeout.as_secs() > 0
); );
// ensure the timeout is a positive value // ensure the timeout is a positive value
@ -486,7 +486,7 @@ impl AgentConfig {
CDH_API_TIMOUT_OPTION, CDH_API_TIMOUT_OPTION,
config.cdh_api_timeout, config.cdh_api_timeout,
get_timeout, get_timeout,
|cdh_api_timeout: time::Duration| cdh_api_timeout.as_secs() > 0 |cdh_api_timeout: &time::Duration| cdh_api_timeout.as_secs() > 0
); );
// vsock port should be positive values // vsock port should be positive values
@ -495,21 +495,21 @@ impl AgentConfig {
DEBUG_CONSOLE_VPORT_OPTION, DEBUG_CONSOLE_VPORT_OPTION,
config.debug_console_vport, config.debug_console_vport,
get_number_value, get_number_value,
|port| port > 0 |port: &i32| *port > 0
); );
parse_cmdline_param!( parse_cmdline_param!(
param, param,
LOG_VPORT_OPTION, LOG_VPORT_OPTION,
config.log_vport, config.log_vport,
get_number_value, get_number_value,
|port| port > 0 |port: &i32| *port > 0
); );
parse_cmdline_param!( parse_cmdline_param!(
param, param,
PASSFD_LISTENER_PORT, PASSFD_LISTENER_PORT,
config.passfd_listener_port, config.passfd_listener_port,
get_number_value, get_number_value,
|port| port > 0 |port: &i32| *port > 0
); );
parse_cmdline_param!( parse_cmdline_param!(
param, param,
@ -722,7 +722,7 @@ where
fields[1] fields[1]
.parse::<T>() .parse::<T>()
.map_err(|e| anyhow!("parse from {} failed: {:?}", &fields[1], e)) .map_err(|e| anyhow!("parse from {} failed: {:?}", fields[1], e))
} }
// Map logrus (https://godoc.org/github.com/sirupsen/logrus) // Map logrus (https://godoc.org/github.com/sirupsen/logrus)