From patchwork Mon May 14 03:23:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10396799 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 481DA6038F for ; Mon, 14 May 2018 06:35:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35585290AB for ; Mon, 14 May 2018 06:35:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29B0D290B4; Mon, 14 May 2018 06:35:20 +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 895CD290AB for ; Mon, 14 May 2018 06:35:19 +0000 (UTC) Received: from localhost ([::1]:42716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fI74o-0007sY-GV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 14 May 2018 02:35:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fI6WF-000694-D2 for qemu-devel@nongnu.org; Mon, 14 May 2018 01:59:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fI46x-0000mh-9a for qemu-devel@nongnu.org; Sun, 13 May 2018 23:25:20 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:33326) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fI46x-0000lI-2q for qemu-devel@nongnu.org; Sun, 13 May 2018 23:25:19 -0400 Received: by mail-pf0-x241.google.com with SMTP id a20-v6so1369984pfo.0 for ; Sun, 13 May 2018 20:25:18 -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=EtLn1VlplhjRL+Oqyu8HuYlcRW/kPez7euXvHhOKC1c=; b=tcf6ejgyzpcp1PysxYqP8jQGledRR3XvQQBBqGpLmnYCi2fjBG9SU9+Ar4nWlEKG7w J6Ihxnh9Zn+6lv0yn26anAsi+OrRcQCXdcb5QiL34VEJXPiwWzRemFkrOhdAvYa6QS0H R0YC0Fnb1/VXdVjd+LE2RIZeq9mkYg8LOXQvglY1pNo7c+MFgsApcUC1MBFG1DouoegJ wplp7zcRXqx4jRu3MQ+jAx4TBKSTVzR5/ADTNiK+46T4/qF6/s/gEr3CUgqwsJb0MK2l m2IOilrnDgfaWebNXO7kwaMcWqW0cCTv4ODk9TX0AGR0cgWUEZkME1GK/7VfKl0zN6aE qV9Q== 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=EtLn1VlplhjRL+Oqyu8HuYlcRW/kPez7euXvHhOKC1c=; b=gUi069TqPcFsfDXICxBT3IZKpxxUKQ9/42fPjevtQR042YzLTC1IsshXc9kY1Nj11M vSGUjQKZyBzbQ+2YZixUXzFDjFyL9Dl7kgH91eEf25gGCc/z24A5dKUU5momvbCEhdZy Jo93sSRTwIjtvg4/rt7Kn1f4OtkpBtMxvKYuXigUw0IY2N0WbHCA2Fas1OarcjQCvU+1 Lx3JpiWd+0JW3D9xVD05OReA5tcSFXYOOUtZuuCiTuoRvVCBoKoh7HmNDWr7L4ZH/qaO TFTQnJqOodj7AnxOAlREUZJJreOGlCAtk90Y50pQpeseW+pL4U/z9t09TntU3BtnoZgD teOg== X-Gm-Message-State: ALKqPwcBhuG/hpRT64C5gjpAihpMkXLfkltLerClchhJZqEtKpU5e3XY CHR0jjQmRzZLw2g24+x8iHNTfg== X-Google-Smtp-Source: AB8JxZrhq41pmOMFkSQjhszUGol5U2b3AtPji62jwT+CqkQ3rQUhIdqkdE+/OzAjAxUVVNgrUmzkbA== X-Received: by 2002:a63:618b:: with SMTP id v133-v6mr6834948pgb.285.1526268317915; Sun, 13 May 2018 20:25:17 -0700 (PDT) Received: from localhost.localdomain (109.227.199.104.bc.googleusercontent.com. [104.199.227.109]) by smtp.gmail.com with ESMTPSA id p6-v6sm17183532pfg.157.2018.05.13.20.25.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 13 May 2018 20:25:17 -0700 (PDT) From: Zhang Chen To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 11:23:45 +0800 Message-Id: <1526268228-27951-15-git-send-email-zhangckid@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526268228-27951-1-git-send-email-zhangckid@gmail.com> References: <1526268228-27951-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::241 Subject: [Qemu-devel] [PATCH V7 14/17] 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: zhanghailiang , Jason Wang , Markus Armbruster , "Dr . David Alan Gilbert" , 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 Filter needs to process the event of checkpoint/failover or other event passed by COLO frame. Signed-off-by: zhanghailiang --- include/net/filter.h | 5 +++++ net/filter.c | 17 +++++++++++++++++ net/net.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/include/net/filter.h b/include/net/filter.h index 435acd6..49da666 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 2fd7d7d..0f17eba 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 dummy_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 = dummy_handle_event; } static const TypeInfo netfilter_info = { diff --git a/net/net.c b/net/net.c index 29f8398..d58691b 100644 --- a/net/net.c +++ b/net/net.c @@ -1335,6 +1335,34 @@ void hmp_info_network(Monitor *mon, const QDict *qdict) } } +void colo_notify_filters_event(int event, Error **errp) +{ + NetClientState *nc, *peer; + NetClientDriver type; + NetFilterState *nf; + NetFilterClass *nfc = NULL; + Error *local_err = NULL; + + QTAILQ_FOREACH(nc, &net_clients, next) { + peer = nc->peer; + type = nc->info->type; + if (!peer || type != NET_CLIENT_DRIVER_TAP) { + continue; + } + QTAILQ_FOREACH(nf, &nc->filters, next) { + nfc = NETFILTER_GET_CLASS(OBJECT(nf)); + if (!nfc->handle_event) { + continue; + } + 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];