From: Pekka Enberg Date: Mon, 22 Mar 2010 21:30:10 +0000 (+0200) Subject: Move KVM fds into 'struct kvm' X-Git-Tag: next-20110824~3^2~528^2~271 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=15a4ac0255c59086df0880ae3414f41f8d390fc4;p=karo-tx-linux.git Move KVM fds into 'struct kvm' 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 --- diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 10f3c5ad732b..5ae47edd48c6 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -4,6 +4,11 @@ #include #include +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();