DM: add logger setting parser function

the logger setting can be input as acrn-dm params;
so need parse it to init logger system.

Tracked-On: #3012
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
This commit is contained in:
Minggui Cao 2019-04-25 17:13:07 +08:00 committed by wenlingz
parent 229d44a884
commit 1cd914f992
3 changed files with 61 additions and 5 deletions

View File

@ -66,6 +66,7 @@
#include "vmcfg.h"
#include "tpm.h"
#include "virtio.h"
#include "log.h"
#define GUEST_NIO_PORT 0x488 /* guest upcalls via i/o port */
@ -140,7 +141,8 @@ usage(int code)
" %*s [-s pci] [-U uuid] [--vsbl vsbl_file_name] [--ovmf ovmf_file_path]\n"
" %*s [--part_info part_info_name] [--enable_trusty] [--intr_monitor param_setting]\n"
" %*s [--vtpm2 sock_path] [--virtio_poll interval] [--mac_seed seed_string]\n"
" %*s [--vmcfg sub_options] [--dump vm_idx] [--ptdev_no_reset] [--debugexit] <vm>\n"
" %*s [--vmcfg sub_options] [--dump vm_idx] [--ptdev_no_reset] [--debugexit] \n"
" %*s [--logger-setting param_setting] <vm>\n"
" -A: create ACPI tables\n"
" -B: bootargs for kernel\n"
" -c: # cpus (default 1)\n"
@ -174,10 +176,12 @@ usage(int code)
" --virtio_poll: enable virtio poll mode with poll interval with ns\n"
" --vtpm2: Virtual TPM2 args: sock_path=$PATH_OF_SWTPM_SOCKET\n"
" --lapic_pt: enable local apic passthrough\n"
" --rtvm: indicate that the guest is rtvm\n",
" --rtvm: indicate that the guest is rtvm\n"
" --logger_setting: params like console,level=4;kmsg,level=3\n",
progname, (int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "");
(int)strnlen(progname, PATH_MAX), "", (int)strnlen(progname, PATH_MAX), "",
(int)strnlen(progname, PATH_MAX), "");
exit(code);
}
@ -720,6 +724,7 @@ enum {
CMD_OPT_VTPM2,
CMD_OPT_LAPIC_PT,
CMD_OPT_RTVM,
CMD_OPT_LOGGER_SETTING,
};
static struct option long_options[] = {
@ -760,6 +765,7 @@ static struct option long_options[] = {
{"vtpm2", required_argument, 0, CMD_OPT_VTPM2},
{"lapic_pt", no_argument, 0, CMD_OPT_LAPIC_PT},
{"rtvm", no_argument, 0, CMD_OPT_RTVM},
{"logger_setting", required_argument, 0, CMD_OPT_LOGGER_SETTING},
{0, 0, 0, 0 },
};
@ -922,6 +928,12 @@ dm_run(int argc, char *argv[])
exit(1);
}
break;
case CMD_OPT_LOGGER_SETTING:
if (init_logger_setting(optarg) != 0) {
errx(EX_USAGE, "invalid logger setting params %s", optarg);
exit(1);
}
break;
case 'h':
usage(0);
default:

View File

@ -28,7 +28,7 @@ struct logger_ops {
void (*output)(const char *fmt, va_list args);
};
void init_logger_setting(const char *opt);
int init_logger_setting(const char *opt);
void output_log(uint8_t level, const char *fmt, ...);
/*

View File

@ -16,6 +16,7 @@
#include <stdbool.h>
#include <fcntl.h>
#include "dm_string.h"
#include "log.h"
@ -25,9 +26,52 @@ DECLARE_LOGGER_SECTION();
* --logger_setting: console,level=4;disk,level=4;kmsg,level=3
* the setting param is from acrn-dm input, will be parsed here
*/
void init_logger_setting(const char *opt)
int init_logger_setting(const char *opt)
{
char *orig, *str, *elem, *name, *level;
uint32_t lvl_val;
int error = 0;
struct logger_ops **pp_logger, *plogger;
orig = str = strdup(opt);
if (!str) {
fprintf(stderr, "%s: strdup returns NULL\n", __func__);
return -1;
}
/* param example: --logger_setting console,level=4;kmsg,level=3 */
for (elem = strsep(&str, ";"); elem != NULL; elem = strsep(&str, ";")) {
name = strsep(&elem, ",");
level = elem;
if ((strncmp(level, "level=", 6) != 0) || (dm_strtoui(level + 6, &level, 10, &lvl_val))) {
fprintf(stderr, "logger setting param error: %s, please check!\n", elem);
error = -1;
break;
}
printf("logger: name=%s, level=%d\n", name, lvl_val);
plogger = NULL;
FOR_EACH_LOGGER(pp_logger) {
plogger = *pp_logger;
if (strcmp(name, plogger->name) == 0) {
if (plogger->init)
plogger->init(true, (uint8_t)lvl_val);
break;
}
}
if (plogger == NULL) {
fprintf(stderr, "there is no logger: %s found in DM, please check!\n", name);
error = -1;
break;
}
}
free(orig);
return error;
}
void output_log(uint8_t level, const char *fmt, ...)