From patchwork Mon Jul 2 10:56:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 168549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 95A782C0094 for ; Mon, 2 Jul 2012 20:58:17 +1000 (EST) Received: from localhost ([::1]:40715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SleKd-0002u5-IH for incoming@patchwork.ozlabs.org; Mon, 02 Jul 2012 06:58:15 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SleJw-00010r-5p for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SleJp-0000bC-RR for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:31 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:44847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SleJp-0000aT-JC for qemu-devel@nongnu.org; Mon, 02 Jul 2012 06:57:25 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jul 2012 11:57:21 +0100 Received: from d06nrmr1707.portsmouth.uk.ibm.com (9.149.39.225) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 2 Jul 2012 11:56:59 +0100 Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q62AuwVv2420882 for ; Mon, 2 Jul 2012 11:56:58 +0100 Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q62Auv9R012596 for ; Mon, 2 Jul 2012 04:56:57 -0600 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.145]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q62AuvA1012593; Mon, 2 Jul 2012 04:56:57 -0600 From: Stefan Hajnoczi To: Date: Mon, 2 Jul 2012 11:56:52 +0100 Message-Id: <1341226613-15577-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1341226613-15577-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1341226613-15577-1-git-send-email-stefanha@linux.vnet.ibm.com> x-cbid: 12070210-3548-0000-0000-00000269A080 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 195.75.94.112 Cc: Paolo Bonzini , Anthony Liguori , lersek@redhat.com, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/4] net: extract notify_link_status_changed() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 5e4957f..8c27ff2 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; } @@ -1129,9 +1134,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. @@ -1140,8 +1143,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); } }