Commit 49a8afd1 authored by Sasha Levin's avatar Sasha Levin Committed by Will Deacon
Browse files

kvm tools: use init/exit where possible



Switch to using init/exit calls instead of the repeating call blocks in builtin-run.

Signed-off-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent 50cb6dc9
......@@ -84,6 +84,7 @@ OBJS += net/uip/buf.o
OBJS += net/uip/csum.o
OBJS += net/uip/dhcp.o
OBJS += kvm-cmd.o
OBJS += util/init.o
OBJS += util/rbtree.o
OBJS += util/threadpool.o
OBJS += util/parse-options.o
......
......@@ -476,7 +476,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
{
static char real_cmdline[2048], default_name[20];
unsigned int nr_online_cpus;
int r;
kvm = kvm__new();
if (IS_ERR(kvm))
......@@ -646,160 +645,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME,
kvm->cfg.kernel_filename, kvm->cfg.ram_size / 1024 / 1024, kvm->cfg.nrcpus, kvm->cfg.guest_name);
r = kvm__init(kvm);
if (r)
goto fail;
r = term_init(kvm);
if (r < 0) {
pr_err("term_init() failed with error %d\n", r);
goto fail;
}
r = ioeventfd__init(kvm);
if (r < 0) {
pr_err("ioeventfd__init() failed with error %d\n", r);
goto fail;
}
r = kvm_cpu__init(kvm);
if (r < 0) {
pr_err("kvm_cpu__init() failed with error %d\n", r);
goto fail;
}
r = irq__init(kvm);
if (r < 0) {
pr_err("irq__init() failed with error %d\n", r);
goto fail;
}
r = pci__init(kvm);
if (r < 0) {
pr_err("pci__init() failed with error %d\n", r);
goto fail;
}
r = ioport__init(kvm);
if (r < 0) {
pr_err("ioport__init() failed with error %d\n", r);
goto fail;
}
r = disk_image__init(kvm);
if (r < 0) {
pr_err("disk_image__init() failed with error %d\n", r);
goto fail;
}
r = symbol_init(kvm);
if (r < 0)
pr_debug("symbol_init() failed with error %d\n", r);
r = rtc__init(kvm);
if (r < 0) {
pr_err("rtc__init() failed with error %d\n", r);
goto fail;
}
r = serial8250__init(kvm);
if (r < 0) {
pr_err("serial__init() failed with error %d\n", r);
goto fail;
}
r = virtio_blk__init(kvm);
if (r < 0) {
pr_err("virtio_blk__init() failed with error %d\n", r);
goto fail;
}
r = virtio_scsi_init(kvm);
if (r < 0) {
pr_err("virtio_scsi_init() failed with error %d\n", r);
goto fail;
}
r = virtio_console__init(kvm);
if (r < 0) {
pr_err("virtio_console__init() failed with error %d\n", r);
goto fail;
}
r = virtio_rng__init(kvm);
if (r < 0) {
pr_err("virtio_rng__init() failed with error %d\n", r);
goto fail;
}
r = virtio_bln__init(kvm);
if (r < 0) {
pr_err("virtio_rng__init() failed with error %d\n", r);
goto fail;
}
r = virtio_9p__init(kvm);
if (r < 0) {
pr_err("virtio_9p__init() failed with error %d\n", r);
goto fail;
}
r = virtio_net__init(kvm);
if (r < 0) {
pr_err("virtio_net__init() failed with error %d\n", r);
goto fail;
}
r = kbd__init(kvm);
if (r < 0) {
pr_err("kbd__init() failed with error %d\n", r);
goto fail;
}
r = pci_shmem__init(kvm);
if (r < 0) {
pr_err("pci_shmem__init() failed with error %d\n", r);
goto fail;
}
r = vnc__init(kvm);
if (r < 0) {
pr_err("vnc__init() failed with error %d\n", r);
goto fail;
}
r = sdl__init(kvm);
if (r < 0) {
pr_err("sdl__init() failed with error %d\n", r);
goto fail;
}
r = fb__init(kvm);
if (r < 0) {
pr_err("fb__init() failed with error %d\n", r);
goto fail;
}
/*
* Device init all done; firmware init must
* come after this (it may set up device trees etc.)
*/
r = kvm_timer__init(kvm);
if (r < 0) {
pr_err("kvm_timer__init() failed with error %d\n", r);
goto fail;
}
r = thread_pool__init(kvm);
if (r < 0) {
pr_err("thread_pool__init() failed with error %d\n", r);
goto fail;
}
fail:
return r;
return init_list__init(kvm);
}
static int kvm_cmd_run_work(void)
......@@ -818,97 +664,9 @@ static int kvm_cmd_run_work(void)
static void kvm_cmd_run_exit(int guest_ret)
{
int r = 0;
compat__print_all_messages();
r = kvm_cpu__exit(kvm);
if (r < 0)
pr_warning("kvm_cpu__exit() failed with error %d\n", r);
r = symbol_exit(kvm);
if (r < 0)
pr_warning("symbol_exit() failed with error %d\n", r);
r = irq__exit(kvm);
if (r < 0)
pr_warning("irq__exit() failed with error %d\n", r);
r = kvm_timer__exit(kvm);
if (r < 0)
pr_warning("kvm_timer__exit() failed with error %d\n", r);
r = fb__exit(kvm);
if (r < 0)
pr_warning("kvm_timer__exit() failed with error %d\n", r);
r = virtio_net__exit(kvm);
if (r < 0)
pr_warning("virtio_net__exit() failed with error %d\n", r);
r = virtio_scsi_exit(kvm);
if (r < 0)
pr_warning("virtio_scsi_exit() failed with error %d\n", r);
r = virtio_blk__exit(kvm);
if (r < 0)
pr_warning("virtio_blk__exit() failed with error %d\n", r);
r = virtio_rng__exit(kvm);
if (r < 0)
pr_warning("virtio_rng__exit() failed with error %d\n", r);
r = virtio_bln__exit(kvm);
if (r < 0)
pr_warning("virtio_bln__exit() failed with error %d\n", r);
r = virtio_console__exit(kvm);
if (r < 0)
pr_warning("virtio_console__exit() failed with error %d\n", r);
r = pci_shmem__exit(kvm);
if (r < 0)
pr_warning("pci_shmem__exit() failed with error %d\n", r);
r = disk_image__exit(kvm);
if (r < 0)
pr_warning("disk_image__exit() failed with error %d\n", r);
r = serial8250__exit(kvm);
if (r < 0)
pr_warning("serial8250__exit() failed with error %d\n", r);
r = rtc__exit(kvm);
if (r < 0)
pr_warning("rtc__exit() failed with error %d\n", r);
r = kvm__arch_free_firmware(kvm);
if (r < 0)
pr_warning("kvm__arch_free_firmware() failed with error %d\n", r);
r = ioport__exit(kvm);
if (r < 0)
pr_warning("ioport__exit() failed with error %d\n", r);
r = ioeventfd__exit(kvm);
if (r < 0)
pr_warning("ioeventfd__exit() failed with error %d\n", r);
r = pci__exit(kvm);
if (r < 0)
pr_warning("pci__exit() failed with error %d\n", r);
r = term_exit(kvm);
if (r < 0)
pr_warning("pci__exit() failed with error %d\n", r);
r = thread_pool__exit(kvm);
if (r < 0)
pr_warning("thread_pool__exit() failed with error %d\n", r);
r = kvm__exit(kvm);
if (r < 0)
pr_warning("pci__exit() failed with error %d\n", r);
init_list__exit(kvm);
if (guest_ret == 0)
printf("\n # KVM session ended normally.\n");
......
......@@ -345,8 +345,10 @@ int disk_image__init(struct kvm *kvm)
return 0;
}
dev_base_init(disk_image__init);
int disk_image__exit(struct kvm *kvm)
{
return disk_image__close_all(kvm->disks, kvm->nr_disks);
}
dev_base_exit(disk_image__exit);
#include "kvm/framebuffer.h"
#include "kvm/kvm.h"
#include <linux/kernel.h>
#include <linux/list.h>
......@@ -58,6 +59,7 @@ int fb__init(struct kvm *kvm)
return 0;
}
firmware_init(fb__init);
int fb__exit(struct kvm *kvm)
{
......@@ -75,3 +77,4 @@ int fb__exit(struct kvm *kvm)
return 0;
}
firmware_exit(fb__exit);
......@@ -352,3 +352,4 @@ int kbd__init(struct kvm *kvm)
return 0;
}
dev_init(kbd__init);
......@@ -396,8 +396,10 @@ int pci_shmem__init(struct kvm *kvm)
mem);
return 0;
}
dev_init(pci_shmem__init);
int pci_shmem__exit(struct kvm *kvm)
{
return 0;
}
dev_exit(pci_shmem__exit);
......@@ -126,6 +126,7 @@ int rtc__init(struct kvm *kvm)
return r;
}
dev_init(rtc__init);
int rtc__exit(struct kvm *kvm)
{
......@@ -135,3 +136,4 @@ int rtc__exit(struct kvm *kvm)
return 0;
}
dev_exit(rtc__exit);
......@@ -432,6 +432,7 @@ cleanup:
return r;
}
dev_init(serial8250__init);
int serial8250__exit(struct kvm *kvm)
{
......@@ -448,3 +449,4 @@ int serial8250__exit(struct kvm *kvm)
return 0;
}
dev_exit(serial8250__exit);
......@@ -3,6 +3,8 @@
#include "kvm/kvm-arch.h"
#include "kvm/kvm-config.h"
#include "kvm/util-init.h"
#include "kvm/kvm.h"
#include <stdbool.h>
#include <linux/types.h>
......
......@@ -93,6 +93,7 @@ cleanup:
return r;
}
base_init(ioeventfd__init);
int ioeventfd__exit(struct kvm *kvm)
{
......@@ -115,6 +116,7 @@ int ioeventfd__exit(struct kvm *kvm)
return 0;
}
base_exit(ioeventfd__exit);
int ioeventfd__add_event(struct ioevent *ioevent, bool is_pio, bool poll_in_userspace)
{
......
......@@ -188,9 +188,11 @@ int ioport__init(struct kvm *kvm)
return 0;
}
dev_base_init(ioport__init);
int ioport__exit(struct kvm *kvm)
{
ioport__unregister_all();
return 0;
}
dev_base_exit(ioport__exit);
......@@ -212,6 +212,7 @@ fail_alloc:
free(kvm->cpus[i]);
return -ENOMEM;
}
base_init(kvm_cpu__init);
int kvm_cpu__exit(struct kvm *kvm)
{
......@@ -238,3 +239,4 @@ int kvm_cpu__exit(struct kvm *kvm)
return r;
}
late_exit(kvm_cpu__exit);
......@@ -477,6 +477,7 @@ err_epoll:
err:
return ret;
}
base_init(kvm_ipc__init);
int kvm_ipc__exit(struct kvm *kvm)
{
......@@ -494,3 +495,4 @@ int kvm_ipc__exit(struct kvm *kvm)
return ret;
}
base_exit(kvm_ipc__exit);
......@@ -140,6 +140,7 @@ int kvm__exit(struct kvm *kvm)
return 0;
}
core_exit(kvm__exit);
/*
* Note: KVM_SET_USER_MEMORY_REGION assumes that we don't pass overlapping
......@@ -274,6 +275,7 @@ err_free:
err:
return ret;
}
core_init(kvm__init);
/* RFC 1952 */
#define GZIP_ID1 0x1f
......@@ -375,6 +377,7 @@ int kvm_timer__init(struct kvm *kvm)
return 0;
}
firmware_init(kvm_timer__init);
int kvm_timer__exit(struct kvm *kvm)
{
......@@ -386,6 +389,7 @@ int kvm_timer__exit(struct kvm *kvm)
return 0;
}
firmware_exit(kvm_timer__exit);
void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size)
{
......
......@@ -203,6 +203,7 @@ int pci__init(struct kvm *kvm)
return 0;
}
base_init(pci__init);
int pci__exit(struct kvm *kvm)
{
......@@ -211,3 +212,4 @@ int pci__exit(struct kvm *kvm)
return 0;
}
base_exit(pci__exit);
......@@ -15,7 +15,7 @@ int symbol_init(struct kvm *kvm)
int ret = 0;
if (!kvm->vmlinux)
return -EINVAL;
return 0;
bfd_init();
......@@ -38,6 +38,7 @@ int symbol_init(struct kvm *kvm)
return ret;
}
late_init(symbol_init);
static asymbol *lookup(asymbol **symbols, int nr_symbols, const char *symbol_name)
{
......@@ -129,3 +130,4 @@ int symbol_exit(struct kvm *kvm)
return -EFAULT;
}
late_exit(symbol_exit);
......@@ -163,8 +163,10 @@ int term_init(struct kvm *kvm)
return 0;
}
dev_init(term_init);
int term_exit(struct kvm *kvm)
{
return 0;
}
dev_exit(term_exit);
......@@ -309,8 +309,13 @@ int sdl__init(struct kvm *kvm)
return fb__attach(fb, &sdl_ops);
}
dev_init(sdl__init);
int sdl__exit(struct kvm *kvm)
{
return sdl__stop(NULL);
if (kvm->cfg.sdl)
return sdl__stop(NULL);
return 0;
}
dev_exit(sdl__exit);
......@@ -236,8 +236,13 @@ int vnc__init(struct kvm *kvm)
return fb__attach(fb, &vnc_ops);
}
dev_init(vnc__init);
int vnc__exit(struct kvm *kvm)
{
return vnc__stop(NULL);
if (kvm->cfg.vnc)
return vnc__stop(NULL);
return 0;
}
dev_exit(vnc__exit);
#include "kvm/threadpool.h"
#include "kvm/mutex.h"
#include "kvm/kvm.h"
#include <linux/kernel.h>
#include <linux/list.h>
......@@ -131,6 +132,7 @@ int thread_pool__init(struct kvm *kvm)
return i;
}
late_init(thread_pool__init);
int thread_pool__exit(struct kvm *kvm)
{
......@@ -151,6 +153,7 @@ int thread_pool__exit(struct kvm *kvm)
return 0;
}
late_exit(thread_pool__exit);
void thread_pool__do_job(struct thread_pool__job *job)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment