From nobody Tue May 13 12:56:18 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354197; cv=none; d=zohomail.com; s=zohoarc; b=jBjUDy+BoG4KwQboqabuVBm5MyoSE974vDv4+gjgtBLZVlCRetYYNbMo0vHqAL5zqom6Wa1MY4N3lO+JKnF6gNzJ1J6hn4Yp3UFxDzuRgvQQ06XbnSAlKrov8++E30e5lcMs3CL9Gyg8VGoUYr2YDZnzl82QDiUrFwYismVNym4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354197; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OLAGoLmZqcKzTwxr0WR3o6KYIS2/7nUjb5oI0hxKkYs=; b=jSGli21y1x5FiY7gk7CxshaNvFeFjXfrSnEYct/C1+5uD+/L9Axk+X6BRNqIEh5rXCwXZVvkBlhIy2oiLdp3vT+BGDh+GN5jNBrOseoCZl/sZMbPxnjrFFgju6qfMdCQamrBZmtD1qZ64thUuTHfyDcUPmbC12E9F7r+7S69yqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354197180426.2117494285303; Thu, 2 Feb 2023 08:09:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc88-00004z-Ff; Thu, 02 Feb 2023 11:08:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc84-0008UA-K3 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc82-0005Cd-7A for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-543-iZMMFGEKODmlR5hY1Q-kuQ-1; Thu, 02 Feb 2023 11:07:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A446857A99; Thu, 2 Feb 2023 16:07:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B040451E5; Thu, 2 Feb 2023 16:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OLAGoLmZqcKzTwxr0WR3o6KYIS2/7nUjb5oI0hxKkYs=; b=MroxaQKxjgFcYvPdUKgyCe+4IOGfa1WxmOCGm2zEC812fUpjg6Yj7EnV5Kf8InvZaSko7N 2hukI/NKTSho32BQJsXcQkPZ6/X2xgGsybtR6ypq1Nzn4ZLyXX7fkXrwRc+9yN04s0aoEv uxM04fVBzD18cp/TMxQXOXK9dl61Y8g= X-MC-Unique: iZMMFGEKODmlR5hY1Q-kuQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 13/26] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup() Date: Thu, 2 Feb 2023 17:06:27 +0100 Message-Id: <20230202160640.2300-14-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354197932100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand ... and store it in the migration state. This is a preparation for storing selected vmds's already in qemu_savevm_state_setup(). Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/migration.h | 4 ++++ migration/migration.c | 2 ++ migration/savevm.c | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index ae4ffd3454..66511ce532 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -17,6 +17,7 @@ #include "exec/cpu-common.h" #include "hw/qdev-core.h" #include "qapi/qapi-types-migration.h" +#include "qapi/qmp/json-writer.h" #include "qemu/thread.h" #include "qemu/coroutine_int.h" #include "io/channel.h" @@ -366,6 +367,9 @@ struct MigrationState { * This save hostname when out-going migration starts */ char *hostname; + + /* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. = */ + JSONWriter *vmdesc; }; =20 void migrate_set_state(int *state, int old_state, int new_state); diff --git a/migration/migration.c b/migration/migration.c index cb9aee76c0..3344c95d26 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1903,6 +1903,8 @@ static void migrate_fd_cleanup(MigrationState *s) =20 g_free(s->hostname); s->hostname =3D NULL; + json_writer_free(s->vmdesc); + s->vmdesc =3D NULL; =20 qemu_savevm_state_cleanup(); =20 diff --git a/migration/savevm.c b/migration/savevm.c index 3e3631652e..28f88b5521 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -42,7 +42,6 @@ #include "postcopy-ram.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qapi/qmp/json-writer.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" @@ -1190,10 +1189,16 @@ bool qemu_savevm_state_guest_unplug_pending(void) =20 void qemu_savevm_state_setup(QEMUFile *f) { + MigrationState *ms =3D migrate_get_current(); SaveStateEntry *se; Error *local_err =3D NULL; int ret; =20 + ms->vmdesc =3D json_writer_new(false); + json_writer_start_object(ms->vmdesc, NULL); + json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size()); + json_writer_start_array(ms->vmdesc, "devices"); + trace_savevm_state_setup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (!se->ops || !se->ops->save_setup) { @@ -1391,15 +1396,12 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, bool in_postcopy, bool inactivate_disks) { - g_autoptr(JSONWriter) vmdesc =3D NULL; + MigrationState *ms =3D migrate_get_current(); + JSONWriter *vmdesc =3D ms->vmdesc; int vmdesc_len; SaveStateEntry *se; int ret; =20 - vmdesc =3D 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 =3D vmstate_save(f, se, vmdesc); if (ret) { @@ -1434,6 +1436,10 @@ int qemu_savevm_state_complete_precopy_non_iterable(= QEMUFile *f, qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); } =20 + /* Free it now to detect any inconsistencies. */ + json_writer_free(vmdesc); + ms->vmdesc =3D NULL; + return 0; } =20 --=20 2.39.1