All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] object: Add can_be_deleted callback to TypeInfo and TypeImpl
@ 2015-03-23 10:10 Lin Ma
  2015-03-23 10:10 ` [Qemu-devel] [PATCH 2/2] memory-backend: Add can_be_deleted impl for ram-backend and file-backend Lin Ma
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Lin Ma @ 2015-03-23 10:10 UTC (permalink / raw)
  To: qemu-devel, imammedo; +Cc: pbonzini, Lin Ma

Add can_be_deleted callback, If it is not null and returns false,
The qmp_object_del won't delete the given object.

Signed-off-by: Lin Ma <lma@suse.com>
---
 include/qom/object.h | 12 ++++++++++++
 qmp.c                |  7 +++++++
 qom/object.c         | 12 ++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/include/qom/object.h b/include/qom/object.h
index d2d7748..6e78cb0 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -428,6 +428,8 @@ struct Object
  *   function.
  * @abstract: If this field is true, then the class is considered abstract and
  *   cannot be directly instantiated.
+ * @can_be_deleted: If this function returns true, then the object can be
+     deleted safely.
  * @class_size: The size of the class object (derivative of #ObjectClass)
  *   for this object.  If @class_size is 0, then the size of the class will be
  *   assumed to be the size of the parent class.  This allows a type to avoid
@@ -463,6 +465,8 @@ struct TypeInfo
     bool abstract;
     size_t class_size;
 
+    bool (*can_be_deleted)(Object *obj);
+
     void (*class_init)(ObjectClass *klass, void *data);
     void (*class_base_init)(ObjectClass *klass, void *data);
     void (*class_finalize)(ObjectClass *klass, void *data);
@@ -671,6 +675,14 @@ ObjectClass *object_get_class(Object *obj);
 const char *object_get_typename(Object *obj);
 
 /**
+ * object_can_be_deleted:
+ * @obj: The object to obtain the deletion for.
+ *
+ * Returns: %true if @obj can be deleted safely, %false otherwise.
+ */
+bool object_can_be_deleted(Object *obj);
+
+/**
  * type_register_static:
  * @info: The #TypeInfo of the new type.
  *
diff --git a/qmp.c b/qmp.c
index c479e77..dbbcb37 100644
--- a/qmp.c
+++ b/qmp.c
@@ -711,6 +711,13 @@ void qmp_object_del(const char *id, Error **errp)
         error_setg(errp, "object id not found");
         return;
     }
+
+    if (!object_can_be_deleted(obj)) {
+        char *path = object_get_canonical_path_component(obj);
+        error_setg(errp, "%s is in used, can not be deleted", path);
+        g_free(path);
+        return;
+    }
     object_unparent(obj);
 }
 
diff --git a/qom/object.c b/qom/object.c
index d167038..dcec108 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -57,6 +57,8 @@ struct TypeImpl
 
     bool abstract;
 
+    bool (*can_be_deleted)(Object *obj);
+
     const char *parent;
     TypeImpl *parent_type;
 
@@ -121,6 +123,8 @@ static TypeImpl *type_new(const TypeInfo *info)
 
     ti->abstract = info->abstract;
 
+    ti->can_be_deleted = info->can_be_deleted;
+
     for (i = 0; info->interfaces && info->interfaces[i].type; i++) {
         ti->interfaces[i].typename = g_strdup(info->interfaces[i].type);
     }
@@ -584,6 +588,14 @@ const char *object_get_typename(Object *obj)
     return obj->class->type->name;
 }
 
+bool object_can_be_deleted(Object *obj)
+{
+    if (obj->class->type->can_be_deleted)
+        return obj->class->type->can_be_deleted(obj);
+    else
+        return true;
+}
+
 ObjectClass *object_get_class(Object *obj)
 {
     return obj->class;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-03-26 14:18 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Qemu-devel] [PATCH 2/2] memory-backend: Add can_be_deleted impl for ram-backend and file-backend Lin Ma
2015-03-23 10:36 ` [Qemu-devel] [PATCH 1/2] object: Add can_be_deleted callback to TypeInfo and TypeImpl 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.