diff mbox

[5/9] remove fd from vcpu_context

Message ID 1248889759-25063-6-git-send-email-glommer@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Glauber Costa July 29, 2009, 5:49 p.m. UTC
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 qemu-kvm-x86.c |   24 ++++++++++++------------
 qemu-kvm.c     |   33 ++++++++++++++++-----------------
 qemu-kvm.h     |    1 -
 3 files changed, 28 insertions(+), 30 deletions(-)
diff mbox

Patch

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 76c7631..c9d741d 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -179,7 +179,7 @@  int kvm_enable_vapic(kvm_vcpu_context_t vcpu, uint64_t vapic)
 		.vapic_addr = vapic,
 	};
 
-	r = ioctl(vcpu->fd, KVM_SET_VAPIC_ADDR, &va);
+	r = ioctl(vcpu->env->kvm_fd, KVM_SET_VAPIC_ADDR, &va);
 	if (r == -1) {
 		r = -errno;
 		perror("kvm_enable_vapic");
@@ -286,7 +286,7 @@  int kvm_get_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s)
 	int r;
 	if (!kvm_irqchip_in_kernel())
 		return 0;
-	r = ioctl(vcpu->fd, KVM_GET_LAPIC, s);
+	r = ioctl(vcpu->env->kvm_fd, KVM_GET_LAPIC, s);
 	if (r == -1) {
 		r = -errno;
 		perror("kvm_get_lapic");
@@ -299,7 +299,7 @@  int kvm_set_lapic(kvm_vcpu_context_t vcpu, struct kvm_lapic_state *s)
 	int r;
 	if (!kvm_irqchip_in_kernel())
 		return 0;
-	r = ioctl(vcpu->fd, KVM_SET_LAPIC, s);
+	r = ioctl(vcpu->env->kvm_fd, KVM_SET_LAPIC, s);
 	if (r == -1) {
 		r = -errno;
 		perror("kvm_set_lapic");
@@ -356,7 +356,7 @@  int kvm_has_pit_state2(kvm_context_t kvm)
 void kvm_show_code(kvm_vcpu_context_t vcpu)
 {
 #define SHOW_CODE_LEN 50
-	int fd = vcpu->fd;
+	int fd = vcpu->env->kvm_fd;
 	struct kvm_regs regs;
 	struct kvm_sregs sregs;
 	int r, n;
@@ -424,7 +424,7 @@  int kvm_get_msrs(kvm_vcpu_context_t vcpu, struct kvm_msr_entry *msrs, int n)
 
     kmsrs->nmsrs = n;
     memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
-    r = ioctl(vcpu->fd, KVM_GET_MSRS, kmsrs);
+    r = ioctl(vcpu->env->kvm_fd, KVM_GET_MSRS, kmsrs);
     e = errno;
     memcpy(msrs, kmsrs->entries, n * sizeof *msrs);
     free(kmsrs);
@@ -439,7 +439,7 @@  int kvm_set_msrs(kvm_vcpu_context_t vcpu, struct kvm_msr_entry *msrs, int n)
 
     kmsrs->nmsrs = n;
     memcpy(kmsrs->entries, msrs, n * sizeof *msrs);
-    r = ioctl(vcpu->fd, KVM_SET_MSRS, kmsrs);
+    r = ioctl(vcpu->env->kvm_fd, KVM_SET_MSRS, kmsrs);
     e = errno;
     free(kmsrs);
     errno = e;
@@ -464,7 +464,7 @@  int kvm_get_mce_cap_supported(kvm_context_t kvm, uint64_t *mce_cap,
 int kvm_setup_mce(kvm_vcpu_context_t vcpu, uint64_t *mcg_cap)
 {
 #ifdef KVM_CAP_MCE
-    return ioctl(vcpu->fd, KVM_X86_SETUP_MCE, mcg_cap);
+    return ioctl(vcpu->env->kvm_fd, KVM_X86_SETUP_MCE, mcg_cap);
 #else
     return -ENOSYS;
 #endif
@@ -473,7 +473,7 @@  int kvm_setup_mce(kvm_vcpu_context_t vcpu, uint64_t *mcg_cap)
 int kvm_set_mce(kvm_vcpu_context_t vcpu, struct kvm_x86_mce *m)
 {
 #ifdef KVM_CAP_MCE
-    return ioctl(vcpu->fd, KVM_X86_SET_MCE, m);
+    return ioctl(vcpu->env->kvm_fd, KVM_X86_SET_MCE, m);
 #else
     return -ENOSYS;
 #endif
@@ -496,7 +496,7 @@  static void print_dt(FILE *file, const char *name, struct kvm_dtable *dt)
 
 void kvm_show_regs(kvm_vcpu_context_t vcpu)
 {
-	int fd = vcpu->fd;
+	int fd = vcpu->env->kvm_fd;
 	struct kvm_regs regs;
 	struct kvm_sregs sregs;
 	int r;
@@ -563,7 +563,7 @@  int kvm_setup_cpuid(kvm_vcpu_context_t vcpu, int nent,
 
 	cpuid->nent = nent;
 	memcpy(cpuid->entries, entries, nent * sizeof(*entries));
-	r = ioctl(vcpu->fd, KVM_SET_CPUID, cpuid);
+	r = ioctl(vcpu->env->kvm_fd, KVM_SET_CPUID, cpuid);
 
 	free(cpuid);
 	return r;
@@ -579,7 +579,7 @@  int kvm_setup_cpuid2(kvm_vcpu_context_t vcpu, int nent,
 
 	cpuid->nent = nent;
 	memcpy(cpuid->entries, entries, nent * sizeof(*entries));
-	r = ioctl(vcpu->fd, KVM_SET_CPUID2, cpuid);
+	r = ioctl(vcpu->env->kvm_fd, KVM_SET_CPUID2, cpuid);
 	if (r == -1) {
 		fprintf(stderr, "kvm_setup_cpuid2: %m\n");
 		r = -errno;
@@ -634,7 +634,7 @@  static int tpr_access_reporting(kvm_vcpu_context_t vcpu, int enabled)
 	r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_VAPIC);
 	if (r <= 0)
 		return -ENOSYS;
-	r = ioctl(vcpu->fd, KVM_TPR_ACCESS_REPORTING, &tac);
+	r = ioctl(vcpu->env->kvm_fd, KVM_TPR_ACCESS_REPORTING, &tac);
 	if (r == -1) {
 		r = -errno;
 		perror("KVM_TPR_ACCESS_REPORTING");
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 47846b3..981640c 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -443,7 +443,6 @@  kvm_vcpu_context_t kvm_create_vcpu(CPUState *env, int id)
 		fprintf(stderr, "kvm_create_vcpu: %m\n");
 		goto err;
 	}
-	vcpu_ctx->fd = r;
 
     env->kvm_fd = r;
     env->kvm_state = kvm_state;
@@ -455,14 +454,14 @@  kvm_vcpu_context_t kvm_create_vcpu(CPUState *env, int id)
 		goto err_fd;
 	}
 	vcpu_ctx->run = mmap(NULL, mmap_size, PROT_READ|PROT_WRITE, MAP_SHARED,
-			      vcpu_ctx->fd, 0);
+			      env->kvm_fd, 0);
 	if (vcpu_ctx->run == MAP_FAILED) {
 		fprintf(stderr, "mmap vcpu area: %m\n");
 		goto err_fd;
 	}
 	return vcpu_ctx;
 err_fd:
-	close(vcpu_ctx->fd);
+	close(env->kvm_fd);
 err:
 	free(vcpu_ctx);
 	return NULL;
@@ -815,32 +814,32 @@  int handle_debug(kvm_vcpu_context_t vcpu, void *env)
 
 int kvm_get_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs)
 {
-    return ioctl(vcpu->fd, KVM_GET_REGS, regs);
+    return ioctl(vcpu->env->kvm_fd, KVM_GET_REGS, regs);
 }
 
 int kvm_set_regs(kvm_vcpu_context_t vcpu, struct kvm_regs *regs)
 {
-    return ioctl(vcpu->fd, KVM_SET_REGS, regs);
+    return ioctl(vcpu->env->kvm_fd, KVM_SET_REGS, regs);
 }
 
 int kvm_get_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu)
 {
-    return ioctl(vcpu->fd, KVM_GET_FPU, fpu);
+    return ioctl(vcpu->env->kvm_fd, KVM_GET_FPU, fpu);
 }
 
 int kvm_set_fpu(kvm_vcpu_context_t vcpu, struct kvm_fpu *fpu)
 {
-    return ioctl(vcpu->fd, KVM_SET_FPU, fpu);
+    return ioctl(vcpu->env->kvm_fd, KVM_SET_FPU, fpu);
 }
 
 int kvm_get_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *sregs)
 {
-    return ioctl(vcpu->fd, KVM_GET_SREGS, sregs);
+    return ioctl(vcpu->env->kvm_fd, KVM_GET_SREGS, sregs);
 }
 
 int kvm_set_sregs(kvm_vcpu_context_t vcpu, struct kvm_sregs *sregs)
 {
-    return ioctl(vcpu->fd, KVM_SET_SREGS, sregs);
+    return ioctl(vcpu->env->kvm_fd, KVM_SET_SREGS, sregs);
 }
 
 #ifdef KVM_CAP_MP_STATE
@@ -850,7 +849,7 @@  int kvm_get_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state)
 
     r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_MP_STATE);
     if (r > 0)
-        return ioctl(vcpu->fd, KVM_GET_MP_STATE, mp_state);
+        return ioctl(vcpu->env->kvm_fd, KVM_GET_MP_STATE, mp_state);
     return -ENOSYS;
 }
 
@@ -860,7 +859,7 @@  int kvm_set_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state)
 
     r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_MP_STATE);
     if (r > 0)
