[PATCH 1/2] kvm tools: Introduce virtio_compat_add_message() helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Asias He <asias.hejun@xxxxxxxxx>
---
 tools/kvm/include/kvm/virtio.h |    1 +
 tools/kvm/virtio/9p.c          |    7 +------
 tools/kvm/virtio/balloon.c     |    7 +------
 tools/kvm/virtio/blk.c         |    7 +------
 tools/kvm/virtio/console.c     |    7 +------
 tools/kvm/virtio/core.c        |   33 +++++++++++++++++++++++++++++++++
 tools/kvm/virtio/net.c         |    7 +------
 tools/kvm/virtio/rng.c         |    7 +------
 8 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio.h b/tools/kvm/include/kvm/virtio.h
index 68eff15..a957a5b 100644
--- a/tools/kvm/include/kvm/virtio.h
+++ b/tools/kvm/include/kvm/virtio.h
@@ -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 */
diff --git a/tools/kvm/virtio/9p.c b/tools/kvm/virtio/9p.c
index 4108e02..b388d66 100644
--- a/tools/kvm/virtio/9p.c
+++ b/tools/kvm/virtio/9p.c
@@ -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;
 
diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index 9f1d9bd..e442714 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -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");
 }
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 9256646..55ce26f 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -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;
 }
 
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index 42472eb..3493905 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -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");
 }
diff --git a/tools/kvm/virtio/core.c b/tools/kvm/virtio/core.c
index da27492..9e18333 100644
--- a/tools/kvm/virtio/core.c
+++ b/tools/kvm/virtio/core.c
@@ -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, device);
+
+	free(desc);
+	free(title);
+
+	return compat_id;
+}
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 50bef74..da44198 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -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");
 }
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 105a429..202104c 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -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);
-- 
1.7.10.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux