@@ -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);
@@ -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 */
@@ -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;
}
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(-)