Skip to contentSkip to conversation

object: Add can_be_deleted callback to TypeInfo and TypeImpl

PATCH In review Lin Ma 5 participants 15 messages Mar 23, 2015 – Mar 26, 2015 Arm STM32

lore
Share & tools
lore

Lin Ma

author
#0 lore raw

PATCH 1/2 object: Add can_be_deleted callback to TypeInfo and TypeImpl

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

---
 include/qom/object.h | 12 ++++++++++++
 qmp.c                |  7 +++++++
 qom/object.c         | 12 ++++++++++++
 3 files changed, 31 insertions(+)
include/qom/object.h +12 -0
index d2d7748..6e78cb0 100644
@@ -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.
  *
qmp.c +7 -0
index c479e77..dbbcb37 100644
@@ -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);
 }
 
qom/object.c +12 -0
index d167038..dcec108 100644
@@ -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;
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH 2/2 memory-backend: Add can_be_deleted impl for ram-backend and file-backend

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

---
 backends/hostmem-file.c | 12 ++++++++++++
 backends/hostmem-ram.c  | 12 ++++++++++++
 2 files changed, 24 insertions(+)
backends/hostmem-file.c +12 -0
index 5179994..33ad8e7 100644
@@ -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),
 };
backends/hostmem-ram.c +12 -0
index a67a134..8724ad1 100644
@@ -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)
Signature · 1 line
2.1.4
#2 lore raw
In reply to Lin Ma
Quoted 24 lines · 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.

---
 include/qom/object.h | 12 ++++++++++++
 qmp.c                |  7 +++++++
 qom/object.c         | 12 ++++++++++++
 3 files changed, 31 insertions(+)
include/qom/object.h +2 -0
index d2d7748..6e78cb0 100644
@@ -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

include/qom/object.h struct TypeInfo · line 469

Quoted 5 lines
include/qom/object.h +2 -0
@@ -463,6 +465,8 @@ struct TypeInfo
     bool abstract;
     size_t class_size;
 
+    bool (*can_be_deleted)(Object *obj);
+

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Quoted 24 lines
include/qom/object.h +8 -0
     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.
  *
qmp.c +0 -0
index c479e77..dbbcb37 100644
@@ -711,6 +711,13 @@ void qmp_object_del(const char *id, Error **errp)
         error_setg(errp, "object id not found");

qmp.c void qmp_object_del(const char *id, Error **errp) · line 721

Quoted 10 lines
qmp.c +7 -0
         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);

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

Regards,
Peter

Quoted 43 lines
qmp.c +0 -0
 }
 
qom/object.c +12 -1
index d167038..dcec108 100644
@@ -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

#3 lore raw
Quoted 3 lines · Peter Crosthwaite

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

In this case, the right place could be UserCreatable. Alternatively...

Quoted 4 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Paolo

#13 lore raw
In reply to Lin Ma

Hi Lin,

Am 23.03.2015 um 11:10 schrieb Lin Ma:

Quoted 9 lines

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

---
 include/qom/object.h | 12 ++++++++++++
 qmp.c                |  7 +++++++
 qom/object.c         | 12 ++++++++++++
 3 files changed, 31 insertions(+)

Why am I not being CC'ed here as QOM maintainer? You can use scripts/get_maintainer.pl to assist you, or read MAINTAINERS file.

Also, when sending more than one patch, always include a cover letter for grouping.

It further seems that this is the second version already, so you should've used --subject-prefix="PATCH v2" and included a change log in the cover letter.

Cf. http://wiki.qemu-project.org/Contribute/SubmitAPatch

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#4 lore raw
In reply to Paolo Bonzini

Hi,

For consistency in git-log, please use "qom:" rather than "object:".

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Agree.

Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

Quoted 8 lines

Alternatively...

Quoted 4 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Well, I have doubts about asking someone who's not ultimately familiar with that code to refactor the API. For instance, we wouldn't want QEMU on shutdown or in error cases refusing to unparent some object.

