From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZM9u-0006bH-26 for qemu-devel@nongnu.org; Fri, 16 Nov 2012 08:40:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TZM9r-0000ch-0A for qemu-devel@nongnu.org; Fri, 16 Nov 2012 08:40:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:7016) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TZM9q-0000cM-NR for qemu-devel@nongnu.org; Fri, 16 Nov 2012 08:40:34 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAGDeVGh006161 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Nov 2012 08:40:32 -0500 From: Stefan Hajnoczi Date: Fri, 16 Nov 2012 14:40:04 +0100 Message-Id: <1353073206-31501-3-git-send-email-stefanha@redhat.com> In-Reply-To: <1353073206-31501-1-git-send-email-stefanha@redhat.com> References: <1353073206-31501-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH 2/4] net: extract notify_link_status_changed() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi 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 --- net.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/net.c b/net.c index 025d999..8cf2a9e 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; } @@ -901,9 +906,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. @@ -912,8 +915,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); } } -- 1.8.0