From 77c571da6cc22070f6f8e1b05f98826f2b3ac851 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Wed, 5 Sep 2012 10:31:51 +0200 Subject: [PATCH] kvm tools: virtio-console init/exit Make the init/exit of virtio-console self-contained, so the global init code won't need to check if it was selected or not. Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/builtin-run.c | 12 +++++++++--- tools/kvm/include/kvm/virtio-console.h | 3 ++- tools/kvm/virtio/console.c | 12 +++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index a1825a145563..c9a7f208e011 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -1124,9 +1124,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) goto fail; } - - if (kvm->cfg.active_console == CONSOLE_VIRTIO) - virtio_console__init(kvm); + r = virtio_console__init(kvm); + if (r < 0) { + pr_err("virtio_console__init() failed with error %d\n", r); + goto fail; + } if (kvm->cfg.virtio_rng) virtio_rng__init(kvm); @@ -1282,6 +1284,10 @@ static void kvm_cmd_run_exit(int guest_ret) if (r < 0) pr_warning("virtio_rng__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 = disk_image__exit(kvm); if (r < 0) pr_warning("disk_image__exit() failed with error %d\n", r); diff --git a/tools/kvm/include/kvm/virtio-console.h b/tools/kvm/include/kvm/virtio-console.h index 50d8653aa7bb..89809208786b 100644 --- a/tools/kvm/include/kvm/virtio-console.h +++ b/tools/kvm/include/kvm/virtio-console.h @@ -3,7 +3,8 @@ struct kvm; -void virtio_console__init(struct kvm *kvm); +int virtio_console__init(struct kvm *kvm); void virtio_console__inject_interrupt(struct kvm *kvm); +int virtio_console__exit(struct kvm *kvm); #endif /* KVM__CONSOLE_VIRTIO_H */ diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c index 4a9ca9ff174a..a1cb8f4cb2d9 100644 --- a/tools/kvm/virtio/console.c +++ b/tools/kvm/virtio/console.c @@ -182,10 +182,20 @@ static struct virtio_ops con_dev_virtio_ops = (struct virtio_ops) { .get_size_vq = get_size_vq, }; -void virtio_console__init(struct kvm *kvm) +int virtio_console__init(struct kvm *kvm) { + if (kvm->cfg.active_console != CONSOLE_VIRTIO) + return 0; + virtio_init(kvm, &cdev, &cdev.vdev, &con_dev_virtio_ops, VIRTIO_PCI, PCI_DEVICE_ID_VIRTIO_CONSOLE, VIRTIO_ID_CONSOLE, PCI_CLASS_CONSOLE); if (compat_id == -1) compat_id = virtio_compat_add_message("virtio-console", "CONFIG_VIRTIO_CONSOLE"); + + return 0; +} + +int virtio_console__exit(struct kvm *kvm) +{ + return 0; } -- 2.39.5