[dpdk-dev] [PATCH 25/40] net/virtio: add Virtio-user features ops

Maxime Coquelin maxime.coquelin at redhat.com
Fri Jan 15 15:29:17 CET 2021



On 1/13/21 2:57 PM, Adrian Moreno wrote:
> 
> 
> On 12/20/20 10:13 PM, Maxime Coquelin wrote:
>> This patch introduce new callbacks for getting
>> and setting Virtio features, and implements them
>> for the different backend types.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin at redhat.com>
>> ---
>>  drivers/net/virtio/virtio_user/vhost.h        |   2 +
>>  drivers/net/virtio/virtio_user/vhost_kernel.c | 150 +++++++++---------
>>  .../net/virtio/virtio_user/vhost_kernel_tap.c |  23 +++
>>  .../net/virtio/virtio_user/vhost_kernel_tap.h |   1 +
>>  drivers/net/virtio/virtio_user/vhost_user.c   |  63 +++++++-
>>  drivers/net/virtio/virtio_user/vhost_vdpa.c   |  38 +++--
>>  .../net/virtio/virtio_user/virtio_user_dev.c  |   5 +-
>>  drivers/net/virtio/virtio_user_ethdev.c       |   3 +-
>>  8 files changed, 188 insertions(+), 97 deletions(-)
>>

...

>> diff --git a/drivers/net/virtio/virtio_user/vhost_user.c b/drivers/net/virtio/virtio_user/vhost_user.c
>> index 5ab15318ac..d204fa1eb0 100644
>> --- a/drivers/net/virtio/virtio_user/vhost_user.c
>> +++ b/drivers/net/virtio/virtio_user/vhost_user.c
>> @@ -143,6 +143,62 @@ vhost_user_set_owner(struct virtio_user_dev *dev)
>>  	return 0;
>>  }
>>  
>> +static int
>> +vhost_user_get_features(struct virtio_user_dev *dev, uint64_t *features)
>> +{
>> +	int ret;
>> +	struct vhost_user_msg msg = {
>> +		.request = VHOST_USER_GET_FEATURES,
>> +		.flags = VHOST_USER_VERSION,
>> +	};
>> +
>> +	ret = vhost_user_write(dev->vhostfd, &msg, NULL, 0);
>> +	if (ret < 0)
>> +		goto err;
>> +
>> +	ret = vhost_user_read(dev->vhostfd, &msg);
>> +	if (ret < 0)
>> +		goto err;
>> +
>> +	if (msg.request != VHOST_USER_GET_FEATURES) {
>> +		PMD_DRV_LOG(ERR, "Unexpected request type (%d)", msg.request);
>> +		goto err;
>> +	}
>> +
>> +	if (msg.size != sizeof(*features)) {
>> +		PMD_DRV_LOG(ERR, "Unexpected payload size (%d)", msg.size);
>> +		goto err;
>> +	}
>> +
>> +	*features = msg.payload.u64;
>> +
>> +	return 0;
>> +err:
>> +	PMD_DRV_LOG(ERR, "Failed to get backend features");
>> +
> On possibly socket-related errors, it's sometimes useful to print
> sterror(errno). WDYT?
>> +	return -1;
>> +}


I agree, I will do it in vhost_user_read/vhost_user_write.
Actually I have a already done it in vhost_user_write after earlier
comment from Chenbo.

Thanks,
Maxime



More information about the dev mailing list