Patchwork net: Use iov helper functions

login
register
mail settings
Submitter Benjamin Poirier
Date Feb. 24, 2011, 12:57 a.m.
Message ID <1298509041-1811-1-git-send-email-benjamin.poirier@gmail.com>
Download mbox | patch
Permalink /patch/84290/
State New
Headers show

Comments

Benjamin Poirier - Feb. 24, 2011, 12:57 a.m.
Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
---
 net.c |   28 ++++++----------------------
 1 files changed, 6 insertions(+), 22 deletions(-)
Stefan Hajnoczi - Feb. 24, 2011, 10:08 a.m.
On Thu, Feb 24, 2011 at 12:57 AM, Benjamin Poirier
<benjamin.poirier@gmail.com> wrote:
> Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
> ---
>  net.c |   28 ++++++----------------------
>  1 files changed, 6 insertions(+), 22 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Jason Wang - Feb. 25, 2011, 6:21 a.m.
Benjamin Poirier writes:
 > Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
 > ---
 >  net.c |   28 ++++++----------------------
 >  1 files changed, 6 insertions(+), 22 deletions(-)
 > 

Looks good.

Acked-by: Jason Wang <jasowang@redhat.com>

 > diff --git a/net.c b/net.c
 > index ec4745d..15ed40b 100644
 > --- a/net.c
 > +++ b/net.c
 > @@ -36,6 +36,7 @@
 >  #include "qemu-common.h"
 >  #include "qemu_socket.h"
 >  #include "hw/qdev.h"
 > +#include "iov.h"
 >  
 >  static QTAILQ_HEAD(, VLANState) vlans;
 >  static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
 > @@ -572,30 +573,13 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
 >                                 int iovcnt)
 >  {
 >      uint8_t buffer[4096];
 > -    size_t offset = 0;
 > -    int i;
 > -
 > -    for (i = 0; i < iovcnt; i++) {
 > -        size_t len;
 > +    size_t offset;
 >  
 > -        len = MIN(sizeof(buffer) - offset, iov[i].iov_len);
 > -        memcpy(buffer + offset, iov[i].iov_base, len);
 > -        offset += len;
 > -    }
 > +    offset = iov_to_buf(iov, iovcnt, buffer, 0, sizeof(buffer));
 >  
 >      return vc->info->receive(vc, buffer, offset);
 >  }
 >  
 > -static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
 > -{
 > -    size_t offset = 0;
 > -    int i;
 > -
 > -    for (i = 0; i < iovcnt; i++)
 > -        offset += iov[i].iov_len;
 > -    return offset;
 > -}
 > -
 >  static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
 >                                         unsigned flags,
 >                                         const struct iovec *iov,
 > @@ -605,7 +589,7 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
 >      VLANClientState *vc = opaque;
 >  
 >      if (vc->link_down) {
 > -        return calc_iov_length(iov, iovcnt);
 > +        return iov_size(iov, iovcnt);
 >      }
 >  
 >      if (vc->info->receive_iov) {
 > @@ -633,7 +617,7 @@ static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
 >          }
 >  
 >          if (vc->link_down) {
 > -            ret = calc_iov_length(iov, iovcnt);
 > +            ret = iov_size(iov, iovcnt);
 >              continue;
 >          }
 >  
 > @@ -658,7 +642,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *sender,
 >      NetQueue *queue;
 >  
 >      if (sender->link_down || (!sender->peer && !sender->vlan)) {
 > -        return calc_iov_length(iov, iovcnt);
 > +        return iov_size(iov, iovcnt);
 >      }
 >  
 >      if (sender->peer) {
 > -- 
 > 1.7.2.3
 > 
 >
Aurelien Jarno - March 6, 2011, 6:29 p.m.
On Wed, Feb 23, 2011 at 07:57:21PM -0500, Benjamin Poirier wrote:
> Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
> ---
>  net.c |   28 ++++++----------------------
>  1 files changed, 6 insertions(+), 22 deletions(-)

Thanks, applied.

> diff --git a/net.c b/net.c
> index ec4745d..15ed40b 100644
> --- a/net.c
> +++ b/net.c
> @@ -36,6 +36,7 @@
>  #include "qemu-common.h"
>  #include "qemu_socket.h"
>  #include "hw/qdev.h"
> +#include "iov.h"
>  
>  static QTAILQ_HEAD(, VLANState) vlans;
>  static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
> @@ -572,30 +573,13 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
>                                 int iovcnt)
>  {
>      uint8_t buffer[4096];
> -    size_t offset = 0;
> -    int i;
> -
> -    for (i = 0; i < iovcnt; i++) {
> -        size_t len;
> +    size_t offset;
>  
> -        len = MIN(sizeof(buffer) - offset, iov[i].iov_len);
> -        memcpy(buffer + offset, iov[i].iov_base, len);
> -        offset += len;
> -    }
> +    offset = iov_to_buf(iov, iovcnt, buffer, 0, sizeof(buffer));
>  
>      return vc->info->receive(vc, buffer, offset);
>  }
>  
> -static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
> -{
> -    size_t offset = 0;
> -    int i;
> -
> -    for (i = 0; i < iovcnt; i++)
> -        offset += iov[i].iov_len;
> -    return offset;
> -}
> -
>  static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
>                                         unsigned flags,
>                                         const struct iovec *iov,
> @@ -605,7 +589,7 @@ static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
>      VLANClientState *vc = opaque;
>  
>      if (vc->link_down) {
> -        return calc_iov_length(iov, iovcnt);
> +        return iov_size(iov, iovcnt);
>      }
>  
>      if (vc->info->receive_iov) {
> @@ -633,7 +617,7 @@ static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
>          }
>  
>          if (vc->link_down) {
> -            ret = calc_iov_length(iov, iovcnt);
> +            ret = iov_size(iov, iovcnt);
>              continue;
>          }
>  
> @@ -658,7 +642,7 @@ ssize_t qemu_sendv_packet_async(VLANClientState *sender,
>      NetQueue *queue;
>  
>      if (sender->link_down || (!sender->peer && !sender->vlan)) {
> -        return calc_iov_length(iov, iovcnt);
> +        return iov_size(iov, iovcnt);
>      }
>  
>      if (sender->peer) {
> -- 
> 1.7.2.3
> 
> 
>

Patch

diff --git a/net.c b/net.c
index ec4745d..15ed40b 100644
--- a/net.c
+++ b/net.c
@@ -36,6 +36,7 @@ 
 #include "qemu-common.h"
 #include "qemu_socket.h"
 #include "hw/qdev.h"
+#include "iov.h"
 
 static QTAILQ_HEAD(, VLANState) vlans;
 static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
@@ -572,30 +573,13 @@  static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
                                int iovcnt)
 {
     uint8_t buffer[4096];
-    size_t offset = 0;
-    int i;
-
-    for (i = 0; i < iovcnt; i++) {
-        size_t len;
+    size_t offset;
 
-        len = MIN(sizeof(buffer) - offset, iov[i].iov_len);
-        memcpy(buffer + offset, iov[i].iov_base, len);
-        offset += len;
-    }
+    offset = iov_to_buf(iov, iovcnt, buffer, 0, sizeof(buffer));
 
     return vc->info->receive(vc, buffer, offset);
 }
 
-static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
-{
-    size_t offset = 0;
-    int i;
-
-    for (i = 0; i < iovcnt; i++)
-        offset += iov[i].iov_len;
-    return offset;
-}
-
 static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
                                        unsigned flags,
                                        const struct iovec *iov,
@@ -605,7 +589,7 @@  static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
     VLANClientState *vc = opaque;
 
     if (vc->link_down) {
-        return calc_iov_length(iov, iovcnt);
+        return iov_size(iov, iovcnt);
     }
 
     if (vc->info->receive_iov) {
@@ -633,7 +617,7 @@  static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
         }
 
         if (vc->link_down) {
-            ret = calc_iov_length(iov, iovcnt);
+            ret = iov_size(iov, iovcnt);
             continue;
         }
 
@@ -658,7 +642,7 @@  ssize_t qemu_sendv_packet_async(VLANClientState *sender,
     NetQueue *queue;
 
     if (sender->link_down || (!sender->peer && !sender->vlan)) {
-        return calc_iov_length(iov, iovcnt);
+        return iov_size(iov, iovcnt);
     }
 
     if (sender->peer) {