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 <zhang.zhanghaili...@huawei.com> Cc: Jason Wang <jasow...@redhat.com> Cc: Yang Hongyang <hongyang.y...@easystack.cn> --- 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 aebf753..bdd3e7b 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; } -- 1.8.3.1