From patchwork Thu Jan 4 06:01: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: 10143897 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 040E76034B for ; Thu, 4 Jan 2018 06:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC67A28414 for ; Thu, 4 Jan 2018 06:08:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFDE628418; Thu, 4 Jan 2018 06:08:57 +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 D28C728414 for ; Thu, 4 Jan 2018 06:08:56 +0000 (UTC) Received: from localhost ([::1]:47485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWyi0-0001lo-1x for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Jan 2018 01:08:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37137) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eWybm-00041e-GR for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eWybj-0004Ra-5E for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:30 -0500 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:38756) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eWybj-0004R1-0k for qemu-devel@nongnu.org; Thu, 04 Jan 2018 01:02:27 -0500 Received: by mail-pg0-x242.google.com with SMTP id t67so340224pgc.5 for ; Wed, 03 Jan 2018 22:02: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=dNmSKhTDLMTyVxdEvuJCjtTojXvAAXhnbn7P5Alaofc=; b=dONUvBP5Vz4Qifc2ofkK25wruNzB9INNlWemXTx0i9cE2Vaot0BgQ39bROCsYz1e5u sWIKH9oStTf+1YqC8Pc8rsANzeFwUYengjpzFriFHVmeDxjl7R1uyIe0jHCPqk/9R6kT /lU0o0UlniiDURgsL3nY29O/8xotj6u8notkwZ7QTCxLtH3oszplpG/bszqxpQXq0toP yStbkQBK7dPMZqazzlKH0VxOYh1WGUc5yrBIO7ZtPM9rD2ANfw1MAgahlXysAGelI8gv jED8GWSu7STjEuxV6CriYTZMjOB/Tx6aT03rL7sIAXHuDl9mdxZ4nrd+Dtpslu55YpsF X09w== 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=dNmSKhTDLMTyVxdEvuJCjtTojXvAAXhnbn7P5Alaofc=; b=qYlOiWr8iYuoA8bwBAgVg0d9cZkQ0EMsSmEly+8Sjcb7/07ngIpx5lNNxph9pnVQyI Ia845dSKKsV7pXkzD1zbCHLatmTF1+cVFWpIrYjTnWjCI4dr6I1odYMjTM9pL8Qx8+wA DB6DbTvmkU0g2y6rDRsHkLZ2lCWBj8lCnwtP8RC/R9AYkzwMzEQUVWBm2X+BbODnJvrD d+Z11eFIZPqCcdTtnGl3eNVvCK8a+6TY3u1aYECi/pMMHLUkMZDeLetRTHKy4ywgaJmf KXMYGSsG1ZIqFucGdRwauE0FrgqTsJTbjhlRS38qqEtCSI2/mC9hgWMLgJWW7wXdine3 A53w== X-Gm-Message-State: AKGB3mLoUNSVWpUUfuIzN9lH3pEiuKSgLApAfvN+xSujjoVeUjp7SUM+ 5/Btt3bOubc88radXgNWnBB94/dU X-Google-Smtp-Source: ACJfBoveSFy3jfh24ZBTHgSYdio/cUx71MBEcVtHi611FvlfgYzgjD+bxlr2mLaDCL0mMRaRXgxbIQ== X-Received: by 10.99.4.145 with SMTP id 139mr3134863pge.367.1515045745748; Wed, 03 Jan 2018 22:02: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 w5sm6214775pfi.74.2018.01.03.22.02.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Jan 2018 22:02:24 -0800 (PST) From: Zhang Chen To: qemu devel Date: Thu, 4 Jan 2018 14:01:12 +0800 Message-Id: <1515045675-6993-14-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:c05::242 Subject: [Qemu-devel] [PATCH RESEND V3 13/16] 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: 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 Filter needs to process the event of checkpoint/failover or other event passed by COLO frame. Cc: Jason Wang 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 0c4a2ea..df4510d 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -37,6 +37,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; @@ -44,6 +46,7 @@ typedef struct NetFilterClass { FilterSetup *setup; FilterCleanup *cleanup; FilterStatusChanged *status_changed; + FilterHandleEvent *handle_event; /* mandatory */ FilterReceiveIOV *receive_iov; } NetFilterClass; @@ -76,4 +79,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 39ef546..babbfd4 100644 --- a/net/net.c +++ b/net/net.c @@ -1399,6 +1399,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];