]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce virtio_compat_add_message() helper
authorAsias He <asias.hejun@gmail.com>
Tue, 5 Jun 2012 16:40:41 +0000 (00:40 +0800)
committerPekka Enberg <penberg@kernel.org>
Tue, 5 Jun 2012 20:31:39 +0000 (23:31 +0300)
This patch introduces a helper virtio_compat_add_message() to simplify
adding compat message for virtio device.

Signed-off-by: Asias He <asias.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/include/kvm/virtio.h
tools/kvm/virtio/9p.c
tools/kvm/virtio/balloon.c
tools/kvm/virtio/blk.c
tools/kvm/virtio/console.c
tools/kvm/virtio/core.c
tools/kvm/virtio/net.c
tools/kvm/virtio/rng.c

index 68eff1524f35feb1ce66ba829fea4b73a1dfed8b..a957a5bd3213778f6052a09fd5ff5f3ec37cd96c 100644 (file)
@@ -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 */
index 4108e02cef1f39837207dc76da3a39de4dd803f5..b388d66131837ecbe914b3a58fb0efcc7804df56 100644 (file)
@@ -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;
 
index 9f1d9bd426c22b3cf24167268134bdfdddbf9643..e442714186d304a4ce5632f5a763186a00773326 100644 (file)
@@ -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");
 }
index 9256646a9de5f2082b50f77cc8f952b7c5e5093b..55ce26fc6386e4f1bc10ec0075bbb4f4bfa00d76 100644 (file)
@@ -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;
 }
 
index 42472eb0769731a64e76fbb91eb12f0fcc533855..3493905e2f1a72a1b1f7b66e479b5513f0ba4de1 100644 (file)
@@ -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");
 }
index da2749212fc6b8cd365a9a954bc5848c8537b6fa..8e0f63ba4e0aa6bb8b4d5f6534bbf890fef35b37 100644 (file)
@@ -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;
+}
index 50bef742767374d10fdfe0028d750201589464e6..da4419815b0d13dbf71eca75755959b1944b9013 100644 (file)
@@ -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");
 }
index 105a4298406c8b6409d6dd4f2b6d9c3f6a46e961..202104cfb784d1fab649a15d2a864f240d337e62 100644 (file)
@@ -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);