qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lin Ma <lma@suse.com>
To: qemu-devel@nongnu.org, imammedo@redhat.com
Cc: pbonzini@redhat.com, Lin Ma <lma@suse.com>
Subject: [Qemu-devel] [PATCH 2/2] memory-backend: Add can_be_deleted impl for ram-backend and file-backend
Date: Mon, 23 Mar 2015 18:10:42 +0800	[thread overview]
Message-ID: <1427105442-23484-2-git-send-email-lma@suse.com> (raw)
In-Reply-To: <1427105442-23484-1-git-send-email-lma@suse.com>

The can_be_deleted callback returns false if the backend is in used,
Otherwise returns true.

Signed-off-by: Lin Ma <lma@suse.com>
---
 backends/hostmem-file.c | 12 ++++++++++++
 backends/hostmem-ram.c  | 12 ++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 5179994..33ad8e7 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -118,10 +118,22 @@ file_backend_instance_init(Object *o)
                             set_mem_path, NULL);
 }
 
+static bool
+file_backend_can_be_deleted(Object *obj)
+{
+    MemoryRegion *mr;
+    mr = host_memory_backend_get_memory(MEMORY_BACKEND(obj), &error_abort);
+    if (memory_region_is_mapped(mr))
+        return false;
+    else
+        return true;
+}
+
 static const TypeInfo file_backend_info = {
     .name = TYPE_MEMORY_BACKEND_FILE,
     .parent = TYPE_MEMORY_BACKEND,
     .class_init = file_backend_class_init,
+    .can_be_deleted = file_backend_can_be_deleted,
     .instance_init = file_backend_instance_init,
     .instance_size = sizeof(HostMemoryBackendFile),
 };
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index a67a134..8724ad1 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -39,10 +39,22 @@ ram_backend_class_init(ObjectClass *oc, void *data)
     bc->alloc = ram_backend_memory_alloc;
 }
 
+static bool
+ram_backend_can_be_deleted(Object *obj)
+{
+    MemoryRegion *mr;
+    mr = host_memory_backend_get_memory(MEMORY_BACKEND(obj), &error_abort);
+    if (memory_region_is_mapped(mr))
+        return false;
+    else
+        return true;
+}
+
 static const TypeInfo ram_backend_info = {
     .name = TYPE_MEMORY_BACKEND_RAM,
     .parent = TYPE_MEMORY_BACKEND,
     .class_init = ram_backend_class_init,
+    .can_be_deleted = ram_backend_can_be_deleted,
 };
 
 static void register_types(void)
-- 
2.1.4

  reply	other threads:[~2015-03-23 10:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-23 10:10 [Qemu-devel] [PATCH 1/2] object: Add can_be_deleted callback to TypeInfo and TypeImpl Lin Ma
2015-03-23 10:10 ` Lin Ma [this message]
2015-03-23 10:36 ` Peter Crosthwaite
2015-03-23 12:06   ` Paolo Bonzini
2015-03-23 13:13     ` Andreas Färber
2015-03-23 13:30       ` Igor Mammedov
2015-03-25 15:47         ` Lin Ma
2015-03-26 10:05           ` Igor Mammedov
2015-03-26 10:07             ` Andreas Färber
2015-03-26 10:29               ` Igor Mammedov
2015-03-26 13:37                 ` Paolo Bonzini
2015-03-26 14:18                   ` Igor Mammedov
2015-03-23 15:47     ` Lin Ma
2015-03-23 12:52 ` Andreas Färber
2015-03-23 15:25   ` Lin Ma

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=1427105442-23484-2-git-send-email-lma@suse.com \
    --to=lma@suse.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.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).