diff options
author | Glauber Costa <glommer@redhat.com> | 2008-09-23 14:44:35 -0300 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2008-09-24 14:49:22 +0300 |
commit | e2d49aade432652c79f2141bf9d45a84e8bda290 (patch) | |
tree | df81374c7dd141f93778797816934549527e602d /libkvm | |
parent | eb22598d5809348a7f16d519a21ecba303af3804 (diff) |
kvm: libkvm: substitute is_allocated_mem with more general is_containing_region
is_allocated_mem is a function that checks if every relevant aspect of the
memory slot match (start and size). Replace it with a more generic function
that checks if a memory region is totally contained into another. The former
case is also covered.
Signed-off-by: Glauber Costa <glommer@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'libkvm')
-rw-r--r-- | libkvm/libkvm.c | 34 | ||||
-rw-r--r-- | libkvm/libkvm.h | 4 |
2 files changed, 14 insertions, 24 deletions
diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c index c2610530..11a95292 100644 --- a/libkvm/libkvm.c +++ b/libkvm/libkvm.c @@ -125,17 +125,27 @@ int get_slot(unsigned long phys_addr) return -1; } -int get_intersecting_slot(unsigned long phys_addr) +/* Returns -1 if this slot is not totally contained on any other, + * and the number of the slot otherwise */ +int get_container_slot(uint64_t phys_addr, unsigned long size) { int i; for (i = 0; i < KVM_MAX_NUM_MEM_REGIONS ; ++i) - if (slots[i].len && slots[i].phys_addr < phys_addr && - (slots[i].phys_addr + slots[i].len) > phys_addr) + if (slots[i].len && slots[i].phys_addr <= phys_addr && + (slots[i].phys_addr + slots[i].len) >= phys_addr + size) return i; return -1; } +int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_addr, unsigned long size) +{ + int slot = get_container_slot(phys_addr, size); + if (slot == -1) + return 0; + return 1; +} + /* * dirty pages logging control */ @@ -421,24 +431,6 @@ void *kvm_create_phys_mem(kvm_context_t kvm, unsigned long phys_start, return ptr; } -int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start) -{ - return get_intersecting_slot(phys_start) != -1; -} - -int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len) -{ - int slot; - - slot = get_slot(phys_start); - if (slot == -1) - return 0; - if (slots[slot].len == len) - return 1; - return 0; -} - int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start, void *userspace_addr, unsigned long len, int log) diff --git a/libkvm/libkvm.h b/libkvm/libkvm.h index 77fd903f..cb77c6cf 100644 --- a/libkvm/libkvm.h +++ b/libkvm/libkvm.h @@ -454,9 +454,7 @@ void *kvm_create_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len, int log, int writable); void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, unsigned long len); -int kvm_is_intersecting_mem(kvm_context_t kvm, unsigned long phys_start); -int kvm_is_allocated_mem(kvm_context_t kvm, unsigned long phys_start, - unsigned long len); +int kvm_is_containing_region(kvm_context_t kvm, unsigned long phys_start, unsigned long size); int kvm_register_phys_mem(kvm_context_t kvm, unsigned long phys_start, void *userspace_addr, unsigned long len, int log); |