diff mbox

[01/22] memory: add memory_region_ram_resize

Message ID 1427391520-29497-2-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini March 26, 2015, 5:38 p.m. UTC
This is a simple MemoryRegion wrapper for qemu_ram_resize.

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/exec/memory.h | 12 ++++++++++++
 memory.c              |  7 +++++++
 2 files changed, 19 insertions(+)

Comments

Michael S. Tsirkin March 28, 2015, 6:58 p.m. UTC | #1
On Thu, Mar 26, 2015 at 06:38:19PM +0100, Paolo Bonzini wrote:
> This is a simple MemoryRegion wrapper for qemu_ram_resize.
> 
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  include/exec/memory.h | 12 ++++++++++++
>  memory.c              |  7 +++++++
>  2 files changed, 19 insertions(+)
> 
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 06ffa1d..a2ea587 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -605,6 +605,18 @@ int memory_region_get_fd(MemoryRegion *mr);
>   */
>  void *memory_region_get_ram_ptr(MemoryRegion *mr);
>  
> +/* memory_region_ram_resize: Resize a RAM region.
> + *
> + * Only legal before guest might have detected the memory size: e.g. on
> + * incoming migration, or right after reset.
> + *
> + * @mr: a memory region created with @memory_region_init_resizeable_ram.
> + * @newsize: the new size the region
> + * @errp: pointer to Error*, to store an error if it happens.
> + */
> +void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize,
> +                              Error **errp);
> +
>  /**
>   * memory_region_set_log: Turn dirty logging on or off for a region.
>   *
> diff --git a/memory.c b/memory.c
> index ee3f2a8..a11e9bf 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1452,6 +1452,13 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr)
>      return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
>  }
>  
> +void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp)
> +{
> +    assert(mr->terminates);

Why? Does "terminates" guarantee that ram_addr
is valid? In any case, I think this needs a comment.

> +
> +    qemu_ram_resize(mr->ram_addr, newsize, errp);
> +}
> +
>  static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
>  {
>      FlatView *view;
> -- 
> 2.3.3
>
Paolo Bonzini March 29, 2015, 7:30 a.m. UTC | #2
On 28/03/2015 19:58, Michael S. Tsirkin wrote:
>> > +void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp)
>> > +{
>> > +    assert(mr->terminates);
> Why? Does "terminates" guarantee that ram_addr
> is valid? In any case, I think this needs a comment.

More or less, but not really; I was just cutting/pasting it from other
functions that use ram_addr.  I will clean it up.

Paolo
diff mbox

Patch

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 06ffa1d..a2ea587 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -605,6 +605,18 @@  int memory_region_get_fd(MemoryRegion *mr);
  */
 void *memory_region_get_ram_ptr(MemoryRegion *mr);
 
+/* memory_region_ram_resize: Resize a RAM region.
+ *
+ * Only legal before guest might have detected the memory size: e.g. on
+ * incoming migration, or right after reset.
+ *
+ * @mr: a memory region created with @memory_region_init_resizeable_ram.
+ * @newsize: the new size the region
+ * @errp: pointer to Error*, to store an error if it happens.
+ */
+void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize,
+                              Error **errp);
+
 /**
  * memory_region_set_log: Turn dirty logging on or off for a region.
  *
diff --git a/memory.c b/memory.c
index ee3f2a8..a11e9bf 100644
--- a/memory.c
+++ b/memory.c
@@ -1452,6 +1452,13 @@  void *memory_region_get_ram_ptr(MemoryRegion *mr)
     return qemu_get_ram_ptr(mr->ram_addr & TARGET_PAGE_MASK);
 }
 
+void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp)
+{
+    assert(mr->terminates);
+
+    qemu_ram_resize(mr->ram_addr, newsize, errp);
+}
+
 static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
 {
     FlatView *view;