[PATCH] qemu: Fix connectGetType() API

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

 



This patch fixes qemuConnectGetType() API function to return KVM if
appropriate, i.e. when /dev/kvm exists as the KVM module is loaded.
No further check is being done so it's merely showing the possibility
that KVM virtualization is available on the host however we don't
have any guest information (as it's connection-only related) so we
cannot sure we can use KVM. This can be useful to identify we have
KVM (Virt Support) available on the host if host and guest archs
are the same.

Testing:
Done using a simple application with C source code below.

[before patch applied]$ ./test
Hypervisor type: QEMU
[after patch applied]$ ./test
Hypervisor type: KVM
$

Testing C code:

int main()
{
        virConnectPtr conn = NULL;

        conn = virConnectOpen("qemu:///system");
        if (!conn)
                return 1;

        printf("Hypervisor type: %s\n", virConnectGetType(conn));
        virConnectClose(conn);

        return 0;
}

Compiled on F-17 x86_64 host using: gcc -o test test.c -lvirt

Signed-off-by: Michal Novotny <minovotn@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9b5d126..b770967 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1132,6 +1132,16 @@ static const char *qemuConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
     if (virConnectGetTypeEnsureACL(conn) < 0)
         return NULL;
 
+    /*
+     * If KVM is available for the host architecture then report KVM support.
+     * This approach merely shows it is possible to have KVM support as module is
+     * loaded however if you select different architecture, e.g. ARM on x86_64 host,
+     * the KVM option will not be available as there is no KVM virtualization
+     * support for ARM architecture that could be running on top of x86_64 host.
+     */
+    if (access("/dev/kvm", F_OK) == 0)
+        return "KVM";
+
     return "QEMU";
 }
 
-- 
1.7.11.7

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]