aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Ma <lma@suse.com>2015-03-30 16:36:28 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2015-04-01 10:06:38 +0200
commitd6edb15576643ab348a9f73e115c2e037edf7460 (patch)
tree54365e3a269416ad3fac1efee0a9c320754f9185
parent033a20359aaf93f4d8aa2be12558901e8e028baa (diff)
qom: Add can_be_deleted callback to UserCreatableClass
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> Message-Id: <1427704589-7688-2-git-send-email-lma@suse.com> Reviewed-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--include/qom/object_interfaces.h13
-rw-r--r--qmp.c5
-rw-r--r--qom/object_interfaces.c12
3 files changed, 30 insertions, 0 deletions
diff --git a/include/qom/object_interfaces.h b/include/qom/object_interfaces.h
index b7922833e1..283ae0db4d 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;
/**
@@ -59,4 +62,14 @@ typedef struct UserCreatableClass {
* nothing.
*/
void user_creatable_complete(Object *obj, Error **errp);
+
+/**
+ * user_creatable_can_be_deleted:
+ * @uc: the object whose can_be_deleted() method is called if implemented
+ * @errp: if an error occurs, a pointer to an area to store the error
+ *
+ * Wrapper to call can_be_deleted() method if one of types it's inherited
+ * from implements USER_CREATABLE interface.
+ */
+bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp);
#endif
diff --git a/qmp.c b/qmp.c
index c479e7751c..e6c70504df 100644
--- a/qmp.c
+++ b/qmp.c
@@ -711,6 +711,11 @@ void qmp_object_del(const char *id, Error **errp)
error_setg(errp, "object id not found");
return;
}
+
+ if (!user_creatable_can_be_deleted(USER_CREATABLE(obj), errp)) {
+ error_setg(errp, "%s is in use, can not be deleted", id);
+ return;
+ }
object_unparent(obj);
}
diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 6360818397..a66cd6026c 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -18,6 +18,18 @@ void user_creatable_complete(Object *obj, Error **errp)
}
}
+bool user_creatable_can_be_deleted(UserCreatable *uc, Error **errp)
+{
+
+ UserCreatableClass *ucc = USER_CREATABLE_GET_CLASS(uc);
+
+ if (ucc->can_be_deleted) {
+ return ucc->can_be_deleted(uc, errp);
+ } else {
+ return true;
+ }
+}
+
static void register_types(void)
{
static const TypeInfo uc_interface_info = {