-        return ioctl(vcpu->fd, KVM_SET_MP_STATE, mp_state);
+        return ioctl(vcpu->env->kvm_fd, KVM_SET_MP_STATE, mp_state);
     return -ENOSYS;
 }
 #endif
@@ -924,7 +923,7 @@  int kvm_is_ready_for_interrupt_injection(kvm_vcpu_context_t vcpu)
 int kvm_run(kvm_vcpu_context_t vcpu, void *env)
 {
 	int r;
-	int fd = vcpu->fd;
+	int fd = vcpu->env->kvm_fd;
 	struct kvm_run *run = vcpu->run;
 	kvm_context_t kvm = vcpu->kvm;
 
@@ -1037,13 +1036,13 @@  int kvm_inject_irq(kvm_vcpu_context_t vcpu, unsigned irq)
 	struct kvm_interrupt intr;
 
 	intr.irq = irq;
-	return ioctl(vcpu->fd, KVM_INTERRUPT, &intr);
+	return ioctl(vcpu->env->kvm_fd, KVM_INTERRUPT, &intr);
 }
 
 #ifdef KVM_CAP_SET_GUEST_DEBUG
 int kvm_set_guest_debug(kvm_vcpu_context_t vcpu, struct kvm_guest_debug *dbg)
 {
-	return ioctl(vcpu->fd, KVM_SET_GUEST_DEBUG, dbg);
+	return ioctl(vcpu->env->kvm_fd, KVM_SET_GUEST_DEBUG, dbg);
 }
 #endif
 
