From patchwork Thu Mar 31 15:08:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12797226 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 AE004C433EF for ; Thu, 31 Mar 2022 15:14:37 +0000 (UTC) Received: from localhost ([::1]:33324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZwVQ-0002lb-O4 for qemu-devel@archiver.kernel.org; Thu, 31 Mar 2022 11:14:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:52390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZwQ9-00024S-K4 for qemu-devel@nongnu.org; Thu, 31 Mar 2022 11:09:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:59816) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZwQ8-0001LL-10 for qemu-devel@nongnu.org; Thu, 31 Mar 2022 11:09:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1648739347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=muISGSqC4VLW6KPUHb9CY6sFKOFruXP+msv79+xlWRw=; b=i/V9NQdOz0+AE/xbg5xBbE8lKjH5FO0ltt+ZpMFTyFETmU+N3P0YyDRz1qBZGNo2jKi+7E I1kcM7k1g2n2aOV6yRet47Qp0isubxOXo/ITXRxg/NM17TBViCqNcUFeelSPr0xzoi/BtO YuKApU77LxUS78oaraVeCNGeUZXFn10= 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-329-CHclpZ32MTi4xUpm2lDtRg-1; Thu, 31 Mar 2022 11:09:06 -0400 X-MC-Unique: CHclpZ32MTi4xUpm2lDtRg-1 Received: by mail-qt1-f197.google.com with SMTP id f3-20020ac84983000000b002e22396acfbso20237367qtq.18 for ; Thu, 31 Mar 2022 08:09:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=muISGSqC4VLW6KPUHb9CY6sFKOFruXP+msv79+xlWRw=; b=5f4SDsU5M9MlTsKXcXn50cYr6JBWnQ6kIl+AaP/z+MEczjlZuE/+W1AmctAC1peQ1m wQrxnl4S9yAaoqhggIRtwiBuNPzlsyrIQEudM7X8minWALGzBD0A5U4w1+zgC+F1FTJc WD0E+UnKs+HMbGDCfS775P+jmMOK9EVGkXG95r6AhDCJToNTpyzl/DschhjhGQAl9dD8 lUQIZdFrf/5VadXeLtqdRn2wvcoGYxD9IWp8b78r9/a4nP+cxZrpnIzg4Cje8Et4ifZM E1cbEB9jTFpS+5EWiUxXQLFihe4dQteorasBbdcp53V7N3yJSDB/LQTd93eUjbvK6hSl llRA== X-Gm-Message-State: AOAM531bccqLn6eLudqDc4kqDv8VK5oiBVi9mkdgj4rDyRsAu+hBopgJ UfVpUM6wawuEOq9eoqE2wNDLRjnpedNI9iUdj8uop5zAOPJ74FEcjJpf31Xfcasegr+i0mYC0Kp BuL6YkNna5NzXUsl5Q2B+WuVA2UlEtyx/UiZ80zP9unpA0LFic/usUL/3yAFTnm8t X-Received: by 2002:a05:620a:2892:b0:67e:be24:e5d7 with SMTP id j18-20020a05620a289200b0067ebe24e5d7mr3590970qkp.762.1648739345748; Thu, 31 Mar 2022 08:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQZD9a4p3NxNCkqYi7waHR7En2ta75aR+IxOT0DIpCa+zZsiDRHMBJpIC68PaTswppMh71ag== X-Received: by 2002:a05:620a:2892:b0:67e:be24:e5d7 with SMTP id j18-20020a05620a289200b0067ebe24e5d7mr3590935qkp.762.1648739345355; Thu, 31 Mar 2022 08:09:05 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id 21-20020ac85715000000b002e1ce9605ffsm20246871qtw.65.2022.03.31.08.09.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 31 Mar 2022 08:09:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Subject: [PATCH v4 06/19] migration: Move channel setup out of postcopy_try_recover() Date: Thu, 31 Mar 2022 11:08:44 -0400 Message-Id: <20220331150857.74406-7-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220331150857.74406-1-peterx@redhat.com> References: <20220331150857.74406-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Cc: Leonardo Bras Soares Passos , "Daniel P . Berrange" , "Dr . David Alan Gilbert" , peterx@redhat.com, Juan Quintela Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We used to use postcopy_try_recover() to replace migration_incoming_setup() to setup incoming channels. That's fine for the old world, but in the new world there can be more than one channels that need setup. Better move the channel setup out of it so that postcopy_try_recover() only handles the last phase of switching to the recovery phase. To do that in migration_fd_process_incoming(), move the postcopy_try_recover() call to be after migration_incoming_setup(), which will setup the channels. While in migration_ioc_process_incoming(), postpone the recover() routine right before we'll jump into migration_incoming_process(). A side benefit is we don't need to pass in QEMUFile* to postcopy_try_recover() anymore. Remove it. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Daniel P. Berrangé --- migration/migration.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 596d3d30b4..8ecf78f2c7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -671,19 +671,20 @@ void migration_incoming_process(void) } /* Returns true if recovered from a paused migration, otherwise false */ -static bool postcopy_try_recover(QEMUFile *f) +static bool postcopy_try_recover(void) { MigrationIncomingState *mis = migration_incoming_get_current(); if (mis->state == MIGRATION_STATUS_POSTCOPY_PAUSED) { /* Resumed from a paused postcopy migration */ - mis->from_src_file = f; + /* This should be set already in migration_incoming_setup() */ + assert(mis->from_src_file); /* Postcopy has standalone thread to do vm load */ - qemu_file_set_blocking(f, true); + qemu_file_set_blocking(mis->from_src_file, true); /* Re-configure the return path */ - mis->to_src_file = qemu_file_get_return_path(f); + mis->to_src_file = qemu_file_get_return_path(mis->from_src_file); migrate_set_state(&mis->state, MIGRATION_STATUS_POSTCOPY_PAUSED, MIGRATION_STATUS_POSTCOPY_RECOVER); @@ -704,11 +705,10 @@ static bool postcopy_try_recover(QEMUFile *f) void migration_fd_process_incoming(QEMUFile *f, Error **errp) { - if (postcopy_try_recover(f)) { + if (!migration_incoming_setup(f, errp)) { return; } - - if (!migration_incoming_setup(f, errp)) { + if (postcopy_try_recover()) { return; } migration_incoming_process(); @@ -724,11 +724,6 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) /* The first connection (multifd may have multiple) */ QEMUFile *f = qemu_fopen_channel_input(ioc); - /* If it's a recovery, we're done */ - if (postcopy_try_recover(f)) { - return; - } - if (!migration_incoming_setup(f, errp)) { return; } @@ -749,6 +744,10 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) } if (start_migration) { + /* If it's a recovery, we're done */ + if (postcopy_try_recover()) { + return; + } migration_incoming_process(); } }