From patchwork Sat Mar 10 21:22:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10274375 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 E935660594 for ; Sat, 10 Mar 2018 21:33:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA1B528DF6 for ; Sat, 10 Mar 2018 21:33:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEFEB28E08; Sat, 10 Mar 2018 21:33:37 +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 109A628E05 for ; Sat, 10 Mar 2018 21:33:35 +0000 (UTC) Received: from localhost ([::1]:52025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eum7T-0003Si-6c for patchwork-qemu-devel@patchwork.kernel.org; Sat, 10 Mar 2018 16:33:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eulxg-00037N-3b for qemu-devel@nongnu.org; Sat, 10 Mar 2018 16:23:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eulxf-0003Sj-4z for qemu-devel@nongnu.org; Sat, 10 Mar 2018 16:23:28 -0500 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:37779) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eulxe-0003SZ-V3 for qemu-devel@nongnu.org; Sat, 10 Mar 2018 16:23:27 -0500 Received: by mail-pl0-x241.google.com with SMTP id w12-v6so7169350plp.4 for ; Sat, 10 Mar 2018 13:23:26 -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=yijnkq2aZJzcfDOsrvzCmN7/fNn/vCG0KxlIi2wD7mQ=; b=EtcHL8sbMhFFFuRH9b0BzoneuesHyZc6jmN6Cgzj+pFx9sSc0D14x/eY85fSmkXL0U +z6H8Sjs2kNzE6zM2yV/7oWTNptq3eqKgQ081bd5XD1KIdHdCGqF9npYJ/EPgwZcbQU8 wP0F0riAAYphZZUMuyEz0gozyC7IdykWSVmjtCDf18Q5QweuNDohCfpbHJZBvrEMXOeD 8jheF7aCzlKqLuZNoZ2KfeLwQhmdkDidlxwD0S00Z9N+BUkH/vEKoRvis3OifSlBIsPw W6nWvqvEm0hanJ6J0UeBw7Bdh88Oy9sbmP040PBzPEtQKEMWa68N93ywGOJnttR51vnU sQtQ== 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=yijnkq2aZJzcfDOsrvzCmN7/fNn/vCG0KxlIi2wD7mQ=; b=KHLiIVwdrsixBBlLpEowl+bhijcK/olzeD39+eZ47b2pQfAmx2RhdP/rACw14MbA/E 1hW9kvkzdHy0NV7C376hhGzfhoehX7/gIeUMPeYUOwvxPlg4AqhAVT5slgx1V6l719rY yvnC8UzD4oY+mI04LKrrSOs2Q4D3pWiwR2pBFLTUGLkVrQizC5Gq148NEPOWST8FyqIp ZBKUE+IDq1+mlyyu7WZ6hcaTeqHMvMJ6C7d+SS5w+4Fpqng6Ztl1qrKtAmP8uizyroZH yV2ZDA/nUJ9KHgEWvohhbJtIs8r+UeSWnc8QI5SipfT1EvGEhOBkolzHTzG83lVRucJg Ob5A== X-Gm-Message-State: AElRT7F/qG81vXEtvxWl84b7YMIkZUQFqvVSq0rvnuu+9l/otbb3s4ea pnfrkEZZdrPXbFqVlwLzdsmNYncT X-Google-Smtp-Source: AG47ELtJD7r0urY1LzA6o2dfIFQ1mbl0gC+7Uc7JSOJQ28VfCQKFbivTy5+YP30Y1fpRaqm1D03iLQ== X-Received: by 2002:a17:902:7598:: with SMTP id j24-v6mr3089083pll.1.1520717005736; Sat, 10 Mar 2018 13:23:25 -0800 (PST) Received: from localhost.localdomain (120.236.201.35.bc.googleusercontent.com. [35.201.236.120]) by smtp.gmail.com with ESMTPSA id q65sm10532191pfd.140.2018.03.10.13.23.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 13:23:24 -0800 (PST) From: Zhang Chen To: qemu-devel@nongnu.org Date: Sun, 11 Mar 2018 05:22:05 +0800 Message-Id: <1520716927-17068-16-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520716927-17068-1-git-send-email-zhangckid@gmail.com> References: <1520716927-17068-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:c01::241 Subject: [Qemu-devel] [PATCH V5 15/17] 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: zhanghailiang , Li Zhijian , Juan Quintela , Jason Wang , "Dr . David Alan Gilbert" , Markus Armbruster , Zhang Chen , Paolo Bonzini 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. 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 1633aed..6834f3d 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -30,6 +30,7 @@ #include "block/block.h" #include "qapi/qapi-events-migration.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"); @@ -787,6 +793,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 0909a9a..f3c306c 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -20,6 +20,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) @@ -277,6 +279,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); @@ -332,6 +371,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 = {