@@ -1053,7 +1052,7 @@  int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset)
 	int r;
 
 	if (!sigset) {
-		r = ioctl(vcpu->fd, KVM_SET_SIGNAL_MASK, NULL);
+		r = ioctl(vcpu->env->kvm_fd, KVM_SET_SIGNAL_MASK, NULL);
 		if (r == -1)
 			r = -errno;
 		return r;
@@ -1062,7 +1061,7 @@  int kvm_set_signal_mask(kvm_vcpu_context_t vcpu, const sigset_t *sigset)
 
 	sigmask->len = 8;
 	memcpy(sigmask->sigset, sigset, sizeof(*sigset));
-	r = ioctl(vcpu->fd, KVM_SET_SIGNAL_MASK, sigmask);
+	r = ioctl(vcpu->env->kvm_fd, KVM_SET_SIGNAL_MASK, sigmask);
 	if (r == -1)
 		r = -errno;
 	free(sigmask);
@@ -1081,7 +1080,7 @@  int kvm_has_sync_mmu(void)
 int kvm_inject_nmi(kvm_vcpu_context_t vcpu)
 {
 #ifdef KVM_CAP_USER_NMI
-	return ioctl(vcpu->fd, KVM_NMI);
+	return ioctl(vcpu->env->kvm_fd, KVM_NMI);
 #else
 	return -ENOSYS;
 #endif
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 3f14f13..473e8e3 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -71,7 +71,6 @@  struct kvm_context {
 struct kvm_vcpu_context
 {
     CPUState *env;
-	int fd;
 	struct kvm_run *run;
 	struct kvm_context *kvm;
 	uint32_t id;