[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 3/6] memory: add ref/unref interface for MemroyRe
From: |
Liu Ping Fan |
Subject: |
[Qemu-devel] [PATCH v2 3/6] memory: add ref/unref interface for MemroyRegionOps |
Date: |
Fri, 3 May 2013 10:45:19 +0800 |
From: Liu Ping Fan <address@hidden>
This pair of interface are optinal, except for those device which is
used outside the biglock's protection for hot unplug. Currently,
HostMem used by virtio-blk dataplane is outside biglock, so the RAM
device should implement this.
Signed-off-by: Liu Ping Fan <address@hidden>
---
include/exec/memory.h | 10 ++++++++++
memory.c | 18 ++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2761668..edeb480 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -54,6 +54,12 @@ struct MemoryRegionIORange {
* Memory region callbacks
*/
struct MemoryRegionOps {
+
+ /* ref/unref pair is optional; ref.
+ * inc refcnt of object who store MemoryRegion
+ */
+ void (*ref)(void);
+ void (*unref)(void);
/* Read from the memory region. @addr is relative to @mr; @size is
* in bytes. */
uint64_t (*read)(void *opaque,
@@ -223,6 +229,10 @@ struct MemoryListener {
QTAILQ_ENTRY(MemoryListener) link;
};
+/**/
+bool memory_region_ref(MemoryRegion *mr);
+bool memory_region_unref(MemoryRegion *mr);
+
/**
* memory_region_init: Initialize a memory region
*
diff --git a/memory.c b/memory.c
index 75ca281..c29998d 100644
--- a/memory.c
+++ b/memory.c
@@ -786,6 +786,24 @@ static bool memory_region_wrong_endianness(MemoryRegion
*mr)
#endif
}
+bool memory_region_ref(MemoryRegion *mr)
+{
+ if (mr->ops && mr->ops->ref) {
+ mr->ops->ref();
+ return true;
+ }
+ return false;
+}
+
+bool memory_region_unref(MemoryRegion *mr)
+{
+ if (mr->ops && mr->ops->unref) {
+ mr->ops->unref();
+ return true;
+ }
+ return false;
+}
+
void memory_region_init(MemoryRegion *mr,
const char *name,
uint64_t size)
--
1.7.4.4
- [Qemu-devel] [PATCH v2 0/6] proposal to make hostmem listener RAM unplug safe, Liu Ping Fan, 2013/05/02
- [Qemu-devel] [PATCH v2 1/6] hostmem: make hostmem single, not per Vring related, Liu Ping Fan, 2013/05/02
- [Qemu-devel] [PATCH v2 2/6] hostmem: AddressSpace has its own map and maintained by RCU prepared style, Liu Ping Fan, 2013/05/02
- [Qemu-devel] [PATCH v2 3/6] memory: add ref/unref interface for MemroyRegionOps,
Liu Ping Fan <=
- [Qemu-devel] [PATCH v2 4/6] hostmem: hostmem listener pin RAM-Device by refcnt, Liu Ping Fan, 2013/05/02
- [Qemu-devel] [PATCH v2 5/6] Vring: use hostmem's RAM safe api, Liu Ping Fan, 2013/05/02
- [Qemu-devel] [PATCH v2 6/6] virtio-blk: release reference to RAM's memoryRegion, Liu Ping Fan, 2013/05/02
- Re: [Qemu-devel] [PATCH v2 0/6] proposal to make hostmem listener RAM unplug safe, Paolo Bonzini, 2013/05/04