Doing it at QMP level (ObjectClass/UserCreatable) seems safer, given that Chun Yan's trivial block option fix ended up respinning a QemuOpts refactoring some twenty times before it got merged.

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#5 lore raw
Quoted 10 lines · On Mon, 23 Mar 2015 14:13:07 +0100 Andreas Färber <[email protected]> wrote:

Hi,

For consistency in git-log, please use "qom:" rather than "object:".

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Quoted 6 lines

Agree.

Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

object_del() works only with /objects children, and so far the only way that child placed there is via object_add() which requires a new object to have TYPE_USER_CREATABLE interface.
I'd go this way rather than overhaul object_unparent() in this case.

Quoted 21 lines
Quoted 9 lines

Alternatively...

Quoted 4 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Well, I have doubts about asking someone who's not ultimately familiar with that code to refactor the API. For instance, we wouldn't want QEMU on shutdown or in error cases refusing to unparent some object.

Doing it at QMP level (ObjectClass/UserCreatable) seems safer, given that Chun Yan's trivial block option fix ended up respinning a QemuOpts refactoring some twenty times before it got merged.

Regards,
Andreas

author
#14 lore raw
In reply to Andreas Färber
Quoted 6 lines · Andreas Färber

Hi Lin,

Am 23.03.2015 um 11:10 schrieb Lin Ma:

Quoted 3 lines

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

Quoted 8 lines
Quoted 6 lines
---
  include/qom/object.h | 12 ++++++++++++
  qmp.c                |  7 +++++++
  qom/object.c         | 12 ++++++++++++
  3 files changed, 31 insertions(+)

Why am I not being CC'ed here as QOM maintainer? You can use scripts/get_maintainer.pl to assist you, or read MAINTAINERS file.

Really sorry about that.

Quoted 3 lines

Also, when sending more than one patch, always include a cover letter for grouping.

Thanks for reminding.

Quoted 9 lines

It further seems that this is the second version already, so you should've used --subject-prefix="PATCH v2" and included a change log in the cover letter.

Cf. http://wiki.qemu-project.org/Contribute/SubmitAPatch

Regards,
Andreas

Because the patch v1 is a single patch and not generic, So I dropped it.
That's why I didn't used --subject-prefix here. But I'll add all the info & format that you mentioned in patch v3.

Thanks,
Lin

author
#12 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini
Quoted 3 lines · Peter Crosthwaite

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

In this case, the right place could be UserCreatable. Alternatively...

Well... Because I'm not familiar with qom very much, Let me dig more details about UserCreatable first :-)

Quoted 9 lines
Quoted 5 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Paolo

author
#6 lore raw
In reply to Igor Mammedov
Quoted 14 lines · Igor Mammedov
Quoted 11 lines · On Mon, 23 Mar 2015 14:13:07 +0100 Andreas Färber <[email protected]> wrote:

Hi,

For consistency in git-log, please use "qom:" rather than "object:".

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Agree.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

object_del() works only with /objects children, and so far the only way that child placed there is via object_add() which requires a new object to have TYPE_USER_CREATABLE interface.
I'd go this way rather than overhaul object_unparent() in this case.

What about these changes?
1. Add a callback function named 'ObjectCanBeDeleted *can_be_deleted' to struct ObjectClass in object.h
2. Call the function in qmp_object_del of qmp.c, says:

    ObjectClass *obj_class = object_get_class(obj);
        if (obj_class->can_be_deleted)
            if (!obj_class->can_be_deleted(obj))
                error out

3. Then implement can_be_deleted callback in backends, says:
static bool host_memory_backend_can_be_deleted(Object *obj) {......}

static void host_memory_backend_class_init(ObjectClass *oc, void

*data) {
        ......
        oc->can_be_deleted = host_memory_backend_can_be_deleted;
    }
