Skip to contentSkip to conversation

net: move rxfilter_notify() to net.c

PATCH Superseded Amos Kong 3 participants 4 messages Nov 5, 2013 – Nov 18, 2013 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 net: move rxfilter_notify() to net.c

rxfilter_notify() is a generic function for all nics, not only for virtio_net, so move it to net.c

---
 hw/net/virtio-net.c | 32 +++++---------------------------
 include/net/net.h   |  1 +
 net/net.c           | 20 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 27 deletions(-)
hw/net/virtio-net.c +5 -27
index 22dbd05..d34c1c7 100644
@@ -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;
 }
include/net/net.h +1 -0
index 11e1468..a8192a1 100644
@@ -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 */
net/net.c +20 -0
index c330c9a..f41a457 100644
@@ -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)
 {
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 9 lines · Amos Kong
hw/net/virtio-net.c +1 -1
@@ -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;
 }

[...]

Quoted 24 lines
net/net.c +9 -0
index c330c9a..f41a457 100644
@@ -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);

net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 983

Quoted 10 lines
net/net.c +10 -0
+        } 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;
+    }
+}

Please fix the memory leak:
object_get_canonical_path() returns a gchar* that the caller must free.

Stefan

#2 lore raw
Quoted 40 lines · Stefan Hajnoczi
Quoted 9 lines · Amos Kong
hw/net/virtio-net.c +1 -1
@@ -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;
  }

[...]

Quoted 29 lines
net/net.c +14 -0
index c330c9a..f41a457 100644
@@ -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);
Quoted 9 lines

net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 983

Quoted 5 lines
net/net.c +5 -0
+
+        /* disable event notification to avoid events flooding */
+        nc->rxfilter_notify_enabled = 0;
+    }
+}

Please fix the memory leak:
object_get_canonical_path() returns a gchar* that the caller must free.

Wow, this memory leak is all over the place and not just in this patch.

-vlad

author
#3 lore raw
Quoted 50 lines · Vlad Yasevich
Quoted 40 lines · Stefan Hajnoczi
Quoted 9 lines · Amos Kong
hw/net/virtio-net.c +1 -1
@@ -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;
 }

[...]

Quoted 29 lines
net/net.c +14 -0
index c330c9a..f41a457 100644
@@ -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);
Quoted 8 lines

net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 983

Quoted 5 lines
net/net.c +5 -0
+
+        /* disable event notification to avoid events flooding */
+        nc->rxfilter_notify_enabled = 0;
+    }
+}

Please fix the memory leak:
object_get_canonical_path() returns a gchar* that the caller must free.

Quoted 1 line

Wow, this memory leak is all over the place and not just in this patch.

Yes, my v2 fix the memory leak in rxfilter_notify(). I just check the code, your patch fixed _the last_ leak of object_get_canonical_path(). Thanks.

Quoted 1 line

-vlad

Signature · 1 line
			Amos.