mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-20 20:53:46 +00:00
tools: acrnctl: Free vmmngr list after vm ops done
vmmngr_struct entry is allocated in get_vm_list. we should free it after vm ops done. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com> Reviewed-by: Yan, Like <like.yan@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
2da5e7c16a
commit
3000edc6ad
@ -93,6 +93,17 @@ void get_vm_list(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void put_vm_list(void)
|
||||||
|
{
|
||||||
|
struct vmmngr_struct *s;
|
||||||
|
|
||||||
|
while (!LIST_EMPTY(&vmmngr_head)) {
|
||||||
|
s = LIST_FIRST(&vmmngr_head);
|
||||||
|
LIST_REMOVE(s, list);
|
||||||
|
free(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* helper functions */
|
/* helper functions */
|
||||||
int shell_cmd(const char *cmd, char *outbuf, int len)
|
int shell_cmd(const char *cmd, char *outbuf, int len)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,6 @@ struct acrnctl_cmd {
|
|||||||
/* command: list */
|
/* command: list */
|
||||||
static int acrnctl_do_list(int argc, char *argv[])
|
static int acrnctl_do_list(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
get_vm_list();
|
|
||||||
return list_vm();
|
return list_vm();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +264,6 @@ static int acrnctl_do_add(int argc, char *argv[])
|
|||||||
snprintf(cmd, sizeof(cmd), "mkdir -p %s/add", ACRNCTL_OPT_ROOT);
|
snprintf(cmd, sizeof(cmd), "mkdir -p %s/add", ACRNCTL_OPT_ROOT);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
|
|
||||||
get_vm_list();
|
|
||||||
s = vmmngr_find(vmname);
|
s = vmmngr_find(vmname);
|
||||||
if (s) {
|
if (s) {
|
||||||
printf("%s(%s) already exist, can't add %s%s\n",
|
printf("%s(%s) already exist, can't add %s%s\n",
|
||||||
@ -313,7 +311,6 @@ static int acrnctl_do_stop(int argc, char *argv[])
|
|||||||
struct vmmngr_struct *s;
|
struct vmmngr_struct *s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
get_vm_list();
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
s = vmmngr_find(argv[i]);
|
s = vmmngr_find(argv[i]);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
@ -338,7 +335,6 @@ static int acrnctl_do_del(int argc, char *argv[])
|
|||||||
int i;
|
int i;
|
||||||
char cmd[128];
|
char cmd[128];
|
||||||
|
|
||||||
get_vm_list();
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
s = vmmngr_find(argv[i]);
|
s = vmmngr_find(argv[i]);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
@ -365,7 +361,6 @@ static int acrnctl_do_start(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
struct vmmngr_struct *s;
|
struct vmmngr_struct *s;
|
||||||
|
|
||||||
get_vm_list();
|
|
||||||
s = vmmngr_find(argv[1]);
|
s = vmmngr_find(argv[1]);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
printf("can't find %s\n", argv[1]);
|
printf("can't find %s\n", argv[1]);
|
||||||
@ -451,7 +446,7 @@ static void usage(void)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i, err;
|
||||||
|
|
||||||
if (argc == 1 || !strcmp(argv[1], "help")) {
|
if (argc == 1 || !strcmp(argv[1], "help")) {
|
||||||
usage();
|
usage();
|
||||||
@ -471,7 +466,11 @@ int main(int argc, char *argv[])
|
|||||||
if (acmds[i].valid_args(&acmds[i], argc - 1, &argv[1])) {
|
if (acmds[i].valid_args(&acmds[i], argc - 1, &argv[1])) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return acmds[i].func(argc - 1, &argv[1]);
|
get_vm_list();
|
||||||
|
err = acmds[i].func(argc - 1, &argv[1]);
|
||||||
|
put_vm_list();
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,11 @@ static const char *state_str[] = {
|
|||||||
*/
|
*/
|
||||||
void get_vm_list(void);
|
void get_vm_list(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief free all vmmngr_struct allocated by get_vm_list
|
||||||
|
*/
|
||||||
|
void put_vm_list(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief search vm indentified by vm from vmmngr_head
|
* @brief search vm indentified by vm from vmmngr_head
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user