Quoted 21 lines
Quoted 19 lines
Quoted 8 lines

Alternatively...

Quoted 4 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Well, I have doubts about asking someone who's not ultimately familiar with that code to refactor the API. For instance, we wouldn't want QEMU on shutdown or in error cases refusing to unparent some object.

Doing it at QMP level (ObjectClass/UserCreatable) seems safer, given that Chun Yan's trivial block option fix ended up respinning a QemuOpts refactoring some twenty times before it got merged.

Regards,
Andreas

#7 lore raw
Quoted 32 lines · On Wed, 25 Mar 2015 23:47:46 +0800 Lin Ma <[email protected]> wrote:
Quoted 14 lines · Igor Mammedov
Quoted 11 lines · On Mon, 23 Mar 2015 14:13:07 +0100 Andreas Färber <[email protected]> wrote:

Hi,

For consistency in git-log, please use "qom:" rather than "object:".

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Agree.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

object_del() works only with /objects children, and so far the only way that child placed there is via object_add() which requires a new object to have TYPE_USER_CREATABLE interface.
I'd go this way rather than overhaul object_unparent() in this case.

What about these changes?
1. Add a callback function named 'ObjectCanBeDeleted *can_be_deleted' to struct ObjectClass in object.h
2. Call the function in qmp_object_del of qmp.c, says:

     ObjectClass *obj_class = object_get_class(obj);
         if (obj_class->can_be_deleted)
             if (!obj_class->can_be_deleted(obj))
                 error out
Quoted 8 lines

3. Then implement can_be_deleted callback in backends, says:
static bool host_memory_backend_can_be_deleted(Object *obj) {......}

static void host_memory_backend_class_init(ObjectClass *oc, void

*data) {
         ......
         oc->can_be_deleted = host_memory_backend_can_be_deleted;
     }

all backends currently implement TYPE_USER_CREATABLE interface, so I'd rather extend UserCreatableClass with:

bool can_be_deleted(UserCreatable *uc)

callback, which backends could implement if needed.

Quoted 22 lines
Quoted 21 lines
Quoted 19 lines
Quoted 8 lines

Alternatively...

Quoted 4 lines

But is a better way to do this to add error handling to object_unparent API and override object_unparent for your device in question to throw the error? Then your change doesn't have to be limited to QMP.

... this is also a good choice.

Well, I have doubts about asking someone who's not ultimately familiar with that code to refactor the API. For instance, we wouldn't want QEMU on shutdown or in error cases refusing to unparent some object.

Doing it at QMP level (ObjectClass/UserCreatable) seems safer, given that Chun Yan's trivial block option fix ended up respinning a QemuOpts refactoring some twenty times before it got merged.

Regards,
Andreas

#8 lore raw

Am 26.03.2015 um 11:05 schrieb Igor Mammedov:

Quoted 37 lines
Quoted 26 lines · On Wed, 25 Mar 2015 23:47:46 +0800 Lin Ma <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov
Quoted 7 lines · On Mon, 23 Mar 2015 14:13:07 +0100 Andreas Färber <[email protected]> wrote:

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Agree.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

object_del() works only with /objects children, and so far the only way that child placed there is via object_add() which requires a new object to have TYPE_USER_CREATABLE interface.
I'd go this way rather than overhaul object_unparent() in this case.

What about these changes?
1. Add a callback function named 'ObjectCanBeDeleted *can_be_deleted' to struct ObjectClass in object.h
2. Call the function in qmp_object_del of qmp.c, says:

     ObjectClass *obj_class = object_get_class(obj);
         if (obj_class->can_be_deleted)
             if (!obj_class->can_be_deleted(obj))
                 error out
Quoted 8 lines

3. Then implement can_be_deleted callback in backends, says:
static bool host_memory_backend_can_be_deleted(Object *obj) {......}

