Received: from eggs.gnu.org ([2001:4830:134:3::10]:52176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdeNc-0001IK-5H for qemu-devel@nongnu.org; Tue, 05 Nov 2013 06:01:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VdeNW-00007H-6G for qemu-devel@nongnu.org; Tue, 05 Nov 2013 06:01:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:27234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdeNV-00006y-VA for qemu-devel@nongnu.org; Tue, 05 Nov 2013 06:00:58 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA5B0tqs009750 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Nov 2013 06:00:55 -0500 From: Amos Kong Date: Tue, 5 Nov 2013 19:00:48 +0800 Message-Id: <1383649248-13854-1-git-send-email-akong@redhat.com> Subject: [Qemu-devel] [PATCH] net: move rxfilter_notify() to net.c List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: jasowang@redhat.com, stefanha@redhat.com, mst@redhat.com rxfilter_notify() is a generic function for all nics, not only for virtio_net, so move it to net.c Signed-off-by: Amos Kong --- hw/net/virtio-net.c | 32 +++++--------------------------- include/net/net.h | 1 + net/net.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 22dbd05..d34c1c7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -194,28 +194,6 @@ static void virtio_net_set_link_status(NetClientState *nc) virtio_net_set_status(vdev, vdev->status); } -static void rxfilter_notify(NetClientState *nc) -{ - QObject *event_data; - VirtIONet *n = qemu_get_nic_opaque(nc); - - if (nc->rxfilter_notify_enabled) { - if (n->netclient_name) { - event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }", - n->netclient_name, - object_get_canonical_path(OBJECT(n->qdev))); - } else { - event_data = qobject_from_jsonf("{ 'path': %s }", - object_get_canonical_path(OBJECT(n->qdev))); - } - monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data); - qobject_decref(event_data); - - /* disable event notification to avoid events flooding */ - nc->rxfilter_notify_enabled = 0; - } -} - static char *mac_strdup_printf(const uint8_t *mac) { return g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], @@ -545,7 +523,7 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, return VIRTIO_NET_ERR; } - rxfilter_notify(nc); + rxfilter_notify(nc, object_get_canonical_path(OBJECT(n->qdev))); return VIRTIO_NET_OK; } @@ -601,7 +579,7 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s = iov_to_buf(iov, iov_cnt, 0, &n->mac, sizeof(n->mac)); assert(s == sizeof(n->mac)); qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); - rxfilter_notify(nc); + rxfilter_notify(nc, object_get_canonical_path(OBJECT(n->qdev))); return VIRTIO_NET_OK; } @@ -667,12 +645,12 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow = 1; } - rxfilter_notify(nc); + rxfilter_notify(nc, object_get_canonical_path(OBJECT(n->qdev))); return VIRTIO_NET_OK; error: - rxfilter_notify(nc); + rxfilter_notify(nc, object_get_canonical_path(OBJECT(n->qdev))); return VIRTIO_NET_ERR; } @@ -699,7 +677,7 @@ static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd, else return VIRTIO_NET_ERR; - rxfilter_notify(nc); + rxfilter_notify(nc, object_get_canonical_path(OBJECT(n->qdev))); return VIRTIO_NET_OK; } diff --git a/include/net/net.h b/include/net/net.h index 11e1468..a8192a1 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -138,6 +138,7 @@ ssize_t qemu_deliver_packet_iov(NetClientState *sender, void *opaque); void print_net_client(Monitor *mon, NetClientState *nc); +void rxfilter_notify(NetClientState *nc, const char *path); void do_info_network(Monitor *mon, const QDict *qdict); /* NIC info */ diff --git a/net/net.c b/net/net.c index c330c9a..f41a457 100644 --- a/net/net.c +++ b/net/net.c @@ -40,6 +40,7 @@ #include "qapi-visit.h" #include "qapi/opts-visitor.h" #include "qapi/dealloc-visitor.h" +#include "qapi/qmp/qjson.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -962,6 +963,25 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +void rxfilter_notify(NetClientState *nc, const char *path) +{ + QObject *event_data; + + if (nc->rxfilter_notify_enabled) { + if (nc->name) { + event_data = qobject_from_jsonf("{ 'name': %s, 'path': %s }", + nc->name, path); + } else { + event_data = qobject_from_jsonf("{ 'path': %s }", path); + } + monitor_protocol_event(QEVENT_NIC_RX_FILTER_CHANGED, event_data); + qobject_decref(event_data); + + /* disable event notification to avoid events flooding */ + nc->rxfilter_notify_enabled = 0; + } +} + RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name, Error **errp) { -- 1.8.3.1