{"id":2225934,"url":"http://patchwork.ozlabs.org/api/patches/2225934/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260421202110.306051-7-peterx@redhat.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260421202110.306051-7-peterx@redhat.com>","list_archive_url":null,"date":"2026-04-21T20:21:00","name":"[v2,06/16] migration: Use the new save_query_pending() API directly","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"288253a57752d21865407be4a0af0bd9d0ce47f6","submitter":{"id":67717,"url":"http://patchwork.ozlabs.org/api/people/67717/?format=json","name":"Peter Xu","email":"peterx@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260421202110.306051-7-peterx@redhat.com/mbox/","series":[{"id":500889,"url":"http://patchwork.ozlabs.org/api/series/500889/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500889","date":"2026-04-21T20:20:55","name":"migration/vfio: Fix a few issues on API misuse or statistic reports","version":2,"mbox":"http://patchwork.ozlabs.org/series/500889/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225934/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225934/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Slh5Exd5;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=google header.b=DMK/LoR5;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g0Yh16JGfz1yGs\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 06:22:57 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wFHbI-00010z-Uh; Tue, 21 Apr 2026 16:21:40 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1wFHb7-0000x8-2U\n for qemu-devel@nongnu.org; Tue, 21 Apr 2026 16:21:30 -0400","from us-smtp-delivery-124.mimecast.com ([170.10.129.124])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <peterx@redhat.com>) id 1wFHb5-0008Qg-5M\n for qemu-devel@nongnu.org; Tue, 21 Apr 2026 16:21:28 -0400","from mail-qv1-f71.google.com (mail-qv1-f71.google.com\n [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-247-z636bWEuPiegWh0oc0GkHA-1; Tue, 21 Apr 2026 16:21:24 -0400","by mail-qv1-f71.google.com with SMTP id\n 6a1803df08f44-8aca154e2b5so18598166d6.2\n for <qemu-devel@nongnu.org>; Tue, 21 Apr 2026 13:21:24 -0700 (PDT)","from x1.local ([142.189.10.167]) by smtp.gmail.com with ESMTPSA id\n 6a1803df08f44-8b02ae5c26csm114343556d6.31.2026.04.21.13.21.21\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 21 Apr 2026 13:21:22 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776802886;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=aXWd2xheC1/z+v9Law34/KvsAvj1ejFluJIlYRzmNs4=;\n b=Slh5Exd59MHcJXu6QD3NqbJTHhbrsITtF6zcVd9M2CxeSv9elrUZTfHdgjaQsERc1xc4Ng\n BUAGbOL64rHn/V+tHuRmbF/onTYBb1Kqobtw8y+1Zyzva5kcUG+0k9R1LuqC88Ad+n8uw2\n sZsRjgu1nYku93fqrq41wCQTumUnz2s=","v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=redhat.com; s=google; t=1776802883; x=1777407683; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=aXWd2xheC1/z+v9Law34/KvsAvj1ejFluJIlYRzmNs4=;\n b=DMK/LoR5qNDm5T3yDxBTHsvTCQzl3FZVHmn1zAs8M7KzJOpQiht11EPXdHPJVMhBO6\n FO5WmDq3jVdaUhz0L7gOeQw6qRuWT/J+K5OoBdTXnElmj4+Va8Is+B56TdXYB4AfPgIm\n eyLftYcZwRUp4FQBvWF7ZUQTHHQTlBb7nbg5RRtbzNlpgZjI0xUy9UuWOrpzSR5GCH9z\n 2OClUMQcn/JrPfopOaCojauQwIAjA93HPr7gh2CW/QIXwUeF7mhtNWo6IzmRMqNjSBsB\n 9/qE9KVMwcu5aWwitdyp+j/V7PY+z98PHRTN34ngGzde6dTaJ+MAjkmLycdwmACg8Crz\n lZJw=="],"X-MC-Unique":"z636bWEuPiegWh0oc0GkHA-1","X-Mimecast-MFC-AGG-ID":"z636bWEuPiegWh0oc0GkHA_1776802884","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776802883; x=1777407683;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=aXWd2xheC1/z+v9Law34/KvsAvj1ejFluJIlYRzmNs4=;\n b=tPJc78gO+JbWFSBV6UBAp/tsI4DYmzIb4Ouii24e+/Elc8AHv9+bRKJxtd4T7MSZ2P\n 4WYquCrpZ736tw8saPOsn2ct7OE/gYrLb7z+p7yOwqEhVM9Ebk5OXPaTz6ISpnMgUkTR\n 2EvUW7W3sKt8jy6hJfMzH6R7jDWQGfaocj5f9yRHeNBRBDfSpLch26ZU+i+JBRE85kJS\n n1GgSCpD1DcD40zM/vz/tihuJypZSOYaB6fYyVwbNzN94aXH9gSsNQfO3vp0w8RQm8GQ\n kMkBULLpWe1KeHpJ+3hu10HeOYDqg4tF/tbftbCAoyEgCsu3P9W/anchFW69VC3l7e2E\n 8XVg==","X-Gm-Message-State":"AOJu0Yzt7tgFwFCSUft8v5C/220GtymJ5JRXgGF/lDU+02gcj2gXbrc4\n YG2LL41o7F5cTKpOo8WZ66+boJ6MO+U20gcWznzU5Q6J5hebuxa9zltQFJeQxPB0qFPt2k+QfVI\n IoFJkqftGdgVuj36D7lu68+Q63mha7CdD8Twhpzf4hTiIFssdF04s1C1LScqMFgLU1oqSLbm0bZ\n L/AnE2ZHK9qG7LkDXwY5QGiF050LfIrjtMZST0LQ==","X-Gm-Gg":"AeBDiev4Qx6N2f8KVpwgAmwmuLKx9d1hOpy/wLnLTCR838MvrylQ7tYvRe4sr2UYjG3\n dCyI7hVe94Y9EUQzwMjph/K7T4gYf4aSFFfhSc5cHdMFxH5mCph7S59LnZewEW/5ut0zbPa6+LL\n m+6phDfTFG4Y6CxbpaRMDRfUYJWV5A1IwcAafcQPNE9hIL4zx7DfPhZS8Dtg/WtR0+GJZX2h2+N\n H8txGmJlBZp0hPk7lSkRytSuDtJOl2VU9iWZlEZz17v7vljTtgm7ZC5qJvtnH1Zmh4dTCf5YpMy\n 3E7Tge7gviplaxEKtNbOAYG+PIQ7M2apifAey9b0kUbloW5COsD02diaH/uDyzT2a2vS/0loCb3\n 5lipbBWt/eTeovrZbx/jrsWwbxa1qIqTKj/o9gmHdn/B8XFhbLGURYVXjFA==","X-Received":["by 2002:a05:6214:598c:b0:8ac:b6d7:e60e with SMTP id\n 6a1803df08f44-8b027fd9d4amr316352556d6.7.1776802883390;\n Tue, 21 Apr 2026 13:21:23 -0700 (PDT)","by 2002:a05:6214:598c:b0:8ac:b6d7:e60e with SMTP id\n 6a1803df08f44-8b027fd9d4amr316351876d6.7.1776802882837;\n Tue, 21 Apr 2026 13:21:22 -0700 (PDT)"],"From":"Peter Xu <peterx@redhat.com>","To":"qemu-devel@nongnu.org","Cc":"Joao Martins <joao.m.martins@oracle.com>,\n Markus Armbruster <armbru@redhat.com>,\n =?utf-8?q?C=C3=A9dric_Le_Goater?= <clg@redhat.com>,\n Avihai Horon <avihaih@nvidia.com>,\n =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= <berrange@redhat.com>,\n Fabiano Rosas <farosas@suse.de>, Prasad Pandit <ppandit@redhat.com>,\n Alex Williamson <alex@shazbot.org>, Kirti Wankhede <kwankhede@nvidia.com>,\n Zhiyi Guo <zhguo@redhat.com>, Peter Xu <peterx@redhat.com>,\n \"Maciej S . Szmigiero\" <mail@maciej.szmigiero.name>,\n Juraj Marcin <jmarcin@redhat.com>","Subject":"[PATCH v2 06/16] migration: Use the new save_query_pending() API\n directly","Date":"Tue, 21 Apr 2026 16:21:00 -0400","Message-ID":"<20260421202110.306051-7-peterx@redhat.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260421202110.306051-1-peterx@redhat.com>","References":"<20260421202110.306051-1-peterx@redhat.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com;\n 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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001,\n SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no","X-Spam_action":"no action","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"It's easier to use the new API directly in the migration iterations.  This\nalso paves way for follow up patches to add new data to report directly to\nthe iterator function.\n\nWhen at it, merge the tracepoints too into one.\n\nNo functional change intended.\n\nReviewed-by: Juraj Marcin <jmarcin@redhat.com>\nReviewed-by: Avihai Horon <avihaih@nvidia.com>\nSigned-off-by: Peter Xu <peterx@redhat.com>\n---\n migration/savevm.h     |  4 ----\n migration/migration.c  | 16 +++++++---------\n migration/savevm.c     | 23 ++---------------------\n migration/trace-events |  3 +--\n 4 files changed, 10 insertions(+), 36 deletions(-)","diff":"diff --git a/migration/savevm.h b/migration/savevm.h\nindex e4efd243f3..96fdf96d4e 100644\n--- a/migration/savevm.h\n+++ b/migration/savevm.h\n@@ -46,10 +46,6 @@ void qemu_savevm_state_cleanup(void);\n void qemu_savevm_state_complete_postcopy(QEMUFile *f);\n int qemu_savevm_state_complete_precopy(MigrationState *s);\n void qemu_savevm_query_pending(MigPendingData *pending, bool exact);\n-void qemu_savevm_state_pending_exact(uint64_t *must_precopy,\n-                                     uint64_t *can_postcopy);\n-void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,\n-                                        uint64_t *can_postcopy);\n int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy);\n bool qemu_savevm_state_postcopy_prepare(QEMUFile *f, Error **errp);\n void qemu_savevm_state_end(QEMUFile *f);\ndiff --git a/migration/migration.c b/migration/migration.c\nindex dfc60372cf..68cfe2d3bf 100644\n--- a/migration/migration.c\n+++ b/migration/migration.c\n@@ -3204,17 +3204,17 @@ typedef enum {\n  */\n static MigIterateState migration_iteration_run(MigrationState *s)\n {\n-    uint64_t must_precopy, can_postcopy, pending_size;\n     Error *local_err = NULL;\n     bool in_postcopy = (s->state == MIGRATION_STATUS_POSTCOPY_DEVICE ||\n                         s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);\n     bool can_switchover = migration_can_switchover(s);\n+    MigPendingData pending = { };\n+    uint64_t pending_size;\n     bool complete_ready;\n \n     /* Fast path - get the estimated amount of pending data */\n-    qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy);\n-    pending_size = must_precopy + can_postcopy;\n-    trace_migrate_pending_estimate(pending_size, must_precopy, can_postcopy);\n+    qemu_savevm_query_pending(&pending, false);\n+    pending_size = pending.precopy_bytes + pending.postcopy_bytes;\n \n     if (in_postcopy) {\n         /*\n@@ -3243,14 +3243,12 @@ static MigIterateState migration_iteration_run(MigrationState *s)\n          * during postcopy phase.\n          */\n         if (pending_size <= s->threshold_size) {\n-            qemu_savevm_state_pending_exact(&must_precopy, &can_postcopy);\n-            pending_size = must_precopy + can_postcopy;\n-            trace_migrate_pending_exact(pending_size, must_precopy,\n-                                        can_postcopy);\n+            qemu_savevm_query_pending(&pending, true);\n+            pending_size = pending.precopy_bytes + pending.postcopy_bytes;\n         }\n \n         /* Should we switch to postcopy now? */\n-        if (must_precopy <= s->threshold_size &&\n+        if (pending.precopy_bytes <= s->threshold_size &&\n             can_switchover && qatomic_read(&s->start_postcopy)) {\n             if (postcopy_start(s, &local_err)) {\n                 migrate_error_propagate(s, error_copy(local_err));\ndiff --git a/migration/savevm.c b/migration/savevm.c\nindex 392d840955..397f602257 100644\n--- a/migration/savevm.c\n+++ b/migration/savevm.c\n@@ -1778,28 +1778,9 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)\n         }\n         se->ops->save_query_pending(se->opaque, pending, exact);\n     }\n-}\n-\n-void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,\n-                                        uint64_t *can_postcopy)\n-{\n-    MigPendingData pending;\n-\n-    qemu_savevm_query_pending(&pending, false);\n-\n-    *must_precopy = pending.precopy_bytes;\n-    *can_postcopy = pending.postcopy_bytes;\n-}\n-\n-void qemu_savevm_state_pending_exact(uint64_t *must_precopy,\n-                                     uint64_t *can_postcopy)\n-{\n-    MigPendingData pending;\n-\n-    qemu_savevm_query_pending(&pending, true);\n \n-    *must_precopy = pending.precopy_bytes;\n-    *can_postcopy = pending.postcopy_bytes;\n+    trace_qemu_savevm_query_pending(exact, pending->precopy_bytes,\n+                                    pending->postcopy_bytes);\n }\n \n void qemu_savevm_state_cleanup(void)\ndiff --git a/migration/trace-events b/migration/trace-events\nindex 60e5087e38..f8995b8d0d 100644\n--- a/migration/trace-events\n+++ b/migration/trace-events\n@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) \"%u\"\n qemu_loadvm_state_post_main(int ret) \"%d\"\n qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) \"%u(%s) %u %u\"\n qemu_savevm_send_packaged(void) \"\"\n+qemu_savevm_query_pending(bool exact, uint64_t precopy, uint64_t postcopy) \"exact=%d, precopy=%\"PRIu64\", postcopy=%\"PRIu64\n loadvm_state_switchover_ack_needed(unsigned int switchover_ack_pending_num) \"Switchover ack pending num=%u\"\n loadvm_state_setup(void) \"\"\n loadvm_state_cleanup(void) \"\"\n@@ -159,8 +160,6 @@ migration_cleanup(void) \"\"\n migrate_error(const char *error_desc) \"error=%s\"\n migration_cancel(void) \"\"\n migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) \"in %s at 0x%zx len 0x%zx\"\n-migrate_pending_exact(uint64_t size, uint64_t pre, uint64_t post) \"exact pending size %\" PRIu64 \" (pre = %\" PRIu64 \" post=%\" PRIu64 \")\"\n-migrate_pending_estimate(uint64_t size, uint64_t pre, uint64_t post) \"estimate pending size %\" PRIu64 \" (pre = %\" PRIu64 \" post=%\" PRIu64 \")\"\n migrate_send_rp_message(int msg_type, uint16_t len) \"%d: len %d\"\n migrate_send_rp_recv_bitmap(char *name, int64_t size) \"block '%s' size 0x%\"PRIi64\n migration_completion_file_err(void) \"\"\n","prefixes":["v2","06/16"]}