DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Xia, Chenbo" <chenbo.xia@intel.com>
To: Maxime Coquelin <maxime.coquelin@redhat.com>,
	"dev@dpdk.org" <dev@dpdk.org>,
	"Fu, Patrick" <patrick.fu@intel.com>,
	"amorenoz@redhat.com" <amorenoz@redhat.com>
Subject: Re: [dpdk-dev] [PATCH v3 4/8] net/virtio: introduce Vhost-vDPA backend type
Date: Wed, 30 Sep 2020 05:49:47 +0000	[thread overview]
Message-ID: <MN2PR11MB4063CE17ACB920A7B7DF7B4F9C330@MN2PR11MB4063.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20200929161404.124580-5-maxime.coquelin@redhat.com>

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Wednesday, September 30, 2020 12:14 AM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; Fu, Patrick
> <patrick.fu@intel.com>; amorenoz@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [PATCH v3 4/8] net/virtio: introduce Vhost-vDPA backend type
> 
> Backend type is determined by checking char-device major numbers
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> Signed-off-by: Adrian Moreno <amorenoz@redhat.com>
> ---
>  .../net/virtio/virtio_user/virtio_user_dev.h  |  1 +
>  drivers/net/virtio/virtio_user_ethdev.c       | 48 +++++++++++++++++--
>  2 files changed, 45 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> index 575bf430c0..1c8c98b1cd 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
> @@ -14,6 +14,7 @@ enum virtio_user_backend_type {
>  	VIRTIO_USER_BACKEND_UNKNOWN,
>  	VIRTIO_USER_BACKEND_VHOST_USER,
>  	VIRTIO_USER_BACKEND_VHOST_KERNEL,
> +	VIRTIO_USER_BACKEND_VHOST_VDPA,
>  };
> 
>  struct virtio_user_queue {
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index 38b49bad5f..3a51afd711 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -6,7 +6,9 @@
>  #include <sys/types.h>
>  #include <unistd.h>
>  #include <fcntl.h>
> +#include <linux/major.h>
>  #include <sys/stat.h>
> +#include <sys/sysmacros.h>
>  #include <sys/socket.h>
> 
>  #include <rte_malloc.h>
> @@ -519,17 +521,55 @@ get_integer_arg(const char *key __rte_unused,
>  	return -errno;
>  }
> 
> +static uint32_t
> +vdpa_dynamic_major_num(void)
> +{
> +	FILE *fp;
> +	char *line = NULL;
> +	size_t size;
> +	char name[11];
> +	bool found = false;
> +	uint32_t num;
> +
> +	fp = fopen("/proc/devices", "r");
> +	if (fp == NULL) {
> +		PMD_INIT_LOG(ERR, "Cannot open /proc/devices: %s",
> +			     strerror(errno));
> +		return UNNAMED_MAJOR;
> +	}
> +
> +	while (getline(&line, &size, fp) > 0) {
> +		char *stripped = line + strspn(line, " ");
> +		if ((sscanf(stripped, "%u %10s", &num, name) == 2) &&
> +		    (strncmp(name, "vhost-vdpa", 10) == 0)) {
> +			found = true;
> +			break;
> +		}
> +	}
> +	fclose(fp);
> +	return found ? num : UNNAMED_MAJOR;
> +}
> +
>  static enum virtio_user_backend_type
>  virtio_user_backend_type(const char *path)
>  {
>  	struct stat sb;
> 
> -	if (stat(path, &sb) == -1)
> +	if (stat(path, &sb) == -1) {
> +		PMD_INIT_LOG(ERR, "Stat fails: %s (%s)\n", path,
> +			     strerror(errno));
>  		return VIRTIO_USER_BACKEND_UNKNOWN;
> +	}
> 
> -	return S_ISSOCK(sb.st_mode) ?
> -		VIRTIO_USER_BACKEND_VHOST_USER :
> -		VIRTIO_USER_BACKEND_VHOST_KERNEL;
> +	if (S_ISSOCK(sb.st_mode)) {
> +		return VIRTIO_USER_BACKEND_VHOST_USER;
> +	} else if (S_ISCHR(sb.st_mode)) {
> +		if (major(sb.st_rdev) == MISC_MAJOR)
> +			return VIRTIO_USER_BACKEND_VHOST_KERNEL;
> +		if (major(sb.st_rdev) == vdpa_dynamic_major_num())
> +			return VIRTIO_USER_BACKEND_VHOST_VDPA;
> +	}
> +	return VIRTIO_USER_BACKEND_UNKNOWN;
>  }
> 
>  static struct rte_eth_dev *
> --
> 2.26.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

  reply	other threads:[~2020-09-30  5:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-29 16:13 [dpdk-dev] [PATCH v3 0/8] virtio-user: introduce vhost-vdpa backend Maxime Coquelin
2020-09-29 16:13 ` [dpdk-dev] [PATCH v3 1/8] bus/vdev: add DMA mapping ops Maxime Coquelin
2020-09-30  5:47   ` Xia, Chenbo
2020-09-29 16:13 ` [dpdk-dev] [PATCH v3 2/8] net/virtio: introduce DMA ops Maxime Coquelin
2020-09-30  5:47   ` Xia, Chenbo
2020-09-29 16:13 ` [dpdk-dev] [PATCH v3 3/8] net/virtio: move backend type selection to ethdev Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo
2020-10-16  5:42   ` Wang, Yinan
2020-10-16  5:58     ` Wang, Yinan
2020-10-20  1:52     ` Wang, Yinan
2020-10-20  7:11       ` Maxime Coquelin
2020-10-20  7:20         ` Adrian Moreno
2020-09-29 16:14 ` [dpdk-dev] [PATCH v3 4/8] net/virtio: introduce Vhost-vDPA backend type Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo [this message]
2020-09-29 16:14 ` [dpdk-dev] [PATCH v3 5/8] net/virtio: check protocol feature in user backend Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo
2020-09-29 16:14 ` [dpdk-dev] [PATCH v3 6/8] net/virtio: adapt Virtio-user status size Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo
2020-09-29 16:14 ` [dpdk-dev] [PATCH v3 7/8] net/virtio: split virtio-user start Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo
2020-09-29 16:14 ` [dpdk-dev] [PATCH v3 8/8] net/virtio: introduce Vhost-vDPA backend Maxime Coquelin
2020-09-30  5:49   ` Xia, Chenbo
2020-09-30 16:22 ` [dpdk-dev] [PATCH v3 0/8] virtio-user: introduce vhost-vdpa backend Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MN2PR11MB4063CE17ACB920A7B7DF7B4F9C330@MN2PR11MB4063.namprd11.prod.outlook.com \
    --to=chenbo.xia@intel.com \
    --cc=amorenoz@redhat.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=patrick.fu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).