Patchwork [V6,2/4] net: model specific announcing support

login
register
mail settings
Submitter Jason Wang
Date March 28, 2012, 5:40 a.m.
Message ID <20120328054021.34135.47880.stgit@amd-6168-8-1.englab.nay.redhat.com>
Download mbox | patch
Permalink /patch/149143/
State New
Headers show

Comments

Jason Wang - March 28, 2012, 5:40 a.m.
This patch introduces a function pointer in NetClientInfo which is
called during self announcement. With this, each kind of card can
announce the link with a specific way. The old method is still kept
for cards that have not implemented this or old guest. The first user
would be virtio-net.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 net.h    |    2 ++
 savevm.c |    8 +++++---
 2 files changed, 7 insertions(+), 3 deletions(-)
Paolo Bonzini - March 28, 2012, 7:23 a.m.
Il 28/03/2012 07:40, Jason Wang ha scritto:
> This patch introduces a function pointer in NetClientInfo which is
> called during self announcement. With this, each kind of card can
> announce the link with a specific way. The old method is still kept
> for cards that have not implemented this or old guest. The first user
> would be virtio-net.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  net.h    |    2 ++
>  savevm.c |    8 +++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/net.h b/net.h
> index 75a8c15..7195bfc 100644
> --- a/net.h
> +++ b/net.h
> @@ -48,6 +48,7 @@ typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
>  typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
>  typedef void (NetCleanup) (VLANClientState *);
>  typedef void (LinkStatusChanged)(VLANClientState *);
> +typedef int (NetAnnounce)(VLANClientState *);
>  
>  typedef struct NetClientInfo {
>      net_client_type type;
> @@ -59,6 +60,7 @@ typedef struct NetClientInfo {
>      NetCleanup *cleanup;
>      LinkStatusChanged *link_status_changed;
>      NetPoll *poll;
> +    NetAnnounce *announce;
>  } NetClientInfo;
>  
>  struct VLANClientState {
> diff --git a/savevm.c b/savevm.c
> index 80be1ff..7558c1d 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -123,10 +123,12 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque)
>  {
>      uint8_t buf[60];
>      int len;
> +    NetAnnounce *func = nic->nc.info->announce;
>  
> -    len = announce_self_create(buf, nic->conf->macaddr.a);
> -
> -    qemu_send_packet_raw(&nic->nc, buf, len);
> +    if (!func || func(&nic->nc) != 0) {
> +        len = announce_self_create(buf, nic->conf->macaddr.a);
> +        qemu_send_packet_raw(&nic->nc, buf, len);
> +    }
>  }
>  
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

Patch

diff --git a/net.h b/net.h
index 75a8c15..7195bfc 100644
--- a/net.h
+++ b/net.h
@@ -48,6 +48,7 @@  typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
 typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
 typedef void (NetCleanup) (VLANClientState *);
 typedef void (LinkStatusChanged)(VLANClientState *);
+typedef int (NetAnnounce)(VLANClientState *);
 
 typedef struct NetClientInfo {
     net_client_type type;
@@ -59,6 +60,7 @@  typedef struct NetClientInfo {
     NetCleanup *cleanup;
     LinkStatusChanged *link_status_changed;
     NetPoll *poll;
+    NetAnnounce *announce;
 } NetClientInfo;
 
 struct VLANClientState {
diff --git a/savevm.c b/savevm.c
index 80be1ff..7558c1d 100644
--- a/savevm.c
+++ b/savevm.c
@@ -123,10 +123,12 @@  static void qemu_announce_self_iter(NICState *nic, void *opaque)
 {
     uint8_t buf[60];
     int len;
+    NetAnnounce *func = nic->nc.info->announce;
 
-    len = announce_self_create(buf, nic->conf->macaddr.a);
-
-    qemu_send_packet_raw(&nic->nc, buf, len);
+    if (!func || func(&nic->nc) != 0) {
+        len = announce_self_create(buf, nic->conf->macaddr.a);
+        qemu_send_packet_raw(&nic->nc, buf, len);
+    }
 }