diff options
author | Glauber Costa <glommer@redhat.com> | 2008-09-10 16:21:03 -0300 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-09-11 11:56:24 +0300 |
commit | c34861b17e51a2e71a6a4eb386f1f789ba07e79d (patch) | |
tree | 0d65a5c06ede66fcdbdce8bdb7fe834438722ba9 /libkvm | |
parent | 813b2a3efb8d72f14d846925eb36b7eb9a5c647e (diff) |
kvm: libkvm: merge destroy phys mem functions
kvm_destroy_userspace_phys_mem() and kvm_destroy_phys_mem()
can be merged into a single function, now that kernel allocation
is no more.
Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'libkvm')
-rw-r--r-- | libkvm/libkvm.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c index 9a3f6c66..c3f85a28 100644 --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -418,32 +418,6 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, return ptr; } -void kvm_destroy_userspace_phys_mem(kvm_context_t kvm, - unsigned long phys_start) -{ - int r; - struct kvm_userspace_memory_region memory = { - .memory_size = 0, - .guest_phys_addr = phys_start, - .flags = 0, - }; - - memory.userspace_addr = 0; - memory.slot = get_slot(phys_start); - - if (memory.slot == -1) - return; - - r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory); - if (r == -1) { - fprintf(stderr, "destroy_userspace_phys_mem: %s", - strerror(errno)); - return; - } - - free_slot(memory.slot); -} - int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start) { return get_intersecting_slot(phys_start) != -1; @@ -559,10 +533,17 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, unsigned long len) { int slot; + int r; + struct kvm_userspace_memory_region memory = { + .memory_size = 0, + .guest_phys_addr = phys_start, + .userspace_addr = 0, + .flags = 0, + }; slot = get_slot(phys_start); - if (slot >= KVM_MAX_NUM_MEM_REGIONS) { + if ((slot >= KVM_MAX_NUM_MEM_REGIONS) || (slot == -1)) { fprintf(stderr, "BUG: %s: invalid parameters (slot=%d)\n", __FUNCTION__, slot); return; @@ -574,7 +555,15 @@ void kvm_destroy_phys_mem(kvm_context_t kvm, unsigned long phys_start, phys_start = slots[slot].phys_addr; } - kvm_destroy_userspace_phys_mem(kvm, phys_start); + memory.slot = slot; + r = ioctl(kvm->vm_fd, KVM_SET_USER_MEMORY_REGION, &memory); + if (r == -1) { + fprintf(stderr, "destroy_userspace_phys_mem: %s", + strerror(errno)); + return; + } + + free_slot(memory.slot); } static int kvm_get_map(kvm_context_t kvm, int ioctl_num, int slot, void *buf) |