From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>,
"Michael S . Tsirkin" <mst@redhat.com>,
Michal Privoznik <mprivozn@redhat.com>
Subject: Re: [PATCH v3 2/8] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup()
Date: Fri, 13 Jan 2023 14:05:25 +0100 [thread overview]
Message-ID: <6edccb93-f591-def9-5a3c-3d89677602a0@redhat.com> (raw)
In-Reply-To: <c8bc09e7-d671-844c-4418-60a53668d355@redhat.com>
On 13.01.23 14:01, David Hildenbrand wrote:
> On 12.01.23 23:06, Peter Xu wrote:
>> On Thu, Jan 12, 2023 at 06:40:00PM +0000, Dr. David Alan Gilbert wrote:
>>> * David Hildenbrand (david@redhat.com) wrote:
>>>> On 12.01.23 18:43, Dr. David Alan Gilbert wrote:
>>>>> * David Hildenbrand (david@redhat.com) wrote:
>>>>>> ... and store it in the migration state. This is a preparation for
>>>>>> storing selected vmds's already in qemu_savevm_state_setup().
>>>>>>
>>>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>>>> ---
>>>>>> migration/migration.c | 4 ++++
>>>>>> migration/migration.h | 4 ++++
>>>>>> migration/savevm.c | 18 ++++++++++++------
>>>>>> 3 files changed, 20 insertions(+), 6 deletions(-)
>>>>>>
>>>>
>>>> [1]
>>>>
>>>>>> diff --git a/migration/migration.c b/migration/migration.c
>>>>>> index 52b5d39244..1d33a7efa0 100644
>>>>>> --- a/migration/migration.c
>>>>>> +++ b/migration/migration.c
>>>>>> @@ -2170,6 +2170,9 @@ void migrate_init(MigrationState *s)
>>>>>> s->vm_was_running = false;
>>>>>> s->iteration_initial_bytes = 0;
>>>>>> s->threshold_size = 0;
>>>>>> +
>>>>>> + json_writer_free(s->vmdesc);
>>>>>> + s->vmdesc = NULL;
>>>>>> }
>>>>
>>>> [...]
>>>>
>>>>>> trace_savevm_state_setup();
>>>>>> QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
>>>>>> if (!se->ops || !se->ops->save_setup) {
>>>>>> @@ -1390,15 +1395,12 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
>>>>>> bool in_postcopy,
>>>>>> bool inactivate_disks)
>>>>>> {
>>>>>> - g_autoptr(JSONWriter) vmdesc = NULL;
>>>>>> + MigrationState *ms = migrate_get_current();
>>>>>> + JSONWriter *vmdesc = ms->vmdesc;
>>>>>> int vmdesc_len;
>>>>>> SaveStateEntry *se;
>>>>>> int ret;
>>>>>> - vmdesc = json_writer_new(false);
>>>>>> - json_writer_start_object(vmdesc, NULL);
>>>>>> - json_writer_int64(vmdesc, "page_size", qemu_target_page_size());
>>>>>> - json_writer_start_array(vmdesc, "devices");
>>>>>> QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
>>>>>> ret = vmstate_save(f, se, vmdesc);
>>>>>> if (ret) {
>>>>>> @@ -1433,6 +1435,10 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
>>>>>> qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len);
>>>>>> }
>>>>>> + /* Free it now to detect any inconsistencies. */
>>>>>> + json_writer_free(vmdesc);
>>>>>> + ms->vmdesc = NULL;
>>>>>
>>>>> and this only happens when this succesfully exits; so if this errors
>>>>> out, and then you retry an outwards migration, I think you've leaked a
>>>>> writer.
>>>>
>>>> Shouldn't the change [1] to migrate_init() cover that?
>>>
>>> Hmm OK, yes it does - I guess it does mean you keep the allocation
>>> around for a bit longer, but that's OK in practice since normally you'll
>>> be quitting soon.
>>
>> Instead of json_writer_free() here and there, how about free it in
>> migrate_fd_cleanup() once and for all?
>>
>
> Sure, if that works. I assume I can get rid of the migrate_init() and
> migration_instance_finalize() change then, correct?
>
Yeah, that should be much better and matches how we handle the other
members:
diff --git a/migration/migration.c b/migration/migration.c
index 1d33a7efa0..fcd2f20d7c 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1903,6 +1903,8 @@ static void migrate_fd_cleanup(MigrationState *s)
g_free(s->hostname);
s->hostname = NULL;
+ json_writer_free(s->vmdesc);
+ s->vmdesc = NULL;
qemu_savevm_state_cleanup();
@@ -2170,9 +2172,6 @@ void migrate_init(MigrationState *s)
s->vm_was_running = false;
s->iteration_initial_bytes = 0;
s->threshold_size = 0;
-
- json_writer_free(s->vmdesc);
- s->vmdesc = NULL;
}
int migrate_add_blocker_internal(Error *reason, Error **errp)
@@ -4448,7 +4447,6 @@ static void migration_instance_finalize(Object *obj)
qemu_sem_destroy(&ms->rp_state.rp_sem);
qemu_sem_destroy(&ms->postcopy_qemufile_src_sem);
error_free(ms->error);
- json_writer_free(ms->vmdesc);
}
static void migration_instance_init(Object *obj)
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2023-01-13 13:06 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-12 16:43 [PATCH v3 0/8] virtio-mem: Handle preallocation with migration David Hildenbrand
2023-01-12 16:43 ` [PATCH v3 1/8] migration/savevm: Move more savevm handling into vmstate_save() David Hildenbrand
2023-01-12 16:58 ` Dr. David Alan Gilbert
2023-01-12 17:49 ` David Hildenbrand
2023-01-12 18:36 ` Dr. David Alan Gilbert
2023-01-13 12:59 ` David Hildenbrand
2023-01-12 16:43 ` [PATCH v3 2/8] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup() David Hildenbrand
2023-01-12 17:43 ` Dr. David Alan Gilbert
2023-01-12 17:47 ` David Hildenbrand
2023-01-12 18:40 ` Dr. David Alan Gilbert
2023-01-12 22:06 ` Peter Xu
2023-01-13 13:01 ` David Hildenbrand
2023-01-13 13:05 ` David Hildenbrand [this message]
2023-01-12 16:43 ` [PATCH v3 3/8] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM) David Hildenbrand
2023-01-12 17:56 ` Dr. David Alan Gilbert
2023-01-12 18:21 ` David Hildenbrand
2023-01-12 19:52 ` Dr. David Alan Gilbert
2023-01-12 22:14 ` Peter Xu
2023-01-12 22:28 ` Peter Xu
2023-01-13 13:47 ` David Hildenbrand
2023-01-13 15:20 ` Peter Xu
2023-01-13 15:27 ` Peter Xu
2023-01-16 10:35 ` David Hildenbrand
2023-01-16 14:56 ` Peter Xu
2023-01-16 14:57 ` David Hildenbrand
2023-01-13 15:28 ` David Hildenbrand
2023-01-12 16:43 ` [PATCH v3 4/8] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST() David Hildenbrand
2023-01-12 16:44 ` [PATCH v3 5/8] migration/ram: Factor out check for advised postcopy David Hildenbrand
2023-01-12 18:23 ` Dr. David Alan Gilbert
2023-01-12 16:44 ` [PATCH v3 6/8] virtio-mem: Fail if a memory backend with "prealloc=on" is specified David Hildenbrand
2023-01-12 18:33 ` Dr. David Alan Gilbert
2023-01-12 16:44 ` [PATCH v3 7/8] virtio-mem: Migrate immutable properties early David Hildenbrand
2023-01-12 19:44 ` Dr. David Alan Gilbert
2023-01-13 13:59 ` David Hildenbrand
2023-01-12 16:44 ` [PATCH v3 8/8] virtio-mem: Proper support for preallocation with migration David Hildenbrand
2023-01-12 19:50 ` Dr. David Alan Gilbert
2023-01-12 16:45 ` [PATCH v3 0/8] virtio-mem: Handle " David Hildenbrand
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=6edccb93-f591-def9-5a3c-3d89677602a0@redhat.com \
--to=david@redhat.com \
--cc=dgilbert@redhat.com \
--cc=mprivozn@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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).