Skip to content

Commit

Permalink
DM: main loop cleanup
Browse files Browse the repository at this point in the history
Move all virtual devices init/deinit to function to simplify the
failure path of main loop. In the future, new virtual device will
not touch main loop.

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
Acked-by: Eddie Dong <Eddie.dong@intel.com>
  • Loading branch information
fyin1 authored and jren1 committed May 15, 2018
1 parent edc5846 commit 81cf3e1
Showing 1 changed file with 68 additions and 34 deletions.
102 changes: 68 additions & 34 deletions devicemodel/core/main.c
Expand Up @@ -459,6 +459,63 @@ handle_vmexit(struct vmctx *ctx, struct vhm_request *vhm_req, int vcpu)
vm_notify_request_done(ctx, vcpu);
}

static int
vm_init_vdevs(struct vmctx *ctx)
{
int ret;

init_mem();
init_inout();
pci_irq_init(ctx);
atkbdc_init(ctx);
ioapic_init(ctx);

/*
* We don't care ioc_init return value so far.
* Will add return value check once ioc is full function.
*/
ret = ioc_init(ctx);

ret = vrtc_init(ctx);
if (ret < 0)
goto vrtc_fail;

sci_init(ctx);
init_bvmcons();

ret = monitor_init(ctx);
if (ret < 0)
goto monitor_fail;

ret = init_pci(ctx);
if (ret < 0)
goto pci_fail;

return 0;
pci_fail:
monitor_close();
monitor_fail:
deinit_bvmcons();
vrtc_deinit(ctx);
vrtc_fail:
ioc_deinit(ctx);
atkbdc_deinit(ctx);
pci_irq_deinit(ctx);
return -1;
}

static void
vm_deinit_vdevs(struct vmctx *ctx)
{
deinit_pci(ctx);
monitor_close();
deinit_bvmcons();
vrtc_deinit(ctx);
ioc_deinit(ctx);
atkbdc_deinit(ctx);
pci_irq_deinit(ctx);
}

static void
vm_loop(struct vmctx *ctx)
{
Expand Down Expand Up @@ -776,29 +833,14 @@ main(int argc, char *argv[])
goto mevent_fail;
}

init_mem();
init_inout();
pci_irq_init(ctx);
atkbdc_init(ctx);
ioapic_init(ctx);
ioc_init(ctx);

vrtc_init(ctx);
sci_init(ctx);
init_bvmcons();
monitor_init(ctx);

/*
* Exit if a device emulation finds an error in its
* initialization
*/
if (init_pci(ctx) != 0) {
goto pci_fail;
}

if (gdb_port != 0)
fprintf(stderr, "dbgport not supported\n");

if (vm_init_vdevs(ctx) < 0) {
fprintf(stderr, "Unable to init vdev (%d)\n", errno);
goto dev_fail;
}

/*
* build the guest tables, MP etc.
*/
Expand Down Expand Up @@ -847,28 +889,20 @@ main(int argc, char *argv[])
if (vm_get_suspend_mode() != VM_SUSPEND_RESET)
break;

pci_irq_deinit(ctx);
deinit_pci(ctx);
monitor_close();
deinit_bvmcons();
vrtc_deinit(ctx);
atkbdc_deinit(ctx);
vm_unsetup_memory(ctx);
vm_deinit_vdevs(ctx);
mevent_deinit();
vm_unsetup_memory(ctx);
vm_destroy(ctx);
vm_close(ctx);
_ctx = 0;

vm_set_suspend_mode(VM_SUSPEND_NONE);
}

vm_fail:
pci_irq_deinit(ctx);
deinit_pci(ctx);
pci_fail:
monitor_close();
deinit_bvmcons();
vrtc_deinit(ctx);
atkbdc_deinit(ctx);
vm_deinit_vdevs(ctx);
dev_fail:
mevent_deinit();
mevent_fail:
vm_unsetup_memory(ctx);
fail:
Expand Down

0 comments on commit 81cf3e1

Please sign in to comment.