static void host_memory_backend_class_init(ObjectClass *oc, void

*data) {
         ......
         oc->can_be_deleted = host_memory_backend_can_be_deleted;
     }
Quoted 6 lines

all backends currently implement TYPE_USER_CREATABLE interface, so I'd rather extend UserCreatableClass with:

bool can_be_deleted(UserCreatable *uc)

callback, which backends could implement if needed.

As for the implementation, could we simply look at Object::ref field?

Regards,
Andreas

Signature · 3 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)
#9 lore raw
Quoted 38 lines · On Thu, 26 Mar 2015 11:07:27 +0100 Andreas Färber <[email protected]> wrote:

Am 26.03.2015 um 11:05 schrieb Igor Mammedov:

Quoted 37 lines
Quoted 34 lines · On Wed, 25 Mar 2015 23:47:46 +0800 Lin Ma <[email protected]> wrote:
Quoted 9 lines · Igor Mammedov
Quoted 7 lines · On Mon, 23 Mar 2015 14:13:07 +0100 Andreas Färber <[email protected]> wrote:

Am 23.03.2015 um 13:06 schrieb Paolo Bonzini:

Quoted 4 lines · Peter Crosthwaite
Quoted 3 lines

I don't think TypeInfo is the right place for this. You can however define function hooks for Object in ObjectClass. See the unparent field of ObjectClass for a precedent.

Agree.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

In this case, the right place could be UserCreatable.

Maybe, not so familiar with that interface myself. Does object_del allow to delete non-UserCreatable objects? Then it wouldn't help much.

object_del() works only with /objects children, and so far the only way that child placed there is via object_add() which requires a new object to have TYPE_USER_CREATABLE interface.
I'd go this way rather than overhaul object_unparent() in this case.

What about these changes?
1. Add a callback function named 'ObjectCanBeDeleted *can_be_deleted' to struct ObjectClass in object.h
2. Call the function in qmp_object_del of qmp.c, says:

     ObjectClass *obj_class = object_get_class(obj);
         if (obj_class->can_be_deleted)
             if (!obj_class->can_be_deleted(obj))
                 error out

3. Then implement can_be_deleted callback in backends, says:
static bool host_memory_backend_can_be_deleted(Object *obj) {......}

static void host_memory_backend_class_init(ObjectClass *oc, void

*data) {
         ......
         oc->can_be_deleted = host_memory_backend_can_be_deleted;
     }
Quoted 8 lines
Quoted 6 lines

all backends currently implement TYPE_USER_CREATABLE interface, so I'd rather extend UserCreatableClass with:

bool can_be_deleted(UserCreatable *uc)

callback, which backends could implement if needed.

As for the implementation, could we simply look at Object::ref field?

What value of ref, one would use to decide if deletion is possible?

In generic case object can have ref > 1 but still be eligible for deleting via object-del.

Quoted 4 lines

Regards,
Andreas

#10 lore raw
Quoted 4 lines · Igor Mammedov

What value of ref, one would use to decide if deletion is possible?

In generic case object can have ref > 1 but still be eligible for deleting via object-del.

Right, for example devices are unparented with ref > 1.

Still, it could be a sane default implementation. It doesn't even need a function pointer until someone comes up with an object that has different needs.

Paolo

#11 lore raw
Quoted 5 lines · On Thu, 26 Mar 2015 14:37:13 +0100 Paolo Bonzini <[email protected]> wrote:
Quoted 2 lines · Igor Mammedov

What value of ref, one would use to decide if deletion is possible?

Quoted 8 lines
Quoted 2 lines

In generic case object can have ref > 1 but still be eligible for deleting via object-del.

Right, for example devices are unparented with ref > 1.

Still, it could be a sane default implementation. It doesn't even need a function pointer until someone comes up with an object that has different needs.

Not in case of memory backend, its 'ref' in unused state is 2 since it contains at least one child, backend object is owner of MemoryRegion.

Quoted 1 line

Paolo