All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, armbru@redhat.com, ppandit@redhat.com,
	Michael Roth <michael.roth@amd.com>
Subject: Re: [PATCH v2 4/9] qapi: Implement qapi_dealloc_present_visitor
Date: Fri, 6 Feb 2026 12:38:42 -0500	[thread overview]
Message-ID: <aYYnItBr-FOhgRNq@x1.local> (raw)
In-Reply-To: <87fr7eqd2u.fsf@suse.de>

On Fri, Feb 06, 2026 at 09:19:21AM -0300, Fabiano Rosas wrote:
> >> +static void qapi_dealloc_push(Visitor *v, QObject *obj, void *qapi)
> >> +{
> >> +    QapiDeallocVisitor *qdv = container_of(v, QapiDeallocVisitor, visitor);
> >> +    QStackEntry *se = g_new0(QStackEntry, 1);
> >> +
> >> +    assert(obj);
> >> +    se->obj = obj;
> >> +    se->qapi = qapi;
> >> +
> >> +    if (qobject_type(obj) == QTYPE_QLIST) {
> >> +        se->entry = qlist_first(qobject_to(QList, obj));
> >
> > I still don't yet understand why do we care about lists here.
> >
> > I'm trying to guess, what this code wanted to do: we pushed the 1st entry
> > of the list into the stack, trying to make it as a reference for all the
> > items later within the list.
> >
> > But IIUC we can still define the conditiona-dealloc visitor to be even
> > simpler, right?  Say, if the ref qobject has the qlist object, then free
> > the whole list?
> >
> 
> I need to look at this closely, but I think we need to hold the list ref
> so we can walk each of the objects inside of it and free them, then free
> the empty list. When you "free the whole list" that would mean
> qapi_free_<something>, which we can't do here, being already inside
> visitor code; and free(list) doesn't free it's children, of course.

True.

> 
> > IMHO there're three things we need to manage on conditional deallocations:
> > (1) struct, (2) list, (3) alternatives.  All the rest seem to be scalars.
> >
> > So I wonder if we could define this visitor, so that it treats both (2) and
> > (3) the same way (to always dealloc as long as present).
> >
> > That sounds at least making more sense when I picture that in migration
> > parameters: if we have a list in the parameters (e.g. cpr-exec-command), as
> > long as the list is present in the ref, we should free the whole thing
> > completely on the other one being visited.
> >
> 
> Yes, that makes sense. I'm not expecting individual list items to be
> ever updated separately. However, as I said above, I'm not sure whether
> we can free the whole list without some sort of a walk of its
> members. I'll check and get back to you.

My QAPI kongfu is very limited.. but my current understanding is the
visitor framework will make sure everything will be visited properly within
the list, and after each visit to the list entry, it'll finally free the
list structure (in case of dealloc visitor) via qapi_dealloc_next_list().
I believe that's also what the new dealloc_present visitor should rely on.

So my understanding is maybe we don't need to hold any reference to the
list being walked.  However maybe we want to remember we're walking this
list, then no matter how deep we walk into this list, we should stop
checking / referencing the ref object but just always free everything (aka,
fallback to the basic dealloc operations).

When thinking about that, I found maybe it's not that list is special; it's
when the "top level" is special.

Consider if we have a migration parameter that is a nested struct:

  - struct1
    - struct2
      - int
    - struct3
      - boolean

Then if currently we have this value for this parameter:

  - struct1
    - struct2
      - int=1
    - struct3
      - string="foobar"

When we take an update from the user on this specific parameter, and if the
user's input is:

  - struct1
    - struct2
      - int=2
    (omit struct3)

With your current patch, you'll leave struct3 and the sub-field string
untouched.  However, IIUC the current semantics (of migrate_set_parameters,
at least) should be that we use the new data to fully replace the old
struct1 tree, making sure struct3 alone with the string to be unset?

So I wonder if we should just remember the top of the stack (which must be
a qdict), then free anything below that whenever the top element is present
in the ref.

-- 
Peter Xu



  reply	other threads:[~2026-02-06 17:39 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-02 22:40 [PATCH v2 0/9] qapi: Use visitors for migration parameters handling Fabiano Rosas
2026-02-02 22:40 ` [PATCH v2 1/9] migration/options.c: Don't export migrate_tls_opts_free Fabiano Rosas
2026-02-05 20:19   ` Peter Xu
2026-02-02 22:40 ` [PATCH v2 2/9] migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply Fabiano Rosas
2026-02-05 20:19   ` Peter Xu
2026-02-02 22:40 ` [PATCH v2 3/9] migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply Fabiano Rosas
2026-02-02 22:40 ` [PATCH v2 4/9] qapi: Implement qapi_dealloc_present_visitor Fabiano Rosas
2026-02-05 21:45   ` Peter Xu
2026-02-06 12:19     ` Fabiano Rosas
2026-02-06 17:38       ` Peter Xu [this message]
2026-02-02 22:40 ` [PATCH v2 5/9] qapi: Add QAPI_MERGE Fabiano Rosas
2026-02-13 14:57   ` Markus Armbruster
2026-02-02 22:40 ` [PATCH v2 6/9] migration/options: Use QAPI_MERGE in migrate_params_test_apply Fabiano Rosas
2026-02-02 22:40 ` [PATCH v2 7/9] migration/options: Open code migrate_params_apply Fabiano Rosas
2026-02-05 22:14   ` Peter Xu
2026-02-06 12:25     ` Fabiano Rosas
2026-02-02 22:41 ` [PATCH v2 8/9] migration/options: Stop freeing s->parameters members individually Fabiano Rosas
2026-02-05 22:16   ` Peter Xu
2026-02-06 12:29     ` Fabiano Rosas
2026-02-06 16:20       ` Peter Xu
2026-02-06 19:50         ` Fabiano Rosas
2026-02-09 15:37           ` Peter Xu
2026-02-02 22:41 ` [PATCH v2 9/9] migration: Use migrate_params_free during finalize Fabiano Rosas
2026-02-05 22:21   ` Peter Xu
2026-02-05 22:05 ` [PATCH v2 0/9] qapi: Use visitors for migration parameters handling Peter Xu
2026-02-06 12:34   ` Fabiano Rosas
2026-02-06 17:40     ` Peter Xu
2026-02-06 18:36       ` Fabiano Rosas

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=aYYnItBr-FOhgRNq@x1.local \
    --to=peterx@redhat.com \
    --cc=armbru@redhat.com \
    --cc=farosas@suse.de \
    --cc=michael.roth@amd.com \
    --cc=ppandit@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.