From patchwork Thu Oct 18 14:56:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 192344 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 103C52C0092 for ; Fri, 19 Oct 2012 01:59:26 +1100 (EST) Received: from localhost ([::1]:37074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOrZE-0007Yh-8w for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2012 10:59:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOrZ3-0007Xy-6X for qemu-devel@nongnu.org; Thu, 18 Oct 2012 10:59:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOrYx-00036T-A8 for qemu-devel@nongnu.org; Thu, 18 Oct 2012 10:59:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOrYx-00036G-0y for qemu-devel@nongnu.org; Thu, 18 Oct 2012 10:59:07 -0400 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 q9IEvAPW009585 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 18 Oct 2012 10:57:10 -0400 Received: from localhost (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9IEv9sJ004787; Thu, 18 Oct 2012 10:57:10 -0400 From: Stefan Hajnoczi To: Date: Thu, 18 Oct 2012 16:56:54 +0200 Message-Id: <1350572215-2231-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1350572215-2231-1-git-send-email-stefanha@redhat.com> References: <1350572215-2231-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Laszlo Ersek , 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 From: 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 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); } }