Commit 52f34d2c authored by Asias He's avatar Asias He Committed by Will Deacon
Browse files

kvm tools: Introduce virtio_compat_add_message() helper



This patch introduces a helper virtio_compat_add_message() to simplify
adding compat message for virtio device.

Signed-off-by: default avatarAsias He <asias.hejun@gmail.com>
Signed-off-by: default avatarPekka Enberg <penberg@kernel.org>
parent b7c2f3bc
......@@ -98,4 +98,5 @@ struct virtio_ops {
int virtio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
struct virtio_ops *ops, enum virtio_trans trans,
int device_id, int subsys_id, int class);
int virtio_compat_add_message(const char *device, const char *config);
#endif /* KVM__VIRTIO_H */
......@@ -1313,12 +1313,7 @@ int virtio_9p__register(struct kvm *kvm, const char *root, const char *tag_name)
list_add(&p9dev->list, &devs);
if (compat_id != -1)
compat_id = compat__add_message("virtio-9p device was not detected",
"While you have requested a virtio-9p device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_NET_9P_VIRTIO=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-9p", "CONFIG_NET_9P_VIRTIO");
return err;
......
......@@ -263,10 +263,5 @@ void virtio_bln__init(struct kvm *kvm)
VIRTIO_PCI, PCI_DEVICE_ID_VIRTIO_BLN, VIRTIO_ID_BALLOON, PCI_CLASS_BLN);
if (compat_id != -1)
compat_id = compat__add_message("virtio-balloon device was not detected",
"While you have requested a virtio-balloon device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_VIRTIO_BALLOON=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-balloon", "CONFIG_VIRTIO_BALLOON");
}
......@@ -250,12 +250,7 @@ static int virtio_blk__init_one(struct kvm *kvm, struct disk_image *disk)
disk_image__set_callback(bdev->disk, virtio_blk_complete);
if (compat_id != -1)
compat_id = compat__add_message("virtio-blk device was not detected",
"While you have requested a virtio-blk device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_VIRTIO_BLK=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-blk", "CONFIG_VIRTIO_BLK");
return 0;
}
......
......@@ -189,10 +189,5 @@ void virtio_console__init(struct kvm *kvm)
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 = compat__add_message("virtio-console device was not detected",
"While you have requested a virtio-console device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_VIRTIO_CONSOLE=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-console", "CONFIG_VIRTIO_CONSOLE");
}
......@@ -3,6 +3,7 @@
#include <sys/uio.h>
#include <stdlib.h>
#include "kvm/guest_compat.h"
#include "kvm/barrier.h"
#include "kvm/virtio.h"
#include "kvm/virtio-pci.h"
......@@ -198,3 +199,35 @@ int virtio_init(struct kvm *kvm, void *dev, struct virtio_device *vdev,
return 0;
}
int virtio_compat_add_message(const char *device, const char *config)
{
int len = 1024;
int compat_id;
char *title;
char *desc;
title = malloc(len);
if (!title)
return -ENOMEM;
desc = malloc(len);
if (!desc) {
free(title);
return -ENOMEM;
}
snprintf(title, len, "%s device was not detected", device);
snprintf(desc, len, "While you have requested a %s device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with %s=y enabled in its .config",
device, config);
compat_id = compat__add_message(title, desc);
free(desc);
free(title);
return compat_id;
}
......@@ -548,10 +548,5 @@ void virtio_net__init(const struct virtio_net_params *params)
virtio_net__io_thread_init(params->kvm, ndev);
if (compat_id != -1)
compat_id = compat__add_message("virtio-net device was not detected",
"While you have requested a virtio-net device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_VIRTIO_NET=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-net", "CONFIG_VIRTIO_NET");
}
......@@ -171,12 +171,7 @@ int virtio_rng__init(struct kvm *kvm)
list_add_tail(&rdev->list, &rdevs);
if (compat_id != -1)
compat_id = compat__add_message("virtio-rng device was not detected",
"While you have requested a virtio-rng device, "
"the guest kernel did not initialize it.\n"
"Please make sure that the guest kernel was "
"compiled with CONFIG_HW_RANDOM_VIRTIO=y enabled "
"in its .config");
compat_id = virtio_compat_add_message("virtio-rng", "CONFIG_HW_RANDOM_VIRTIO");
return 0;
cleanup:
close(rdev->fd);
......
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