HV: show correct vm name per config

The patch will show correct VM name per its configuration. As we do not
validate vm id when call get_vm_from_vmid() any more, we only show VM's
states which their VM type are defined;

If VM name is not configured in config file, then the name is specified
with vm id, i.e. "ACRN VM_(vm id)"

Tracked-On: #2291

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Victor Sun 2019-01-21 12:29:49 +08:00 committed by Eddie Dong
parent e6117e0d5b
commit f3014a3c89
2 changed files with 17 additions and 16 deletions

View File

@ -141,6 +141,10 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_
hva2hpa(ept_mem_ops->get_sworld_memory_base(ept_mem_ops->info)),
TRUSTY_EPT_REBASE_GPA, TRUSTY_RAM_SIZE, EPT_WB | EPT_RWX);
}
if (vm_config->name[0] == '\0') {
/* if VM name is not configured, specify with VM ID */
snprintf(vm_config->name, 16, "ACRN VM_%d", vm_id);
}
(void)memcpy_s(&vm->GUID[0], sizeof(vm->GUID),
&vm_config->GUID[0], sizeof(vm_config->GUID));
@ -411,7 +415,7 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config)
/* start vm BSP automatically */
start_vm(vm);
pr_acrnlog("Start VM%x", vm->vm_id);
pr_acrnlog("Start VM id: %x name: %s", vm_id, vm_config->name);
}
}

View File

@ -513,17 +513,15 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv)
{
char temp_str[MAX_STR_SIZE];
struct acrn_vm *vm;
uint16_t idx;
struct acrn_vm_config *vm_config;
uint16_t vm_id;
char state[32];
shell_puts("\r\nVM NAME VM ID VM STATE"
"\r\n======= ===== ========\r\n");
shell_puts("\r\nVM NAME\t\t\t\tVM ID\t\tVM STATE"
"\r\n=======\t\t\t\t=====\t\t========\r\n");
for (idx = 0U; idx < CONFIG_MAX_VM_NUM; idx++) {
vm = get_vm_from_vmid(idx);
if (vm == NULL) {
continue;
}
for (vm_id = 0U; vm_id < CONFIG_MAX_VM_NUM; vm_id++) {
vm = get_vm_from_vmid(vm_id);
switch (vm->state) {
case VM_CREATED:
(void)strncpy_s(state, 32U, "Created", 32U);
@ -538,14 +536,13 @@ static int32_t shell_list_vm(__unused int32_t argc, __unused char **argv)
(void)strncpy_s(state, 32U, "Unknown", 32U);
break;
}
/* Create output string consisting of VM name and VM id
*/
snprintf(temp_str, MAX_STR_SIZE,
"vm_%-24d %-16d %-8s\r\n", vm->vm_id,
vm->vm_id, state);
vm_config = get_vm_config(vm_id);
if (vm_config->type != UNDEFINED_VM) {
snprintf(temp_str, MAX_STR_SIZE, "%-34s%-14d%-8s\r\n", vm_config->name, vm_id, state);
/* Output information for this task */
shell_puts(temp_str);
/* Output information for this task */
shell_puts(temp_str);
}
}
return 0;