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 1/2] object: Add can_be_deleted callback to TypeInfo and TypeImpl
Date: Mon, 23 Mar 2015 18:10:41 +0800 [thread overview]
Message-ID: <1427105442-23484-1-git-send-email-lma@suse.com> (raw)
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
next 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 Lin Ma [this message]
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
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-1-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).