qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Lin Ma <lma@suse.com>,
	imammedo@redhat.com, afaerber@suse.de,
	peter.crosthwaite@xilinx.com
Cc: qemu-devel@nongnu.org
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	[thread overview]
Message-ID: <55146D6F.3020109@redhat.com> (raw)
In-Reply-To: <1427389626-23487-2-git-send-email-lma@suse.com>



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 <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)) {

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	other threads:[~2015-03-26 20:35 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 ` [Qemu-devel] [PATCH v3 1/2] qom: Add can_be_deleted callback " Lin Ma
2015-03-26 20:34   ` Paolo Bonzini [this message]
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=55146D6F.3020109@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=lma@suse.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).