From nobody Sun Apr 6 22:08:58 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1736896217; cv=none; d=zohomail.com; s=zohoarc; b=BCWLTKh8yFF47JtMNLC1XKEE6e71XgSyfopVvI9p4dWfN719wWH22FUBj7NOzN7ezRXJ0JUN5Tbvb8++ptgQq/3ID6Uev1fxDtuDwi0UY063DNVJkf8PFPiE4PjX3ehS+Cm3ipdOb+Dyclrl2c5iA4vstlmhE9OLvmVu97dFZ+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736896217; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=irKgyuwlTgCopG55dQ+ETYiKtWcHjCzYi9viy9UqP5I=; b=iYwexluGFucdPZSEPdKtli86ycosUqibM2/VpqFO5kp3nBk/yGeykqKCpbpL9iDTzwk1W0T/ZZEPOB2y0BP5xcMMjp20so2qGYLCCAkfNP1gMZIy7MuzbZDzRmmm3W+Jn5IoUmFtrZGYoTVlxi3WeONHRI+I0MrhFLp6lIQ/V0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1736896217529828.2820754280943; Tue, 14 Jan 2025 15:10:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq2N-0004Bg-G9; Tue, 14 Jan 2025 18:09:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tXq27-0003qS-B9 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:09:15 -0500 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 1tXq25-0004IM-GN for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:09:15 -0500 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-VpB0c27yPpOt808-YVBATQ-1; Tue, 14 Jan 2025 18:08:06 -0500 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6f3b93f5cso59843085a.0 for ; Tue, 14 Jan 2025 15:08:05 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896152; 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=irKgyuwlTgCopG55dQ+ETYiKtWcHjCzYi9viy9UqP5I=; b=W9RY3KorhVghtmo4Xw8+RNrKBJu7+XZ7Y5mPRTQ8bh10H8NcUwqJpwcuBUOwQ7MJXS3ItA ZlB2TrBP5ZsI2YZd35cqEAHmKi7G+JwPnNcfmPCxtt6Q1LQ7tV3RgezHRRepeGsH/5EmqZ Dyy4IBhDhcrizhjgkVIZ7YiIo7lNIRU= X-MC-Unique: VpB0c27yPpOt808-YVBATQ-1 X-Mimecast-MFC-AGG-ID: VpB0c27yPpOt808-YVBATQ X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896085; x=1737500885; 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=irKgyuwlTgCopG55dQ+ETYiKtWcHjCzYi9viy9UqP5I=; b=X6UKw5FiwoKwHkGHBPVnZmz94Pq1h0OAWdwb4x1SE21tjRNum55vWOp7g7v6+pV4vP uuS2dNTmQNJbStC+BM8F0h1owY5R/7GidOxhSCzJsQ5KhqHn7owZ5XyTMNKhytdasbRv /RIQ4YNdYhG33yVtoPzQ+OJdVP19zVIprqPJwoQqRTg3wjZSDDJeE+FQll7ClBeA4SXw 0pHtQwsTSUft7AZQDaV3amlbRAUELJlu5ML0oZ5SrMoKpaFR0lSDphEHns8vIpeszfbZ MUEm4qJz+vJ0vfGWsnTrdPnwkyCKpKe6n/NhzofjV/Z5++j/6LuOKLZ128IQSX0Lm4ev Fxsg== X-Gm-Message-State: AOJu0YyDeQA6cv+wdvqN1R2oeais3dUwOuD9/EA2J1QisaMCbjWDqRyw PFEpspTaKBnA/s8iiPAxn+IaS+HaHSybJiyged6C5qb+CLqA9fRFWpMelrHvkjLp3wGrf5no/9/ zp0OiL4uQAN23CLlyhfbzozpDvo6fpRmqsbn8fACBX0sRNmXdisSR0y7c9kRAsmhrjdtRFw1RId k/WylfdjHATclmaOorYNFVZhE0eKmKVeZPRg== X-Gm-Gg: ASbGnctRVO4lBimVOVnIKAlA8hTTdwUWHP/gxoqK6ur+dMJplnc09ixJcP20Ke/M3/H hH+EwNkUUMDM4nGlIoA/LzQBtZNrtwFTJAZUOXfWBU/y3wbuUgRpu5uHItR2r4vHtFkKwQNcVLr Rx+xoW/+SaNENtq/UrIJToubAJhFyPzpzf46xOP+cXL9HbO4fck2mvkQ7n9AucUG4a6bFoQB4tr HkW/VD+q8j/1LtgjomhnSoni9L+XoDnqABFNtjtq6t/0UzXmSgNdMvBfpivVjXk6tTqjNrXcIzO QBU+cOaxYe8aAjpM4UKTfMMp1t/S1Sw7 X-Received: by 2002:ad4:5d68:0:b0:6d8:893b:2a13 with SMTP id 6a1803df08f44-6e192acacb8mr14123026d6.0.1736896085162; Tue, 14 Jan 2025 15:08:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsMXaZrSKXmWGtmuQ5k0JobhExFbGUbgkJjmQTuJfxe4fV5xRDGJdJhXw52VxqYhCAMd8OuQ== X-Received: by 2002:ad4:5d68:0:b0:6d8:893b:2a13 with SMTP id 6a1803df08f44-6e192acacb8mr14122736d6.0.1736896084835; Tue, 14 Jan 2025 15:08:04 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 09/16] migration: Drop cached migration state in migration_maybe_pause() Date: Tue, 14 Jan 2025 18:07:39 -0500 Message-ID: <20250114230746.3268797-10-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1736896219463019000 Content-Type: text/plain; charset="utf-8" I can't see why we must cache the state now after we avoided possible CANCEL race: that's the only thing I can think of that can modify the migration state concurrently with the migration thread itself. Make all the state updates to happen always, then we don't need to cache the state anymore. Signed-off-by: Peter Xu --- migration/migration.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5c688059de..5850c90c9f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -102,9 +102,7 @@ static MigrationIncomingState *current_incoming; static GSList *migration_blockers[MIG_MODE__MAX]; =20 static bool migration_object_check(MigrationState *ms, Error **errp); -static int migration_maybe_pause(MigrationState *s, - int *current_active_state, - int new_state); +static int migration_maybe_pause(MigrationState *s, int new_state); static void migrate_fd_cancel(MigrationState *s); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); @@ -2502,7 +2500,6 @@ static int postcopy_start(MigrationState *ms, Error *= *errp) int ret; QIOChannelBuffer *bioc; QEMUFile *fb; - int cur_state =3D MIGRATION_STATUS_ACTIVE; =20 /* * Now we're 100% sure to switch to postcopy, so JSON writer won't be @@ -2537,8 +2534,7 @@ static int postcopy_start(MigrationState *ms, Error *= *errp) goto fail; } =20 - ret =3D migration_maybe_pause(ms, &cur_state, - MIGRATION_STATUS_POSTCOPY_ACTIVE); + ret =3D migration_maybe_pause(ms, MIGRATION_STATUS_POSTCOPY_ACTIVE); if (ret < 0) { error_setg_errno(errp, -ret, "%s: Failed in migration_maybe_pause(= )", __func__); @@ -2676,9 +2672,7 @@ fail: * migrate_pause_before_switchover called with the BQL locked * Returns: 0 on success */ -static int migration_maybe_pause(MigrationState *s, - int *current_active_state, - int new_state) +static int migration_maybe_pause(MigrationState *s, int new_state) { if (!migrate_pause_before_switchover()) { return 0; @@ -2701,21 +2695,19 @@ static int migration_maybe_pause(MigrationState *s, * wait for the 'pause_sem' semaphore. */ if (s->state !=3D MIGRATION_STATUS_CANCELLING) { - migrate_set_state(&s->state, *current_active_state, + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_PRE_SWITCHOVER); bql_unlock(); qemu_sem_wait(&s->pause_sem); bql_lock(); migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, new_state); - *current_active_state =3D new_state; } =20 return s->state =3D=3D new_state ? 0 : -EINVAL; } =20 -static int migration_completion_precopy(MigrationState *s, - int *current_active_state) +static int migration_completion_precopy(MigrationState *s) { int ret; =20 @@ -2728,8 +2720,7 @@ static int migration_completion_precopy(MigrationStat= e *s, } } =20 - ret =3D migration_maybe_pause(s, current_active_state, - MIGRATION_STATUS_DEVICE); + ret =3D migration_maybe_pause(s, MIGRATION_STATUS_DEVICE); if (ret < 0) { goto out_unlock; } @@ -2782,11 +2773,10 @@ static void migration_completion_postcopy(Migration= State *s) static void migration_completion(MigrationState *s) { int ret =3D 0; - int current_active_state =3D s->state; Error *local_err =3D NULL; =20 if (s->state =3D=3D MIGRATION_STATUS_ACTIVE) { - ret =3D migration_completion_precopy(s, ¤t_active_state); + ret =3D migration_completion_precopy(s); } else if (s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE) { migration_completion_postcopy(s); } else { @@ -2826,8 +2816,7 @@ fail: error_free(local_err); } =20 - migrate_set_state(&s->state, current_active_state, - MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); } =20 /** --=20 2.47.0