From patchwork Wed Oct 11 20:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D39B2CDB483 for ; Wed, 11 Oct 2023 20:36:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvg-0005CK-Mi; Wed, 11 Oct 2023 16:35:40 -0400 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 1qqfvf-0005C3-06 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:39 -0400 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 1qqfvc-0002xB-VZ for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056534; 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=2bveod3zV302dT9+bvUxbCDIqqJYCvUreoQBtxaXQAg=; b=F2MKqI5XYPCodgYWK33GHQhMMIK4Qun5K9LF336kHBO3Ebxx6zvvhNtRYBR7nzNSTXuJtv R16st6UqkL9JrvYwGa6LZkulppz/SUMTXo4fIZ7wMiijbowYCFW+T1VONsSAq6/RhEd3xF cdB5ePcVWJ281qJP3kcpOkmywuYIYFA= 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-21-3ARPpw69P0SUXQ5dlSFAQA-1; Wed, 11 Oct 2023 16:35:31 -0400 X-MC-Unique: 3ARPpw69P0SUXQ5dlSFAQA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2E705101A597; Wed, 11 Oct 2023 20:35:31 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A730492B06; Wed, 11 Oct 2023 20:35:30 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 01/13] migration: Create migrate_rdma() Date: Wed, 11 Oct 2023 22:35:15 +0200 Message-ID: <20231011203527.9061-2-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Helper to say if we are doing a migration over rdma. Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/migration.h | 2 ++ migration/options.h | 1 + migration/migration.c | 1 + migration/options.c | 7 +++++++ migration/rdma.c | 4 +++- 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/migration/migration.h b/migration/migration.h index cd5534337c..96260138d1 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -469,6 +469,8 @@ struct MigrationState { * switchover has been received. */ bool switchover_acked; + /* Is this a rdma migration */ + bool rdma_migration; }; void migrate_set_state(int *state, int old_state, int new_state); diff --git a/migration/options.h b/migration/options.h index 045e2a41a2..a26fd1680b 100644 --- a/migration/options.h +++ b/migration/options.h @@ -56,6 +56,7 @@ bool migrate_zero_copy_send(void); bool migrate_multifd_flush_after_each_section(void); bool migrate_postcopy(void); +bool migrate_rdma(void); bool migrate_tls(void); /* capabilities helpers */ diff --git a/migration/migration.c b/migration/migration.c index 1c6c81ad49..4213c645c6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1451,6 +1451,7 @@ int migrate_init(MigrationState *s, Error **errp) s->iteration_initial_bytes = 0; s->threshold_size = 0; s->switchover_acked = false; + s->rdma_migration = false; /* * set mig_stats compression_counters memory to zero for a * new migration diff --git a/migration/options.c b/migration/options.c index 6bbfd4853d..da379e7f7a 100644 --- a/migration/options.c +++ b/migration/options.c @@ -376,6 +376,13 @@ bool migrate_postcopy(void) return migrate_postcopy_ram() || migrate_dirty_bitmaps(); } +bool migrate_rdma(void) +{ + MigrationState *s = migrate_get_current(); + + return s->rdma_migration; +} + bool migrate_tls(void) { MigrationState *s = migrate_get_current(); diff --git a/migration/rdma.c b/migration/rdma.c index f6fc226c9b..f155f3e1c8 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -4113,6 +4113,7 @@ static void rdma_accept_incoming_migration(void *opaque) void rdma_start_incoming_migration(const char *host_port, Error **errp) { + MigrationState *s = migrate_get_current(); int ret; RDMAContext *rdma; @@ -4144,7 +4145,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp) } trace_rdma_start_incoming_migration_after_rdma_listen(); - + s->rdma_migration = true; qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration, NULL, (void *)(intptr_t)rdma); return; @@ -4220,6 +4221,7 @@ void rdma_start_outgoing_migration(void *opaque, trace_rdma_start_outgoing_migration_after_rdma_connect(); s->to_dst_file = rdma_new_output(rdma); + s->rdma_migration = true; migrate_fd_connect(s, NULL); return; return_path_err: From patchwork Wed Oct 11 20:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417936 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B70EECDB482 for ; Wed, 11 Oct 2023 20:37:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvt-0005Hl-55; Wed, 11 Oct 2023 16:35:53 -0400 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 1qqfvq-0005Gy-Lx for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:50 -0400 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 1qqfvo-00034X-RO for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056546; 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=MSg9mVm0nCeYK6LONcmEHwDZVZY4+o1FoAk7BDVnJ8M=; b=gEpQ4rqBEP2DKz6i52G2naPYVYyfx7v17aBIUL5b2ihDQQqFg38ijR+c2HexqoVXCfdNbp ljHKOO6PfBGanA5cNQibRfw/ou8oFWVPI6h9lESv6FEz3E2QVG2D4ciH5c+OVMDiaTtjpQ zMDUKnTUKplHy5MI9/mk7zN8bj1tqkg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-211-sXewtaFhPoSYP3M0LQjWyg-1; Wed, 11 Oct 2023 16:35:33 -0400 X-MC-Unique: sXewtaFhPoSYP3M0LQjWyg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9423C3C0C4AA; Wed, 11 Oct 2023 20:35:32 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EB0E492B06; Wed, 11 Oct 2023 20:35:31 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 02/13] migration/rdma: Unfold ram_control_before_iterate() Date: Wed, 11 Oct 2023 22:35:16 +0200 Message-ID: <20231011203527.9061-3-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Once there: - Remove unused data parameter - unfold it in its callers. - change all callers to call qemu_rdma_registration_start() - We need to call QIO_CHANNEL_RDMA() after we check for migrate_rdma() Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Fabiano Rosas Reviewed-by: Li Zhijian --- initilazize rioc after checknig that rdma is enabled. Signed-off-by: Juan Quintela --- migration/qemu-file.h | 2 -- migration/rdma.h | 7 +++++++ migration/qemu-file.c | 13 +------------ migration/ram.c | 16 +++++++++++++--- migration/rdma.c | 12 ++++-------- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 03e718c264..d6a370c569 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -55,7 +55,6 @@ typedef int (QEMURamSaveFunc)(QEMUFile *f, size_t size); typedef struct QEMUFileHooks { - QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate; QEMURamHookFunc *hook_ram_load; QEMURamSaveFunc *save_page; @@ -127,7 +126,6 @@ void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); -void ram_control_before_iterate(QEMUFile *f, uint64_t flags); void ram_control_after_iterate(QEMUFile *f, uint64_t flags); void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data); diff --git a/migration/rdma.h b/migration/rdma.h index de2ba09dc5..670c67a8cb 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -22,4 +22,11 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, void rdma_start_incoming_migration(const char *host_port, Error **errp); + +#ifdef CONFIG_RDMA +int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); +#else +static inline +int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } +#endif #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 7fb659296f..5e2d73fd68 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -32,6 +32,7 @@ #include "trace.h" #include "options.h" #include "qapi/error.h" +#include "rdma.h" #define IO_BUF_SIZE 32768 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) @@ -297,18 +298,6 @@ void qemu_fflush(QEMUFile *f) f->iovcnt = 0; } -void ram_control_before_iterate(QEMUFile *f, uint64_t flags) -{ - int ret = 0; - - if (f->hooks && f->hooks->before_ram_iterate) { - ret = f->hooks->before_ram_iterate(f, flags, NULL); - if (ret < 0) { - qemu_file_set_error(f, ret); - } - } -} - void ram_control_after_iterate(QEMUFile *f, uint64_t flags) { int ret = 0; diff --git a/migration/ram.c b/migration/ram.c index 2f5ce4d60b..ab590a983f 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -59,6 +59,7 @@ #include "qemu/iov.h" #include "multifd.h" #include "sysemu/runstate.h" +#include "rdma.h" #include "options.h" #include "sysemu/dirtylimit.h" #include "sysemu/kvm.h" @@ -3062,7 +3063,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } } - ram_control_before_iterate(f, RAM_CONTROL_SETUP); + ret = qemu_rdma_registration_start(f, RAM_CONTROL_SETUP); + if (ret < 0) { + qemu_file_set_error(f, ret); + } ram_control_after_iterate(f, RAM_CONTROL_SETUP); migration_ops = g_malloc0(sizeof(MigrationOps)); @@ -3122,7 +3126,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) /* Read version before ram_list.blocks */ smp_rmb(); - ram_control_before_iterate(f, RAM_CONTROL_ROUND); + ret = qemu_rdma_registration_start(f, RAM_CONTROL_ROUND); + if (ret < 0) { + qemu_file_set_error(f, ret); + } t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); i = 0; @@ -3227,7 +3234,10 @@ static int ram_save_complete(QEMUFile *f, void *opaque) migration_bitmap_sync_precopy(rs, true); } - ram_control_before_iterate(f, RAM_CONTROL_FINISH); + ret = qemu_rdma_registration_start(f, RAM_CONTROL_FINISH); + if (ret < 0) { + qemu_file_set_error(f, ret); + } /* try transferring iterative blocks of memory */ diff --git a/migration/rdma.c b/migration/rdma.c index f155f3e1c8..a8bfc052c4 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3850,18 +3850,15 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data) } } -static int qemu_rdma_registration_start(QEMUFile *f, - uint64_t flags, void *data) +int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { - QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); - RDMAContext *rdma; - - if (migration_in_postcopy()) { + if (!migrate_rdma () || migration_in_postcopy()) { return 0; } + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); RCU_READ_LOCK_GUARD(); - rdma = qatomic_rcu_read(&rioc->rdmaout); + RDMAContext *rdma = qatomic_rcu_read(&rioc->rdmaout); if (!rdma) { return -1; } @@ -4002,7 +3999,6 @@ static const QEMUFileHooks rdma_read_hooks = { }; static const QEMUFileHooks rdma_write_hooks = { - .before_ram_iterate = qemu_rdma_registration_start, .after_ram_iterate = qemu_rdma_registration_stop, .save_page = qemu_rdma_save_page, }; From patchwork Wed Oct 11 20:35:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 393EDCDB47E for ; Wed, 11 Oct 2023 20:36:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvh-0005Cz-Lp; Wed, 11 Oct 2023 16:35:41 -0400 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 1qqfvg-0005CN-I3 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:40 -0400 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 1qqfve-0002zB-6l for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056537; 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=u1x5haXn7atDjonP8E/33bwDgNkkf+VsBPQsfRc84qY=; b=JNqAxyL7Q/LzQw3F3JZSyiY0ch6lxHX8MN1Om92/SwmDxch+13k4zkYjDJ+RTr540w3Cac OvltdM+uXFB+71MTkYkKlpIn+kJgGjgD0D04PrloCPXc3gF5qYPIrCvUOOr+MjYssEahDs Y482XhQuMVBnu66f5ehm/mSKR7eBsZA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-191-bk25NGRlONObM-Tlads72w-1; Wed, 11 Oct 2023 16:35:34 -0400 X-MC-Unique: bk25NGRlONObM-Tlads72w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCFE71C09A46; Wed, 11 Oct 2023 20:35:33 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id D49AF492B06; Wed, 11 Oct 2023 20:35:32 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 03/13] migration/rdma: Unfold ram_control_after_iterate() Date: Wed, 11 Oct 2023 22:35:17 +0200 Message-ID: <20231011203527.9061-4-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Once there: - Remove unused data parameter - unfold it in its callers - change all callers to call qemu_rdma_registration_stop() - We need to call QIO_CHANNEL_RDMA() after we check for migrate_rdma() Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- This function has goto's. So I don't change the place where we declare variables, althought I think that it is correct, just don't start that discussion. --- migration/qemu-file.h | 2 -- migration/rdma.h | 3 +++ migration/qemu-file.c | 12 ------------ migration/ram.c | 17 ++++++++++++++--- migration/rdma.c | 9 ++++----- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index d6a370c569..35e671a01e 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -55,7 +55,6 @@ typedef int (QEMURamSaveFunc)(QEMUFile *f, size_t size); typedef struct QEMUFileHooks { - QEMURamHookFunc *after_ram_iterate; QEMURamHookFunc *hook_ram_load; QEMURamSaveFunc *save_page; } QEMUFileHooks; @@ -126,7 +125,6 @@ void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); -void ram_control_after_iterate(QEMUFile *f, uint64_t flags); void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data); /* Whenever this is found in the data stream, the flags diff --git a/migration/rdma.h b/migration/rdma.h index 670c67a8cb..c13b94c782 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -25,8 +25,11 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp); #ifdef CONFIG_RDMA int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); +int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags); #else static inline int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } +static inline +int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } #endif #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 5e2d73fd68..e7dba2a849 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -298,18 +298,6 @@ void qemu_fflush(QEMUFile *f) f->iovcnt = 0; } -void ram_control_after_iterate(QEMUFile *f, uint64_t flags) -{ - int ret = 0; - - if (f->hooks && f->hooks->after_ram_iterate) { - ret = f->hooks->after_ram_iterate(f, flags, NULL); - if (ret < 0) { - qemu_file_set_error(f, ret); - } - } -} - void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data) { if (f->hooks && f->hooks->hook_ram_load) { diff --git a/migration/ram.c b/migration/ram.c index ab590a983f..15bd4ad697 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3067,7 +3067,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque) if (ret < 0) { qemu_file_set_error(f, ret); } - ram_control_after_iterate(f, RAM_CONTROL_SETUP); + + ret = qemu_rdma_registration_stop(f, RAM_CONTROL_SETUP); + if (ret < 0) { + qemu_file_set_error(f, ret); + } migration_ops = g_malloc0(sizeof(MigrationOps)); migration_ops->ram_save_target_page = ram_save_target_page_legacy; @@ -3186,7 +3190,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. */ - ram_control_after_iterate(f, RAM_CONTROL_ROUND); + ret = qemu_rdma_registration_stop(f, RAM_CONTROL_ROUND); + if (ret < 0) { + qemu_file_set_error(f, ret); + } out: if (ret >= 0 @@ -3259,7 +3266,11 @@ static int ram_save_complete(QEMUFile *f, void *opaque) qemu_mutex_unlock(&rs->bitmap_mutex); ram_flush_compressed_data(rs); - ram_control_after_iterate(f, RAM_CONTROL_FINISH); + + int ret = qemu_rdma_registration_stop(f, RAM_CONTROL_FINISH); + if (ret < 0) { + qemu_file_set_error(f, ret); + } } if (ret < 0) { diff --git a/migration/rdma.c b/migration/rdma.c index a8bfc052c4..99c0914a23 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3878,20 +3878,20 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) * Inform dest that dynamic registrations are done for now. * First, flush writes, if any. */ -static int qemu_rdma_registration_stop(QEMUFile *f, - uint64_t flags, void *data) +int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { - QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); + QIOChannelRDMA *rioc; Error *err = NULL; RDMAContext *rdma; RDMAControlHeader head = { .len = 0, .repeat = 1 }; int ret; - if (migration_in_postcopy()) { + if (!migrate_rdma() || migration_in_postcopy()) { return 0; } RCU_READ_LOCK_GUARD(); + rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); rdma = qatomic_rcu_read(&rioc->rdmaout); if (!rdma) { return -1; @@ -3999,7 +3999,6 @@ static const QEMUFileHooks rdma_read_hooks = { }; static const QEMUFileHooks rdma_write_hooks = { - .after_ram_iterate = qemu_rdma_registration_stop, .save_page = qemu_rdma_save_page, }; From patchwork Wed Oct 11 20:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417934 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCB2BCDB47E for ; Wed, 11 Oct 2023 20:37:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvj-0005Df-TB; Wed, 11 Oct 2023 16:35:43 -0400 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 1qqfvg-0005CJ-Df for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfve-0002z3-2a for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056537; 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=jpjcgYW7wsEMjUfN5eXAOTUl5ZZzO1Zh5Yyg7x/5W5I=; b=Omq6Uw9xbK1oRyVJAatbRtc3RJJfhWNbYSSLLSYolcOEpfTpZvbcprCfVZ185hAyP58AUp gkSXMEHJZRMMo56XfGJa3sCbERvb0cHfBKoRDhe35hFWYOENRbR0bpQr3uQ1cXRb4DEjr8 gJLOYTtRtTCJFIPa8T99EyjkxNN42oA= 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-584-O0m9BYB_ONamzl1X8FMUmA-1; Wed, 11 Oct 2023 16:35:35 -0400 X-MC-Unique: O0m9BYB_ONamzl1X8FMUmA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 34337810BD4; Wed, 11 Oct 2023 20:35:35 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2C670492B06; Wed, 11 Oct 2023 20:35:34 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 04/13] migration/rdma: Remove all uses of RAM_CONTROL_HOOK Date: Wed, 11 Oct 2023 22:35:18 +0200 Message-ID: <20231011203527.9061-5-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Instead of going trhough ram_control_load_hook(), call qemu_rdma_registration_handle() directly. Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/qemu-file.h | 1 - migration/rdma.h | 3 +++ migration/ram.c | 5 ++++- migration/rdma.c | 12 +++++++----- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 35e671a01e..14ff0d9cc4 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -41,7 +41,6 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data); */ #define RAM_CONTROL_SETUP 0 #define RAM_CONTROL_ROUND 1 -#define RAM_CONTROL_HOOK 2 #define RAM_CONTROL_FINISH 3 #define RAM_CONTROL_BLOCK_REG 4 diff --git a/migration/rdma.h b/migration/rdma.h index c13b94c782..8bd277efb9 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -24,10 +24,13 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp); #ifdef CONFIG_RDMA +int qemu_rdma_registration_handle(QEMUFile *f); int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags); #else static inline +int qemu_rdma_registration_handle(QEMUFile *f) { return 0; } +static inline int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } static inline int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } diff --git a/migration/ram.c b/migration/ram.c index 15bd4ad697..ee8bdcdc82 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4072,7 +4072,10 @@ static int ram_load_precopy(QEMUFile *f) } break; case RAM_SAVE_FLAG_HOOK: - ram_control_load_hook(f, RAM_CONTROL_HOOK, NULL); + ret = qemu_rdma_registration_handle(f); + if (ret < 0) { + qemu_file_set_error(f, ret); + } break; default: error_report("Unknown combination of migration flags: 0x%x", flags); diff --git a/migration/rdma.c b/migration/rdma.c index 99c0914a23..e533814599 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3522,7 +3522,7 @@ static int dest_ram_sort_func(const void *a, const void *b) * * Keep doing this until the source tells us to stop. */ -static int qemu_rdma_registration_handle(QEMUFile *f) +int qemu_rdma_registration_handle(QEMUFile *f) { RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult), .type = RDMA_CONTROL_REGISTER_RESULT, @@ -3534,7 +3534,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) }; RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT, .repeat = 1 }; - QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); + QIOChannelRDMA *rioc; Error *err = NULL; RDMAContext *rdma; RDMALocalBlocks *local; @@ -3550,7 +3550,12 @@ static int qemu_rdma_registration_handle(QEMUFile *f) int count = 0; int i = 0; + if (!migrate_rdma()) { + return 0; + } + RCU_READ_LOCK_GUARD(); + rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); rdma = qatomic_rcu_read(&rioc->rdmain); if (!rdma) { @@ -3841,9 +3846,6 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data) case RAM_CONTROL_BLOCK_REG: return rdma_block_notification_handle(f, data); - case RAM_CONTROL_HOOK: - return qemu_rdma_registration_handle(f); - default: /* Shouldn't be called with any other values */ abort(); From patchwork Wed Oct 11 20:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DC77C41513 for ; Wed, 11 Oct 2023 20:37:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvk-0005Dv-JX; Wed, 11 Oct 2023 16:35:44 -0400 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 1qqfvh-0005Cq-8G for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfvf-000304-CQ for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056538; 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=+lS/1Zaz2QG7xgs8peGdWQEly7CbQFxnl5u1oDcK3/M=; b=Zrolpcf+O/4w0VikqUng+EWCsUBJacFFcVJSg1aYm9PmjpQFj5t7tkrFQhPOLPwNki86VV pNwWKTdA1hwkCLdKXUccftkdqcNi1feD2/ZEvlYyh2McEVrOQCMdsebhCWQSMlHB5lc30m y3V19955RJU/njBXTUdmIzQCjQz0Uak= 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-638--YZS99W7M4W58LYyes9K6A-1; Wed, 11 Oct 2023 16:35:37 -0400 X-MC-Unique: -YZS99W7M4W58LYyes9K6A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FD988015F8; Wed, 11 Oct 2023 20:35:36 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77EE9492B06; Wed, 11 Oct 2023 20:35:35 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 05/13] migration/rdma: Unfold hook_ram_load() Date: Wed, 11 Oct 2023 22:35:19 +0200 Message-ID: <20231011203527.9061-6-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org There is only one flag called with: RAM_CONTROL_BLOCK_REG. Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/qemu-file.h | 11 ----------- migration/rdma.h | 3 +++ migration/qemu-file.c | 10 ---------- migration/ram.c | 6 ++++-- migration/rdma.c | 34 +++++++++++----------------------- 5 files changed, 18 insertions(+), 46 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 14ff0d9cc4..80c30631dc 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -29,20 +29,12 @@ #include "exec/cpu-common.h" #include "io/channel.h" -/* - * This function provides hooks around different - * stages of RAM migration. - * 'data' is call specific data associated with the 'flags' value - */ -typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data); - /* * Constants used by ram_control_* hooks */ #define RAM_CONTROL_SETUP 0 #define RAM_CONTROL_ROUND 1 #define RAM_CONTROL_FINISH 3 -#define RAM_CONTROL_BLOCK_REG 4 /* * This function allows override of where the RAM page @@ -54,7 +46,6 @@ typedef int (QEMURamSaveFunc)(QEMUFile *f, size_t size); typedef struct QEMUFileHooks { - QEMURamHookFunc *hook_ram_load; QEMURamSaveFunc *save_page; } QEMUFileHooks; @@ -124,8 +115,6 @@ void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); -void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data); - /* Whenever this is found in the data stream, the flags * will be passed to ram_control_load_hook in the incoming-migration * side. This lets before_ram_iterate/after_ram_iterate add diff --git a/migration/rdma.h b/migration/rdma.h index 8bd277efb9..8df8b4089a 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -27,6 +27,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp); int qemu_rdma_registration_handle(QEMUFile *f); int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags); +int rdma_block_notification_handle(QEMUFile *f, const char *name); #else static inline int qemu_rdma_registration_handle(QEMUFile *f) { return 0; } @@ -34,5 +35,7 @@ static inline int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } static inline int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } +static inline +int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; } #endif #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index e7dba2a849..4a414b8976 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -298,16 +298,6 @@ void qemu_fflush(QEMUFile *f) f->iovcnt = 0; } -void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data) -{ - if (f->hooks && f->hooks->hook_ram_load) { - int ret = f->hooks->hook_ram_load(f, flags, data); - if (ret < 0) { - qemu_file_set_error(f, ret); - } - } -} - int ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size) { diff --git a/migration/ram.c b/migration/ram.c index ee8bdcdc82..d6a9f90b94 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4023,8 +4023,10 @@ static int ram_load_precopy(QEMUFile *f) ret = -EINVAL; } } - ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, - block->idstr); + ret = rdma_block_notification_handle(f, block->idstr); + if (ret < 0) { + qemu_file_set_error(f, ret); + } } else { error_report("Unknown ramblock \"%s\", cannot " "accept migration", id); diff --git a/migration/rdma.c b/migration/rdma.c index e533814599..6bca9e8f19 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3799,22 +3799,23 @@ err: } /* Destination: - * Called via a ram_control_load_hook during the initial RAM load section which - * lists the RAMBlocks by name. This lets us know the order of the RAMBlocks - * on the source. - * We've already built our local RAMBlock list, but not yet sent the list to - * the source. + * Called during the initial RAM load section which lists the + * RAMBlocks by name. This lets us know the order of the RAMBlocks on + * the source. We've already built our local RAMBlock list, but not + * yet sent the list to the source. */ -static int -rdma_block_notification_handle(QEMUFile *f, const char *name) +int rdma_block_notification_handle(QEMUFile *f, const char *name) { - RDMAContext *rdma; - QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); int curr; int found = -1; + if (!migrate_rdma()) { + return 0; + } + RCU_READ_LOCK_GUARD(); - rdma = qatomic_rcu_read(&rioc->rdmain); + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); + RDMAContext *rdma = qatomic_rcu_read(&rioc->rdmain); if (!rdma) { return -1; @@ -3840,18 +3841,6 @@ rdma_block_notification_handle(QEMUFile *f, const char *name) return 0; } -static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data) -{ - switch (flags) { - case RAM_CONTROL_BLOCK_REG: - return rdma_block_notification_handle(f, data); - - default: - /* Shouldn't be called with any other values */ - abort(); - } -} - int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { if (!migrate_rdma () || migration_in_postcopy()) { @@ -3997,7 +3986,6 @@ err: } static const QEMUFileHooks rdma_read_hooks = { - .hook_ram_load = rdma_load_hook, }; static const QEMUFileHooks rdma_write_hooks = { From patchwork Wed Oct 11 20:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417938 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B7CE5CDB47E for ; Wed, 11 Oct 2023 20:37:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvo-0005Ed-9M; Wed, 11 Oct 2023 16:35:48 -0400 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 1qqfvl-0005ED-M9 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfvj-00033b-UU for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056543; 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=tNvGit9SfVOejyYVgNK2Rq8RuJMTvMvnwpSWOheA1iw=; b=ZrhiXYl5zfcD3nu+Z8XnPNfYWd+BtTQ0+ZVWik1HAuKGddnjcOpRch5knmLy7+++S2Rx88 Vu14073ZvzSUkkZwoMRr3VwqKlndzpyJ6w30KhCue/mtgqqvOg2sCCLiob6ew5qJpEcHZb yzvgjJcUc+pQtNepcrcqSjlGo3E8nII= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-140-vSXdMWypOzCUtUkTWSeTAw-1; Wed, 11 Oct 2023 16:35:39 -0400 X-MC-Unique: vSXdMWypOzCUtUkTWSeTAw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A90A42825EB3; Wed, 11 Oct 2023 20:35:38 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0124E492B06; Wed, 11 Oct 2023 20:35:36 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 06/13] migration/rdma: Create rdma_control_save_page() Date: Wed, 11 Oct 2023 22:35:20 +0200 Message-ID: <20231011203527.9061-7-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The only user of ram_control_save_page() and save_page() hook was rdma. Just move the function to rdma.c, rename it to rdma_control_save_page(). Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/qemu-file.h | 12 ------------ migration/rdma.h | 10 ++++++++++ migration/qemu-file.c | 20 -------------------- migration/ram.c | 4 ++-- migration/rdma.c | 20 +++++++++++++++++++- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 80c30631dc..60510a2819 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -36,17 +36,7 @@ #define RAM_CONTROL_ROUND 1 #define RAM_CONTROL_FINISH 3 -/* - * This function allows override of where the RAM page - * is saved (such as RDMA, for example.) - */ -typedef int (QEMURamSaveFunc)(QEMUFile *f, - ram_addr_t block_offset, - ram_addr_t offset, - size_t size); - typedef struct QEMUFileHooks { - QEMURamSaveFunc *save_page; } QEMUFileHooks; QEMUFile *qemu_file_new_input(QIOChannel *ioc); @@ -125,8 +115,6 @@ int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); #define RAM_SAVE_CONTROL_NOT_SUPP -1000 #define RAM_SAVE_CONTROL_DELAYED -2000 -int ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, - ram_addr_t offset, size_t size); QIOChannel *qemu_file_get_ioc(QEMUFile *file); #endif diff --git a/migration/rdma.h b/migration/rdma.h index 8df8b4089a..09a16c1e3c 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -17,6 +17,8 @@ #ifndef QEMU_MIGRATION_RDMA_H #define QEMU_MIGRATION_RDMA_H +#include "exec/memory.h" + void rdma_start_outgoing_migration(void *opaque, const char *host_port, Error **errp); @@ -28,6 +30,8 @@ int qemu_rdma_registration_handle(QEMUFile *f); int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags); int rdma_block_notification_handle(QEMUFile *f, const char *name); +int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset, + ram_addr_t offset, size_t size); #else static inline int qemu_rdma_registration_handle(QEMUFile *f) { return 0; } @@ -37,5 +41,11 @@ static inline int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } static inline int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; } +static inline +int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset, + ram_addr_t offset, size_t size) +{ + return RAM_SAVE_CONTROL_NOT_SUPP; +} #endif #endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 4a414b8976..745eaf7a5b 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -298,26 +298,6 @@ void qemu_fflush(QEMUFile *f) f->iovcnt = 0; } -int ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, - ram_addr_t offset, size_t size) -{ - if (f->hooks && f->hooks->save_page) { - int ret = f->hooks->save_page(f, block_offset, offset, size); - /* - * RAM_SAVE_CONTROL_* are negative values - */ - if (ret != RAM_SAVE_CONTROL_DELAYED && - ret != RAM_SAVE_CONTROL_NOT_SUPP) { - if (ret < 0) { - qemu_file_set_error(f, ret); - } - } - return ret; - } - - return RAM_SAVE_CONTROL_NOT_SUPP; -} - /* * Attempt to fill the buffer from the underlying file * Returns the number of bytes read, or negative value for an error. diff --git a/migration/ram.c b/migration/ram.c index d6a9f90b94..fd5c61c739 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1197,8 +1197,8 @@ static bool control_save_page(PageSearchStatus *pss, RAMBlock *block, { int ret; - ret = ram_control_save_page(pss->pss_channel, block->offset, offset, - TARGET_PAGE_SIZE); + ret = rdma_control_save_page(pss->pss_channel, block->offset, offset, + TARGET_PAGE_SIZE); if (ret == RAM_SAVE_CONTROL_NOT_SUPP) { return false; } diff --git a/migration/rdma.c b/migration/rdma.c index 6bca9e8f19..bf16990f91 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3314,6 +3314,25 @@ err: return -1; } +int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset, + ram_addr_t offset, size_t size) +{ + if (!migrate_rdma()) { + return RAM_SAVE_CONTROL_NOT_SUPP; + } + + int ret = qemu_rdma_save_page(f, block_offset, offset, size); + + if (ret != RAM_SAVE_CONTROL_DELAYED && + ret != RAM_SAVE_CONTROL_NOT_SUPP) { + if (ret < 0) { + qemu_file_set_error(f, ret); + } + } + return ret; +} + + static void rdma_accept_incoming_migration(void *opaque); static void rdma_cm_poll_handler(void *opaque) @@ -3989,7 +4008,6 @@ static const QEMUFileHooks rdma_read_hooks = { }; static const QEMUFileHooks rdma_write_hooks = { - .save_page = qemu_rdma_save_page, }; From patchwork Wed Oct 11 20:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 586CFCDB47E for ; Wed, 11 Oct 2023 20:37:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvo-0005GT-9G; Wed, 11 Oct 2023 16:35:48 -0400 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 1qqfvm-0005EL-8b for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:46 -0400 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 1qqfvk-00033f-Oz for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056544; 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=WkeaZK6VYgRr9u+laAr7zDd9jA0PYLOfVUvIKZcQa3I=; b=hgByzzWc/oym3YUZuCJ2bjK/0nyjeSJ0p3XsL686a2uR4UCvWofnMYf3h//BPICjsbtQO8 yBEVu54qpB1XG7vEFNAQ19dUFcLzlF7NLRgYWnRoRg5f4xBsmg4MHKfiXiqWnMerfvEWvV 3VQCO6ZPyI+hGAA0I5cmWxIjQfJWqIE= 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-551-mPdUnkByMNSnenn9bFnWKg-1; Wed, 11 Oct 2023 16:35:40 -0400 X-MC-Unique: mPdUnkByMNSnenn9bFnWKg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4545C185A7B2; Wed, 11 Oct 2023 20:35:40 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA157492B06; Wed, 11 Oct 2023 20:35:38 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 07/13] qemu-file: Remove QEMUFileHooks Date: Wed, 11 Oct 2023 22:35:21 +0200 Message-ID: <20231011203527.9061-8-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The only user was rdma, and its use is gone. Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/qemu-file.h | 4 ---- migration/qemu-file.c | 6 ------ migration/rdma.c | 9 --------- 3 files changed, 19 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 60510a2819..0b22d8335f 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -36,12 +36,8 @@ #define RAM_CONTROL_ROUND 1 #define RAM_CONTROL_FINISH 3 -typedef struct QEMUFileHooks { -} QEMUFileHooks; - QEMUFile *qemu_file_new_input(QIOChannel *ioc); QEMUFile *qemu_file_new_output(QIOChannel *ioc); -void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_fclose(QEMUFile *f); /* diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 745eaf7a5b..3fb25148d1 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -38,7 +38,6 @@ #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) struct QEMUFile { - const QEMUFileHooks *hooks; QIOChannel *ioc; bool is_writable; @@ -133,11 +132,6 @@ QEMUFile *qemu_file_new_input(QIOChannel *ioc) return qemu_file_new_impl(ioc, false); } -void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) -{ - f->hooks = hooks; -} - /* * Get last error for stream f with optional Error* * diff --git a/migration/rdma.c b/migration/rdma.c index bf16990f91..ca2a15be99 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -4004,13 +4004,6 @@ err: return -1; } -static const QEMUFileHooks rdma_read_hooks = { -}; - -static const QEMUFileHooks rdma_write_hooks = { -}; - - static void qio_channel_rdma_finalize(Object *obj) { QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(obj); @@ -4062,7 +4055,6 @@ static QEMUFile *rdma_new_input(RDMAContext *rdma) rioc->file = qemu_file_new_input(QIO_CHANNEL(rioc)); rioc->rdmain = rdma; rioc->rdmaout = rdma->return_path; - qemu_file_set_hooks(rioc->file, &rdma_read_hooks); return rioc->file; } @@ -4074,7 +4066,6 @@ static QEMUFile *rdma_new_output(RDMAContext *rdma) rioc->file = qemu_file_new_output(QIO_CHANNEL(rioc)); rioc->rdmaout = rdma; rioc->rdmain = rdma->return_path; - qemu_file_set_hooks(rioc->file, &rdma_write_hooks); return rioc->file; } From patchwork Wed Oct 11 20:35:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2488CDB47E for ; Wed, 11 Oct 2023 20:37:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvu-0005Ho-4a; Wed, 11 Oct 2023 16:35:54 -0400 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 1qqfvs-0005HJ-Io for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfvp-00035F-VY for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056548; 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=tRK5ENGEPeGTzcHGfH3u9nvv9hiBkyVzSRFra10gAkg=; b=RCnXCOr5VcM6PzcqK2mzOyYSrkgE26eNfqhflmGBaLTVmXYTKmyJtoGRCKp7FGHl+UoKIG hZUUeLCsDdxPUwCnLqIEOiEWJZrHWvXxjTZRqvfhGveA7CAcey3FiGh5bMsIo25AZf5EG3 drLWYhaqG7q0Xj+6Zk0hY43MZ0wAMDc= 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-678-VnciLxV0P-KlsMPZ5A-25A-1; Wed, 11 Oct 2023 16:35:41 -0400 X-MC-Unique: VnciLxV0P-KlsMPZ5A-25A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F27E811E88; Wed, 11 Oct 2023 20:35:41 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88223492B06; Wed, 11 Oct 2023 20:35:40 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 08/13] migration/rdma: Move rdma constants from qemu-file.h to rdma.h Date: Wed, 11 Oct 2023 22:35:22 +0200 Message-ID: <20231011203527.9061-9-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/qemu-file.h | 17 ----------------- migration/rdma.h | 16 ++++++++++++++++ migration/ram.c | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 0b22d8335f..a29c37b0d0 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -29,13 +29,6 @@ #include "exec/cpu-common.h" #include "io/channel.h" -/* - * Constants used by ram_control_* hooks - */ -#define RAM_CONTROL_SETUP 0 -#define RAM_CONTROL_ROUND 1 -#define RAM_CONTROL_FINISH 3 - QEMUFile *qemu_file_new_input(QIOChannel *ioc); QEMUFile *qemu_file_new_output(QIOChannel *ioc); int qemu_fclose(QEMUFile *f); @@ -101,16 +94,6 @@ void qemu_fflush(QEMUFile *f); void qemu_file_set_blocking(QEMUFile *f, bool block); int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size); -/* Whenever this is found in the data stream, the flags - * will be passed to ram_control_load_hook in the incoming-migration - * side. This lets before_ram_iterate/after_ram_iterate add - * transport-specific sections to the RAM migration data. - */ -#define RAM_SAVE_FLAG_HOOK 0x80 - -#define RAM_SAVE_CONTROL_NOT_SUPP -1000 -#define RAM_SAVE_CONTROL_DELAYED -2000 - QIOChannel *qemu_file_get_ioc(QEMUFile *file); #endif diff --git a/migration/rdma.h b/migration/rdma.h index 09a16c1e3c..1ff3718a76 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -24,6 +24,22 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port, void rdma_start_incoming_migration(const char *host_port, Error **errp); +/* + * Constants used by rdma return codes + */ +#define RAM_CONTROL_SETUP 0 +#define RAM_CONTROL_ROUND 1 +#define RAM_CONTROL_FINISH 3 + +/* + * Whenever this is found in the data stream, the flags + * will be passed to rdma functions in the incoming-migration + * side. + */ +#define RAM_SAVE_FLAG_HOOK 0x80 + +#define RAM_SAVE_CONTROL_NOT_SUPP -1000 +#define RAM_SAVE_CONTROL_DELAYED -2000 #ifdef CONFIG_RDMA int qemu_rdma_registration_handle(QEMUFile *f); diff --git a/migration/ram.c b/migration/ram.c index fd5c61c739..f9bbd17028 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -89,7 +89,7 @@ #define RAM_SAVE_FLAG_EOS 0x10 #define RAM_SAVE_FLAG_CONTINUE 0x20 #define RAM_SAVE_FLAG_XBZRLE 0x40 -/* 0x80 is reserved in qemu-file.h for RAM_SAVE_FLAG_HOOK */ +/* 0x80 is reserved in rdma.h for RAM_SAVE_FLAG_HOOK */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 #define RAM_SAVE_FLAG_MULTIFD_FLUSH 0x200 /* We can't use any flag that is bigger than 0x200 */ From patchwork Wed Oct 11 20:35:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C4C1ACDB47E for ; Wed, 11 Oct 2023 20:36:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfvq-0005Gu-2E; Wed, 11 Oct 2023 16:35:50 -0400 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 1qqfvo-0005Gi-K5 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfvl-00033n-41 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056544; 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=Y2LHK6VfUFbYPT3SpJ8DO+IC9lYv67yXDQXJvDfTekw=; b=WRHvRmy9EwGJByZxhsod2oyoJj34rmvieExWm7R25/hcd2t304+Th8Cgk/YJBxOdAw+V3L MvIjoBfrzSHLGgRVB4sk+f4eWCQaknt0u1LKDADTM0b5W4/0fdTndS3M2/OpSWMSMI09lt y3/SF3slbKyiIGw+gklBtZGHZqX+vzU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-680-V7gF9mTiMt-mlrCODgcVSA-1; Wed, 11 Oct 2023 16:35:43 -0400 X-MC-Unique: V7gF9mTiMt-mlrCODgcVSA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 05AEC1C09A4B; Wed, 11 Oct 2023 20:35:43 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3C1C492B06; Wed, 11 Oct 2023 20:35:41 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 09/13] migration/rdma: Remove qemu_ prefix from exported functions Date: Wed, 11 Oct 2023 22:35:23 +0200 Message-ID: <20231011203527.9061-10-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Functions are long enough even without this. Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/rdma.h | 12 ++++++------ migration/ram.c | 14 +++++++------- migration/rdma.c | 40 +++++++++++++++++++--------------------- migration/trace-events | 28 ++++++++++++++-------------- 4 files changed, 46 insertions(+), 48 deletions(-) diff --git a/migration/rdma.h b/migration/rdma.h index 1ff3718a76..30b15b4466 100644 --- a/migration/rdma.h +++ b/migration/rdma.h @@ -42,19 +42,19 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp); #define RAM_SAVE_CONTROL_DELAYED -2000 #ifdef CONFIG_RDMA -int qemu_rdma_registration_handle(QEMUFile *f); -int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags); -int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags); +int rdma_registration_handle(QEMUFile *f); +int rdma_registration_start(QEMUFile *f, uint64_t flags); +int rdma_registration_stop(QEMUFile *f, uint64_t flags); int rdma_block_notification_handle(QEMUFile *f, const char *name); int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size); #else static inline -int qemu_rdma_registration_handle(QEMUFile *f) { return 0; } +int rdma_registration_handle(QEMUFile *f) { return 0; } static inline -int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } +int rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; } static inline -int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } +int rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; } static inline int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; } static inline diff --git a/migration/ram.c b/migration/ram.c index f9bbd17028..2f65535d05 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3063,12 +3063,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque) } } - ret = qemu_rdma_registration_start(f, RAM_CONTROL_SETUP); + ret = rdma_registration_start(f, RAM_CONTROL_SETUP); if (ret < 0) { qemu_file_set_error(f, ret); } - ret = qemu_rdma_registration_stop(f, RAM_CONTROL_SETUP); + ret = rdma_registration_stop(f, RAM_CONTROL_SETUP); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -3130,7 +3130,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) /* Read version before ram_list.blocks */ smp_rmb(); - ret = qemu_rdma_registration_start(f, RAM_CONTROL_ROUND); + ret = rdma_registration_start(f, RAM_CONTROL_ROUND); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -3190,7 +3190,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. */ - ret = qemu_rdma_registration_stop(f, RAM_CONTROL_ROUND); + ret = rdma_registration_stop(f, RAM_CONTROL_ROUND); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -3241,7 +3241,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) migration_bitmap_sync_precopy(rs, true); } - ret = qemu_rdma_registration_start(f, RAM_CONTROL_FINISH); + ret = rdma_registration_start(f, RAM_CONTROL_FINISH); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -3267,7 +3267,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) ram_flush_compressed_data(rs); - int ret = qemu_rdma_registration_stop(f, RAM_CONTROL_FINISH); + int ret = rdma_registration_stop(f, RAM_CONTROL_FINISH); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -4074,7 +4074,7 @@ static int ram_load_precopy(QEMUFile *f) } break; case RAM_SAVE_FLAG_HOOK: - ret = qemu_rdma_registration_handle(f); + ret = rdma_registration_handle(f); if (ret < 0) { qemu_file_set_error(f, ret); } diff --git a/migration/rdma.c b/migration/rdma.c index ca2a15be99..d3bba05262 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3541,7 +3541,7 @@ static int dest_ram_sort_func(const void *a, const void *b) * * Keep doing this until the source tells us to stop. */ -int qemu_rdma_registration_handle(QEMUFile *f) +int rdma_registration_handle(QEMUFile *f) { RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult), .type = RDMA_CONTROL_REGISTER_RESULT, @@ -3587,7 +3587,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) local = &rdma->local_ram_blocks; do { - trace_qemu_rdma_registration_handle_wait(); + trace_rdma_registration_handle_wait(); ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE, &err); @@ -3607,9 +3607,9 @@ int qemu_rdma_registration_handle(QEMUFile *f) comp = (RDMACompress *) rdma->wr_data[idx].control_curr; network_to_compress(comp); - trace_qemu_rdma_registration_handle_compress(comp->length, - comp->block_idx, - comp->offset); + trace_rdma_registration_handle_compress(comp->length, + comp->block_idx, + comp->offset); if (comp->block_idx >= rdma->local_ram_blocks.nb_blocks) { error_report("rdma: 'compress' bad block index %u (vs %d)", (unsigned int)comp->block_idx, @@ -3625,11 +3625,11 @@ int qemu_rdma_registration_handle(QEMUFile *f) break; case RDMA_CONTROL_REGISTER_FINISHED: - trace_qemu_rdma_registration_handle_finished(); + trace_rdma_registration_handle_finished(); return 0; case RDMA_CONTROL_RAM_BLOCKS_REQUEST: - trace_qemu_rdma_registration_handle_ram_blocks(); + trace_rdma_registration_handle_ram_blocks(); /* Sort our local RAM Block list so it's the same as the source, * we can do this since we've filled in a src_index in the list @@ -3668,7 +3668,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) rdma->dest_blocks[i].length = local->block[i].length; dest_block_to_network(&rdma->dest_blocks[i]); - trace_qemu_rdma_registration_handle_ram_blocks_loop( + trace_rdma_registration_handle_ram_blocks_loop( local->block[i].block_name, local->block[i].offset, local->block[i].length, @@ -3691,7 +3691,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) break; case RDMA_CONTROL_REGISTER_REQUEST: - trace_qemu_rdma_registration_handle_register(head.repeat); + trace_rdma_registration_handle_register(head.repeat); reg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; @@ -3705,7 +3705,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) reg_result = &results[count]; - trace_qemu_rdma_registration_handle_register_loop(count, + trace_rdma_registration_handle_register_loop(count, reg->current_index, reg->key.current_addr, reg->chunks); if (reg->current_index >= rdma->local_ram_blocks.nb_blocks) { @@ -3753,8 +3753,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) reg_result->host_addr = (uintptr_t)block->local_host_addr; - trace_qemu_rdma_registration_handle_register_rkey( - reg_result->rkey); + trace_rdma_registration_handle_register_rkey(reg_result->rkey); result_to_network(reg_result); } @@ -3768,7 +3767,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) } break; case RDMA_CONTROL_UNREGISTER_REQUEST: - trace_qemu_rdma_registration_handle_unregister(head.repeat); + trace_rdma_registration_handle_unregister(head.repeat); unreg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; @@ -3776,7 +3775,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) reg = ®isters[count]; network_to_register(reg); - trace_qemu_rdma_registration_handle_unregister_loop(count, + trace_rdma_registration_handle_unregister_loop(count, reg->current_index, reg->key.chunk); block = &(rdma->local_ram_blocks.block[reg->current_index]); @@ -3792,8 +3791,7 @@ int qemu_rdma_registration_handle(QEMUFile *f) rdma->total_registrations--; - trace_qemu_rdma_registration_handle_unregister_success( - reg->key.chunk); + trace_rdma_registration_handle_unregister_success(reg->key.chunk); } ret = qemu_rdma_post_send_control(rdma, NULL, &unreg_resp, &err); @@ -3860,7 +3858,7 @@ int rdma_block_notification_handle(QEMUFile *f, const char *name) return 0; } -int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) +int rdma_registration_start(QEMUFile *f, uint64_t flags) { if (!migrate_rdma () || migration_in_postcopy()) { return 0; @@ -3877,7 +3875,7 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) return -1; } - trace_qemu_rdma_registration_start(flags); + trace_rdma_registration_start(flags); qemu_put_be64(f, RAM_SAVE_FLAG_HOOK); qemu_fflush(f); @@ -3888,7 +3886,7 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) * Inform dest that dynamic registrations are done for now. * First, flush writes, if any. */ -int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) +int rdma_registration_stop(QEMUFile *f, uint64_t flags) { QIOChannelRDMA *rioc; Error *err = NULL; @@ -3924,7 +3922,7 @@ int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) int reg_result_idx, i, nb_dest_blocks; head.type = RDMA_CONTROL_RAM_BLOCKS_REQUEST; - trace_qemu_rdma_registration_stop_ram(); + trace_rdma_registration_stop_ram(); /* * Make sure that we parallelize the pinning on both sides. @@ -3988,7 +3986,7 @@ int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) } } - trace_qemu_rdma_registration_stop(flags); + trace_rdma_registration_stop(flags); head.type = RDMA_CONTROL_REGISTER_FINISHED; ret = qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL, &err); diff --git a/migration/trace-events b/migration/trace-events index ee9c8f4d63..b56442d7dd 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -231,20 +231,6 @@ qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.." qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %" PRIu64 " bytes @ %p" qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Paging memory region: %s" qemu_rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const char *res) "Try to advise block %s prefetch at %" PRIu32 "@0x%" PRIx64 ": %s" -qemu_rdma_registration_handle_compress(int64_t length, int index, int64_t offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64 -qemu_rdma_registration_handle_finished(void) "" -qemu_rdma_registration_handle_ram_blocks(void) "" -qemu_rdma_registration_handle_ram_blocks_loop(const char *name, uint64_t offset, uint64_t length, void *local_host_addr, unsigned int src_index) "%s: @0x%" PRIx64 "/%" PRIu64 " host:@%p src_index: %u" -qemu_rdma_registration_handle_register(int requests) "%d requests" -qemu_rdma_registration_handle_register_loop(int req, int index, uint64_t addr, uint64_t chunks) "Registration request (%d): index %d, current_addr %" PRIu64 " chunks: %" PRIu64 -qemu_rdma_registration_handle_register_rkey(int rkey) "0x%x" -qemu_rdma_registration_handle_unregister(int requests) "%d requests" -qemu_rdma_registration_handle_unregister_loop(int count, int index, uint64_t chunk) "Unregistration request (%d): index %d, chunk %" PRIu64 -qemu_rdma_registration_handle_unregister_success(uint64_t chunk) "%" PRIu64 -qemu_rdma_registration_handle_wait(void) "" -qemu_rdma_registration_start(uint64_t flags) "%" PRIu64 -qemu_rdma_registration_stop(uint64_t flags) "%" PRIu64 -qemu_rdma_registration_stop_ram(void) "" qemu_rdma_resolve_host_trying(const char *host, const char *ip) "Trying %s => %s" qemu_rdma_signal_unregister_append(uint64_t chunk, int pos) "Appending unregister chunk %" PRIu64 " at position %d" qemu_rdma_signal_unregister_already(uint64_t chunk) "Unregister chunk %" PRIu64 " already in queue" @@ -263,6 +249,20 @@ qemu_rdma_write_one_zero(uint64_t chunk, int len, int index, int64_t offset) "En rdma_add_block(const char *block_name, int block, uint64_t addr, uint64_t offset, uint64_t len, uint64_t end, uint64_t bits, int chunks) "Added Block: '%s':%d, addr: %" PRIu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: %" PRIu64 " bits %" PRIu64 " chunks %d" rdma_block_notification_handle(const char *name, int index) "%s at %d" rdma_delete_block(void *block, uint64_t addr, uint64_t offset, uint64_t len, uint64_t end, uint64_t bits, int chunks) "Deleted Block: %p, addr: %" PRIu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: %" PRIu64 " bits %" PRIu64 " chunks %d" +rdma_registration_handle_compress(int64_t length, int index, int64_t offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64 +rdma_registration_handle_finished(void) "" +rdma_registration_handle_ram_blocks(void) "" +rdma_registration_handle_ram_blocks_loop(const char *name, uint64_t offset, uint64_t length, void *local_host_addr, unsigned int src_index) "%s: @0x%" PRIx64 "/%" PRIu64 " host:@%p src_index: %u" +rdma_registration_handle_register(int requests) "%d requests" +rdma_registration_handle_register_loop(int req, int index, uint64_t addr, uint64_t chunks) "Registration request (%d): index %d, current_addr %" PRIu64 " chunks: %" PRIu64 +rdma_registration_handle_register_rkey(int rkey) "0x%x" +rdma_registration_handle_unregister(int requests) "%d requests" +rdma_registration_handle_unregister_loop(int count, int index, uint64_t chunk) "Unregistration request (%d): index %d, chunk %" PRIu64 +rdma_registration_handle_unregister_success(uint64_t chunk) "%" PRIu64 +rdma_registration_handle_wait(void) "" +rdma_registration_start(uint64_t flags) "%" PRIu64 +rdma_registration_stop(uint64_t flags) "%" PRIu64 +rdma_registration_stop_ram(void) "" rdma_start_incoming_migration(void) "" rdma_start_incoming_migration_after_dest_init(void) "" rdma_start_incoming_migration_after_rdma_listen(void) "" From patchwork Wed Oct 11 20:35:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25F47CDB482 for ; Wed, 11 Oct 2023 20:36:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfw9-0005Pf-Cu; Wed, 11 Oct 2023 16:36:09 -0400 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 1qqfw3-0005OT-UM for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:03 -0400 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 1qqfw0-0003CJ-DA for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056559; 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=2nWMXP3oPeoJgr5juTsatg7IVNwzncGL9zS6ISTx9tI=; b=eBYU7bliEmE3g3i83HoxBJdqzhchTr8Z4XzSjrPk/n9Bl1hxu6TcQRx8DcFVPjzvjTk7DU MubeKo2axf49JM0xYeRzLX4WXkhvV0Am9jxaP7WBV1h+Ze0L01SYWE4TdJT5LQ8Yy8urN2 cLxonuCnx3joIimHV/JfXsGPoxwtTB4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-A45FMQTLNei6IKweNc_jSw-1; Wed, 11 Oct 2023 16:35:44 -0400 X-MC-Unique: A45FMQTLNei6IKweNc_jSw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F5291C09A4D; Wed, 11 Oct 2023 20:35:44 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 48DE0492B06; Wed, 11 Oct 2023 20:35:43 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 10/13] migration/rdma: Check sooner if we are in postcopy for save_page() Date: Wed, 11 Oct 2023 22:35:24 +0200 Message-ID: <20231011203527.9061-11-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Reviewed-by: Li Zhijian --- migration/rdma.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index d3bba05262..932d4eda9b 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3240,10 +3240,6 @@ static int qemu_rdma_save_page(QEMUFile *f, ram_addr_t block_offset, RDMAContext *rdma; int ret; - if (migration_in_postcopy()) { - return RAM_SAVE_CONTROL_NOT_SUPP; - } - RCU_READ_LOCK_GUARD(); rdma = qatomic_rcu_read(&rioc->rdmaout); @@ -3317,7 +3313,7 @@ err: int rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offset, size_t size) { - if (!migrate_rdma()) { + if (!migrate_rdma() || migration_in_postcopy()) { return RAM_SAVE_CONTROL_NOT_SUPP; } From patchwork Wed Oct 11 20:35:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE890CDB483 for ; Wed, 11 Oct 2023 20:37:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfw3-0005LQ-27; Wed, 11 Oct 2023 16:36:03 -0400 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 1qqfvx-0005I8-D7 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:59 -0400 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 1qqfvt-00037H-U9 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:35:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056551; 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=s/qGmGYXe6gL5MhKv99upggtxl9WhBfonC2F94zdk/w=; b=PU03wMcgugas+5rMHEnMUxuMfLU2STt5x3tqZmToLsR+3kwhtx31fxodzoBOThtyWvNNSA gXg1K5f/CW7jwI0zWRVp78TodO59JtvTN0YJbFbanQTtk4dcrv/i9KjArU3sCzJo6Jo7gr kcNovBbPs5MD1/lIGfJ5mJCxaa3gjiM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-203-upP1kMxFPqOImG5QQGaMAg-1; Wed, 11 Oct 2023 16:35:46 -0400 X-MC-Unique: upP1kMxFPqOImG5QQGaMAg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9C0782825EB3; Wed, 11 Oct 2023 20:35:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92C2B492B06; Wed, 11 Oct 2023 20:35:44 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 11/13] migration/rdma: Use i as for index instead of idx Date: Wed, 11 Oct 2023 22:35:25 +0200 Message-ID: <20231011203527.9061-12-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Once there, all the uses are local to the for, so declare the variable inside the for statement. Signed-off-by: Juan Quintela Reviewed-by: Fabiano Rosas Reviewed-by: Li Zhijian --- migration/rdma.c | 49 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 932d4eda9b..e29e5551d1 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2354,7 +2354,6 @@ static int qemu_rdma_write(RDMAContext *rdma, static void qemu_rdma_cleanup(RDMAContext *rdma) { Error *err = NULL; - int idx; if (rdma->cm_id && rdma->connected) { if ((rdma->errored || @@ -2381,12 +2380,12 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) g_free(rdma->dest_blocks); rdma->dest_blocks = NULL; - for (idx = 0; idx < RDMA_WRID_MAX; idx++) { - if (rdma->wr_data[idx].control_mr) { + for (int i = 0; i < RDMA_WRID_MAX; i++) { + if (rdma->wr_data[i].control_mr) { rdma->total_registrations--; - ibv_dereg_mr(rdma->wr_data[idx].control_mr); + ibv_dereg_mr(rdma->wr_data[i].control_mr); } - rdma->wr_data[idx].control_mr = NULL; + rdma->wr_data[i].control_mr = NULL; } if (rdma->local_ram_blocks.block) { @@ -2452,7 +2451,7 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **errp) { - int ret, idx; + int ret; /* * Will be validated against destination's actual capabilities @@ -2480,18 +2479,17 @@ static int qemu_rdma_source_init(RDMAContext *rdma, bool pin_all, Error **errp) /* Build the hash that maps from offset to RAMBlock */ rdma->blockmap = g_hash_table_new(g_direct_hash, g_direct_equal); - for (idx = 0; idx < rdma->local_ram_blocks.nb_blocks; idx++) { + for (int i = 0; i < rdma->local_ram_blocks.nb_blocks; i++) { g_hash_table_insert(rdma->blockmap, - (void *)(uintptr_t)rdma->local_ram_blocks.block[idx].offset, - &rdma->local_ram_blocks.block[idx]); + (void *)(uintptr_t)rdma->local_ram_blocks.block[i].offset, + &rdma->local_ram_blocks.block[i]); } - for (idx = 0; idx < RDMA_WRID_MAX; idx++) { - ret = qemu_rdma_reg_control(rdma, idx); + for (int i = 0; i < RDMA_WRID_MAX; i++) { + ret = qemu_rdma_reg_control(rdma, i); if (ret < 0) { - error_setg(errp, - "RDMA ERROR: rdma migration: error registering %d control!", - idx); + error_setg(errp, "RDMA ERROR: rdma migration: error " + "registering %d control!", i); goto err_rdma_source_init; } } @@ -2625,16 +2623,16 @@ err_rdma_source_connect: static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) { Error *err = NULL; - int ret, idx; + int ret; struct rdma_cm_id *listen_id; char ip[40] = "unknown"; struct rdma_addrinfo *res, *e; char port_str[16]; int reuse = 1; - for (idx = 0; idx < RDMA_WRID_MAX; idx++) { - rdma->wr_data[idx].control_len = 0; - rdma->wr_data[idx].control_curr = NULL; + for (int i = 0; i < RDMA_WRID_MAX; i++) { + rdma->wr_data[i].control_len = 0; + rdma->wr_data[i].control_curr = NULL; } if (!rdma->host || !rdma->host[0]) { @@ -2723,11 +2721,9 @@ err_dest_init_create_listen_id: static void qemu_rdma_return_path_dest_init(RDMAContext *rdma_return_path, RDMAContext *rdma) { - int idx; - - for (idx = 0; idx < RDMA_WRID_MAX; idx++) { - rdma_return_path->wr_data[idx].control_len = 0; - rdma_return_path->wr_data[idx].control_curr = NULL; + for (int i = 0; i < RDMA_WRID_MAX; i++) { + rdma_return_path->wr_data[i].control_len = 0; + rdma_return_path->wr_data[i].control_curr = NULL; } /*the CM channel and CM id is shared*/ @@ -3377,7 +3373,6 @@ static int qemu_rdma_accept(RDMAContext *rdma) struct rdma_cm_event *cm_event; struct ibv_context *verbs; int ret; - int idx; ret = rdma_get_cm_event(rdma->channel, &cm_event); if (ret < 0) { @@ -3463,10 +3458,10 @@ static int qemu_rdma_accept(RDMAContext *rdma) qemu_rdma_init_ram_blocks(rdma); - for (idx = 0; idx < RDMA_WRID_MAX; idx++) { - ret = qemu_rdma_reg_control(rdma, idx); + for (int i = 0; i < RDMA_WRID_MAX; i++) { + ret = qemu_rdma_reg_control(rdma, i); if (ret < 0) { - error_report("rdma: error registering %d control", idx); + error_report("rdma: error registering %d control", i); goto err_rdma_dest_wait; } } From patchwork Wed Oct 11 20:35:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 769E2CDB47E for ; Wed, 11 Oct 2023 20:37:33 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfwM-0005ka-3G; Wed, 11 Oct 2023 16:36:22 -0400 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 1qqfwL-0005iA-By for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfwJ-0003FO-IU for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056576; 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=hMZ/Im8CDGWdic4kq0mnTpu0EPhSBpilRlc7eATBD/E=; b=fnOfe3iCcNARy8X1jSSV2wVxxpG2iPS9i++NVlIiZoqaqGeDRw788/FijCYiB6HkyuQ+sT toSWPAvZa+L+q5L11z01VaIzNMqRjio7wrt4md7jOUFRGvxQzgG2yaOFnDI8JKmrs3iwJf 7Ts951puQCpKl1cUgj6edo3fThh+CDs= 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-154-tDcIV7uYO8mRr1GBGUtQAw-1; Wed, 11 Oct 2023 16:35:51 -0400 X-MC-Unique: tDcIV7uYO8mRr1GBGUtQAw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E75C4858280; Wed, 11 Oct 2023 20:35:46 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFD36492B07; Wed, 11 Oct 2023 20:35:45 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 12/13] migration/rdma: Declare for index variables local Date: Wed, 11 Oct 2023 22:35:26 +0200 Message-ID: <20231011203527.9061-13-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Declare all variables that are only used inside a for loop inside the for statement. This makes clear that they are not used outside of the for loop. Signed-off-by: Juan Quintela Reviewed-by: Fabiano Rosas Reviewed-by: Li Zhijian --- migration/rdma.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index e29e5551d1..a43527a83c 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -559,10 +559,8 @@ static void rdma_add_block(RDMAContext *rdma, const char *block_name, local->block = g_new0(RDMALocalBlock, local->nb_blocks + 1); if (local->nb_blocks) { - int x; - if (rdma->blockmap) { - for (x = 0; x < local->nb_blocks; x++) { + for (int x = 0; x < local->nb_blocks; x++) { g_hash_table_remove(rdma->blockmap, (void *)(uintptr_t)old[x].offset); g_hash_table_insert(rdma->blockmap, @@ -649,15 +647,12 @@ static void rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block) { RDMALocalBlocks *local = &rdma->local_ram_blocks; RDMALocalBlock *old = local->block; - int x; if (rdma->blockmap) { g_hash_table_remove(rdma->blockmap, (void *)(uintptr_t)block->offset); } if (block->pmr) { - int j; - - for (j = 0; j < block->nb_chunks; j++) { + for (int j = 0; j < block->nb_chunks; j++) { if (!block->pmr[j]) { continue; } @@ -687,7 +682,7 @@ static void rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block) block->block_name = NULL; if (rdma->blockmap) { - for (x = 0; x < local->nb_blocks; x++) { + for (int x = 0; x < local->nb_blocks; x++) { g_hash_table_remove(rdma->blockmap, (void *)(uintptr_t)old[x].offset); } @@ -705,7 +700,7 @@ static void rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block) memcpy(local->block + block->index, old + (block->index + 1), sizeof(RDMALocalBlock) * (local->nb_blocks - (block->index + 1))); - for (x = block->index; x < local->nb_blocks - 1; x++) { + for (int x = block->index; x < local->nb_blocks - 1; x++) { local->block[x].index--; } } @@ -725,7 +720,7 @@ static void rdma_delete_block(RDMAContext *rdma, RDMALocalBlock *block) local->nb_blocks--; if (local->nb_blocks && rdma->blockmap) { - for (x = 0; x < local->nb_blocks; x++) { + for (int x = 0; x < local->nb_blocks; x++) { g_hash_table_insert(rdma->blockmap, (void *)(uintptr_t)local->block[x].offset, &local->block[x]); @@ -828,12 +823,12 @@ static int qemu_rdma_broken_ipv6_kernel(struct ibv_context *verbs, Error **errp) * Otherwise, there are no guarantees until the bug is fixed in linux. */ if (!verbs) { - int num_devices, x; + int num_devices; struct ibv_device **dev_list = ibv_get_device_list(&num_devices); bool roce_found = false; bool ib_found = false; - for (x = 0; x < num_devices; x++) { + for (int x = 0; x < num_devices; x++) { verbs = ibv_open_device(dev_list[x]); /* * ibv_open_device() is not documented to set errno. If @@ -925,7 +920,6 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) char port_str[16]; struct rdma_cm_event *cm_event; char ip[40] = "unknown"; - struct rdma_addrinfo *e; if (rdma->host == NULL || !strcmp(rdma->host, "")) { error_setg(errp, "RDMA ERROR: RDMA hostname has not been set"); @@ -957,7 +951,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) } /* Try all addresses, saving the first error in @err */ - for (e = res; e != NULL; e = e->ai_next) { + for (struct rdma_addrinfo *e = res; e != NULL; e = e->ai_next) { Error **local_errp = err ? NULL : &err; inet_ntop(e->ai_family, @@ -2777,7 +2771,7 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *ioc, RDMAContext *rdma; int ret; ssize_t done = 0; - size_t i, len; + size_t len; RCU_READ_LOCK_GUARD(); rdma = qatomic_rcu_read(&rioc->rdmaout); @@ -2803,7 +2797,7 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *ioc, return -1; } - for (i = 0; i < niov; i++) { + for (int i = 0; i < niov; i++) { size_t remaining = iov[i].iov_len; uint8_t * data = (void *)iov[i].iov_base; while (remaining) { @@ -2866,7 +2860,7 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, RDMAControlHeader head; int ret; ssize_t done = 0; - size_t i, len; + size_t len; RCU_READ_LOCK_GUARD(); rdma = qatomic_rcu_read(&rioc->rdmain); @@ -2882,7 +2876,7 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, return -1; } - for (i = 0; i < niov; i++) { + for (int i = 0; i < niov; i++) { size_t want = iov[i].iov_len; uint8_t *data = (void *)iov[i].iov_base; @@ -3557,8 +3551,6 @@ int rdma_registration_handle(QEMUFile *f) void *host_addr; int ret; int idx = 0; - int count = 0; - int i = 0; if (!migrate_rdma()) { return 0; @@ -3629,7 +3621,7 @@ int rdma_registration_handle(QEMUFile *f) qsort(rdma->local_ram_blocks.block, rdma->local_ram_blocks.nb_blocks, sizeof(RDMALocalBlock), dest_ram_sort_func); - for (i = 0; i < local->nb_blocks; i++) { + for (int i = 0; i < local->nb_blocks; i++) { local->block[i].index = i; } @@ -3647,7 +3639,7 @@ int rdma_registration_handle(QEMUFile *f) * Both sides use the "remote" structure to communicate and update * their "local" descriptions with what was sent. */ - for (i = 0; i < local->nb_blocks; i++) { + for (int i = 0; i < local->nb_blocks; i++) { rdma->dest_blocks[i].remote_host_addr = (uintptr_t)(local->block[i].local_host_addr); @@ -3687,7 +3679,7 @@ int rdma_registration_handle(QEMUFile *f) reg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; - for (count = 0; count < head.repeat; count++) { + for (int count = 0; count < head.repeat; count++) { uint64_t chunk; uint8_t *chunk_start, *chunk_end; @@ -3762,7 +3754,7 @@ int rdma_registration_handle(QEMUFile *f) unreg_resp.repeat = head.repeat; registers = (RDMARegister *) rdma->wr_data[idx].control_curr; - for (count = 0; count < head.repeat; count++) { + for (int count = 0; count < head.repeat; count++) { reg = ®isters[count]; network_to_register(reg); @@ -3910,7 +3902,7 @@ int rdma_registration_stop(QEMUFile *f, uint64_t flags) if (flags == RAM_CONTROL_SETUP) { RDMAControlHeader resp = {.type = RDMA_CONTROL_RAM_BLOCKS_RESULT }; RDMALocalBlocks *local = &rdma->local_ram_blocks; - int reg_result_idx, i, nb_dest_blocks; + int reg_result_idx, nb_dest_blocks; head.type = RDMA_CONTROL_RAM_BLOCKS_REQUEST; trace_rdma_registration_stop_ram(); @@ -3958,7 +3950,7 @@ int rdma_registration_stop(QEMUFile *f, uint64_t flags) qemu_rdma_move_header(rdma, reg_result_idx, &resp); memcpy(rdma->dest_blocks, rdma->wr_data[reg_result_idx].control_curr, resp.len); - for (i = 0; i < nb_dest_blocks; i++) { + for (int i = 0; i < nb_dest_blocks; i++) { network_to_dest_block(&rdma->dest_blocks[i]); /* We require that the blocks are in the same order */ From patchwork Wed Oct 11 20:35:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 13417933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F847CDB47E for ; Wed, 11 Oct 2023 20:37:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqfwA-0005RC-NW; Wed, 11 Oct 2023 16:36:10 -0400 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 1qqfw6-0005Oq-OG for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqfw1-0003CR-P1 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 16:36:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697056560; 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=Qtmc3KGTusy7cfgz4qom4SunS56CKsgeizxUNwC5MCc=; b=Mh33Wf4hrlB9B5akFk6uEuHUcNIRY5gHnzq2ZgYbZAH47YB/Pmga/kPv4dFg//TIkVHwmZ di0LcWcbqfDNjY/4pixoc56rE84Zrb3AtAvBgAl3TkIyPEm700StikN3kl/7So9yafhNCv xp8OjjndD6Xb+enPKfY43B/9tdYsJ5U= 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-312-6Ta4wqfhM6qVc3ncW0WE-A-1; Wed, 11 Oct 2023 16:35:49 -0400 X-MC-Unique: 6Ta4wqfhM6qVc3ncW0WE-A-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3CB34101A550; Wed, 11 Oct 2023 20:35:48 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3717B492B06; Wed, 11 Oct 2023 20:35:47 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Cc: Fabiano Rosas , Peter Xu , Juan Quintela , Leonardo Bras , Li Zhijian Subject: [PATCH v3 13/13] migration/rdma: Remove all "ret" variables that are used only once Date: Wed, 11 Oct 2023 22:35:27 +0200 Message-ID: <20231011203527.9061-14-quintela@redhat.com> In-Reply-To: <20231011203527.9061-1-quintela@redhat.com> References: <20231011203527.9061-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Received-SPF: pass client-ip=170.10.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Change code that is: int ret; ... ret = foo(); if (ret[ < 0]?) { to: if (foo()[ < 0]) { Signed-off-by: Juan Quintela Reviewed-by: Fabiano Rosas Reviewed-by: Li Zhijian --- migration/rdma.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index a43527a83c..c382588b26 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1107,7 +1107,6 @@ err_alloc_pd_cq: static int qemu_rdma_alloc_qp(RDMAContext *rdma) { struct ibv_qp_init_attr attr = { 0 }; - int ret; attr.cap.max_send_wr = RDMA_SIGNALED_SEND_MAX; attr.cap.max_recv_wr = 3; @@ -1117,8 +1116,7 @@ static int qemu_rdma_alloc_qp(RDMAContext *rdma) attr.recv_cq = rdma->recv_cq; attr.qp_type = IBV_QPT_RC; - ret = rdma_create_qp(rdma->cm_id, rdma->pd, &attr); - if (ret < 0) { + if (rdma_create_qp(rdma->cm_id, rdma->pd, &attr) < 0) { return -1; } @@ -1130,8 +1128,8 @@ static int qemu_rdma_alloc_qp(RDMAContext *rdma) static bool rdma_support_odp(struct ibv_context *dev) { struct ibv_device_attr_ex attr = {0}; - int ret = ibv_query_device_ex(dev, NULL, &attr); - if (ret) { + + if (ibv_query_device_ex(dev, NULL, &attr)) { return false; } @@ -1508,7 +1506,6 @@ static int qemu_rdma_wait_comp_channel(RDMAContext *rdma, struct ibv_comp_channel *comp_channel) { struct rdma_cm_event *cm_event; - int ret; /* * Coroutine doesn't start until migration_fd_process_incoming() @@ -1544,8 +1541,7 @@ static int qemu_rdma_wait_comp_channel(RDMAContext *rdma, } if (pfds[1].revents) { - ret = rdma_get_cm_event(rdma->channel, &cm_event); - if (ret < 0) { + if (rdma_get_cm_event(rdma->channel, &cm_event) < 0) { return -1; } @@ -2317,12 +2313,10 @@ static int qemu_rdma_write(RDMAContext *rdma, uint64_t current_addr = block_offset + offset; uint64_t index = rdma->current_index; uint64_t chunk = rdma->current_chunk; - int ret; /* If we cannot merge it, we flush the current buffer first. */ if (!qemu_rdma_buffer_mergeable(rdma, current_addr, len)) { - ret = qemu_rdma_write_flush(rdma, errp); - if (ret < 0) { + if (qemu_rdma_write_flush(rdma, errp) < 0) { return -1; } rdma->current_length = 0; @@ -2936,7 +2930,6 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, static int qemu_rdma_drain_cq(RDMAContext *rdma) { Error *err = NULL; - int ret; if (qemu_rdma_write_flush(rdma, &err) < 0) { error_report_err(err); @@ -2944,8 +2937,7 @@ static int qemu_rdma_drain_cq(RDMAContext *rdma) } while (rdma->nb_sent) { - ret = qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL); - if (ret < 0) { + if (qemu_rdma_block_for_wrid(rdma, RDMA_WRID_RDMA_WRITE, NULL) < 0) { error_report("rdma migration: complete polling error!"); return -1; } @@ -3324,12 +3316,10 @@ static void rdma_accept_incoming_migration(void *opaque); static void rdma_cm_poll_handler(void *opaque) { RDMAContext *rdma = opaque; - int ret; struct rdma_cm_event *cm_event; MigrationIncomingState *mis = migration_incoming_get_current(); - ret = rdma_get_cm_event(rdma->channel, &cm_event); - if (ret < 0) { + if (rdma_get_cm_event(rdma->channel, &cm_event) < 0) { error_report("get_cm_event failed %d", errno); return; } @@ -4054,14 +4044,11 @@ static QEMUFile *rdma_new_output(RDMAContext *rdma) static void rdma_accept_incoming_migration(void *opaque) { RDMAContext *rdma = opaque; - int ret; QEMUFile *f; Error *local_err = NULL; trace_qemu_rdma_accept_incoming_migration(); - ret = qemu_rdma_accept(rdma); - - if (ret < 0) { + if (qemu_rdma_accept(rdma) < 0) { error_report("RDMA ERROR: Migration initialization failed"); return; }