From patchwork Sun Mar 11 07:45:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10274553 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 4C8E560211 for ; Sun, 11 Mar 2018 07:57:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4277A28DE5 for ; Sun, 11 Mar 2018 07:57:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3708128DEE; Sun, 11 Mar 2018 07:57:30 +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 A3E5C28DE5 for ; Sun, 11 Mar 2018 07:57:29 +0000 (UTC) Received: from localhost ([::1]:53401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euvrE-0006tD-UZ for patchwork-qemu-devel@patchwork.kernel.org; Sun, 11 Mar 2018 03:57:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euvgl-0006l9-3x for qemu-devel@nongnu.org; Sun, 11 Mar 2018 03:46:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euvgi-00013D-0q for qemu-devel@nongnu.org; Sun, 11 Mar 2018 03:46:39 -0400 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]:35567) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1euvgh-00012C-Qd for qemu-devel@nongnu.org; Sun, 11 Mar 2018 03:46:35 -0400 Received: by mail-pl0-x241.google.com with SMTP id w22-v6so7601574pll.2 for ; Sat, 10 Mar 2018 23:46:35 -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=krjBqgTGepsjEspcz8jZq5t+zPYFaaJLMjzJbngN1Vw=; b=ohZISyGmd37q+ACVKHMe6+0Lk4caqU3hf4z7ddKzIgfmNqEa/ub12tR4S0tQWeM1ld ++e/M4vffcRq2TMA5anqvDMlEAyKHl0aIILeAyXWJycg1/CdMupQ2yGbULb3/5InDErU UC0XyTXSx6YcqLi95ZXWZ9bRUdd/Yl5zKXjSbWy5RxJW7He/QA6aA5LtP40oXHcWuMqs ksSijr2CWijpUDhbHBf9WUzsv73jHyg/Rqst7jxQtDSgK295JtyLyOtfj3le7lq8Aj9W Y1bnD9dCv564EKqfUOuVaIOaq3A11kSlVKdb8dvNn2EipHAXcKD9YVVLJJwP94al/4fT IOow== 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=krjBqgTGepsjEspcz8jZq5t+zPYFaaJLMjzJbngN1Vw=; b=eAcAEH6giF+RYp2k4gyKTPB/XmZZ0nD4+jOkv0o5FohySc97ckAUg7Rrg9SAEU81uO vS0sdCI+TI9ztfdnQRBR9VTLxs7qum79Bav1mg7SY5gSRsmR9FsZ3Sa9tHrDR1f2FCJi /kPq754zZFqP2GUnZxumrLnj9i7DHn3leLBiNqz0UaFUUVdcj+e2EIvZgM4mwMoQqRrq /W2cgxNkv66hq/gGKcEUvByVJackWKfmHmt6v0NQmHCA4FFvxgJ+yJc6mm/uxRFYOR3Z lGPL4MLrgcAKLeqzancT3to6G3qO4TszIdngHL2T6lcaDmm80GUT6U2gIKxqmcRpb/5N o7yQ== X-Gm-Message-State: AElRT7E0b+ftNRhPhDwOYzqCpzj+ty3gogvX7a1s1OnY8uHT2Q01+e1T HcLG39VhuYxla2hBMVdh1bM7kZnD X-Google-Smtp-Source: AG47ELv51iD+8NRqRff+v/LxzPxpbIQc5nSiX7WLzo7VhtwiNQ6SW6DQupOsRsqGGTTtVB87B5Ez3w== X-Received: by 2002:a17:902:c5:: with SMTP id a63-v6mr4252068pla.391.1520754394505; Sat, 10 Mar 2018 23:46:34 -0800 (PST) Received: from localhost.localdomain (120.236.201.35.bc.googleusercontent.com. [35.201.236.120]) by smtp.gmail.com with ESMTPSA id t16sm10917037pfm.69.2018.03.10.23.46.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 23:46:32 -0800 (PST) From: Zhang Chen To: qemu-devel@nongnu.org Date: Sun, 11 Mar 2018 15:45:12 +0800 Message-Id: <1520754314-5969-17-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520754314-5969-1-git-send-email-zhangckid@gmail.com> References: <1520754314-5969-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 V6 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 f514492..f3d588e 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"); @@ -783,6 +789,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 = {