From: "Yang, Zhiyong" <zhiyong.yang@intel.com>
To: "Bie, Tiwei" <tiwei.bie@intel.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
"maxime.coquelin@redhat.com" <maxime.coquelin@redhat.com>,
"thomas@monjalon.net" <thomas@monjalon.net>,
"Tan, Jianfeng" <jianfeng.tan@intel.com>,
"Wang, Zhihong" <zhihong.wang@intel.com>,
"Wang, Dong1" <dong1.wang@intel.com>
Subject: Re: [dpdk-dev] [PATCH v5] net/virtio-user: add support for server mode
Date: Thu, 5 Apr 2018 09:19:23 +0000 [thread overview]
Message-ID: <E182254E98A5DA4EB1E657AC7CB9BD2A8B087F16@BGSMSX101.gar.corp.intel.com> (raw)
In-Reply-To: <20180405082929.d53geeppwianqmy4@debian>
Tiwei,
Thanks a lot for your review and comments.
Reply inline.
> -----Original Message-----
> From: Bie, Tiwei
> Sent: Thursday, April 5, 2018 4:29 PM
> To: Yang, Zhiyong <zhiyong.yang@intel.com>
> Cc: dev@dpdk.org; maxime.coquelin@redhat.com; thomas@monjalon.net;
> Tan, Jianfeng <jianfeng.tan@intel.com>; Wang, Zhihong
> <zhihong.wang@intel.com>; Wang, Dong1 <dong1.wang@intel.com>
> Subject: Re: [PATCH v5] net/virtio-user: add support for server mode
>
> On Thu, Apr 05, 2018 at 01:17:53AM +0800, zhiyong.yang@intel.com wrote:
> [...]
> > +static int
> > +virtio_user_start_server(struct virtio_user_dev *dev, struct
> > +sockaddr_un *un) {
> > + int ret;
> > + int flag;
> > + int fd = dev->listenfd;
> > +
> > + ret = bind(fd, (struct sockaddr *)un, sizeof(*un));
> > + if (ret < 0) {
> > + PMD_DRV_LOG(ERR, "failed to bind to %s: %s; remove it and
> try again\n",
> > + dev->path, strerror(errno));
> > + goto err;
> > + }
> > + ret = listen(fd, MAX_VIRTIO_USER_BACKLOG);
> > + if (ret < 0)
> > + goto err;
> > +
> > + flag = fcntl(fd, F_GETFL);
> > + fcntl(fd, F_SETFL, flag | O_NONBLOCK);
> > + dev->vhostfd = -1;
> > +
> > + return 0;
> > +err:
> > + close(dev->listenfd);
>
> The dev->listenfd isn't created in this function, maybe it's better to avoid
> closing this file in this function.
>
Ok.
> > + return -1;
> > +}
> > +
> > /**
> > * Set up environment to talk with a vhost user backend.
> > *
> > @@ -390,6 +418,7 @@ vhost_user_setup(struct virtio_user_dev *dev) {
> > int fd;
> > int flag;
> > + int ret = 0;
> > struct sockaddr_un un;
> >
> > fd = socket(AF_UNIX, SOCK_STREAM, 0); @@ -405,14 +434,20 @@
> > vhost_user_setup(struct virtio_user_dev *dev)
> > memset(&un, 0, sizeof(un));
> > un.sun_family = AF_UNIX;
> > snprintf(un.sun_path, sizeof(un.sun_path), "%s", dev->path);
> > - if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
> > - PMD_DRV_LOG(ERR, "connect error, %s", strerror(errno));
> > - close(fd);
> > - return -1;
> > +
> > + if (dev->is_server) {
> > + dev->listenfd = fd;
> > + ret = virtio_user_start_server(dev, &un);
> > + } else {
>
> Maybe it's better to keep the style consistent. How about something like this:
>
> if (dev->is_server) {
> if (virtio_user_start_server(fd, &un) < 0) {
> PMD_DRV_LOG(ERR, some messages...);
> close(fd);
> return -1;
> }
> dev->listenfd = fd;
> dev->vhostfd = -1;
> } else {
>
Ok. it looks better.
So, the following code changes also.
> > + if (connect(fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
> > + PMD_DRV_LOG(ERR, "connect error, %s",
> strerror(errno));
> > + close(fd);
> > + return -1;
> > + }
> > + dev->vhostfd = fd;
Keep consistency.
> > }
> >
> > - dev->vhostfd = fd;
> > - return 0;
> > + return ret;
> > }
> >
> > static int
> > diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > index f90fee9e5..45e324679 100644
> > --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> > @@ -254,7 +254,8 @@ virtio_user_fill_intr_handle(struct virtio_user_dev
> *dev)
> > eth_dev->intr_handle->fd = -1;
> > if (dev->vhostfd >= 0)
> > eth_dev->intr_handle->fd = dev->vhostfd;
> > -
>
> Maybe it's better to keep this empty line (keep it before the return 0).
>
Ok.
> > + else if (dev->is_server)
> > + eth_dev->intr_handle->fd = dev->listenfd;
> > return 0;
> > }
> >
> > @@ -267,24 +268,29 @@ virtio_user_dev_setup(struct virtio_user_dev
> *dev)
> > dev->vhostfds = NULL;
> > dev->tapfds = NULL;
> >
> > - if (is_vhost_user_by_type(dev->path)) {
> > - dev->ops = &ops_user;
> > + if (dev->is_server) {
> > + dev->ops = &ops_user;/* server mode only supports vhost
> user */
> > } else {
> > - dev->ops = &ops_kernel;
> > -
> > - dev->vhostfds = malloc(dev->max_queue_pairs *
> sizeof(int));
> > - dev->tapfds = malloc(dev->max_queue_pairs * sizeof(int));
> > - if (!dev->vhostfds || !dev->tapfds) {
> > - PMD_INIT_LOG(ERR, "Failed to malloc");
> > - return -1;
> > - }
> > -
> > - for (q = 0; q < dev->max_queue_pairs; ++q) {
> > - dev->vhostfds[q] = -1;
> > - dev->tapfds[q] = -1;
> > + if (is_vhost_user_by_type(dev->path)) {
> > + dev->ops = &ops_user;
> > + } else {
> > + dev->ops = &ops_kernel;
> > +
> > + dev->vhostfds = malloc(dev->max_queue_pairs *
> > + sizeof(int));
> > + dev->tapfds = malloc(dev->max_queue_pairs *
> > + sizeof(int));
> > + if (!dev->vhostfds || !dev->tapfds) {
> > + PMD_INIT_LOG(ERR, "Failed to malloc");
> > + return -1;
> > + }
> > +
> > + for (q = 0; q < dev->max_queue_pairs; ++q) {
> > + dev->vhostfds[q] = -1;
> > + dev->tapfds[q] = -1;
> > + }
> > }
> > }
> > -
>
> There is no need to remove this empty line.
>
Ok
> > if (dev->ops->setup(dev) < 0)
> > return -1;
> >
> > @@ -337,16 +343,21 @@ virtio_user_dev_init(struct virtio_user_dev *dev,
> char *path, int queues,
> > return -1;
> > }
> >
> > - if (dev->ops->send_request(dev, VHOST_USER_SET_OWNER, NULL)
> < 0) {
> > - PMD_INIT_LOG(ERR, "set_owner fails: %s", strerror(errno));
> > - return -1;
> > - }
> > + if (dev->vhostfd >= 0) {
> > + if (dev->ops->send_request(dev,
> VHOST_USER_SET_OWNER, NULL) < 0) {
> > + PMD_INIT_LOG(ERR, "set_owner fails: %s",
> strerror(errno));
> > + return -1;
> > + }
> >
> > - if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
> > - &dev->device_features) < 0) {
> > - PMD_INIT_LOG(ERR, "get_features failed: %s",
> strerror(errno));
> > - return -1;
> > + if (dev->ops->send_request(dev,
> VHOST_USER_GET_FEATURES,
> > + &dev->device_features) < 0) {
> > + PMD_INIT_LOG(ERR, "get_features failed: %s",
> strerror(errno));
> > + return -1;
> > + }
> > + } else {
> > + dev->device_features =
> VIRTIO_USER_SUPPORTED_FEATURES;
>
> If the backend doesn't support e.g. VIRTIO_RING_F_INDIRECT_DESC.
> Will it cause any problem?
>
Let me try it and see what will be happening.
> > }
> > +
> > if (dev->mac_specified)
> > dev->device_features |= (1ull << VIRTIO_NET_F_MAC);
> >
> > @@ -388,6 +399,11 @@ virtio_user_dev_uninit(struct virtio_user_dev
> > *dev)
> >
> > close(dev->vhostfd);
> >
> > + if (dev->is_server && dev->listenfd >= 0) {
> > + close(dev->listenfd);
> > + dev->listenfd = -1;
> > + }
> > +
> > if (dev->vhostfds) {
> > for (i = 0; i < dev->max_queue_pairs; ++i)
> > close(dev->vhostfds[i]);
> > @@ -396,6 +412,9 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
> > }
> >
> > free(dev->ifname);
> > +
> > + if (dev->is_server)
> > + unlink(dev->path);
> > }
> [...]
> >
> > static int
> > get_string_arg(const char *key __rte_unused, @@ -378,10 +438,12 @@
> > virtio_user_pmd_probe(struct rte_vdev_device *dev)
> > uint64_t queues = VIRTIO_USER_DEF_Q_NUM;
> > uint64_t cq = VIRTIO_USER_DEF_CQ_EN;
> > uint64_t queue_size = VIRTIO_USER_DEF_Q_SZ;
> > + uint64_t server_mode = VIRTIO_USER_DEF_SERVER_MODE;
> > char *path = NULL;
> > char *ifname = NULL;
> > char *mac_addr = NULL;
> > int ret = -1;
> > + struct virtio_user_dev *vu_dev = NULL;
>
> Maybe it's better to move the definition of vu_dev after eth_dev. And there
> isn't no need to initialize it.
>
Ok.
thanks
Zhiyong
next prev parent reply other threads:[~2018-04-05 9:19 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-14 14:53 [dpdk-dev] [PATCH 0/4] add to support for virtio-user " Zhiyong Yang
2018-02-14 14:53 ` [dpdk-dev] [PATCH 1/4] vhost: move fdset functions from fd_man.c to fd_man.h Zhiyong Yang
2018-02-27 17:51 ` Maxime Coquelin
2018-02-28 1:36 ` Yang, Zhiyong
2018-02-28 8:45 ` Maxime Coquelin
2018-03-01 6:02 ` Tan, Jianfeng
2018-03-01 14:13 ` Thomas Monjalon
2018-03-05 7:43 ` Yang, Zhiyong
2018-03-05 8:54 ` Thomas Monjalon
2018-03-13 8:46 ` Yang, Zhiyong
[not found] ` <9059097.ABoCBN0gVk@xps>
2018-03-13 9:50 ` Yang, Zhiyong
2018-03-15 9:32 ` Thomas Monjalon
2018-03-16 8:43 ` Yang, Zhiyong
2018-03-21 6:51 ` Yang, Zhiyong
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 0/5] add support for virtio-user server mode zhiyong.yang
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 1/5] net/virtio: fix add pointer checking zhiyong.yang
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 2/5] net/virtio: add checking for cvq zhiyong.yang
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 3/5] eal: expose fdset related APIs zhiyong.yang
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 4/5] net/virtio-user: add support for server mode zhiyong.yang
2018-03-15 9:45 ` [dpdk-dev] [PATCH v2 5/5] net/vhost: add memory checking zhiyong.yang
2018-02-14 14:53 ` [dpdk-dev] [PATCH 2/4] net/virtio-user: add data members to support server mode Zhiyong Yang
2018-02-27 17:53 ` Maxime Coquelin
2018-02-28 1:38 ` Yang, Zhiyong
2018-02-14 14:53 ` [dpdk-dev] [PATCH 3/4] net/virtio-user: " Zhiyong Yang
2018-02-27 18:01 ` Maxime Coquelin
2018-02-28 1:53 ` Yang, Zhiyong
2018-02-28 8:33 ` Maxime Coquelin
2018-02-14 14:53 ` [dpdk-dev] [PATCH 4/4] net/vhost: add memory checking to support client mode Zhiyong Yang
2018-03-21 3:03 ` [dpdk-dev] [PATCH v3 0/4] add support for virtio-user server mode zhiyong.yang
2018-03-21 3:03 ` [dpdk-dev] [PATCH v3 1/4] net/virtio: fix add pointer checking zhiyong.yang
2018-03-28 7:26 ` Tan, Jianfeng
2018-03-28 7:48 ` Yang, Zhiyong
2018-03-29 11:59 ` Maxime Coquelin
2018-03-29 12:01 ` Maxime Coquelin
2018-03-21 3:03 ` [dpdk-dev] [PATCH v3 2/4] net/virtio: add checking for cvq zhiyong.yang
2018-03-28 8:34 ` Tan, Jianfeng
2018-03-29 11:59 ` Maxime Coquelin
2018-03-29 12:06 ` Maxime Coquelin
2018-03-21 3:03 ` [dpdk-dev] [PATCH v3 3/4] net/virtio-user: add support for server mode zhiyong.yang
2018-03-28 15:14 ` Tan, Jianfeng
2018-03-30 2:08 ` Yang, Zhiyong
2018-03-21 3:03 ` [dpdk-dev] [PATCH v3 4/4] net/vhost: add NULL pointer checking zhiyong.yang
2018-03-29 13:19 ` Maxime Coquelin
2018-03-30 2:00 ` Yang, Zhiyong
2018-03-30 7:41 ` Yang, Zhiyong
2018-04-03 12:20 ` [dpdk-dev] [PATCH v4 0/1] server mode virtio-user zhiyong.yang
2018-04-03 12:20 ` [dpdk-dev] [PATCH v4 1/1] net/virtio-user: add support for server mode zhiyong.yang
2018-04-03 15:16 ` Tan, Jianfeng
2018-04-04 3:31 ` Yang, Zhiyong
2018-04-04 3:47 ` Tan, Jianfeng
2018-04-04 5:37 ` Tiwei Bie
2018-04-04 9:59 ` Yang, Zhiyong
2018-04-04 14:57 ` Yang, Zhiyong
2018-04-04 17:17 ` [dpdk-dev] [PATCH v5] " zhiyong.yang
2018-04-05 8:29 ` Tiwei Bie
2018-04-05 9:19 ` Yang, Zhiyong [this message]
2018-04-06 7:22 ` Yang, Zhiyong
2018-04-05 9:21 ` Yang, Zhiyong
2018-04-06 0:18 ` [dpdk-dev] [PATCH v6] " zhiyong.yang
2018-04-05 18:13 ` Tan, Jianfeng
2018-04-06 7:14 ` Yang, Zhiyong
2018-04-06 9:25 ` [dpdk-dev] [PATCH v7] " zhiyong.yang
2018-04-08 0:36 ` Tan, Jianfeng
2018-04-10 11:55 ` 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=E182254E98A5DA4EB1E657AC7CB9BD2A8B087F16@BGSMSX101.gar.corp.intel.com \
--to=zhiyong.yang@intel.com \
--cc=dev@dpdk.org \
--cc=dong1.wang@intel.com \
--cc=jianfeng.tan@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=thomas@monjalon.net \
--cc=tiwei.bie@intel.com \
--cc=zhihong.wang@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).