From patchwork Wed Jun 27 20:41:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 10492647 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 235AF601A0 for ; Wed, 27 Jun 2018 20:53:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 278EC2A001 for ; Wed, 27 Jun 2018 20:53:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B3A92A048; Wed, 27 Jun 2018 20:53:19 +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 966AD2A001 for ; Wed, 27 Jun 2018 20:53:18 +0000 (UTC) Received: from localhost ([::1]:33155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHRF-0003tD-RE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 27 Jun 2018 16:53:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYHHV-0004YZ-Me for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:43:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYHHU-0006xr-Lf for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:43:13 -0400 Received: from mail-pf0-x22a.google.com ([2607:f8b0:400e:c00::22a]:35755) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYHHU-0006wl-Ef for qemu-devel@nongnu.org; Wed, 27 Jun 2018 16:43:12 -0400 Received: by mail-pf0-x22a.google.com with SMTP id c22-v6so1504959pfi.2 for ; Wed, 27 Jun 2018 13:43:12 -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=ktX0J9bUdPM6g6Qi3dOomt5iQ9JyknqMDbDqhS9ZkG4=; b=LHU9cWIuCGP1YP/cWXBnLlheTQAOncXqJCQW3swsDGwJnpgbUgqTN7qHDhP2l1j1YT hEi/fvmHX0Utu6skTNafoqq+VHKQPwK+iGHd3RfzP8luKRdL7fC0YgbxF9EFn0DT0D94 gKECsEow3rzcnCv/WQ8vmQbkeOXFbmt/3QDUX1mmt4NP0k6AvppOGTwFRqYY0J0C0R0z 5kfy6UBbdaAVnJsGJApFVfbxbQcQlv7nOQdlv4WZkCBIAqaF/PYgFrnbf/d3a36OHm9m arCQfOUzXcDTPkwQPMgBqmo3FF36kuQcyV0EkS/ISXOe6sUGBK5XnQbz/NkaCpC1BJth cipg== 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=ktX0J9bUdPM6g6Qi3dOomt5iQ9JyknqMDbDqhS9ZkG4=; b=HwVemI8HGS+QeJ/v8W2Fk5zQea1vmTCRGoh4zyGM4pGEdd7iRjUynW2ccAeb1WPd/0 nGPRvP7cDwXDb01gqpEk/6EvtSzVaahT0gYIdI9dsjt1nvgFNscGUqFIQ2tLr28awfo6 U2WP6C/xiCJAaKT5UKtvGNrUiLL8v3r/sz7P/GllIdMgFXu7Lkl3IbqP7LbNHsiikKSx zP9IWIaatRFjOBIZNCYTYT3aR2kdZmf99F8d6wD5tcVzzg1OqYR27s5JNChAh3WTlmKO hsGa12b5frsGPjbzJKEnA2UCijOjrhRQsw3Xy/epYX1GqDrm5lF0hhl0uAGlzwsucr7T THZA== X-Gm-Message-State: APt69E0SSSGFlimym3bd5p/HXSJWBNDkOnMbPp5dx3UAyVIZLvrFvmry B4g5DdhPNaYUy5CJPnM1xdKZrA== X-Google-Smtp-Source: AAOMgpf0oYA2jApftsEntNcOEqSp+x3LEcpmpMcN+MNYCH00bvhldizNhHl3opS2KSZc9FRY7FwFwQ== X-Received: by 2002:a62:494f:: with SMTP id w76-v6mr7319374pfa.152.1530132191159; Wed, 27 Jun 2018 13:43:11 -0700 (PDT) Received: from localhost.localdomain (155.150.229.35.bc.googleusercontent.com. [35.229.150.155]) by smtp.gmail.com with ESMTPSA id c67-v6sm9690428pfj.173.2018.06.27.13.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 13:43:10 -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: Thu, 28 Jun 2018 04:41:32 +0800 Message-Id: <20180627204136.4177-17-zhangckid@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180627204136.4177-1-zhangckid@gmail.com> References: <20180627204136.4177-1-zhangckid@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::22a Subject: [Qemu-devel] [PATCH V9 16/20] 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 , 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 --- 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 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..0f17eba143 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 a77ea88fff..b4f6a2efb2 100644 --- a/net/net.c +++ b/net/net.c @@ -1331,6 +1331,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];