diff mbox

[17/33] kvm tools: virtio-console init/exit

Message ID 1346833927-15740-18-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin Sept. 5, 2012, 8:31 a.m. UTC
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 <levinsasha928@gmail.com>
---
 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 mbox

Patch

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index f09aac8..ef539b9a 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 50d8653..8980920 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 4a9ca9f..a1cb8f4 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;
 }