]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Move KVM fds into 'struct kvm'
authorPekka Enberg <penberg@cs.helsinki.fi>
Mon, 22 Mar 2010 21:30:10 +0000 (23:30 +0200)
committerPekka Enberg <penberg@cs.helsinki.fi>
Mon, 22 Mar 2010 21:30:10 +0000 (23:30 +0200)
This patch introduces a 'struct kvm' and moves the KVM related file descriptors
into it so that we can introduce helper functions more easily.

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/kvm.c

index 10f3c5ad732b8eb132ff56c88c5f219f7d8cb856..5ae47edd48c63e26e652d02caa6848165e08a656 100644 (file)
@@ -4,6 +4,11 @@
 #include <stdlib.h>
 #include <fcntl.h>
 
+struct kvm {
+       int                     fd;             /* /dev/kvm */
+       int                     vmfd;
+};
+
 static void die(const char *s)
 {
        perror(s);
@@ -24,20 +29,19 @@ static struct cpu *cpu__new(void)
 int main(int argc, char *argv[])
 {
        struct cpu *cpu;
-       int vmfd;
+       struct kvm kvm;
        int ret;
-       int fd;
 
-       fd = open("/dev/kvm", O_RDWR);
-       if (fd < 0)
+       kvm.fd = open("/dev/kvm", O_RDWR);
+       if (kvm.fd < 0)
                die("open");
 
-       ret = ioctl(fd, KVM_GET_API_VERSION, 0);
+       ret = ioctl(kvm.fd, KVM_GET_API_VERSION, 0);
        if (ret != KVM_API_VERSION)
                die("ioctl");
 
-       vmfd = ioctl(fd, KVM_CREATE_VM, 0);
-       if (vmfd < 0)
+       kvm.vmfd = ioctl(kvm.fd, KVM_CREATE_VM, 0);
+       if (kvm.vmfd < 0)
                die("open");
 
        cpu = cpu__new();