From patchwork Wed Jul 5 16:34:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302394 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 11D88EB64DD for ; Wed, 5 Jul 2023 16:36:46 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TI-0001ba-4r; Wed, 05 Jul 2023 12:35:17 -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 1qH5TB-0001VN-Kz for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:11 -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 1qH5T9-0003b1-R1 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574906; 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=x1IaGXK1wBtXrLilN+yF3vXwn+M9gw6WL28vnSu7RWk=; b=Wm8ysF7caJyQI8tJVlgiaMbHnZE249zN17aEtGcL1q80PfFhner3QWt1eL8Ajj5Hfcd+4m TlMHTxxFnZbmARKxBgd+/rcvi5yNMOb3kSvxZlwnNxOFbJFJGGgufdmmdqfKv5zIESfhAy lASoavQYjMMCA9z+OoitNAKuDf3XEl0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-115-FPi4OSR2Ohq9xHRlrW_QAg-1; Wed, 05 Jul 2023 12:35:05 -0400 X-MC-Unique: FPi4OSR2Ohq9xHRlrW_QAg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-401e1fc831fso10171611cf.1 for ; Wed, 05 Jul 2023 09:35:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574905; x=1691166905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x1IaGXK1wBtXrLilN+yF3vXwn+M9gw6WL28vnSu7RWk=; b=djMzMp3HhCUcGqrlVRAZpYwpN48jaeIjEpzC5fD07F60KHzCqw8PEaiSjlpVTZTje+ 2SzAVJM1Yxj0qbBjZVDCG0oSnoCXowN1ONkC7lcC7P4CRvdOaGVYhxrpUiYRxaiNggDw GWqj1rRlYdHE3c/24E41xZaUZuPL//ShwDe0VFDDENthgB37iHGTQs/FOiC78kkYDUoi As87HuylN6/0W3fjRa7LXhZ7xFv1Lh8R7R+Ae22dn0o6wjgotTF4ZzhPavi+U5t5U2th WJaF215StEN2vwRpjzftBBgyiUsG51hdbfBryeU7p7gyJfM38YNB5Zeci6SOSoNjWIr7 Mujg== X-Gm-Message-State: AC+VfDyIFOyu+vFvNCe4qh3WILxE+wCoo9tV7/ueADkb4XIV/L2d9o4P nr6rWMWlzFgz/cKLINNKS6RhWesKo4ARSlRpOcO3KS0R4sPw+PsyIflNY5Tiaur6bMb3g1XWh01 fnnJB9/YsUYqaQ4mnhRr9gvj8Z5WAQCOe7RvmWrGT1wFqG6GTxRWthkllCiKJuB39T7HlBb2n X-Received: by 2002:a05:620a:45a7:b0:767:1a23:137 with SMTP id bp39-20020a05620a45a700b007671a230137mr19543413qkb.2.1688574904834; Wed, 05 Jul 2023 09:35:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EhDq2otfPQCoLFdr2sg+XMJP6hTo9FbH3eNFRjblWkNkJfjlidleQp1BMALbEKYN3dmHoaA== X-Received: by 2002:a05:620a:45a7:b0:767:1a23:137 with SMTP id bp39-20020a05620a45a700b007671a230137mr19543393qkb.2.1688574904551; Wed, 05 Jul 2023 09:35:04 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 1/7] migration: Display error in query-migrate irrelevant of status Date: Wed, 5 Jul 2023 12:34:56 -0400 Message-ID: <20230705163502.331007-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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 Display it as long as being set, irrelevant of FAILED status. E.g., it may also be applicable to PAUSED stage of postcopy, to provide hint on what has gone wrong. The error_mutex seems to be overlooked when referencing the error, add it to be very safe. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2018404 Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- qapi/migration.json | 5 ++--- migration/migration.c | 8 +++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index c050081555..ade45d564d 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -222,9 +222,8 @@ # throttled during auto-converge. This is only present when # auto-converge has started throttling guest cpus. (Since 2.7) # -# @error-desc: the human readable error description string, when -# @status is 'failed'. Clients should not attempt to parse the -# error strings. (Since 2.7) +# @error-desc: the human readable error description string. Clients +# should not attempt to parse the error strings. (Since 2.7) # # @postcopy-blocktime: total time when all vCPU were blocked during # postcopy live migration. This is only present when the diff --git a/migration/migration.c b/migration/migration.c index d75c2bd63c..6a4c245f74 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1039,9 +1039,6 @@ static void fill_source_migration_info(MigrationInfo *info) break; case MIGRATION_STATUS_FAILED: info->has_status = true; - if (s->error) { - info->error_desc = g_strdup(error_get_pretty(s->error)); - } break; case MIGRATION_STATUS_CANCELLED: info->has_status = true; @@ -1051,6 +1048,11 @@ static void fill_source_migration_info(MigrationInfo *info) break; } info->status = state; + + QEMU_LOCK_GUARD(&s->error_mutex); + if (s->error) { + info->error_desc = g_strdup(error_get_pretty(s->error)); + } } static void fill_destination_migration_info(MigrationInfo *info) From patchwork Wed Jul 5 16:34:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302393 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 26F26EB64DA for ; Wed, 5 Jul 2023 16:36:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TN-0001dP-Bj; Wed, 05 Jul 2023 12:35:21 -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 1qH5TE-0001Vv-Jx for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:13 -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 1qH5TC-0003bE-F8 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574908; 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=tJRTau+SR09fXAE0IlyF/GqILORZ33ahEu2EbKHFPQo=; b=f9j+ri25+951RhEtFNaJHPntHDdqOFcRP5iqaYsRXXMhM5icNG65mINU9vW2PcHt2c2soS wEhf5P3pD3Sa2eLAtuY7nkH9Hq5K7Y4U5ow8SDflD+YQVTZv5+y0q5eBsQ3wqy/NYXZgR3 wn1/9Cd0Ddd4MY+AKP1xGkepdGQna9g= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-sfNr0H41OoCrH25r1n7Pfg-1; Wed, 05 Jul 2023 12:35:06 -0400 X-MC-Unique: sfNr0H41OoCrH25r1n7Pfg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7673887b2cfso189624185a.1 for ; Wed, 05 Jul 2023 09:35:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574906; x=1691166906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tJRTau+SR09fXAE0IlyF/GqILORZ33ahEu2EbKHFPQo=; b=Dviu/bs4AOg+52U3S9Wswe34Uuig90BNBsRMOWnQDnCG3HYwTVnXy+B9sD1Fe9lT7z 8ySKsJZJ1h5DlkhIQimevVT7AY/ixy5E9xqj31Sm4OOVXX0+Pl51OHNnjSWTiyh41Xf5 xOi3eBz+W0cm5g7/ybx5Amy30HhI8khzBGfDey1jUkRMA9kQDWSFrOTdZx0Ct2HtU+96 yiEOThUTkP14uZlF5GzD/ts4RkkWVte7oo6QkMoUHt+4VnsHhhSCWjpWn5bWd7nmSWh5 Ymgv6BnUwJW4qvpp8qkO3csdWEuVmxUozvu159KPF/BliZ8xJOvvjbjhrQmZbUgDcZim IHyA== X-Gm-Message-State: AC+VfDyffUdHfFekaX6CSYuFx/NE+T/b3LLw+CyaE9X2Zkpp6vIP6piE J5yQQoCsRPQC7uTGdr5AobatYalVjku5LecP3kvkD9tqEWVyavfhqN0Fn0AJI/fbBw60xxGLopD NGppS0+JEwvJHQAliebQdmEfOtU0ZwRJaehxjTijodIrbwxV3W27ODmb0PzwLkmcwSaC/G0/k X-Received: by 2002:a05:620a:4010:b0:766:3190:8052 with SMTP id h16-20020a05620a401000b0076631908052mr22819750qko.0.1688574905916; Wed, 05 Jul 2023 09:35:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5/5QepMsRaPcTYSamgqdNA9EMTX/3m4ncTXj7rRq2vMcJjLpwUZckBnx4pnMxoPKiQLcWwaQ== X-Received: by 2002:a05:620a:4010:b0:766:3190:8052 with SMTP id h16-20020a05620a401000b0076631908052mr22819725qko.0.1688574905521; Wed, 05 Jul 2023 09:35:05 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 2/7] migration: Let migrate_set_error() take ownership Date: Wed, 5 Jul 2023 12:34:57 -0400 Message-ID: <20230705163502.331007-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 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, T_SCC_BODY_TEXT_LINE=-0.01, URG_BIZ=0.573 autolearn=no 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 migrate_set_error() used one error_copy() so it always copy an error. However that's not the major use case - the major use case is one would like to pass the error to migrate_set_error() without further touching the error. It can be proved if we see most of the callers are freeing the error explicitly right afterwards. There're a few outliers (only if when the caller) where we can use error_copy() explicitly there. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/migration.h | 6 +++--- migration/channel.c | 1 - migration/migration.c | 20 ++++++++++++++------ migration/multifd.c | 10 ++++------ migration/postcopy-ram.c | 1 - migration/ram.c | 1 - 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 6b31a4b371..507f2f111e 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -482,8 +482,8 @@ bool migration_has_all_channels(void); uint64_t migrate_max_downtime(void); -void migrate_set_error(MigrationState *s, const Error *error); -void migrate_fd_error(MigrationState *s, const Error *error); +void migrate_set_error(MigrationState *s, Error *error); +void migrate_fd_error(MigrationState *s, Error *error); void migrate_fd_connect(MigrationState *s, Error *error_in); @@ -528,7 +528,7 @@ int foreach_not_ignored_block(RAMBlockIterFunc func, void *opaque); void migration_make_urgent_request(void); void migration_consume_urgent_request(void); bool migration_rate_limit(void); -void migration_cancel(const Error *error); +void migration_cancel(Error *error); void populate_vfio_info(MigrationInfo *info); void reset_vfio_bytes_transferred(void); diff --git a/migration/channel.c b/migration/channel.c index ca3319a309..48b3f6abd6 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -90,7 +90,6 @@ void migration_channel_connect(MigrationState *s, } } migrate_fd_connect(s, error); - error_free(error); } diff --git a/migration/migration.c b/migration/migration.c index 6a4c245f74..e5d207699b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -161,7 +161,7 @@ void migration_object_init(void) dirty_bitmap_mig_init(); } -void migration_cancel(const Error *error) +void migration_cancel(Error *error) { if (error) { migrate_set_error(current_migration, error); @@ -1205,11 +1205,20 @@ static void migrate_fd_cleanup_bh(void *opaque) object_unref(OBJECT(s)); } -void migrate_set_error(MigrationState *s, const Error *error) +/* + * Set error for current migration state. The `error' ownership will be + * moved from the caller to MigrationState, so the caller doesn't need to + * free the error. + * + * If the caller still needs to reference the `error' passed in, one should + * use error_copy() explicitly. + */ +void migrate_set_error(MigrationState *s, Error *error) { QEMU_LOCK_GUARD(&s->error_mutex); if (!s->error) { - s->error = error_copy(error); + /* Record the first error triggered */ + s->error = error; } } @@ -1222,7 +1231,7 @@ static void migrate_error_free(MigrationState *s) } } -void migrate_fd_error(MigrationState *s, const Error *error) +void migrate_fd_error(MigrationState *s, Error *error) { trace_migrate_fd_error(error_get_pretty(error)); assert(s->to_dst_file == NULL); @@ -1688,7 +1697,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, if (!(has_resume && resume)) { yank_unregister_instance(MIGRATION_YANK_INSTANCE); } - migrate_fd_error(s, local_err); + migrate_fd_error(s, error_copy(local_err)); error_propagate(errp, local_err); return; } @@ -2611,7 +2620,6 @@ static MigThrError migration_detect_error(MigrationState *s) if (local_error) { migrate_set_error(s, local_error); - error_free(local_error); } if (state == MIGRATION_STATUS_POSTCOPY_ACTIVE && ret) { diff --git a/migration/multifd.c b/migration/multifd.c index 3387d8277f..62bc2dbf49 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -551,7 +551,6 @@ void multifd_save_cleanup(void) multifd_send_state->ops->send_cleanup(p, &local_err); if (local_err) { migrate_set_error(migrate_get_current(), local_err); - error_free(local_err); } } qemu_sem_destroy(&multifd_send_state->channels_ready); @@ -750,7 +749,6 @@ out: if (local_err) { trace_multifd_send_error(p->id); multifd_send_terminate_threads(local_err); - error_free(local_err); } /* @@ -883,7 +881,6 @@ static void multifd_new_send_channel_cleanup(MultiFDSendParams *p, */ p->quit = true; object_unref(OBJECT(ioc)); - error_free(err); } static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) @@ -1148,7 +1145,6 @@ static void *multifd_recv_thread(void *opaque) if (local_err) { multifd_recv_terminate_threads(local_err); - error_free(local_err); } qemu_mutex_lock(&p->mutex); p->running = false; @@ -1240,7 +1236,8 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) id = multifd_recv_initial_packet(ioc, &local_err); if (id < 0) { - multifd_recv_terminate_threads(local_err); + /* Copy local error because we'll also return it to caller */ + multifd_recv_terminate_threads(error_copy(local_err)); error_propagate_prepend(errp, local_err, "failed to receive packet" " via multifd channel %d: ", @@ -1253,7 +1250,8 @@ void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) if (p->c != NULL) { error_setg(&local_err, "multifd: received id '%d' already setup'", id); - multifd_recv_terminate_threads(local_err); + /* Copy local error because we'll also return it to caller */ + multifd_recv_terminate_threads(error_copy(local_err)); error_propagate(errp, local_err); return; } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 5615ec29eb..6f6fb52bf1 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1594,7 +1594,6 @@ postcopy_preempt_send_channel_done(MigrationState *s, { if (local_err) { migrate_set_error(s, local_err); - error_free(local_err); } else { migration_ioc_register_yank(ioc); s->postcopy_qemufile_src = qemu_file_new_output(ioc); diff --git a/migration/ram.c b/migration/ram.c index 5283a75f02..ba4890563d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4267,7 +4267,6 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host, */ error_setg(&err, "RAM block '%s' resized during precopy.", rb->idstr); migration_cancel(err); - error_free(err); } switch (ps) { From patchwork Wed Jul 5 16:34:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302395 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 9EAF9EB64DA for ; Wed, 5 Jul 2023 16:36:49 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TI-0001bQ-2F; Wed, 05 Jul 2023 12:35:16 -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 1qH5TE-0001Vq-8I for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:13 -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 1qH5TC-0003bM-4p for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574908; 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=XoXI2u60Rfd6U/07kOVks6txLlPvzpf0qHa8kUjUOZk=; b=cxCuPQhBX/zNq/AqQq2Hh/Rqnsr9pWDrcEOa2gK8IPTIjNQMbnt+WomeEFjgWcgLJZ4QuV SepTNe6yNSa4wA38H6fnw2fqp5nU2dUv/GRSHRIMHiNWm6XyY6xOTiCnYxQTRKJrerb71Q jAu5rZOMOm3eBStLn0IGITa5Mh6Smis= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-30-4mrD0ptMP9GAfLZ_Fjg75g-1; Wed, 05 Jul 2023 12:35:07 -0400 X-MC-Unique: 4mrD0ptMP9GAfLZ_Fjg75g-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-74faf5008bbso128202785a.0 for ; Wed, 05 Jul 2023 09:35:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574907; x=1691166907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XoXI2u60Rfd6U/07kOVks6txLlPvzpf0qHa8kUjUOZk=; b=KpkiRnJQS5WQe44DSdgwMRHAtoVWzA7zxwKVVj3Re2EVRZ3QruEPg/NRBHARaVUXtL ImhhXnwZb4K4o1+6DeDBRewIFCIvIvtYS8k15qm7SCSyJYyBDhJlvPU1cGp4dFZnoEWB 7VPaiBakuZFd8bTvpsNIcf7SxuAZgfhmDDg0dxQyUmLOyeBSWKSyogUaoZ+ZG/rN0iV+ gvq30bInjd8dSUnED6yUi0q4Z03716bBxkx0pvsrsdDwfO0OxtKgp8h5OTItLL63QKGp uExhf/yM3m8YCcre3WvBua63lhIGMEg3Jg0hnbxaZsVwfQSM/m85w75M8Ad5MMxGKcs7 kaCw== X-Gm-Message-State: AC+VfDxOGxD1D+oqDVmBltNypXL6CidH2fjLfl6wl3Yt7Y00QWg41mxp i5OZvRPLnz5rE+799JoLdXLP5xpuXGtNp1Dn+l1v+HgvDFkcXMNCN2lJa349EguG1ZUqihDJ9bg 0qe4Z/i+Mt2PuDzRpZINjyLNeqrqTgRrGPrrBqgN3S640rnCVP+cFnK6A3XrlX+1fN01Gkadq X-Received: by 2002:a05:620a:468f:b0:763:c764:577c with SMTP id bq15-20020a05620a468f00b00763c764577cmr24148056qkb.5.1688574907102; Wed, 05 Jul 2023 09:35:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5P6DjMIlpZXsWRPYWHaDsfR8lA3EefNtDpylanKXMC95Jh00vSv6mniTKuHhAKGaqteUFqOw== X-Received: by 2002:a05:620a:468f:b0:763:c764:577c with SMTP id bq15-20020a05620a468f00b00763c764577cmr24148026qkb.5.1688574906693; Wed, 05 Jul 2023 09:35:06 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 3/7] migration: Introduce migrate_has_error() Date: Wed, 5 Jul 2023 12:34:58 -0400 Message-ID: <20230705163502.331007-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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 Introduce a helper to detect whether MigrationState.error is set for whatever reason. It is intended to not taking the error_mutex here because neither do we reference the pointer, nor do we modify the pointer. State why it's safe to do so. This is preparation work for any thread (e.g. source return path thread) to setup errors in an unified way to MigrationState, rather than relying on its own way to set errors (mark_source_rp_bad()). Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/migration.h | 1 + migration/migration.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/migration/migration.h b/migration/migration.h index 507f2f111e..7d916e13e1 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -483,6 +483,7 @@ bool migration_has_all_channels(void); uint64_t migrate_max_downtime(void); void migrate_set_error(MigrationState *s, Error *error); +bool migrate_has_error(MigrationState *s); void migrate_fd_error(MigrationState *s, Error *error); void migrate_fd_connect(MigrationState *s, Error *error_in); diff --git a/migration/migration.c b/migration/migration.c index e5d207699b..c54c195603 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1222,6 +1222,21 @@ void migrate_set_error(MigrationState *s, Error *error) } } +/* + * Whether the migration state has error set? + * + * Note this function explicitly didn't use error_mutex, because it only + * reads the error pointer for a boolean status. + * + * As long as the Error* is set, it shouldn't be freed before migration + * cleanup, so any thread can use this helper to safely detect whether + * there's anything wrong happened already. + */ +bool migrate_has_error(MigrationState *s) +{ + return qatomic_read(&s->error); +} + static void migrate_error_free(MigrationState *s) { QEMU_LOCK_GUARD(&s->error_mutex); From patchwork Wed Jul 5 16:34:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302392 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 8B0D4EB64DD for ; Wed, 5 Jul 2023 16:36:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TN-0001dU-EQ; Wed, 05 Jul 2023 12:35:21 -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 1qH5TF-0001WS-M3 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:15 -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 1qH5TD-0003bh-3g for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574910; 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=aGrfk825ZP3YmCTGHj57QpLRVTqYuPZizLENAuPst8A=; b=Ok8iSOlqCUThIPV75xUjBXDsNSzPy2L+zaWGnmoL3zRw2flfFP68f4uhbk5NceZptnjYC2 Nmmx+R2ZmMorGAE4pNnkzIEA+Yl0+JXvH5zWTWjrNPbyUVufurQUOzn7qIFMEjz0P0hhY+ BOIR/NBhtdgJlEw9IjgdgTqNO+143CE= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-p0FU5Q1bNSmdnTszpRgbwg-1; Wed, 05 Jul 2023 12:35:09 -0400 X-MC-Unique: p0FU5Q1bNSmdnTszpRgbwg-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-765ad67e690so127644785a.1 for ; Wed, 05 Jul 2023 09:35:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574908; x=1691166908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aGrfk825ZP3YmCTGHj57QpLRVTqYuPZizLENAuPst8A=; b=bF1nKmwDEVuJ4BGOmqCt0bGvmsYhcWb9+O0LhkZfnwNDTOX+YabqqCe4JYXyc7I5iH 27kcHRHWPhirReblhRhdcJJ3cWF+IbGtm2uR+MxC638WRzyYg+oUJjw/7WHc882aCguI XF8PKS5glNYq7vXC9my5gKnfDX5WhOGvC0KxTMZz0x0JzePRRPajfnoa+k4QooB5t2wm Z/YgQpnhWbgOC85Lu0xPioNNW3Ri0L7VV+83tp4H1jM7CIlPR7RrIEO45Pw/n+0e+4Bd eL8zswmduiOqr8DZ3W2S4HrGJRLclzxOJfC5+W4OHRcWuIZ9Y8aruTWqQrDVpp7HFiHo inCA== X-Gm-Message-State: AC+VfDwWv7xG26pLrDsectOk8Qe8S4hTLMdqodJ7zXGQjZyckunrXg22 S2eyhRsSvEqGBCU0kwzM0V7ccKwU1IwsIrbZzqNzMbalu538qGXHI4eAu5u6KAitKtKb/7hIJXz TUIkILWijI3+No0AEL6RLs8ZKecjNnrSzaD0kSsYrGhvFaE0R3eJsqYosKQzticp9omnHmP5c X-Received: by 2002:a05:620a:2687:b0:765:97b7:cfb5 with SMTP id c7-20020a05620a268700b0076597b7cfb5mr20455469qkp.6.1688574908341; Wed, 05 Jul 2023 09:35:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ozcmX8lz7znhmsRuC0lQtZCKmSVxw8KGVVgqux29JkECtDQbUNhGx9BpAtAhQeCLRt1unQQ== X-Received: by 2002:a05:620a:2687:b0:765:97b7:cfb5 with SMTP id c7-20020a05620a268700b0076597b7cfb5mr20455442qkp.6.1688574907827; Wed, 05 Jul 2023 09:35:07 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:07 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 4/7] migration: Refactor error handling in source return path Date: Wed, 5 Jul 2023 12:34:59 -0400 Message-ID: <20230705163502.331007-5-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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 rp_state.error was a boolean used to show error happened in return path thread. That's not only duplicating error reporting (migrate_set_error), but also not good enough in that we only do error_report() and set it to true, we never can keep a history of the exact error and show it in query-migrate. To make this better, a few things done: - Use error_setg() rather than error_report() across the whole lifecycle of return path thread, keeping the error in an Error*. - Use migrate_set_error() to apply that captured error to the global migration object when error occured in this thread. - With above, no need to have mark_source_rp_bad(), remove it, alongside with rp_state.error itself. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/migration.h | 1 - migration/ram.h | 5 +- migration/migration.c | 118 ++++++++++++++++++++--------------------- migration/ram.c | 41 +++++++------- migration/trace-events | 2 +- 5 files changed, 82 insertions(+), 85 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 7d916e13e1..0fb6355225 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -297,7 +297,6 @@ struct MigrationState { /* Protected by qemu_file_lock */ QEMUFile *from_dst_file; QemuThread rp_thread; - bool error; /* * We can also check non-zero of rp_thread, but there's no "official" * way to do this, so this bool makes it slightly more elegant. diff --git a/migration/ram.h b/migration/ram.h index ea1f3c25b5..02a4af2db6 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -52,7 +52,8 @@ uint64_t ram_bytes_total(void); void mig_throttle_counter_reset(void); uint64_t ram_pagesize_summary(void); -int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len); +int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len, + Error **errp); void ram_postcopy_migrated_memory_release(MigrationState *ms); /* For outgoing discard bitmap */ void ram_postcopy_send_discard_bitmap(MigrationState *ms); @@ -72,7 +73,7 @@ void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); void ramblock_recv_bitmap_set_range(RAMBlock *rb, void *host_addr, size_t nr); int64_t ramblock_recv_bitmap_send(QEMUFile *file, const char *block_name); -int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb); +int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *rb, Error **errp); bool ramblock_page_is_discarded(RAMBlock *rb, ram_addr_t start); void postcopy_preempt_shutdown_file(MigrationState *s); void *postcopy_preempt_thread(void *opaque); diff --git a/migration/migration.c b/migration/migration.c index c54c195603..46dbfb07c4 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1417,7 +1417,6 @@ void migrate_init(MigrationState *s) s->to_dst_file = NULL; s->state = MIGRATION_STATUS_NONE; s->rp_state.from_dst_file = NULL; - s->rp_state.error = false; s->mbps = 0.0; s->pages_per_second = 0.0; s->downtime = 0; @@ -1734,16 +1733,6 @@ void qmp_migrate_continue(MigrationStatus state, Error **errp) qemu_sem_post(&s->pause_sem); } -/* migration thread support */ -/* - * Something bad happened to the RP stream, mark an error - * The caller shall print or trace something to indicate why - */ -static void mark_source_rp_bad(MigrationState *s) -{ - s->rp_state.error = true; -} - static struct rp_cmd_args { ssize_t len; /* -1 = variable */ const char *name; @@ -1765,7 +1754,7 @@ static struct rp_cmd_args { * and we don't need to send pages that have already been sent. */ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, - ram_addr_t start, size_t len) + ram_addr_t start, size_t len, Error **errp) { long our_host_ps = qemu_real_host_page_size(); @@ -1777,15 +1766,12 @@ static void migrate_handle_rp_req_pages(MigrationState *ms, const char* rbname, */ if (!QEMU_IS_ALIGNED(start, our_host_ps) || !QEMU_IS_ALIGNED(len, our_host_ps)) { - error_report("%s: Misaligned page request, start: " RAM_ADDR_FMT - " len: %zd", __func__, start, len); - mark_source_rp_bad(ms); + error_setg(errp, "MIG_RP_MSG_REQ_PAGES: Misaligned page request, start:" + RAM_ADDR_FMT " len: %zd", start, len); return; } - if (ram_save_queue_pages(rbname, start, len)) { - mark_source_rp_bad(ms); - } + ram_save_queue_pages(rbname, start, len, errp); } /* Return true to retry, false to quit */ @@ -1800,26 +1786,28 @@ static bool postcopy_pause_return_path_thread(MigrationState *s) return true; } -static int migrate_handle_rp_recv_bitmap(MigrationState *s, char *block_name) +static int migrate_handle_rp_recv_bitmap(MigrationState *s, char *block_name, + Error **errp) { RAMBlock *block = qemu_ram_block_by_name(block_name); if (!block) { - error_report("%s: invalid block name '%s'", __func__, block_name); + error_setg(errp, "MIG_RP_MSG_RECV_BITMAP has invalid block name '%s'", + block_name); return -EINVAL; } /* Fetch the received bitmap and refresh the dirty bitmap */ - return ram_dirty_bitmap_reload(s, block); + return ram_dirty_bitmap_reload(s, block, errp); } -static int migrate_handle_rp_resume_ack(MigrationState *s, uint32_t value) +static int migrate_handle_rp_resume_ack(MigrationState *s, + uint32_t value, Error **errp) { trace_source_return_path_thread_resume_ack(value); if (value != MIGRATION_RESUME_ACK_VALUE) { - error_report("%s: illegal resume_ack value %"PRIu32, - __func__, value); + error_setg(errp, "illegal resume_ack value %"PRIu32, value); return -1; } @@ -1878,49 +1866,47 @@ static void *source_return_path_thread(void *opaque) uint32_t tmp32, sibling_error; ram_addr_t start = 0; /* =0 to silence warning */ size_t len = 0, expected_len; + Error *err = NULL; int res; trace_source_return_path_thread_entry(); rcu_register_thread(); retry: - while (!ms->rp_state.error && !qemu_file_get_error(rp) && + while (!migrate_has_error(ms) && !qemu_file_get_error(rp) && migration_is_setup_or_active(ms->state)) { trace_source_return_path_thread_loop_top(); + header_type = qemu_get_be16(rp); header_len = qemu_get_be16(rp); if (qemu_file_get_error(rp)) { - mark_source_rp_bad(ms); goto out; } if (header_type >= MIG_RP_MSG_MAX || header_type == MIG_RP_MSG_INVALID) { - error_report("RP: Received invalid message 0x%04x length 0x%04x", - header_type, header_len); - mark_source_rp_bad(ms); + error_setg(&err, "Received invalid message 0x%04x length 0x%04x", + header_type, header_len); goto out; } if ((rp_cmd_args[header_type].len != -1 && header_len != rp_cmd_args[header_type].len) || header_len > sizeof(buf)) { - error_report("RP: Received '%s' message (0x%04x) with" - "incorrect length %d expecting %zu", - rp_cmd_args[header_type].name, header_type, header_len, - (size_t)rp_cmd_args[header_type].len); - mark_source_rp_bad(ms); + error_setg(&err, "Received '%s' message (0x%04x) with" + "incorrect length %d expecting %zu", + rp_cmd_args[header_type].name, header_type, header_len, + (size_t)rp_cmd_args[header_type].len); goto out; } /* We know we've got a valid header by this point */ res = qemu_get_buffer(rp, buf, header_len); if (res != header_len) { - error_report("RP: Failed reading data for message 0x%04x" - " read %d expected %d", - header_type, res, header_len); - mark_source_rp_bad(ms); + error_setg(&err, "Failed reading data for message 0x%04x" + " read %d expected %d", + header_type, res, header_len); goto out; } @@ -1930,8 +1916,7 @@ retry: sibling_error = ldl_be_p(buf); trace_source_return_path_thread_shut(sibling_error); if (sibling_error) { - error_report("RP: Sibling indicated error %d", sibling_error); - mark_source_rp_bad(ms); + error_setg(&err, "Sibling indicated error %d", sibling_error); } /* * We'll let the main thread deal with closing the RP @@ -1949,7 +1934,10 @@ retry: case MIG_RP_MSG_REQ_PAGES: start = ldq_be_p(buf); len = ldl_be_p(buf + 8); - migrate_handle_rp_req_pages(ms, NULL, start, len); + migrate_handle_rp_req_pages(ms, NULL, start, len, &err); + if (err) { + goto out; + } break; case MIG_RP_MSG_REQ_PAGES_ID: @@ -1964,32 +1952,32 @@ retry: expected_len += tmp32; } if (header_len != expected_len) { - error_report("RP: Req_Page_id with length %d expecting %zd", - header_len, expected_len); - mark_source_rp_bad(ms); + error_setg(&err, "Req_Page_id with length %d expecting %zd", + header_len, expected_len); + goto out; + } + migrate_handle_rp_req_pages(ms, (char *)&buf[13], start, len, + &err); + if (err) { goto out; } - migrate_handle_rp_req_pages(ms, (char *)&buf[13], start, len); break; case MIG_RP_MSG_RECV_BITMAP: if (header_len < 1) { - error_report("%s: missing block name", __func__); - mark_source_rp_bad(ms); + error_setg(&err, "MIG_RP_MSG_RECV_BITMAP missing block name"); goto out; } /* Format: len (1B) + idstr (<255B). This ends the idstr. */ buf[buf[0] + 1] = '\0'; - if (migrate_handle_rp_recv_bitmap(ms, (char *)(buf + 1))) { - mark_source_rp_bad(ms); + if (migrate_handle_rp_recv_bitmap(ms, (char *)(buf + 1), &err)) { goto out; } break; case MIG_RP_MSG_RESUME_ACK: tmp32 = ldl_be_p(buf); - if (migrate_handle_rp_resume_ack(ms, tmp32)) { - mark_source_rp_bad(ms); + if (migrate_handle_rp_resume_ack(ms, tmp32, &err)) { goto out; } break; @@ -2005,6 +1993,19 @@ retry: } out: + if (err) { + /* + * Collect any error in return-path thread and report it to the + * migration state object. + */ + migrate_set_error(ms, err); + /* + * We lost ownership to Error*, clear it, prepared to capture the + * next error. + */ + err = NULL; + } + res = qemu_file_get_error(rp); if (res) { if (res && migration_in_postcopy()) { @@ -2020,13 +2021,11 @@ out: * it's reset only by us above, or when migration completes */ rp = ms->rp_state.from_dst_file; - ms->rp_state.error = false; goto retry; } } trace_source_return_path_thread_bad_end(); - mark_source_rp_bad(ms); } trace_source_return_path_thread_end(); @@ -2059,8 +2058,7 @@ static int open_return_path_on_source(MigrationState *ms, return 0; } -/* Returns 0 if the RP was ok, otherwise there was an error on the RP */ -static int await_return_path_close_on_source(MigrationState *ms) +static void await_return_path_close_on_source(MigrationState *ms) { /* * If this is a normal exit then the destination will send a SHUT and the @@ -2073,13 +2071,11 @@ static int await_return_path_close_on_source(MigrationState *ms) * waiting for the destination. */ qemu_file_shutdown(ms->rp_state.from_dst_file); - mark_source_rp_bad(ms); } trace_await_return_path_close_on_source_joining(); qemu_thread_join(&ms->rp_state.rp_thread); ms->rp_state.rp_thread_created = false; trace_await_return_path_close_on_source_close(); - return ms->rp_state.error; } static inline void @@ -2382,11 +2378,11 @@ static void migration_completion(MigrationState *s) * a SHUT command). */ if (s->rp_state.rp_thread_created) { - int rp_error; trace_migration_return_path_end_before(); - rp_error = await_return_path_close_on_source(s); - trace_migration_return_path_end_after(rp_error); - if (rp_error) { + await_return_path_close_on_source(s); + trace_migration_return_path_end_after(); + /* If return path has error, should have been set here */ + if (migrate_has_error(s)) { goto fail; } } diff --git a/migration/ram.c b/migration/ram.c index ba4890563d..567b179fb9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1922,7 +1922,8 @@ static void migration_page_queue_free(RAMState *rs) * @start: starting address from the start of the RAMBlock * @len: length (in bytes) to send */ -int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len) +int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len, + Error **errp) { RAMBlock *ramblock; RAMState *rs = ram_state; @@ -1939,7 +1940,7 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len) * Shouldn't happen, we can't reuse the last RAMBlock if * it's the 1st request. */ - error_report("ram_save_queue_pages no previous block"); + error_setg(errp, "MIG_RP_MSG_REQ_PAGES has no previous block"); return -1; } } else { @@ -1947,16 +1948,17 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len) if (!ramblock) { /* We shouldn't be asked for a non-existent RAMBlock */ - error_report("ram_save_queue_pages no block '%s'", rbname); + error_setg(errp, "MIG_RP_MSG_REQ_PAGES has no block '%s'", rbname); return -1; } rs->last_req_rb = ramblock; } trace_ram_save_queue_pages(ramblock->idstr, start, len); if (!offset_in_ramblock(ramblock, start + len - 1)) { - error_report("%s request overrun start=" RAM_ADDR_FMT " len=" - RAM_ADDR_FMT " blocklen=" RAM_ADDR_FMT, - __func__, start, len, ramblock->used_length); + error_setg(errp, "MIG_RP_MSG_REQ_PAGES request overrun, " + "start=" RAM_ADDR_FMT " len=" + RAM_ADDR_FMT " blocklen=" RAM_ADDR_FMT, + start, len, ramblock->used_length); return -1; } @@ -1988,9 +1990,9 @@ int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t len) assert(len % page_size == 0); while (len) { if (ram_save_host_page_urgent(pss)) { - error_report("%s: ram_save_host_page_urgent() failed: " - "ramblock=%s, start_addr=0x"RAM_ADDR_FMT, - __func__, ramblock->idstr, start); + error_setg(errp, "ram_save_host_page_urgent() failed: " + "ramblock=%s, start_addr=0x"RAM_ADDR_FMT, + ramblock->idstr, start); ret = -1; break; } @@ -4124,7 +4126,7 @@ static void ram_dirty_bitmap_reload_notify(MigrationState *s) * This is only used when the postcopy migration is paused but wants * to resume from a middle point. */ -int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) +int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) { int ret = -EINVAL; /* from_dst_file is always valid because we're within rp_thread */ @@ -4136,8 +4138,8 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) trace_ram_dirty_bitmap_reload_begin(block->idstr); if (s->state != MIGRATION_STATUS_POSTCOPY_RECOVER) { - error_report("%s: incorrect state %s", __func__, - MigrationStatus_str(s->state)); + error_setg(errp, "Reload bitmap in incorrect state %s", + MigrationStatus_str(s->state)); return -EINVAL; } @@ -4154,9 +4156,8 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) /* The size of the bitmap should match with our ramblock */ if (size != local_size) { - error_report("%s: ramblock '%s' bitmap size mismatch " - "(0x%"PRIx64" != 0x%"PRIx64")", __func__, - block->idstr, size, local_size); + error_setg(errp, "ramblock '%s' bitmap size mismatch (0x%"PRIx64 + " != 0x%"PRIx64")", block->idstr, size, local_size); ret = -EINVAL; goto out; } @@ -4166,16 +4167,16 @@ int ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block) ret = qemu_file_get_error(file); if (ret || size != local_size) { - error_report("%s: read bitmap failed for ramblock '%s': %d" - " (size 0x%"PRIx64", got: 0x%"PRIx64")", - __func__, block->idstr, ret, local_size, size); + error_setg(errp, "read bitmap failed for ramblock '%s': %d" + " (size 0x%"PRIx64", got: 0x%"PRIx64")", + block->idstr, ret, local_size, size); ret = -EIO; goto out; } if (end_mark != RAMBLOCK_RECV_BITMAP_ENDING) { - error_report("%s: ramblock '%s' end mark incorrect: 0x%"PRIx64, - __func__, block->idstr, end_mark); + error_setg(errp, "ramblock '%s' end mark incorrect: 0x%"PRIx64, + block->idstr, end_mark); ret = -EINVAL; goto out; } diff --git a/migration/trace-events b/migration/trace-events index 5259c1044b..262eb73078 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -163,7 +163,7 @@ migration_completion_postcopy_end_after_complete(void) "" migration_rate_limit_pre(int ms) "%d ms" migration_rate_limit_post(int urgent) "urgent: %d" migration_return_path_end_before(void) "" -migration_return_path_end_after(int rp_error) "%d" +migration_return_path_end_after(void) "" migration_thread_after_loop(void) "" migration_thread_file_err(void) "" migration_thread_setup_complete(void) "" From patchwork Wed Jul 5 16:35:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302391 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 60FD0EB64DA for ; Wed, 5 Jul 2023 16:36:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TM-0001d7-9r; Wed, 05 Jul 2023 12:35:20 -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 1qH5TF-0001W2-Cm for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:13 -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 1qH5TD-0003bv-P4 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574911; 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=MSPRyQuTpTDUJYT7EH8vGfPwFDbvOPj0S0nnbP7Wtyw=; b=SA53UQYhhQ0BF66QHhwLQ2jNucJ/bb/ewZ4l/atAWN6kTSEC0nJwfc3/6/hQno/AMdAvLV JZB6k37C6fo+/tbP6zj6HAF5cL+OrwvGkZkIcK3JE5h9dscY6QmVIpzL30aicNjRheNzAi PhRCMd8cWS0zE4uOwH/Sn6GxPUY0hdw= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-n0QkSvQWP7S_s4RRZ0iNQw-1; Wed, 05 Jul 2023 12:35:09 -0400 X-MC-Unique: n0QkSvQWP7S_s4RRZ0iNQw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7672918d8a4so198144885a.0 for ; Wed, 05 Jul 2023 09:35:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574909; x=1691166909; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MSPRyQuTpTDUJYT7EH8vGfPwFDbvOPj0S0nnbP7Wtyw=; b=HIYl/g0ig4W9uNHtLu7xOBHPSzmq3T4Mfv4oSFoyKHmateQkfBOz6t7kc8BS7bdG+t qfhPzE/JjKkV/2BoCTjLFU/oRm7G5e8U7Qu19p7MsYClzd+U+y4H7AnrMig+MVjsAOfp IVSOzvyRs/S3jgFYFhbvyn0ERTzoWk3KWJWyFbd4gNM1uzGPAEJkEGvfq24hODhg8RD4 NSo0COXb1I7xjwgDwWvMGRbrc3nkzg6dhwtGu70lPRPdzW0RxEHcho8rjNlf+bGT+UOg 548iqpNfp4CjfwnWwqQvht7LdE1Z2P07aMzZsRLoKDQKiDrFInkj2L7OCuNi07ZwXJFR k0yQ== X-Gm-Message-State: AC+VfDy8d5TQW+QIa3PrY8HySDX6m+yXyZIScB+ueXp/sKHSRvsLUcPa 3dD2if7iCqWUG8DmPSNrqHV2M62yxZVcEJ2DL4QLvC1pgUdyAeVU7DN3xkDKlq/sBNKdG/jIZFk mN0HhGq+A2OYlp6l4A1NUtCIgsSc0yNmz8eZr5GS3BAKOEJ6kE41FwhdcljBkagTFJldh5LCz X-Received: by 2002:a05:620a:44c6:b0:766:f972:73da with SMTP id y6-20020a05620a44c600b00766f97273damr24200313qkp.1.1688574909098; Wed, 05 Jul 2023 09:35:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5x4eoFVlILNzJjnW34vKlEWGV3wIAKVD3qvfbWZpj2qwggtiGDDtu58vokIPoY9exYZw5FbQ== X-Received: by 2002:a05:620a:44c6:b0:766:f972:73da with SMTP id y6-20020a05620a44c600b00766f97273damr24200269qkp.1.1688574908663; Wed, 05 Jul 2023 09:35:08 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 5/7] migration: Deliver return path file error to migrate state too Date: Wed, 5 Jul 2023 12:35:00 -0400 Message-ID: <20230705163502.331007-6-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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 We've already did this for most of the return path thread errors, but not yet for the IO errors happened on the return path qemufile. Do that too. Remember to reset "err" always, because the ownership is not us anymore, otherwise we're prone to use-after-free later after recovered. Reviewed-by: Fabiano Rosas Signed-off-by: Peter Xu --- migration/migration.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 46dbfb07c4..8f60de362f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2008,6 +2008,13 @@ out: res = qemu_file_get_error(rp); if (res) { + /* We have forwarded any error in "err" already, reuse "error" */ + assert(err == NULL); + /* Try to deliver this file error to migration state */ + qemu_file_get_error_obj(rp, &err); + migrate_set_error(ms, err); + err = NULL; + if (res && migration_in_postcopy()) { /* * Maybe there is something we can do: it looks like a From patchwork Wed Jul 5 16:35:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302396 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 550DBEB64DD for ; Wed, 5 Jul 2023 16:37:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TN-0001dN-2s; Wed, 05 Jul 2023 12:35:21 -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 1qH5TH-0001ZT-I2 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:15 -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 1qH5TE-0003c5-Gl for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574911; 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=8nfLmUWQ8pB+Gq1IgpYYS03S4VtZKbHTf8LZ4fkY7mg=; b=VGiA8iTEmVyrpBEoTuMpCdo9qQYV6FON1hzmdxede6zrmQOfuI2B2ZjLByQUXbLuOEt7/3 65Daf3OyxbcT2va0SRPEp0vd6LaFHQjARqeUgDPRlFRxzHtqUVn1hJC+hOzxQoBfpVf+OM 7nK953kL/qdRnXJUW8EAYYJ6LWBdm68= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-260-fg8lGj27OkaSh8UCh3_l1Q-1; Wed, 05 Jul 2023 12:35:10 -0400 X-MC-Unique: fg8lGj27OkaSh8UCh3_l1Q-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74faf5008bbso128205585a.0 for ; Wed, 05 Jul 2023 09:35:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574910; x=1691166910; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8nfLmUWQ8pB+Gq1IgpYYS03S4VtZKbHTf8LZ4fkY7mg=; b=eYEWfqAf8v10GdaEqlnzVerEIIMxwR/K9le/ugw5D83Cul54/w7UVr8DIgSqssJEU9 JdZU1MbJPpldyPZd5NQZwzqMDukNa3SZOpozNxDXyzfIrK4+LFm97Nj9ohs3QuNiNtLY BgRyEyKlEGE76gz3Pv0vtXc1N0xfylq6JUtquiQJAUqXm+ySM+ENIE+wDUx/zFcrRwAX ChddTvusixL8ywksuQmpo+i4V4mIgyzRSwgOehaq5E71G84r7sPoL0LguEQcbgJ3MNJo 5Yfqw3528++C4kjK7LvqAXAyz25+PTOTLOhBnsDx/XLuFzFNb6cyKppChS5n+RoYU0tP ROdg== X-Gm-Message-State: AC+VfDyIdkJkNPTVguFbpi9XZ90WpjsnjmrFI9LRxBcBali3cyQv83m0 aTqGzCaZJ7Sdxd9TkV2lYexRYwZkeLVn/tIr0lVPpE0isM8UNI7hPdPJn9FjbKuci59figZC1rz DWWbLWAp4mMpgWgjcmeSIZSLEiHEOmt+YJnR2yxExz2ks0P5AvlEv5vvAhnoqVpLSIIioqva7 X-Received: by 2002:a05:620a:2403:b0:763:a1d3:196d with SMTP id d3-20020a05620a240300b00763a1d3196dmr20496441qkn.0.1688574910075; Wed, 05 Jul 2023 09:35:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jSwk75xhPI6NrZQ9KR/ix+DudwIY9fnl90bo8rdPtUX/g9To91BEoWr0nFkajMc+YnL8JeA== X-Received: by 2002:a05:620a:2403:b0:763:a1d3:196d with SMTP id d3-20020a05620a240300b00763a1d3196dmr20496405qkn.0.1688574909721; Wed, 05 Jul 2023 09:35:09 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:09 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 6/7] qemufile: Always return a verbose error Date: Wed, 5 Jul 2023 12:35:01 -0400 Message-ID: <20230705163502.331007-7-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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're a lot of cases where we only have an errno set in last_error but without a detailed error description. When this happens, try to generate an error contains the errno as a descriptive error. This will be helpful in cases where one relies on the Error*. E.g., migration state only caches Error* in MigrationState.error. With this, we'll display correct error messages in e.g. query-migrate when the error was only set by qemu_file_set_error(). Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/qemu-file.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index acc282654a..419b4092e7 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -156,15 +156,24 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) * * Return negative error value if there has been an error on previous * operations, return 0 if no error happened. - * Optional, it returns Error* in errp, but it may be NULL even if return value - * is not 0. * + * If errp is specified, a verbose error message will be copied over. */ int qemu_file_get_error_obj(QEMUFile *f, Error **errp) { + if (!f->last_error) { + return 0; + } + + /* There is an error */ if (errp) { - *errp = f->last_error_obj ? error_copy(f->last_error_obj) : NULL; + if (f->last_error_obj) { + *errp = error_copy(f->last_error_obj); + } else { + error_setg_errno(errp, -f->last_error, "Channel error"); + } } + return f->last_error; } From patchwork Wed Jul 5 16:35:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13302397 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 A2D20EB64DD for ; Wed, 5 Jul 2023 16:37:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qH5TO-0001e3-Cm; Wed, 05 Jul 2023 12:35: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 1qH5TH-0001ZZ-Im for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:15 -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 1qH5TF-0003cO-O1 for qemu-devel@nongnu.org; Wed, 05 Jul 2023 12:35:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688574913; 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=2wMxl19wPT6NOIYdfEthE3CTENPdu0RlUwoU249Hq90=; b=X4UuWnyiggDHXh60JSm/yrW4V/4pBzWV//Wy/ruOn48XkjHlSputnW4my7wm6Ahm6pOcLJ MFBd/Cexhr0pEYiEKt9c+3AFlxYCvFZSVsgzGbPIBuAVpgLBV3b7a3oLksbG55K5akO0cp uUudXavj+FVQMK68r+I/fUPKA+ucwxI= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-r4bhcU94OHeNE4c0ajZSbw-1; Wed, 05 Jul 2023 12:35:11 -0400 X-MC-Unique: r4bhcU94OHeNE4c0ajZSbw-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-74faf5008bbso128206085a.0 for ; Wed, 05 Jul 2023 09:35:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688574911; x=1691166911; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2wMxl19wPT6NOIYdfEthE3CTENPdu0RlUwoU249Hq90=; b=PYPEiRwbXj2E1vJCRQz5gstRzGDbUL6lQ72sYRQj3TYwNNnKsLSa2grw9jYkWEHli+ a9MrXfGCV6OvtKPV28nSmUMrQg3n8kZiBMT6SSJv5ACkdZ6Pjn0flS5aW3ZdCdc2bBhY R3wC6/4dtgoay0XBSy8VH+epAsOIZoczl6u8D8EXOS+bT5ysUVr31NKDwenrFJAgmAlz to78PXuDuXCTMEQp62jaF0+v6ECegdmw6hNOvqB8bH/HqQDnd9UqpLMeRQjqjL479JUt WD93vjM6LcDOoswgTx+93ltBlAUoAVqhRk8iPzWRzQNNjxX4gPOosRFcestLVZ9quvrW k9kQ== X-Gm-Message-State: AC+VfDz0DGlkqGKWa4EozfNzv/79NPKwn+U209LVjk3bOIqIhTYliPss 3j6Gyrh65p/z/Vm3eFGSvpqwjF3GQp1GGfK2agmzzih0V0D8Eb4cwo+KUtNtXApYI2aGv+OO5Lk pfFCuAw1tksj9mpDz2LqbJTFPFObpL2W6CrRUWismLJlu/m6puiIW8iZzs1W5FcD6Id10sd4S X-Received: by 2002:a05:620a:1a8c:b0:767:3ea3:2ac8 with SMTP id bl12-20020a05620a1a8c00b007673ea32ac8mr20660582qkb.1.1688574911160; Wed, 05 Jul 2023 09:35:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5IFKvxhJeiheKhdmzEftt9xaEk1O0M9sytH+EQvg72sRgoXzLimEQF06RaJH+2BxA6KemY/w== X-Received: by 2002:a05:620a:1a8c:b0:767:3ea3:2ac8 with SMTP id bl12-20020a05620a1a8c00b007673ea32ac8mr20660551qkb.1.1688574910762; Wed, 05 Jul 2023 09:35:10 -0700 (PDT) Received: from x1n.redhat.com (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id x19-20020a05620a12b300b007620b03ee65sm6760094qki.37.2023.07.05.09.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 09:35:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub , Laszlo Ersek , peterx@redhat.com Subject: [PATCH v2 7/7] migration: Provide explicit error message for file shutdowns Date: Wed, 5 Jul 2023 12:35:02 -0400 Message-ID: <20230705163502.331007-8-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230705163502.331007-1-peterx@redhat.com> References: <20230705163502.331007-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@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, T_SCC_BODY_TEXT_LINE=-0.01 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 Provide an explicit reason for qemu_file_shutdown()s, which can be displayed in query-migrate when used. This will make e.g. migrate-pause to display explicit error descriptions, from: "error-desc": "Channel error: Input/output error" To: "error-desc": "Channel is explicitly shutdown by the user" in query-migrate. Signed-off-by: Peter Xu --- migration/qemu-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 419b4092e7..ff605027de 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -87,7 +87,10 @@ int qemu_file_shutdown(QEMUFile *f) * --> guest crash! */ if (!f->last_error) { - qemu_file_set_error(f, -EIO); + Error *err = NULL; + + error_setg(&err, "Channel is explicitly shutdown by the user"); + qemu_file_set_error_obj(f, -EIO, err); } if (!qio_channel_has_feature(f->ioc,