qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lin Ma <lma@suse.com>
To: imammedo@redhat.com, afaerber@suse.de,
	peter.crosthwaite@xilinx.com, pbonzini@redhat.com
Cc: qemu-devel@nongnu.org, Lin Ma <lma@suse.com>
Subject: [Qemu-devel] [PATCH v3 2/2] hostmem: Prevent removing an in-use memory backend object
Date: Fri, 27 Mar 2015 01:07:06 +0800	[thread overview]
Message-ID: <1427389626-23487-3-git-send-email-lma@suse.com> (raw)
In-Reply-To: <1427389626-23487-1-git-send-email-lma@suse.com>

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>
---
 backends/hostmem.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 99e8f99..dbf94a9 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 = {
-- 
2.1.4

      parent reply	other threads:[~2015-03-26 17:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26 17:07 [Qemu-devel] [PATCH v3 0/2] Add generic can_be_deleted to UserCreatableClass Lin Ma
2015-03-26 17:07 ` [Qemu-devel] [PATCH v3 1/2] qom: Add can_be_deleted callback " Lin Ma
2015-03-26 20:34   ` Paolo Bonzini
2015-03-26 17:07 ` Lin Ma [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427389626-23487-3-git-send-email-lma@suse.com \
    --to=lma@suse.com \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.crosthwaite@xilinx.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).