From patchwork Wed Jun 28 21:49: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: 1801297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T5x8ENkK; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJ207rsz20ZC for ; Thu, 29 Jun 2023 07:50:57 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3E-0001IV-QA; Wed, 28 Jun 2023 17:50: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 1qEd3C-0001IG-L2 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:10 -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 1qEd3A-0008Nz-Ny for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989007; 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=D0szFsKgCaXfzNnfYBqomvWHvj0fu1RIdHWfouYlejg=; b=T5x8ENkK1djTRJBLRpoRoCCISuo/10AwPWybAj8A6YNxUKH1W0kAnDjXPqXNiX8OqgrzyL 4MArrpUL46jAlRuTWIuAhWgJ4s1C39XHW8JHlfrwPIOaHmAJhNtBgxbHzIBjYAieyPDWNY L6XnaDPHcScn9BIQNwhKZ7zX8RswHPs= 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-561-HPj_j3ZaPXCBZL8HGcMgcA-1; Wed, 28 Jun 2023 17:50:06 -0400 X-MC-Unique: HPj_j3ZaPXCBZL8HGcMgcA-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-40234d83032so14791cf.1 for ; Wed, 28 Jun 2023 14:50:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989005; x=1690581005; 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=D0szFsKgCaXfzNnfYBqomvWHvj0fu1RIdHWfouYlejg=; b=csc8iQfq3uP0VBRqmrYV354rUk+xgbJM7wNdA4w9Bsv6vqcjUlbGf+l8A0ZnFLwf38 NEynlT/KHEtwsFxN15X5xiE7reZJ46qlH+o5tv+EeSRXP/+7xEiZWUjFmWL+hajQwv24 ENVyvrxm86f9iTptZcS5mKbiXxvyRPais8BMkciE16WGElYy6TKv1OjQQoEq3prr6hJH 6lEs8mNZkrGraSpvt93/avm3WxFgBjpPyQOh7g1yvjFp1QvLOdfGE/9qHoTn/QMo1Efr jOUxAM0ms0iwauww949JXtU1Pduar1BxQqUyf2hD7o50zOt5WUVWCoWRo+CDvxqB1YB7 sXVA== X-Gm-Message-State: AC+VfDwChvbcjZ/saXfWcavl0a5wVeOJhdMcRw+UUCFr/9FaKYd5mhZ4 BRpInbLI7WUy1Ff18w+0lfBbGHm5nZIoVdm1P/Ft2eHaQa1dBzmQsB+LKWBKQuEuWZ/mgtr6Ec/ 3ZFLIPCpOi2l1xPi9eZbA+dKR38PwBVHVdjWyX+6dWik7yFpajV8dnMPYREo5LRNOJK8wmx+P X-Received: by 2002:ac8:7f83:0:b0:400:9ed9:7267 with SMTP id z3-20020ac87f83000000b004009ed97267mr11305956qtj.3.1687989005434; Wed, 28 Jun 2023 14:50:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5RnA39EARoMo8Nbasr27H2y8YkDbDkjQKngBpWjqhPLpBytNv1iuw/uIHSmjv+8a+8/M6JVA== X-Received: by 2002:ac8:7f83:0:b0:400:9ed9:7267 with SMTP id z3-20020ac87f83000000b004009ed97267mr11305939qtj.3.1687989005024; Wed, 28 Jun 2023 14:50:05 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 1/7] migration: Let migrate_set_error() take ownership Date: Wed, 28 Jun 2023 17:49:56 -0400 Message-ID: <20230628215002.73546-2-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 721b1c9473..32f87e3834 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -468,8 +468,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); @@ -513,7 +513,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 postcopy_temp_page_reset(PostcopyTmpPage *tmp_page); 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 203d40d4c9..13dccc4c12 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -160,7 +160,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); @@ -1197,11 +1197,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; } } @@ -1214,7 +1223,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); @@ -1678,7 +1687,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; } @@ -2595,7 +2604,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 Jun 28 21:49: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: 1801300 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d+QMqrBZ; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJc3P2vz20ZC for ; Thu, 29 Jun 2023 07:51:28 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3K-0001Jg-A9; Wed, 28 Jun 2023 17:50:18 -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 1qEd3D-0001IP-9i for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:11 -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 1qEd3B-0008OA-2K for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989008; 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=N4b41QtUM2fY9wK0ZryMneMjNxm7tkASb6Nvu1VQtcE=; b=d+QMqrBZ3xsGJGG/KS3cTcrA64+sN9XtB7bDQoXAIJ6DPiUHputFGarHunfrLYUVzpjzqC R6wH8JVvLO7qX2P1oJvk0ePK8DxZ9fK/s+Ix6kGmNnEXaahkU/t1lUz4CiRV/Pex8Fa75B PuD9zN/RMs8o7DdegoKbqdwhGtgFuMo= 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-654-E5PiDrPJMK-Naw82TgLLxg-1; Wed, 28 Jun 2023 17:50:07 -0400 X-MC-Unique: E5PiDrPJMK-Naw82TgLLxg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-401df9d2dc4so49251cf.0 for ; Wed, 28 Jun 2023 14:50:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989006; x=1690581006; 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=N4b41QtUM2fY9wK0ZryMneMjNxm7tkASb6Nvu1VQtcE=; b=C56KcjzpWlCXDVf2FdVStQuEQ/SrB7gizUumiGioXxL1ppu6QB+MTNUCekqGXrNNvv BpcBOWVo874EsBvt0VF7qJ5TaM+kV5C7niv+6+irTaUUpYgi0yvD+SgjesgaPKIhWxr7 IVx/WEZxz5OnjAhMV1+yzZ/bXwhVjKgDr96NsXs1B8j+/pr3L5sRs/TmtWbvvGwAKqIV xmku/jmNP42rZQGjbyGCvudjPcqARt6PDGunvIXF9eXJWRAIsDQeiHWElHFrOCHCMavd YuBQR51TOGADHYEqbyJF5CJ3p+frC+ge4HFlIgBIGSKvGSgBgh/oqVsWXLsV6AzQra3B yn4w== X-Gm-Message-State: AC+VfDwn2HSV+woI93ZaoosmUhm8XdZLUq4JlLOS2qDxCsFZYk+6ht1J Tdgvq6/AlPlSxahSi5PCqRmixUrXdkv/lAMNRurHRYbZ2XPXttL5ajmHWb20H1y4XM8l1UWc5qw f+QRUsIKSsL9+NEU7kz4DOWJRGVqPVJOLTZoG1W9GNdWcSvKU8BbT/c6nlXXOperNWr39TD3n X-Received: by 2002:ac8:5712:0:b0:400:cdbb:a755 with SMTP id 18-20020ac85712000000b00400cdbba755mr9949819qtw.1.1687989006354; Wed, 28 Jun 2023 14:50:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nvxGmwWcGJ/E5U4eysGE0d3lpBQSHqbXLAD0/9YNcrPgHtkbJy1GioCIUW7WnXDSX+qrSwA== X-Received: by 2002:ac8:5712:0:b0:400:cdbb:a755 with SMTP id 18-20020ac85712000000b00400cdbba755mr9949793qtw.1.1687989005892; Wed, 28 Jun 2023 14:50:05 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:05 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 2/7] migration: Introduce migrate_has_error() Date: Wed, 28 Jun 2023 17:49:57 -0400 Message-ID: <20230628215002.73546-3-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- migration/migration.h | 1 + migration/migration.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/migration/migration.h b/migration/migration.h index 32f87e3834..e48317ca97 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -469,6 +469,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 13dccc4c12..39674a3981 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1214,6 +1214,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 Jun 28 21:49: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: 1801299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=PoVMqufg; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJY5dfMz20ZC for ; Thu, 29 Jun 2023 07:51:25 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3O-0001Kc-5V; Wed, 28 Jun 2023 17:50: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 1qEd3G-0001J2-Cn for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:16 -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 1qEd3C-0008OM-OC for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989010; 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=TfWfnfZbeffLlXkdXeufVqSw59USlbPvC7kn1pj2xSs=; b=PoVMqufgy1rcOu9SQqDW6DM2tu0ai0F2pQoe//itvCzX7t5gIafNEWrpKhYhJnOHFnMCFP zQywuwksnNPtzdANgB1p6uoQZcKeIXtgPyb7T6CzDxdCjvD+8XSgd2F/A08Ok0wesEe/kP mph5G5cb/4ECLxbhxqYkVqFwhHCoPNA= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-112-7OwwT9ClMyOnD0hCY1d3wQ-1; Wed, 28 Jun 2023 17:50:08 -0400 X-MC-Unique: 7OwwT9ClMyOnD0hCY1d3wQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3f8283a3a7aso19731cf.1 for ; Wed, 28 Jun 2023 14:50:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989008; x=1690581008; 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=TfWfnfZbeffLlXkdXeufVqSw59USlbPvC7kn1pj2xSs=; b=jkmCjgHvai+lvk83vRvkFj4V6KbjDZpJp2ifUQw+US9D2JmOiIRhnGzJBf6Ar9uGbS JeGujXZhgX6yyhJdZXRCLZgibe9bOq+q9KYHAhRvDq41llGU6EujA7KD8Lg5+wsP4gJe lmHmiz1P7OyGl0BaBLAG6burDhJWgeU4Qdf//NggNdmmftaKG8yp+XVEXd39eR8/6N3Q eHBb9EMhyXDQ6Kxp/KBKTlwrn2c6CjVkjY+kpPGn0Di2DbykAetY2spkXj9QwJIF5A5l ytNsfJsP6w7Jm3O0/4CzWXZld622NkGFZCyHUiYNhf8r09crh7ynVBBh9GPJBtKkUh7K zyUQ== X-Gm-Message-State: AC+VfDzBkUCKHV7DNMen4UbNFEf6k/VXbKm9Jhs4U7aiRJKohC+90Zda rf1glPqFe+/qh9Hnmbb7QM3FhCLQ022ZwSQ4o1Sa+hFIzuMbn4FRpohUaQuIUV7oZJhSMQ3At3j K+wkU/rwAj6uS2HhGlzrtlsyCcnd/BNmM2g/SYeJZXvPcWTB56qDFWPzlcY33vnPeZw9tPBoy X-Received: by 2002:ac8:7f15:0:b0:3fd:e953:74ee with SMTP id f21-20020ac87f15000000b003fde95374eemr1295506qtk.2.1687989007704; Wed, 28 Jun 2023 14:50:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6AOzX8wZX+USt9lobPJpAfcJi6INISrqchvVjGC//PCSOLWslTnHBwIj0ddjqnfsBVYO2SnA== X-Received: by 2002:ac8:7f15:0:b0:3fd:e953:74ee with SMTP id f21-20020ac87f15000000b003fde95374eemr1295473qtk.2.1687989006946; Wed, 28 Jun 2023 14:50:06 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 3/7] migration: Refactor error handling in source return path Date: Wed, 28 Jun 2023 17:49:58 -0400 Message-ID: <20230628215002.73546-4-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- 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 e48317ca97..d9c4b753b5 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -290,7 +290,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 39674a3981..f8c41c4d98 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1409,7 +1409,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; @@ -1724,16 +1723,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; @@ -1754,7 +1743,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(); @@ -1766,15 +1755,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 */ @@ -1789,26 +1775,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; } @@ -1867,49 +1855,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; } @@ -1919,8 +1905,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 @@ -1938,7 +1923,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: @@ -1953,32 +1941,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; @@ -1989,6 +1977,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()) { @@ -2004,13 +2005,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(); @@ -2043,8 +2042,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 @@ -2057,13 +2055,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 @@ -2366,11 +2362,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 cdaef7a1ea..98aa46c780 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -161,7 +161,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 Jun 28 21:49: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: 1801296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N6C8EaZ/; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJ219Hyz20Zc for ; Thu, 29 Jun 2023 07:50:57 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3T-0001LZ-JR; Wed, 28 Jun 2023 17:50:27 -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 1qEd3F-0001It-6N for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:16 -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 1qEd3D-0008Ok-EB for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989010; 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=vjJkYRz5EOF5MasTvu5YbiFs/LHS6Iesq9X7afvvyA0=; b=N6C8EaZ/LlxTwenBPW7JLMmTh53c4w2MMj+q+S1TtnfPAfrQDmFzlMfIo+eT9MYRQhN3UI RLTwX2Dj0eHFUuMYV2Ww3xjIOArUWcXztAnYfcmobcH327tJZGakb6sA+AzkugYsc0sGmr UPfOvOzQZ75/gdKCB4PRUwabg3n7KUE= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-Zj-Y4xYPMPq0la3jFxVRxw-1; Wed, 28 Jun 2023 17:50:08 -0400 X-MC-Unique: Zj-Y4xYPMPq0la3jFxVRxw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-40234d83032so14841cf.1 for ; Wed, 28 Jun 2023 14:50:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989008; x=1690581008; 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=vjJkYRz5EOF5MasTvu5YbiFs/LHS6Iesq9X7afvvyA0=; b=Bh0e0aL3d4SnaTQ+BTEB2wrqN4FcdnkjSzHqCTpFVjpuUimC/kvdmcAGoKaIr/0yV5 BcanVKseiVnCwVyWFW3kpKv7oBkqH4OmKHA4HF/ALJwfrtMZBgcmRdQ7su9nCfywxKfh 67iQyeViz0+Yn3EmFb/CqYYkybZvgHazDYwya+nv93tAAtSidgf4gweNZWFkpMT6/pcY ilHfqYswaIhuaCHJRdziLnnGCyehrAZL+v+50VXDAi7pSQXaq3UC4pK+JcIkGaRrilur sWwmO6DR2U9Y3qg3h0LrzOrV5fr9h4xUyqPBR+Sz9CBLMsqowCbej3/mDGzhgUesH16s NtlQ== X-Gm-Message-State: AC+VfDy48vFayyE/JrE7opDPHLTyMUWjLqDq4dnoD1FSs0vFCZuCNhpF 6ZmkX0/TD5SoRhmqxkFsBiZIYTRsCAHKdFCUGc8g5Sb+ePTBblY/X4pBn/lTTQIBAcs8/BXk5Nr QElQdS+wYdeJoONy0xxuLitqfbYQCnOfaDRxst+vtSkKtgBqwk5Q5O1/swrh1RL1b0tmFCo71 X-Received: by 2002:ac8:7f83:0:b0:400:9ed9:7267 with SMTP id z3-20020ac87f83000000b004009ed97267mr11306046qtj.3.1687989008247; Wed, 28 Jun 2023 14:50:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5LfU/9nt1CTzLVkQgXQlgdsc5pXUL7JrKgq5YmGxUoBuFrVDOZjC3YYwi2A0HBUvGMm68tmg== X-Received: by 2002:ac8:7f83:0:b0:400:9ed9:7267 with SMTP id z3-20020ac87f83000000b004009ed97267mr11306031qtj.3.1687989007965; Wed, 28 Jun 2023 14:50:07 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:07 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 4/7] migration: Deliver return path file error to migrate state too Date: Wed, 28 Jun 2023 17:49:59 -0400 Message-ID: <20230628215002.73546-5-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/migration.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index f8c41c4d98..234dd3601d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1992,6 +1992,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 Jun 28 21:50: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: 1801301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=B9P24ajr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJg2kppz20ZC for ; Thu, 29 Jun 2023 07:51:31 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3U-0001MI-1d; Wed, 28 Jun 2023 17:50:28 -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 1qEd3G-0001J3-D7 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:16 -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 1qEd3D-0008Oy-V6 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989011; 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=vupwd0bgT3VbYEETQv3z7JejUbkc4mPBy77gLSet1rk=; b=B9P24ajrC+f1oc4JcfnBlGE7sM5kE/EDxf5nU7OV7xSaoIthtrk6MeBR2+PW2VS8HKeoSq 0vQO+RgCj+ktF4lmphE2bF+YrLa+TbLk7Fk2yNxUT5DN0OXVmFahKKeQbTz/+z197iDQCU kscntGvjBIKdHsvaXItpbHHliUBxqWI= 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-628-J5uvn_wqOVO_k4oYAhf1eQ-1; Wed, 28 Jun 2023 17:50:10 -0400 X-MC-Unique: J5uvn_wqOVO_k4oYAhf1eQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4009ad15222so22471cf.1 for ; Wed, 28 Jun 2023 14:50:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989009; x=1690581009; 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=vupwd0bgT3VbYEETQv3z7JejUbkc4mPBy77gLSet1rk=; b=WnHJoNSWMo9cpZarP6glvzrCHet8CtOyf5cmp9GBTOw1MZENsWDTvgwWMoBx7bddly y5XfuRHF8hWBVUC6YtQ+TFYBwbj5P+gl13aht2a6izSOvEk8YpdRKoaQYu6IeCp6MBbQ 46nI4RGGwqGfy+5z3YDKwyCM8PtdQF8pA+CyY6GdobNnHCqov8SszxLAWZnDpMhiqkeR /gByxc9ysNIkro/EJmxc7FvJo0ussRTeVAnktYKYWVGMTNaUbDkRowBpjRCAF+7lkkh1 dXM9FOsgIS6a0Oxz1vaAzm7P/2BEvEj7v3KcCB6nYtXReU98DnEPiKZZSYXm6Ry9Snjq Iw8w== X-Gm-Message-State: AC+VfDyFSAXosJDZkRjZs6xMCFj4SVizw301+txIGWfKr5em9pq2IwA0 Y6K2kAjSC3uAvbnJwZ7r5q64MUjzEhyK816D2Tnl4wYhW3SxVrcJNprKF+Wob3U4BEiQwOe5m/x cNdwbez+MpRyDegJt4loFQgzNePYGZAbeWvv3f+CzL9mQOAdFc7lIYcYHejP7swu5EdM53GOL X-Received: by 2002:a05:622a:292:b0:3ff:3151:a8a7 with SMTP id z18-20020a05622a029200b003ff3151a8a7mr32376618qtw.3.1687989009372; Wed, 28 Jun 2023 14:50:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64JLRuwfLgP0W6kzlJZ9btHAmrUUEY5dCCburW0AnVGS+UMr/2JzV4P8TCiZGW03z43kgXvA== X-Received: by 2002:a05:622a:292:b0:3ff:3151:a8a7 with SMTP id z18-20020a05622a029200b003ff3151a8a7mr32376600qtw.3.1687989009064; Wed, 28 Jun 2023 14:50:09 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 5/7] migration: Display error in query-migrate irrelevant of status Date: Wed, 28 Jun 2023 17:50:00 -0400 Message-ID: <20230628215002.73546-6-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Signed-off-by: Peter Xu Reviewed-by: Fabiano Rosas --- migration/migration.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 234dd3601d..7455353918 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1033,9 +1033,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; @@ -1045,6 +1042,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 Jun 28 21:50: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: 1801302 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ED6avEs1; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJr0ZDFz20ZC for ; Thu, 29 Jun 2023 07:51:40 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3R-0001LJ-Jh; Wed, 28 Jun 2023 17:50:25 -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 1qEd3H-0001J6-MV for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:16 -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 1qEd3G-0008PB-7M for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989012; 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=ED6avEs1BlOzh3tGUAmH0+oCtHs68jqlqsKmiFtP3obg9udSiZ7IG/BAZ6IzowGs0ZV3xC QmtBfQiF6LZk489aRK3II/UhewELudaMGFyaOHJsaUiAnWz9E/mVXKmhY27JrmHL29sJPF l8bNgtB9dO2DQIt5qKd3OsMGtfvlUjI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-aK1qlQawNOCC42VJGncZEw-1; Wed, 28 Jun 2023 17:50:11 -0400 X-MC-Unique: aK1qlQawNOCC42VJGncZEw-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-401df9d2dc4so49461cf.0 for ; Wed, 28 Jun 2023 14:50:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989010; x=1690581010; 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=WrDQwdZLRF8nBf/Cc3lNpQjbLwOuXM+INh8Pgtr58XjMHesYJGWeKmdrqJc+CPger+ JXNh+Zkog1lgVq7T9v2r692Rm7j2w63yufj8D9X00ZP1AYHVEmQ2MHTKjQhmNdzuqNwP 2YioiSjy6S/O0h0rHxe6FXVbSmoBzx8Eceoqj1rW8PnHPzhxWbGOhSvImxq/X9pZJRDE gfpcgUB5RCBLJl79OyH/O/h/S3Vl/PWSw1uzSy1bQS2tjB6LEt+GHuDq6r9UNqhDT1pL GPNy1JXRFywLPBgB15vGyTA2h0PYmiLCX5ESCUzbmY1Dn+vfx1ymPlgOCg5Zo0klri3Z mKAA== X-Gm-Message-State: AC+VfDzfdpE/wDAKKIEsJXAsf6/ALKvOgp73r5m6QEKy3Y4hvGLAjr+A qosexMECHaANM99qN+jdMG1j+WZ9K+Xijn4wVAlFtBIOSagplVNBWMWpL1fx3HRpvEcYqI4RMY4 07sDRBV1tn1ft1aDmHH994j63TESteqWR13bZ2xjvxNQXLZMIAUCnp5qFBXUn7bvJqpkYIGvP X-Received: by 2002:ac8:7d83:0:b0:400:990c:8f7c with SMTP id c3-20020ac87d83000000b00400990c8f7cmr14882219qtd.0.1687989010498; Wed, 28 Jun 2023 14:50:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6n8+yg0+ZfD7+yh4o1pn41UJz8kT4F7tMRXN2TIPJxZnGGz0H2kOEzHAwKv2f5E3iLxSPBmw== X-Received: by 2002:ac8:7d83:0:b0:400:990c:8f7c with SMTP id c3-20020ac87d83000000b00400990c8f7cmr14882199qtd.0.1687989010097; Wed, 28 Jun 2023 14:50:10 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:09 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 6/7] qemufile: Always return a verbose error Date: Wed, 28 Jun 2023 17:50:01 -0400 Message-ID: <20230628215002.73546-7-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 Jun 28 21:50: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: 1801298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DINCsajt; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QrwJW3n9mz20ZC for ; Thu, 29 Jun 2023 07:51:23 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qEd3U-0001MK-RF; Wed, 28 Jun 2023 17:50:28 -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 1qEd3K-0001Jn-K3 for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:19 -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 1qEd3J-0008Q3-7m for qemu-devel@nongnu.org; Wed, 28 Jun 2023 17:50:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687989016; 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=DINCsajt9LRTGrEJ/QXK25bXTbAS1q4nl2KhT+TIv7hdBjVSN1ZRgb2NrTtME/8fFpO+9V Rs1+i9xXQ1y7nJ/sO0sq0UouRT2Yyc86GTb7wbNKVGONqi+BrOLA3+lHM+NFZYHMEzs6Ke EOAF7BFWpSntDGu7f+F/xpWOrDz78MQ= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-0vFcQnnEOueCKhwG6dAjyQ-1; Wed, 28 Jun 2023 17:50:12 -0400 X-MC-Unique: 0vFcQnnEOueCKhwG6dAjyQ-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3a1f0f175f8so3144b6e.1 for ; Wed, 28 Jun 2023 14:50:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687989011; x=1690581011; 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=hW6X4s9/V+H15eaoO34tAZ2G3S5jHXxpxg/xGj9ZoCjN5VRTbNuXD8rNGJV6qmIoe5 zHJ5ISeq72WlwgxvGyVD9dAMeXGX+WAfpXqQTypBMEyr9oqvA0gq36kV+6BNW4kCm93A j9NvPuxBUEb+3kTWfOD0Vlwu8tLxTd1u75YhyhEgc5XFMSwQX9FLrz24qA6t8gW0k/RG gxPzmhQC+L1g29izNk5q38zSGrC0H5CPcwoL52+yJnix5XBFwvM2O2aZcvr3X1rxA9xc bm6enUo0WcSjzWLrYpO9nUyKkJbxVRJ2tDhrClW/KqqB1I6Ro7fpwvl4A3MmLJWAJobB ytDQ== X-Gm-Message-State: AC+VfDxYYqrtL1/LnrIIIgFp5iwwB3csVDdwiGb1yC/j86/98NyrO+g4 9ooemGpBLcJsqMdjwaxNRMGQoW2pzakjANTrCV8WHHgx7MkkneM1hqLkcUolckY51oP4V2zMzE9 6UOcGIswtCq0PjKwimQeDTV5j1GguB/iy/wVgEgXAFDxyB4yk4vpnSIRv3T0/p9L6j2U+nfgk X-Received: by 2002:aca:b956:0:b0:3a1:ebb8:396a with SMTP id j83-20020acab956000000b003a1ebb8396amr879700oif.2.1687989011376; Wed, 28 Jun 2023 14:50:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JqIs26rdIsHa5vAoH3Zji4TcLkG7DaKD57OALkh4PeQJzHwjZ4eSiMDNlVlveJF3Vtuivhg== X-Received: by 2002:aca:b956:0:b0:3a1:ebb8:396a with SMTP id j83-20020acab956000000b003a1ebb8396amr879682oif.2.1687989011101; Wed, 28 Jun 2023 14:50:11 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id w29-20020ac84d1d000000b004032d9209a0sm255552qtv.50.2023.06.28.14.50.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 14:50:10 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Leonardo Bras Soares Passos , Fabiano Rosas , Juan Quintela , Lukas Straub Subject: [PATCH 7/7] migration: Provide explicit error message for file shutdowns Date: Wed, 28 Jun 2023 17:50:02 -0400 Message-ID: <20230628215002.73546-8-peterx@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628215002.73546-1-peterx@redhat.com> References: <20230628215002.73546-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_H5=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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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,