From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
lersek@redhat.com, Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 3/4] net: extract notify_link_status_changed() function
Date: Mon, 2 Jul 2012 11:56:52 +0100 [thread overview]
Message-ID: <1341226613-15577-4-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1341226613-15577-1-git-send-email-stefanha@linux.vnet.ibm.com>
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@linux.vnet.ibm.com>
---
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);
}
}
--
1.7.10
next prev parent reply other threads:[~2012-07-02 10:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-02 10:56 [Qemu-devel] [PATCH 0/4] net: convert NetClientState to QOM Stefan Hajnoczi
2012-07-02 10:56 ` [Qemu-devel] [PATCH 1/4] net: add public qemu_net_poll() function Stefan Hajnoczi
2012-07-02 10:56 ` [Qemu-devel] [PATCH 2/4] net: add net_is_tap_client() Stefan Hajnoczi
2012-07-02 10:56 ` Stefan Hajnoczi [this message]
2012-07-02 10:56 ` [Qemu-devel] [PATCH 4/4] net: convert NetClientState to QOM Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2012-10-18 14:56 [Qemu-devel] [PATCH 0/4] " Stefan Hajnoczi
2012-10-18 14:56 ` [Qemu-devel] [PATCH 3/4] net: extract notify_link_status_changed() function Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1341226613-15577-4-git-send-email-stefanha@linux.vnet.ibm.com \
--to=stefanha@linux.vnet.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=lersek@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).