qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3 1/2] qom: Add can_be_deleted callback to User


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v3 1/2] qom: Add can_be_deleted callback to UserCreatableClass
Date: Thu, 26 Mar 2015 21:34:55 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0


On 26/03/2015 18:07, Lin Ma wrote:
> 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 <address@hidden>
> ---
>  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)) {

Please add a function user_creatable_can_be_deleted(UserCreatable *uc)
that does the call (and returns true if the field is NULL.

> +            char *path = object_get_canonical_path_component(obj);
> +            error_setg(errp, "%s is in used, can not be deleted", path);

You can use id directly, no need to call
object_get_canonical_path_component.

> +            g_free(path);
> +            return;
> +        }

Thanks,

Paolo

> +    }
>      object_unparent(obj);
>  }
>  
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]