summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Ma <lma@suse.com>2015-03-30 16:36:29 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2015-04-01 10:06:38 +0200
commit36bce5ca5da7a7dbdc5001dc65b40b7439472106 (patch)
treec3e9d14330ebf092e3278460e4a51fb5442d75e2
parentd6edb15576643ab348a9f73e115c2e037edf7460 (diff)
hostmem: Prevent removing an in-use memory backend
showing a memory device whose memdev is removed leads an assert: (qemu) object_add memory-backend-ram,id=ram0,size=128M (qemu) device_add pc-dimm,id=d0,memdev=ram0 (qemu) object_del ram0 (qemu) info memory-devices ** ERROR:qom/object.c:1274:object_get_canonical_path_component:\ assertion failed: (obj->parent != NULL) Aborted The patch prevents removing an in-use mem backend and error out. Signed-off-by: Lin Ma <lma@suse.com> Message-Id: <1427704589-7688-3-git-send-email-lma@suse.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--backends/hostmem.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 99e8f99da8..b7b6cf8f4a 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -335,12 +335,26 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
}
}
+static bool
+host_memory_backend_can_be_deleted(UserCreatable *uc, Error **errp)
+{
+ MemoryRegion *mr;
+
+ mr = host_memory_backend_get_memory(MEMORY_BACKEND(uc), errp);
+ if (memory_region_is_mapped(mr)) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
static void
host_memory_backend_class_init(ObjectClass *oc, void *data)
{
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
ucc->complete = host_memory_backend_memory_complete;
+ ucc->can_be_deleted = host_memory_backend_can_be_deleted;
}
static const TypeInfo host_memory_backend_info = {