]> git.proxmox.com Git - qemu.git/commitdiff
memory: add ref/unref
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 May 2013 07:06:00 +0000 (09:06 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 4 Jul 2013 15:42:45 +0000 (17:42 +0200)
Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/exec/memory.h
memory.c

index 2f3e8e426d32245bba572111a60d2fbee68d508f..d2466a7a971fe950ec409142ab2b9f56b706cf6e 100644 (file)
@@ -247,6 +247,36 @@ void memory_region_init(MemoryRegion *mr,
                         struct Object *owner,
                         const char *name,
                         uint64_t size);
+
+/**
+ * memory_region_ref: Add 1 to a memory region's reference count
+ *
+ * Whenever memory regions are accessed outside the BQL, they need to be
+ * preserved against hot-unplug.  MemoryRegions actually do not have their
+ * own reference count; they piggyback on a QOM object, their "owner".
+ * This function adds a reference to the owner.
+ *
+ * All MemoryRegions must have an owner if they can disappear, even if the
+ * device they belong to operates exclusively under the BQL.  This is because
+ * the region could be returned at any time by memory_region_find, and this
+ * is usually under guest control.
+ *
+ * @mr: the #MemoryRegion
+ */
+void memory_region_ref(MemoryRegion *mr);
+
+/**
+ * memory_region_unref: Remove 1 to a memory region's reference count
+ *
+ * Whenever memory regions are accessed outside the BQL, they need to be
+ * preserved against hot-unplug.  MemoryRegions actually do not have their
+ * own reference count; they piggyback on a QOM object, their "owner".
+ * This function removes a reference to the owner and possibly destroys it.
+ *
+ * @mr: the #MemoryRegion
+ */
+void memory_region_unref(MemoryRegion *mr);
+
 /**
  * memory_region_init_io: Initialize an I/O memory region.
  *
index f85774a11ffb214f4264cdb547d515dac22151c3..e04d5196b0da9b11ee6809a31639620cd6a8381b 100644 (file)
--- a/memory.c
+++ b/memory.c
@@ -1019,6 +1019,20 @@ Object *memory_region_owner(MemoryRegion *mr)
     return mr->owner;
 }
 
+void memory_region_ref(MemoryRegion *mr)
+{
+    if (mr && mr->owner) {
+        object_ref(mr->owner);
+    }
+}
+
+void memory_region_unref(MemoryRegion *mr)
+{
+    if (mr && mr->owner) {
+        object_unref(mr->owner);
+    }
+}
+
 uint64_t memory_region_size(MemoryRegion *mr)
 {
     if (int128_eq(mr->size, int128_2_64())) {