diff mbox

[v3,2/3] net: extract notify_link_status_changed() function

Message ID 1351062480-4828-3-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi Oct. 24, 2012, 7:07 a.m. UTC
The code to invoke the NetClientInfo .link_status_changed() callback is
duplicated in several places.  Create a single
notify_link_status_changed() function and avoid duplication.

This is useful because later patches change net internals.  By having a
single function it is easier to make changes without affecting callers.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 net.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/net.c b/net.c
index eb4f4bf..67d2616 100644
--- a/net.c
+++ b/net.c
@@ -153,6 +153,13 @@  void qemu_macaddr_default_if_unset(MACAddr *macaddr)
     macaddr->a[5] = 0x56 + index++;
 }
 
+static void notify_link_status_changed(NetClientState *nc)
+{
+    if (nc->info->link_status_changed) {
+        nc->info->link_status_changed(nc);
+    }
+}
+
 /**
  * Generate a name for net client
  *
@@ -266,9 +273,7 @@  void qemu_del_net_client(NetClientState *nc)
         nic->peer_deleted = true;
         /* Let NIC know peer is gone. */
         nc->peer->link_down = true;
-        if (nc->peer->info->link_status_changed) {
-            nc->peer->info->link_status_changed(nc->peer);
-        }
+        notify_link_status_changed(nc->peer);
         qemu_cleanup_net_client(nc);
         return;
     }
@@ -894,9 +899,7 @@  done:
 
     nc->link_down = !up;
 
-    if (nc->info->link_status_changed) {
-        nc->info->link_status_changed(nc);
-    }
+    notify_link_status_changed(nc);
 
     /* Notify peer. Don't update peer link status: this makes it possible to
      * disconnect from host network without notifying the guest.
@@ -905,8 +908,8 @@  done:
      * Current behaviour is compatible with qemu vlans where there could be
      * multiple clients that can still communicate with each other in
      * disconnected mode. For now maintain this compatibility. */
-    if (nc->peer && nc->peer->info->link_status_changed) {
-        nc->peer->info->link_status_changed(nc->peer);
+    if (nc->peer) {
+        notify_link_status_changed(nc->peer);
     }
 }