misc: life_mngr: add a separate config to allow trigger sysreboot

Tracked-On: #7215
Signed-off-by: Fei Li <fei1.li@intel.com>
This commit is contained in:
Fei Li 2022-03-30 13:28:52 +08:00 committed by acrnsi-robot
parent 187e19da2f
commit e17acec539
4 changed files with 25 additions and 1 deletions

View File

@ -205,6 +205,12 @@ static int is_allowed_s5_channel_dev(struct life_mngr_config *conf, struct chann
TTY_PATH_MAX);
}
static int is_allowed_sysreboot_channel_dev(struct life_mngr_config *conf, struct channel_dev *c_dev)
{
return strncmp(get_allow_sysreboot_config(conf), get_uart_dev_path(c_dev->uart_device),
TTY_PATH_MAX);
}
/**
* @brief The handler of sync command of lifecycle manager in service VM
*
@ -237,7 +243,7 @@ int req_reboot_handler(void *arg, int fd)
if (c_dev == NULL)
return 0;
if (is_allowed_s5_channel_dev(&life_conf, c_dev)) {
if (is_allowed_sysreboot_channel_dev(&life_conf, c_dev)) {
LOG_PRINTF("The user VM (%s) is not allowed to trigger system reboot\n",
c_dev->name);
return 0;

View File

@ -84,6 +84,9 @@ bool load_config(char *conf_path)
else if (strncmp(ALLOW_TRIGGER_S5, (const char *)key_str,
sizeof(ALLOW_TRIGGER_S5)) == 0)
memcpy(life_conf.allow_trigger_s5, value_str, strlen(value_str));
else if (strncmp(ALLOW_TRIGGER_SYSREBOOT, (const char *)key_str,
sizeof(ALLOW_TRIGGER_SYSREBOOT)) == 0)
memcpy(life_conf.allow_trigger_sysreboot, value_str, strlen(value_str));
else
LOG_PRINTF("Invalid item in the configuration file, key=%s, value=%s\n",
key_str, value_str);

View File

@ -24,6 +24,7 @@
#define VM_NAME "VM_NAME"
#define DEV_NAME "DEV_NAME"
#define ALLOW_TRIGGER_S5 "ALLOW_TRIGGER_S5"
#define ALLOW_TRIGGER_SYSREBOOT "ALLOW_TRIGGER_SYSREBOOT"
#define MAX_CONFIG_VALUE_LEN 128
#define CHK_CREAT 1 /* create a directory, if it does not exist */
@ -34,6 +35,7 @@ struct life_mngr_config {
char vm_name[MAX_CONFIG_VALUE_LEN];
char dev_names[MAX_CONFIG_VALUE_LEN];
char allow_trigger_s5[MAX_CONFIG_VALUE_LEN];
char allow_trigger_sysreboot[MAX_CONFIG_VALUE_LEN];
};
extern struct life_mngr_config life_conf;
@ -44,6 +46,13 @@ static inline char *get_allow_s5_config(struct life_mngr_config *conf)
{
return conf->allow_trigger_s5;
}
/**
* @brief Get the name of the device which is allowed to trigger system reboot
*/
static inline char *get_allow_sysreboot_config(struct life_mngr_config *conf)
{
return conf->allow_trigger_sysreboot;
}
/**
* @brief Load configuration item from config file
*

View File

@ -24,3 +24,9 @@ DEV_NAME=tty:/dev/ttyS8,/dev/ttyS9,/dev/ttyS10,/dev/ttyS11,/dev/ttyS12,/dev/ttyS
# s5_trigger.sh.
# For user VM, this field is useless.
ALLOW_TRIGGER_S5=/dev/ttyS10
# The device name of the device which is used to communicate with the VM,
# and this VM is allowed to trigger system reboot through executing
# system_reboot_trigger_win.py.
# For user VM, this field is useless.
ALLOW_TRIGGER_SYSREBOOT=/dev/ttyS10