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 1/2] qom: Add can_be_deleted callback to UserCreatableClass
Date: Fri, 27 Mar 2015 01:07:05 +0800 [thread overview]
Message-ID: <1427389626-23487-2-git-send-email-lma@suse.com> (raw)
In-Reply-To: <1427389626-23487-1-git-send-email-lma@suse.com>
If backends implement the can_be_deleted and it returns false,
Then the qmp_object_del won't delete the given backends.
Signed-off-by: Lin Ma <lma@suse.com>
---
include/qom/object_interfaces.h | 3 +++
qmp.c | 13 +++++++++++++
2 files changed, 16 insertions(+)
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index b792283..19b66f1 100644
--- a/include/qom/object_interfaces.h
+++ b/include/qom/object_interfaces.h
@@ -25,6 +25,8 @@ typedef struct UserCreatable {
* UserCreatableClass:
* @parent_class: the base class
* @complete: callback to be called after @obj's properties are set.
+ * @can_be_deleted: callback to be called before an object is removed
+ * to check if @obj can be removed safely.
*
* Interface is designed to work with -object/object-add/object_add
* commands.
@@ -47,6 +49,7 @@ typedef struct UserCreatableClass {
/* <public> */
void (*complete)(UserCreatable *uc, Error **errp);
+ bool (*can_be_deleted)(UserCreatable *uc, Error **errp);
} UserCreatableClass;
/**
diff --git a/qmp.c b/qmp.c
index c479e77..a9156d6 100644
--- a/qmp.c
+++ b/qmp.c
@@ -711,6 +711,19 @@ void qmp_object_del(const char *id, Error **errp)
error_setg(errp, "object id not found");
return;
}
+
+ UserCreatableClass *ucc;
+ UserCreatable *uc =
+ (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
+ ucc = USER_CREATABLE_GET_CLASS(uc);
+ if (ucc->can_be_deleted) {
+ if (!ucc->can_be_deleted(uc, errp)) {
+ 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);
}
--
2.1.4
next prev 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 ` Lin Ma [this message]
2015-03-26 20:34 ` [Qemu-devel] [PATCH v3 1/2] qom: Add can_be_deleted callback " Paolo Bonzini
2015-03-26 17:07 ` [Qemu-devel] [PATCH v3 2/2] hostmem: Prevent removing an in-use memory backend object 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=1427389626-23487-2-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).