From 8b27daa7789773d201652c406cf1084f9834a1b8 Mon Sep 17 00:00:00 2001 From: "yuhong.tao@intel.com" Date: Thu, 27 Jun 2019 14:30:38 +0000 Subject: [PATCH] tools: acrnctl add '--force' option to 'stop' cmd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Run 'acrnctl stop VM_NAME --force‘ to force stop VM When run 'acrnctl stop VM_NAME', acrn-dm let guest OS to shutdown itself. If something wrong with guest OS, it can't shutdown, we can run 'acrnctl stop VM_NAME --force', thus acrn-dm directly set suspend mode to VM_SUSPEND_POWEROFF and quit main loop. Tracked-On: #3484 Signed-off-by: Tao Yuhong Reviewed-by: Yan, Like --- misc/acrn-manager/acrnctl.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/misc/acrn-manager/acrnctl.c b/misc/acrn-manager/acrnctl.c index e55a43722..61e8e1333 100644 --- a/misc/acrn-manager/acrnctl.c +++ b/misc/acrn-manager/acrnctl.c @@ -29,7 +29,7 @@ /* vm life cycle cmd description */ #define LIST_DESC "List all the virtual machines added" #define START_DESC "Start virtual machine VM_NAME" -#define STOP_DESC "Stop virtual machine VM_NAME" +#define STOP_DESC "Stop virtual machine VM_NAME, [--force/-f, force to stop VM]" #define DEL_DESC "Delete virtual machine VM_NAME" #define ADD_DESC "Add one virtual machine with SCRIPTS and OPTIONS" #define PAUSE_DESC "Block all vCPUs of virtual machine VM_NAME" @@ -442,18 +442,34 @@ static int acrnctl_do_blkrescan(int argc, char *argv[]) static int acrnctl_do_stop(int argc, char *argv[]) { struct vmmngr_struct *s; - int force = 0; + int i, force = 0; + const char *vmname = NULL; - s = vmmngr_find(argv[1]); + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--force") && strcmp(argv[i], "-f")) { + if (vmname == NULL) + vmname = argv[i]; + } else { + force = 1; + } + } + + if (!vmname) { + printf("Please give a VM name\n"); + return -1; + } + + s = vmmngr_find(vmname); if (!s) { - printf("can't find %s\n", argv[1]); + printf("can't find %s\n", vmname); return -1; } if (s->state == VM_CREATED) { - printf("%s is already (%s)\n", argv[1], state_str[s->state]); + printf("%s is already (%s)\n", vmname, state_str[s->state]); return -1; } - return stop_vm(argv[1], force); + + return stop_vm(vmname, force); }