[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] object_del: Prevent removing an in-use memory b

From: Lin Ma
Subject: Re: [Qemu-devel] [PATCH] object_del: Prevent removing an in-use memory backend object
Date: Mon, 23 Mar 2015 16:52:24 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

在 2015年03月20日 18:17, Igor Mammedov 写道:
On Fri, 20 Mar 2015 12:14:58 +0800
Lin Ma <address@hidden> wrote:

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
                             assertion failed: (obj->parent != NULL)

The patch prevents removing an in-use mem backend and outputs an error msg.

Signed-off-by: Lin Ma <address@hidden>
  qmp.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

diff --git a/qmp.c b/qmp.c
index c479e77..0086e2d 100644
--- a/qmp.c
+++ b/qmp.c
@@ -704,6 +704,7 @@ void qmp_object_del(const char *id, Error **errp)
      Object *container;
      Object *obj;
+    const char *typename;
container = container_get(object_get_root(), "/objects");
      obj = object_resolve_path_component(container, id);
@@ -711,6 +712,19 @@ void qmp_object_del(const char *id, Error **errp)
          error_setg(errp, "object id not found");
+    typename = object_class_get_name(object_class_get_parent(\
+                                        object_get_class(OBJECT(obj))));
+    if (strcmp(typename, TYPE_MEMORY_BACKEND) == 0 ) {
+        MemoryRegion *mr;
+        mr = host_memory_backend_get_memory(MEMORY_BACKEND(obj), errp);
+        if (memory_region_is_mapped(mr)) {
+            char *path = object_get_canonical_path_component(obj);
+            error_setg(errp, "memdev %s is in used.", path);
+            g_free(path);
+            return;
+        }
+    }
How about making it more generic?
   if (!obj_class->can_be_deleted(obj))
      error out


That makes sense, I couldn't agree more.
I am going to drop this patch and separate it to 2 patches. One for adding generic can_be_deleted
callback, The other for adding impl in hostmem-ram.c and hostmem-file.c


reply via email to

[Prev in Thread] Current Thread [Next in Thread]