Re: [PATCH 5/9] substitute is_allocated_mem with more general is_containing_region

Avi Kivity
2008-08-13T11:41:37Z

Glauber Costa wrote:
> Signed-off-by: Glauber Costa <gcosta@redhat.com>
> ---
> libkvm/libkvm.c | 34 +++++++++++++++++++++-------------
> libkvm/libkvm.h | 2 +-
> qemu/qemu-kvm.c | 2 +-
> 3 files changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/libkvm/libkvm.c b/libkvm/libkvm.c
> index 33f00b7..c885dee 100644
> --- a/libkvm/libkvm.c
> +++ b/libkvm/libkvm.c
> @@ -140,6 +140,27 @@ int get_intersecting_slot(unsigned long phys_addr)
> return -1;
> }
>
> +/* 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 + size)
> + return i;
> + return -1;
> +}
> +
>

What about partially containing (or: overlapping) slots?

--
error compiling committee.c: too many arguments to function