qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 06/22] char: add a /chardevs container
Date: Fri, 10 Feb 2017 13:26:37 +0100	[thread overview]
Message-ID: <1fdabefe-a492-3c1c-3387-20ad1bc52f9f@redhat.com> (raw)
In-Reply-To: <CAJ+F1CKa2GiJbYycLEuykFkSc5bRi6OsSK4Fd0tK=bTQ4F8c2w@mail.gmail.com>



On 10/02/2017 13:14, Marc-André Lureau wrote:
> Hi
> 
> On Fri, Feb 10, 2017 at 4:18 AM Paolo Bonzini <pbonzini@redhat.com
> <mailto:pbonzini@redhat.com>> wrote:
> 
> 
> 
>     On 07/02/2017 21:03, Marc-André Lureau wrote:
>     > Hi
>     >
>     > ----- Original Message -----
>     >>
>     >>
>     >> On 02/02/2017 15:51, Marc-André Lureau wrote:
>     >>> +    if (QTAILQ_IN_USE(chr, next)) {
>     >>> +        QTAILQ_REMOVE(&chardevs, chr, next);
>     >>> +    }
>     >>> +    if (OBJECT(chr)->parent) {
>     >>> +        object_unparent(OBJECT(chr));
>     >>> +    } else {
>     >>> +        object_unref(OBJECT(chr));
>     >>> +    }
>     >>
>     >> What's the case where the "else" is used?  Probably qemu_chr_delete
>     >> callers should be changed to use object_unparent or object_unref
>     directly.
>     >
>     > I thought about that, but calling object_unparent() seems weird,
>     > since callers aren't much aware of the fact that chardev are added
>     or not to a
>     > container (useless distinction imho). I wish the last object_unref()
>     > would automatically unparent, if the object has a parent. Would
>     that be
>     > acceptable?
> 
>     There is a distinction between the two.  The idea is that unparent
>     removes all persistent references in the object tree, while unref only
>     removes transient references.  So for example unparent will detach a
>     device from its bus.  Unparent is basically exploiting the object tree
>     in order to simplify the handling of reference cycles.
> 
>     Once you add an object with object_property_add_child, you probably
>     should remove any transient references you have (such as the one you got
>     with object_new) and from that point on use object_unparent only.
> 
> 
> But if you unparent with the last ref, you remove the burden of knowing
> if the object has been parented from the user. I don't see why that
> would conflict with object_unparent(), you could still unparent(), and
> keep the object referenced somewhere else.

Isn't that exactly why you want them to be different?  unparent can do
much more than unref, for example in the case of a device it will also
unrealize it and destroy all buses underneath it.  Because the device
and bus have a circular reference, you cannot trigger the magic unparent
behavior just by unref'ing the device.

There are just two cases:

- destruction immediately after creation, e.g. on error: new/unref

- successful creation: new/add_child/unref, unparent when deleting

and it's simpler to remember these two than to add magic behavior.

> The two are not incompatible
> to me. Afaik, most widget/hierarchy API work like that, the last unref
> will implicitely unparent.

LibreOffice's has some similarity with QOM, search for "dispose" at
https://people.gnome.org/~michael/blog/2015-08-05-under-the-hood-5-0.html

Paolo

  reply	other threads:[~2017-02-10 12:26 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-02 14:51 [Qemu-devel] [PATCH 00/22] chardev clean-ups & tests Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 01/22] char: remove qemu_chr_be_generic_open Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 02/22] mux: simplfy muxes_realize_done Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 03/22] xen: use a better chardev type check Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 04/22] container: don't leak container reference Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 05/22] main: free root container Marc-André Lureau
2017-02-06  9:03   ` Paolo Bonzini
2017-02-07 20:01     ` Marc-André Lureau
2017-02-09 17:09       ` Paolo Bonzini
2017-02-02 14:51 ` [Qemu-devel] [PATCH 06/22] char: add a /chardevs container Marc-André Lureau
2017-02-06  9:05   ` Paolo Bonzini
2017-02-07 20:03     ` Marc-André Lureau
2017-02-09 17:16       ` Paolo Bonzini
2017-02-10 12:14         ` Marc-André Lureau
2017-02-10 12:26           ` Paolo Bonzini [this message]
2017-02-10 12:59             ` Marc-André Lureau
2017-02-10 13:12               ` Paolo Bonzini
2017-02-02 14:51 ` [Qemu-devel] [PATCH 07/22] char: use /chardevs container instead of chardevs list Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 08/22] char: remove qemu_chardev_add Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 09/22] char: remove chardevs list Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 10/22] char: useless NULL check Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 11/22] qcow2: remove " Marc-André Lureau
2017-02-06  9:06   ` Paolo Bonzini
2017-02-02 14:51 ` [Qemu-devel] [PATCH 12/22] char-socket: introduce update_disconnected_filename() Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 13/22] char-socket: update local address after listen Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 14/22] char-socket: add 'addr' property Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 15/22] char-socket: add 'connected' property Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 16/22] char-udp: flush as much buffer as possible Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 17/22] tests: add alias check in /char/ringbuf Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 18/22] tests: add /char/pipe test Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 19/22] tests: add /char/file test Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 20/22] tests: add /char/socket test Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 21/22] tests: add /char/udp test Marc-André Lureau
2017-02-02 14:51 ` [Qemu-devel] [PATCH 22/22] tests: add /char/console test Marc-André Lureau

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=1fdabefe-a492-3c1c-3387-20ad1bc52f9f@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=marcandre.lureau@gmail.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).