From patchwork Mon Sep 3 04:38:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10585431 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8C46174C for ; Mon, 3 Sep 2018 04:52:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96F0529124 for ; Mon, 3 Sep 2018 04:52:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AC2C29533; Mon, 3 Sep 2018 04:52:31 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,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 1C98029124 for ; Mon, 3 Sep 2018 04:52:30 +0000 (UTC) Received: from localhost ([::1]:43422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwgqk-0003R5-9v for patchwork-qemu-devel@patchwork.kernel.org; Mon, 03 Sep 2018 00:52:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fwggj-0000sA-1q for qemu-devel@nongnu.org; Mon, 03 Sep 2018 00:42:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fwggh-000614-Cp for qemu-devel@nongnu.org; Mon, 03 Sep 2018 00:42:08 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:44513) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fwggh-00060l-6E for qemu-devel@nongnu.org; Mon, 03 Sep 2018 00:42:07 -0400 Received: by mail-pl1-x62f.google.com with SMTP id ba4-v6so8033478plb.11 for ; Sun, 02 Sep 2018 21:42:07 -0700 (PDT) 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=nOCtUKXmmcYITFocP0lsd6EtsrO318oN3y/72KNpQqw=; b=UFwvjbORyI7TaIojdfIuOZffkiEXvTZXvUt1gN1Zfa+oRS7pw8Unl74gX/8a1ogY4u 2Ab+ogbEnIwc2UnOz4LUvPHidOLI9xbptHcQm4UINfacDjm7mNqDuUvh+2VOPHYR2RCy HrdNP88uM60eHhF0VvM21m/iHmOePgB39m1bVXuf/zlUOCwo9ZtIHYPTL8zWvpMcZhPs FsDLU3wusva643mGGDiwA0DVyiq93w4akiICZ0Te1fV2l0OFnncD48UohAGWrLaZl19O w2W3Zs6OGzk8ECuw/Uu61GWtMwmjZteo/pZkagcvZQgAPdY7icuKP0aneiTwcCzrU//w UOqg== 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=nOCtUKXmmcYITFocP0lsd6EtsrO318oN3y/72KNpQqw=; b=qPjEd+My/f0m4XjFdrS9zWb6YPJ1mpSnLoXWBrO6kYEkFOm7UVg7ajmUgBDy4tp6XK UxSyRth6tE6vIPvQo2abTGCtOpRRMkhGWEHs8IMuIYuEewes3xSNvdeP0PHHqExr3KMs 2SUD3jdXcolF9CCz6c97HTfvzqXUgEyuJ2l/bgJwzUzPNUgrD/M1KmMSPsIWhGiMip6m pIkmtfGf4jy9qr6i3jtkLFid4ct+3mmhu+umexSWlKtvIGpqV0naMVAnmL2K5QM8f3P9 rah+j72VUOhamPncMgh2mY7rlXNrFvAQ3rRdVEoTuvN19i/DitMm/FOBMa7kGAZC5kka T7MQ== X-Gm-Message-State: APzg51BET0oXC2reFIRC0O2iSZ8XajfjKGyFuJVEkrBqwGkrYCS5njK0 Dvsik/y+XrDif8PsnMBGXfFaRRTh X-Google-Smtp-Source: ANB0VdYsr+DA3nf3Jdg0xgwuR6bBERVvPykRiAj/8JDz2QQxe0NgShIlViD1QMrfSc8OmWH25LDJHA== X-Received: by 2002:a17:902:2904:: with SMTP id g4-v6mr25915331plb.70.1535949726079; Sun, 02 Sep 2018 21:42:06 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id g6-v6sm32738308pfb.11.2018.09.02.21.41.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Sep 2018 21:42:05 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org, Paolo Bonzini , Juan Quintela , "Dr . David Alan Gilbert" , Jason Wang , Eric Blake , Markus Armbruster Date: Mon, 3 Sep 2018 12:38:56 +0800 Message-Id: <20180903043900.28592-16-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903043900.28592-1-zhangckid@gmail.com> References: <20180903043900.28592-1-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::62f Subject: [Qemu-devel] [PATCH V12 15/19] filter: Add handle_event method for NetFilterClass 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: Zhang Chen , zhanghailiang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Filter needs to process the event of checkpoint/failover or other event passed by COLO frame. Signed-off-by: zhanghailiang Signed-off-by: Zhang Chen Signed-off-by: Zhang Chen --- include/net/filter.h | 5 +++++ net/filter.c | 17 +++++++++++++++++ net/net.c | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/include/net/filter.h b/include/net/filter.h index 435acd6f82..49da666ac0 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -38,6 +38,8 @@ typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc, typedef void (FilterStatusChanged) (NetFilterState *nf, Error **errp); +typedef void (FilterHandleEvent) (NetFilterState *nf, int event, Error **errp); + typedef struct NetFilterClass { ObjectClass parent_class; @@ -45,6 +47,7 @@ typedef struct NetFilterClass { FilterSetup *setup; FilterCleanup *cleanup; FilterStatusChanged *status_changed; + FilterHandleEvent *handle_event; /* mandatory */ FilterReceiveIOV *receive_iov; } NetFilterClass; @@ -77,4 +80,6 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, int iovcnt, void *opaque); +void colo_notify_filters_event(int event, Error **errp); + #endif /* QEMU_NET_FILTER_H */ diff --git a/net/filter.c b/net/filter.c index 2fd7d7d663..c9f9e5fa08 100644 --- a/net/filter.c +++ b/net/filter.c @@ -17,6 +17,8 @@ #include "net/vhost_net.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" +#include "net/colo.h" +#include "migration/colo.h" static inline bool qemu_can_skip_netfilter(NetFilterState *nf) { @@ -245,11 +247,26 @@ static void netfilter_finalize(Object *obj) g_free(nf->netdev_id); } +static void default_handle_event(NetFilterState *nf, int event, Error **errp) +{ + switch (event) { + case COLO_EVENT_CHECKPOINT: + break; + case COLO_EVENT_FAILOVER: + object_property_set_str(OBJECT(nf), "off", "status", errp); + break; + default: + break; + } +} + static void netfilter_class_init(ObjectClass *oc, void *data) { UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); + NetFilterClass *nfc = NETFILTER_CLASS(oc); ucc->complete = netfilter_complete; + nfc->handle_event = default_handle_event; } static const TypeInfo netfilter_info = { diff --git a/net/net.c b/net/net.c index 2a3133990c..fd8efebfdb 100644 --- a/net/net.c +++ b/net/net.c @@ -1331,6 +1331,25 @@ void hmp_info_network(Monitor *mon, const QDict *qdict) } } +void colo_notify_filters_event(int event, Error **errp) +{ + NetClientState *nc; + NetFilterState *nf; + NetFilterClass *nfc = NULL; + Error *local_err = NULL; + + QTAILQ_FOREACH(nc, &net_clients, next) { + QTAILQ_FOREACH(nf, &nc->filters, next) { + nfc = NETFILTER_GET_CLASS(OBJECT(nf)); + nfc->handle_event(nf, event, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + } + } +} + void qmp_set_link(const char *name, bool up, Error **errp) { NetClientState *ncs[MAX_QUEUE_NUM];