[dpdk-dev,v2,4/7] vhost: Add API to get MTU value

Message ID 20170306082740.5675-5-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Maxime Coquelin March 6, 2017, 8:27 a.m. UTC
  This patch implements the function for the application to
get the MTU value.

rte_vhost_mtu_get() fills the mtu parameter with the MTU value
set in QEMU if VIRTIO_NET_F_MTU has been negotiated and returns 0,
-ENOTSUP otherwise.

The function returns -EAGAIN if Virtio feature negotiation
didn't happened yet.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/rte_virtio_net.h | 15 +++++++++++++++
 lib/librte_vhost/vhost.c          | 19 +++++++++++++++++++
 2 files changed, 34 insertions(+)
  

Comments

Yuanhan Liu March 8, 2017, 2:45 a.m. UTC | #1
On Mon, Mar 06, 2017 at 09:27:37AM +0100, Maxime Coquelin wrote:
> This patch implements the function for the application to
> get the MTU value.
> 
> rte_vhost_mtu_get() fills the mtu parameter with the MTU value
> set in QEMU if VIRTIO_NET_F_MTU has been negotiated and returns 0,
> -ENOTSUP otherwise.
> 
> The function returns -EAGAIN if Virtio feature negotiation
> didn't happened yet.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/librte_vhost/rte_virtio_net.h | 15 +++++++++++++++
>  lib/librte_vhost/vhost.c          | 19 +++++++++++++++++++
>  2 files changed, 34 insertions(+)
> 
> diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
> index 926039c..ff02e9b 100644
> --- a/lib/librte_vhost/rte_virtio_net.h
> +++ b/lib/librte_vhost/rte_virtio_net.h
> @@ -100,6 +100,21 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
>  int rte_vhost_driver_session_start(void);
>  
>  /**
> + * Get the MTU value of the device if set in QEMU.
> + *
> + * @param vid
> + *  virtio-net device ID
> + * @param mtu
> + *  The variable to store the MTU value
> + *
> + * @return
> + *  0: success
> + *  -EAGAIN: device not yet started
> + *  -ENOTSUP: device does not support MTU feature
> + */
> +int rte_vhost_mtu_get(int vid, uint16_t *mtu);

I'd suggest to name it "_get_mtu", to align with the current naming style:
    _get_ifname
    _get_numa_node
    ...

Besides that, you should add an entry to the rte_vhost_version.map.

	--yliu
  
Maxime Coquelin March 12, 2017, 10:23 a.m. UTC | #2
On 03/08/2017 03:45 AM, Yuanhan Liu wrote:
> On Mon, Mar 06, 2017 at 09:27:37AM +0100, Maxime Coquelin wrote:
>> This patch implements the function for the application to
>> get the MTU value.
>>
>> rte_vhost_mtu_get() fills the mtu parameter with the MTU value
>> set in QEMU if VIRTIO_NET_F_MTU has been negotiated and returns 0,
>> -ENOTSUP otherwise.
>>
>> The function returns -EAGAIN if Virtio feature negotiation
>> didn't happened yet.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>  lib/librte_vhost/rte_virtio_net.h | 15 +++++++++++++++
>>  lib/librte_vhost/vhost.c          | 19 +++++++++++++++++++
>>  2 files changed, 34 insertions(+)
>>
>> diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
>> index 926039c..ff02e9b 100644
>> --- a/lib/librte_vhost/rte_virtio_net.h
>> +++ b/lib/librte_vhost/rte_virtio_net.h
>> @@ -100,6 +100,21 @@ int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
>>  int rte_vhost_driver_session_start(void);
>>
>>  /**
>> + * Get the MTU value of the device if set in QEMU.
>> + *
>> + * @param vid
>> + *  virtio-net device ID
>> + * @param mtu
>> + *  The variable to store the MTU value
>> + *
>> + * @return
>> + *  0: success
>> + *  -EAGAIN: device not yet started
>> + *  -ENOTSUP: device does not support MTU feature
>> + */
>> +int rte_vhost_mtu_get(int vid, uint16_t *mtu);
>
> I'd suggest to name it "_get_mtu", to align with the current naming style:
>     _get_ifname
>     _get_numa_node
>     ...

Good point, I named it against the eth_dev's callback name, but it does 
make more sense to be consistent with vhost API style.

>
> Besides that, you should add an entry to the rte_vhost_version.map.
Right.

Thanks,
Maxime
  

Patch

diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h
index 926039c..ff02e9b 100644
--- a/lib/librte_vhost/rte_virtio_net.h
+++ b/lib/librte_vhost/rte_virtio_net.h
@@ -100,6 +100,21 @@  int rte_vhost_driver_callback_register(struct virtio_net_device_ops const * cons
 int rte_vhost_driver_session_start(void);
 
 /**
+ * Get the MTU value of the device if set in QEMU.
+ *
+ * @param vid
+ *  virtio-net device ID
+ * @param mtu
+ *  The variable to store the MTU value
+ *
+ * @return
+ *  0: success
+ *  -EAGAIN: device not yet started
+ *  -ENOTSUP: device does not support MTU feature
+ */
+int rte_vhost_mtu_get(int vid, uint16_t *mtu);
+
+/**
  * Get the numa node from which the virtio net device's memory
  * is allocated.
  *
diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index 3974087..bbf7f7e 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -313,6 +313,25 @@  vhost_enable_dequeue_zero_copy(int vid)
 }
 
 int
+rte_vhost_mtu_get(int vid, uint16_t *mtu)
+{
+	struct virtio_net *dev = get_device(vid);
+
+	if (!dev)
+		return -ENODEV;
+
+	if (!(dev->flags & VIRTIO_DEV_READY))
+		return -EAGAIN;
+
+	if (!(dev->features & VIRTIO_NET_F_MTU))
+		return -ENOTSUP;
+
+	*mtu = dev->mtu;
+
+	return 0;
+}
+
+int
 rte_vhost_get_numa_node(int vid)
 {
 #ifdef RTE_LIBRTE_VHOST_NUMA