From patchwork Sat Feb 6 09:28:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 8242191 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1F9AABEEE5 for ; Sat, 6 Feb 2016 09:44:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7309320204 for ; Sat, 6 Feb 2016 09:44:48 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id ADCE320121 for ; Sat, 6 Feb 2016 09:44:47 +0000 (UTC) Received: from localhost ([::1]:52694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzQ7-00059W-3c for patchwork-qemu-devel@patchwork.kernel.org; Sat, 06 Feb 2016 04:44:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzBv-00035R-Fw for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRzBs-0001W2-4t for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:07 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:22536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRzBr-0001Uc-BV for qemu-devel@nongnu.org; Sat, 06 Feb 2016 04:30:04 -0500 Received: from 172.24.1.49 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.49]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BVU12164; Sat, 06 Feb 2016 17:29:54 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Sat, 6 Feb 2016 17:29:44 +0800 From: zhanghailiang To: Date: Sat, 6 Feb 2016 17:28:46 +0800 Message-ID: <1454750932-7556-35-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 1.9.0.msysgit.0 In-Reply-To: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1454750932-7556-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.56B5BD13.0006, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: a7861adbaf5febf929723fc3884c8167 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.66 Cc: xiecl.fnst@cn.fujitsu.com, lizhijian@cn.fujitsu.com, quintela@redhat.com, armbru@redhat.com, Jason Wang , yunhong.jiang@intel.com, eddie.dong@intel.com, peter.huangpeng@huawei.com, dgilbert@redhat.com, zhanghailiang , arei.gonglei@huawei.com, stefanha@redhat.com, amit.shah@redhat.com, zhangchen.fnst@cn.fujitsu.com, hongyang.yang@easystack.cn Subject: [Qemu-devel] [PATCH COLO-Frame v14 34/40] net: Add notifier/callback for netdev init X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We can register some callback for this notifier, this will be used by COLO to register a callback which will add each netdev a buffer filter. Signed-off-by: zhanghailiang Cc: Jason Wang Cc: Yang Hongyang --- v14: - New patch --- include/net/net.h | 4 ++++ net/net.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 73e4c46..f6f0194 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -176,6 +176,10 @@ struct NICInfo { int nvectors; }; +typedef struct netdev_init_entry NetdevInitEntry; +typedef void NetdevInitHandler(const char *netdev_id, void *opaque); +NetdevInitEntry *netdev_init_add_handler(NetdevInitHandler *cb, void *opaque); + extern int nb_nics; extern NICInfo nd_table[MAX_NICS]; extern int default_net; diff --git a/net/net.c b/net/net.c index c5e414f..36f8345 100644 --- a/net/net.c +++ b/net/net.c @@ -55,6 +55,14 @@ static VMChangeStateEntry *net_change_state_entry; static QTAILQ_HEAD(, NetClientState) net_clients; +struct netdev_init_entry { + NetdevInitHandler *cb; + void *opaque; + QLIST_ENTRY(netdev_init_entry) entries; +}; + +static QLIST_HEAD(netdev_init_head, netdev_init_entry)netdev_init_head; + const char *host_net_devices[] = { "tap", "socket", @@ -953,6 +961,26 @@ static int net_init_nic(const NetClientOptions *opts, const char *name, return idx; } +NetdevInitEntry *netdev_init_add_handler(NetdevInitHandler *cb, void *opaque) +{ + NetdevInitEntry *e; + + e = g_malloc0(sizeof(*e)); + + e->cb = cb; + e->opaque = opaque; + QLIST_INSERT_HEAD(&netdev_init_head, e, entries); + return e; +} + +static void netdev_init_notify(const char *netdev_id) +{ + NetdevInitEntry *e, *next; + + QLIST_FOREACH_SAFE(e, &netdev_init_head, entries, next) { + e->cb(netdev_id, e->opaque); + } +} static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])( const NetClientOptions *opts, @@ -1039,6 +1067,11 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } return -1; } + if (is_netdev) { + const Netdev *netdev = object; + + netdev_init_notify(netdev->id); + } return 0; }