DM: add DM parameter for command monitor

Libvirt or kata container needs to send some commands
(such as VM destory command) to the DM instance of User VM
through command monitor socket, they will specify the socket
path and pass this path name to DM instance through DM parameter.

In this patch, add new DM parameter (cmd_monitor) to get socket
path from libvirt or kata container. If cmd_monitor is specified,
it initialize and deinitialize command monitor in DM main loop.

v2-->v3:
	Include command monitor initialization and deinitialization.

Tracked-On: #5921

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
Xiangyang Wu 2022-02-09 15:24:04 +08:00 committed by acrnsi-robot
parent 02e94b1537
commit cc2efdc049
3 changed files with 29 additions and 0 deletions

View File

@ -115,3 +115,15 @@ void deinit_cmd_monitor(void)
deinit_socket(sock_server);
}
}
int acrn_parse_cmd_monitor(char *arg)
{
int err = -1;
size_t len = strnlen(arg, UNIX_SOCKET_PATH_MAX);
if (len < UNIX_SOCKET_PATH_MAX) {
strncpy(socket_path, arg, len + 1);
pr_notice("Command monitor: using soket path %s\n", socket_path);
err = 0;
}
return err;
}

View File

@ -68,6 +68,7 @@
#include "log.h"
#include "pci_util.h"
#include "vssram.h"
#include "cmd_monitor.h"
#define VM_MAXCPU 16 /* maximum virtual cpus */
@ -102,6 +103,7 @@ static int guest_ncpus;
static int virtio_msix = 1;
static bool debugexit_enabled;
static int pm_notify_channel;
static bool cmd_monitor;
static char *progname;
static const int BSP;
@ -165,6 +167,8 @@ usage(int code)
" --debugexit: enable debug exit function\n"
" --intr_monitor: enable interrupt storm monitor\n"
" its params: threshold/s,probe-period(s),delay_time(ms),delay_duration(ms)\n"
" --cmd_monitor: enable command monitor\n"
" its params: unix domain socket path\n"
" --virtio_poll: enable virtio poll mode with poll interval with ns\n"
" --acpidev_pt: acpi device ID args: HID in ACPI Table\n"
" --mmiodev_pt: MMIO resources args: physical MMIO regions\n"
@ -486,6 +490,9 @@ vm_init_vdevs(struct vmctx *ctx)
if (ret < 0)
goto monitor_fail;
if ((cmd_monitor) && init_cmd_monitor(ctx) < 0)
goto monitor_fail;
ret = init_mmio_devs(ctx);
if (ret < 0)
goto mmio_dev_fail;
@ -757,6 +764,7 @@ enum {
CMD_OPT_VMCFG,
CMD_OPT_DUMP,
CMD_OPT_INTR_MONITOR,
CMD_OPT_CMD_MONITOR,
CMD_OPT_ACPIDEV_PT,
CMD_OPT_MMIODEV_PT,
CMD_OPT_VTPM2,
@ -796,6 +804,7 @@ static struct option long_options[] = {
{"virtio_poll", required_argument, 0, CMD_OPT_VIRTIO_POLL_ENABLE},
{"debugexit", no_argument, 0, CMD_OPT_DEBUGEXIT},
{"intr_monitor", required_argument, 0, CMD_OPT_INTR_MONITOR},
{"cmd_monitor", required_argument, 0, CMD_OPT_CMD_MONITOR},
{"acpidev_pt", required_argument, 0, CMD_OPT_ACPIDEV_PT},
{"mmiodev_pt", required_argument, 0, CMD_OPT_MMIODEV_PT},
{"vtpm2", required_argument, 0, CMD_OPT_VTPM2},
@ -959,6 +968,11 @@ main(int argc, char *argv[])
if (acrn_parse_intr_monitor(optarg) != 0)
errx(EX_USAGE, "invalid intr-monitor params %s", optarg);
break;
case CMD_OPT_CMD_MONITOR:
if (acrn_parse_cmd_monitor(optarg) != 0)
errx(EX_USAGE, "invalid command monitor params %s", optarg);
cmd_monitor = true;
break;
case CMD_OPT_LOGGER_SETTING:
if (init_logger_setting(optarg) != 0)
errx(EX_USAGE, "invalid logger setting params %s", optarg);
@ -1135,6 +1149,8 @@ fail:
vm_pause(ctx);
vm_destroy(ctx);
create_fail:
if (cmd_monitor)
deinit_cmd_monitor();
uninit_hugetlb();
deinit_loggers();
exit(ret);

View File

@ -7,4 +7,5 @@
int init_cmd_monitor(struct vmctx *ctx);
void deinit_cmd_monitor(void);
int acrn_parse_cmd_monitor(char *arg);
#endif