diff mbox

[RFC,v3,2/3] vhost-net: Notify the backend about the host MTU

Message ID 20161130101017.13382-3-maxime.coquelin@redhat.com
State New
Headers show

Commit Message

Maxime Coquelin Nov. 30, 2016, 10:10 a.m. UTC
This patch provides a way for virtio-net to notify the
backend about the host MTU set by the user.

Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Aaron Conole <aconole@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 hw/net/vhost_net.c      | 22 ++++++++++++++++++++++
 include/net/vhost_net.h |  2 ++
 2 files changed, 24 insertions(+)

Comments

Aaron Conole Dec. 6, 2016, 6:31 p.m. UTC | #1
Maxime Coquelin <maxime.coquelin@redhat.com> writes:

> This patch provides a way for virtio-net to notify the
> backend about the host MTU set by the user.
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Aaron Conole <aconole@redhat.com>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  hw/net/vhost_net.c      | 22 ++++++++++++++++++++++
>  include/net/vhost_net.h |  2 ++
>  2 files changed, 24 insertions(+)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index f2d49ad..d7c13d4 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -51,6 +51,7 @@ static const int kernel_feature_bits[] = {
>      VIRTIO_RING_F_EVENT_IDX,
>      VIRTIO_NET_F_MRG_RXBUF,
>      VIRTIO_F_VERSION_1,
> +    VIRTIO_NET_F_MTU,
>      VHOST_INVALID_FEATURE_BIT
>  };
>  
> @@ -74,6 +75,7 @@ static const int user_feature_bits[] = {
>      VIRTIO_NET_F_HOST_ECN,
>      VIRTIO_NET_F_HOST_UFO,
>      VIRTIO_NET_F_MRG_RXBUF,
> +    VIRTIO_NET_F_MTU,
>  
>      /* This bit implies RARP isn't sent by QEMU out of band */
>      VIRTIO_NET_F_GUEST_ANNOUNCE,
> @@ -435,6 +437,22 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
>      return 0;
>  }
>  
> +int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
> +{
> +    const VhostOps *vhost_ops = net->dev.vhost_ops;
> +    int ret;
> +
> +    if (!vhost_ops->vhost_net_set_mtu) {
> +        return -ENOSYS;
> +    }
> +
> +    ret = vhost_ops->vhost_net_set_mtu(&net->dev, mtu);
> +    if (ret < 0) {
> +        return -errno;
> +    }
> +    return 0;
> +}
> +
>  #else
>  uint64_t vhost_net_get_max_queues(VHostNetState *net)
>  {
> @@ -501,4 +519,8 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
>  {
>      return 0;
>  }
> +
> +int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
> +{
> +}
>  #endif

I think this should return something - I don't know what value will come
through if it doesn't :).

> diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
> index 5a08eff..afc1499 100644
> --- a/include/net/vhost_net.h
> +++ b/include/net/vhost_net.h
> @@ -35,4 +35,6 @@ int vhost_set_vring_enable(NetClientState * nc, int enable);
>  
>  uint64_t vhost_net_get_acked_features(VHostNetState *net);
>  
> +int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
> +
>  #endif
Maxime Coquelin Dec. 7, 2016, 7:49 a.m. UTC | #2
On 12/06/2016 07:31 PM, Aaron Conole wrote:
> Maxime Coquelin <maxime.coquelin@redhat.com> writes:
>
>> This patch provides a way for virtio-net to notify the
>> backend about the host MTU set by the user.
>>
>> Cc: Michael S. Tsirkin <mst@redhat.com>
>> Cc: Aaron Conole <aconole@redhat.com>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>  hw/net/vhost_net.c      | 22 ++++++++++++++++++++++
>>  include/net/vhost_net.h |  2 ++
>>  2 files changed, 24 insertions(+)
>>
>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>> index f2d49ad..d7c13d4 100644
>> --- a/hw/net/vhost_net.c
>> +++ b/hw/net/vhost_net.c
>> @@ -51,6 +51,7 @@ static const int kernel_feature_bits[] = {
>>      VIRTIO_RING_F_EVENT_IDX,
>>      VIRTIO_NET_F_MRG_RXBUF,
>>      VIRTIO_F_VERSION_1,
>> +    VIRTIO_NET_F_MTU,
>>      VHOST_INVALID_FEATURE_BIT
>>  };
>>
>> @@ -74,6 +75,7 @@ static const int user_feature_bits[] = {
>>      VIRTIO_NET_F_HOST_ECN,
>>      VIRTIO_NET_F_HOST_UFO,
>>      VIRTIO_NET_F_MRG_RXBUF,
>> +    VIRTIO_NET_F_MTU,
>>
>>      /* This bit implies RARP isn't sent by QEMU out of band */
>>      VIRTIO_NET_F_GUEST_ANNOUNCE,
>> @@ -435,6 +437,22 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
>>      return 0;
>>  }
>>
>> +int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
>> +{
>> +    const VhostOps *vhost_ops = net->dev.vhost_ops;
>> +    int ret;
>> +
>> +    if (!vhost_ops->vhost_net_set_mtu) {
>> +        return -ENOSYS;
>> +    }
>> +
>> +    ret = vhost_ops->vhost_net_set_mtu(&net->dev, mtu);
>> +    if (ret < 0) {
>> +        return -errno;
>> +    }
>> +    return 0;
>> +}
>> +
>>  #else
>>  uint64_t vhost_net_get_max_queues(VHostNetState *net)
>>  {
>> @@ -501,4 +519,8 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
>>  {
>>      return 0;
>>  }
>> +
>> +int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
>> +{
>> +}
>>  #endif
>
> I think this should return something - I don't know what value will come
> through if it doesn't :).

Good catch, of course something should be returned...

Thanks!
Maxime
diff mbox

Patch

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index f2d49ad..d7c13d4 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -51,6 +51,7 @@  static const int kernel_feature_bits[] = {
     VIRTIO_RING_F_EVENT_IDX,
     VIRTIO_NET_F_MRG_RXBUF,
     VIRTIO_F_VERSION_1,
+    VIRTIO_NET_F_MTU,
     VHOST_INVALID_FEATURE_BIT
 };
 
@@ -74,6 +75,7 @@  static const int user_feature_bits[] = {
     VIRTIO_NET_F_HOST_ECN,
     VIRTIO_NET_F_HOST_UFO,
     VIRTIO_NET_F_MRG_RXBUF,
+    VIRTIO_NET_F_MTU,
 
     /* This bit implies RARP isn't sent by QEMU out of band */
     VIRTIO_NET_F_GUEST_ANNOUNCE,
@@ -435,6 +437,22 @@  int vhost_set_vring_enable(NetClientState *nc, int enable)
     return 0;
 }
 
+int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
+{
+    const VhostOps *vhost_ops = net->dev.vhost_ops;
+    int ret;
+
+    if (!vhost_ops->vhost_net_set_mtu) {
+        return -ENOSYS;
+    }
+
+    ret = vhost_ops->vhost_net_set_mtu(&net->dev, mtu);
+    if (ret < 0) {
+        return -errno;
+    }
+    return 0;
+}
+
 #else
 uint64_t vhost_net_get_max_queues(VHostNetState *net)
 {
@@ -501,4 +519,8 @@  int vhost_set_vring_enable(NetClientState *nc, int enable)
 {
     return 0;
 }
+
+int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu)
+{
+}
 #endif
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index 5a08eff..afc1499 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -35,4 +35,6 @@  int vhost_set_vring_enable(NetClientState * nc, int enable);
 
 uint64_t vhost_net_get_acked_features(VHostNetState *net);
 
+int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
+
 #endif