From 15a4ac0255c59086df0880ae3414f41f8d390fc4 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Mon, 22 Mar 2010 23:30:10 +0200 Subject: [PATCH] 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 --- tools/kvm/kvm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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(); -- 2.39.5