From patchwork Thu Jan 4 06:01:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10143909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A12D26034B for ; Thu, 4 Jan 2018 06:14:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95707283FF for ; Thu, 4 Jan 2018 06:14:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A95E28419; Thu, 4 Jan 2018 06:14:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E8169283FF for ; Thu, 4 Jan 2018 06:14:10 +0000 (UTC) Received: from localhost ([::1]:47514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWyn2-0005s2-1k for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Jan 2018 01:14:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWybn-000433-Bc for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWybm-0004Tl-9P for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:31 -0500 Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:44826) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWybm-0004T7-2y for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:30 -0500 Received: by mail-pf0-x236.google.com with SMTP id m26so367467pfj.11 for ; Wed, 03 Jan 2018 22:02:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M02kKhFXyP39YEvXPP+NgdqkZcy5c2++jhMiomAjDl8=; b=lJStB1rUStGsdpcTWwgO6l8uSVp9/zGaeZcimxBKcmN+uC6ToTTbLoJZ6e9f3n6sIN 8oMbqD58jlBXXe2OkmPZ4CCpa66+c+TaCf/bjBvWsgs8Pvk0on8QIw2gHFWuxWxYDa/U uHDCnGnmTssUeqm4qr6q4puRGintldS56sMpL9kvGgAlGGlMGic1RDzVRpN2RUm7srN6 YTu9ZKRxVZVmXK2+Y4BU/seqA0X0BLAc52nFNAVOP6NzPxaih9KKB06tF7yX8MfhyA+U wI0Dt6QUHgqVsSQBMclZvykUNksaX6llEx37G2QHHU0Bp2buPVJBr2MZfzDJl71h2GFz frKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=M02kKhFXyP39YEvXPP+NgdqkZcy5c2++jhMiomAjDl8=; b=DMygjmm3cMeTlYbka9ygUkdh6e57ZLHRNdNpRODHz+bgirywbygKDmPxVn0aFzosqN I8DcplB/50HU9dPvVXZ2FmAi1GAgRMjFsyFphDtzbId6HRw1ght3KE0i7sWGNLbUWY2s 2bQxxomaBzEFfEfx315oemqNYq5xh3t5/1MsDkXNxHhSxoh7I+6oZnp7uFhBOmiYiECF pSygYNnjnmkCWiO9rnxUMkDqTmcGvFBX05wBgSjw9XhZJD1e68DXtr+qXJtEtg/f42Wz gvuba1wNCTIb1KXOVbE5z18jiT7cqE4YnV0FgF/WLW0wMrbWofX/uPDTUDgjNcFD8hHz KCEQ== X-Gm-Message-State: AKGB3mIHz9cj4k/rt916IjXOHDywY2kZedzOekeJSJnnyEA/WSRrnMH4 GL0vyNMLoCaqBLbs6HFyV9Ihq3D7 X-Google-Smtp-Source: ACJfBosYsR/yZYAIr32Ndc8W/y6APSOO115Qm5cPXLmhruei8KxZZXgMVGLod0cTQ7sb6V9jY7iJWw== X-Received: by 10.99.4.21 with SMTP id 21mr3117478pge.72.1515045748787; Wed, 03 Jan 2018 22:02:28 -0800 (PST) Received: from localhost.localdomain (120.236.201.35.bc.googleusercontent.com. [35.201.236.120]) by smtp.gmail.com with ESMTPSA id w5sm6214775pfi.74.2018.01.03.22.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Jan 2018 22:02:27 -0800 (PST) From: Zhang Chen To: qemu devel Date: Thu, 4 Jan 2018 14:01:13 +0800 Message-Id: <1515045675-6993-15-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515045675-6993-1-git-send-email-zhangckid@gmail.com> References: <1515045675-6993-1-git-send-email-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::236 Subject: [Qemu-devel] [PATCH RESEND V3 14/16] filter-rewriter: handle checkpoint and failover event X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , zhanghailiang , Zhang Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After one round of checkpoint, the states between PVM and SVM become consistent, so it is unnecessary to adjust the sequence of net packets for old connections, besides, while failover happens, filter-rewriter needs to check if it still needs to adjust sequence of net packets. Cc: Jason Wang Signed-off-by: zhanghailiang Signed-off-by: Zhang Chen --- migration/colo.c | 13 +++++++++++++ net/filter-rewriter.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/migration/colo.c b/migration/colo.c index a931ff2..9eab4a3 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -30,6 +30,7 @@ #include "block/block.h" #include "replication.h" #include "sysemu/cpus.h" +#include "net/filter.h" static bool vmstate_loading; static Notifier packets_compare_notifier; @@ -81,6 +82,11 @@ static void secondary_vm_do_failover(void) if (local_err) { error_report_err(local_err); } + /* Notify all filters of all NIC to do checkpoint */ + colo_notify_filters_event(COLO_EVENT_FAILOVER, &local_err); + if (local_err) { + error_report_err(local_err); + } if (!autostart) { error_report("\"-S\" qemu option will be ignored in secondary side"); @@ -753,6 +759,13 @@ void *colo_process_incoming_thread(void *opaque) goto out; } + /* Notify all filters of all NIC to do checkpoint */ + colo_notify_filters_event(COLO_EVENT_CHECKPOINT, &local_err); + if (local_err) { + qemu_mutex_unlock_iothread(); + goto out; + } + vmstate_loading = false; vm_start(); trace_colo_vm_state_change("stop", "run"); diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index a58310a..bd4b6cf 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -23,6 +23,8 @@ #include "qemu/main-loop.h" #include "qemu/iov.h" #include "net/checksum.h" +#include "net/colo.h" +#include "migration/colo.h" #define FILTER_COLO_REWRITER(obj) \ OBJECT_CHECK(RewriterState, (obj), TYPE_FILTER_REWRITER) @@ -280,6 +282,43 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, return 0; } +static void reset_seq_offset(gpointer key, gpointer value, gpointer user_data) +{ + Connection *conn = (Connection *)value; + + conn->offset = 0; +} + +static gboolean offset_is_nonzero(gpointer key, + gpointer value, + gpointer user_data) +{ + Connection *conn = (Connection *)value; + + return conn->offset ? true : false; +} + +static void colo_rewriter_handle_event(NetFilterState *nf, int event, + Error **errp) +{ + RewriterState *rs = FILTER_COLO_REWRITER(nf); + + switch (event) { + case COLO_EVENT_CHECKPOINT: + g_hash_table_foreach(rs->connection_track_table, + reset_seq_offset, NULL); + break; + case COLO_EVENT_FAILOVER: + if (!g_hash_table_find(rs->connection_track_table, + offset_is_nonzero, NULL)) { + object_property_set_str(OBJECT(nf), "off", "status", errp); + } + break; + default: + break; + } +} + static void colo_rewriter_cleanup(NetFilterState *nf) { RewriterState *s = FILTER_COLO_REWRITER(nf); @@ -335,6 +374,7 @@ static void colo_rewriter_class_init(ObjectClass *oc, void *data) nfc->setup = colo_rewriter_setup; nfc->cleanup = colo_rewriter_cleanup; nfc->receive_iov = colo_rewriter_receive_iov; + nfc->handle_event = colo_rewriter_handle_event; } static const TypeInfo colo_rewriter_info = {