Skip to content

Commit f95da18

Browse files
liudlongwenlingz
authored andcommitted
dm: acrn-tool: Add del runC configuration in acrnctl del
The patch adds logic to delete runC configuration in acrnctl del command. After launch the VM in container there will have configuration files in user directory. When delete the VM by "acrnctl del" command the command will delete the runC configuration files at same time. Tracked-On: #2020 Signed-off-by: Long Liu <long.liu@intel.com> Reviewed-by: Yu Wang <yu1.wang@intel.com> Reviewed-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Yan, Like <like.yan@intel.com>
1 parent a0efd3e commit f95da18

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tools/acrn-manager/acrnctl.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,52 @@ static int acrnctl_do_stop(int argc, char *argv[])
436436
return 0;
437437
}
438438

439+
/* Function: Delete runC configuration */
440+
static inline int del_runC(char *argv)
441+
{
442+
char cmd[128];
443+
char cmd_out[256];
444+
char runc_path[128];
445+
446+
/* The configuration added by launch_uos script */
447+
if (snprintf(runc_path, sizeof(runc_path), "%s/runc/%s",
448+
ACRN_CONF_PATH_ADD, argv) >= sizeof(runc_path)) {
449+
printf("ERROR: runC path %s is truncated\n", runc_path);
450+
return -1;
451+
}
452+
if (access(runc_path, F_OK) != 0)
453+
return 0;
454+
455+
/* Check if there is a container */
456+
if (snprintf(cmd, sizeof(cmd), "runc list | grep %s",
457+
argv) >= sizeof(cmd)) {
458+
printf("ERROR: runc cmd: %s is truncated\n", cmd);
459+
return -1;
460+
}
461+
shell_cmd(cmd, cmd_out, sizeof(cmd_out));
462+
if (strstr(cmd_out, argv) != NULL) {
463+
/* If the container is still running stop it by runc pause */
464+
if (strstr(cmd_out, "stopped") == NULL) {
465+
printf("Pls stop the runC before del it !!\n");
466+
return -1;
467+
}
468+
if (snprintf(cmd, sizeof(cmd), "runc delete %s",
469+
argv) >= sizeof(cmd)) {
470+
printf("ERROR: del container: %s trancated!", cmd);
471+
return -1;
472+
}
473+
system(cmd);
474+
if (snprintf(cmd, sizeof(cmd), "rm -f %s/runc/%s -rf",
475+
ACRN_CONF_PATH_ADD, argv) >= sizeof(cmd)) {
476+
printf("ERROR: delete cmd: %s trancated!\n", cmd);
477+
return -1;
478+
}
479+
system(cmd);
480+
}
481+
482+
return 0;
483+
}
484+
439485
/* command: delete */
440486
static int acrnctl_do_del(int argc, char *argv[])
441487
{
@@ -466,6 +512,10 @@ static int acrnctl_do_del(int argc, char *argv[])
466512
return -1;
467513
}
468514
system(cmd);
515+
if (del_runC(argv[i]) < 0) {
516+
printf("ERROR: del runC failed!\n");
517+
return -1;
518+
}
469519
}
470520

471521
return 0;

0 commit comments

Comments
 (0)