Skip to contentSkip to conversation

vhost: vhost-cuse removal and code path refactoring

PATCH In review Yuanhan Liu 4 participants 25 messages Aug 18, 2016 – Aug 29, 2016

lore
Share & tools
lore
#0 lore raw

cover vhost: vhost-cuse removal and code path refactoring

The first patch removes the vhost-cuse (see following link for the deprecate note)

    http://dpdk.org/ml/archives/dev/2016-July/044080.html

After the removal, there is no reason to keep the vhost_user sub source dir any more. This also brings a chance to rename all those files in a more proper way (see patch 3 for details).

---
Yuanhan Liu (7):
vhost: remove vhost-cuse
vhost: remove sub source dir
vhost: refactor source code structure
vhost: fold common message handlers
vhost: unify function names
vhost: get device once
vhost: simplify features set/get

 config/common_base                                 |   6 +-
 lib/librte_vhost/Makefile                          |  13 +-
 lib/librte_vhost/eventfd_link/Makefile             |  41 -
 lib/librte_vhost/eventfd_link/eventfd_link.c       | 277 -------
 lib/librte_vhost/eventfd_link/eventfd_link.h       |  94 ---
 lib/librte_vhost/{vhost_user => }/fd_man.c         |   0
 lib/librte_vhost/{vhost_user => }/fd_man.h         |   0
 lib/librte_vhost/libvirt/qemu-wrap.py              | 387 ---------
 .../{vhost_user/vhost-net-user.c => socket.c}      | 209 +----
 lib/librte_vhost/vhost.c                           | 409 +++++++++
 lib/librte_vhost/{vhost-net.h => vhost.h}          |  24 +-
 lib/librte_vhost/vhost_cuse/eventfd_copy.c         | 104 ---
 lib/librte_vhost/vhost_cuse/eventfd_copy.h         |  45 -
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c       | 431 ----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c      | 433 ----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h      |  56 --
 lib/librte_vhost/vhost_user.c                      | 917 +++++++++++++++++++++
 .../{vhost_user/vhost-net-user.h => vhost_user.h}  |  17 +-
 lib/librte_vhost/vhost_user/virtio-net-user.c      | 470 -----------
 lib/librte_vhost/vhost_user/virtio-net-user.h      |  62 --
 lib/librte_vhost/virtio-net.c                      | 847 -------------------
 lib/librte_vhost/{vhost_rxtx.c => virtio_net.c}    |   4 +-
 mk/rte.app.mk                                      |   3 -
 23 files changed, 1367 insertions(+), 3482 deletions(-)
 delete mode 100644 lib/librte_vhost/eventfd_link/Makefile
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h
 rename lib/librte_vhost/{vhost_user => }/fd_man.c (100%)
 rename lib/librte_vhost/{vhost_user => }/fd_man.h (100%)
 delete mode 100755 lib/librte_vhost/libvirt/qemu-wrap.py
 rename lib/librte_vhost/{vhost_user/vhost-net-user.c => socket.c} (71%)
 create mode 100644 lib/librte_vhost/vhost.c
 rename lib/librte_vhost/{vhost-net.h => vhost.h} (92%)
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.h
 delete mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
 create mode 100644 lib/librte_vhost/vhost_user.c
 rename lib/librte_vhost/{vhost_user/vhost-net-user.h => vhost_user.h} (87%)
 delete mode 100644 lib/librte_vhost/vhost_user/virtio-net-user.c
 delete mode 100644 lib/librte_vhost/vhost_user/virtio-net-user.h
 delete mode 100644 lib/librte_vhost/virtio-net.c
 rename lib/librte_vhost/{vhost_rxtx.c => virtio_net.c} (99%)
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/7 vhost: remove vhost-cuse

remove vhost-cuse code, including the eventfd_link kernel module that is for vhost-cuse only.

The lib/virt/qemu-wrap.py is also removed, as it's mainly for vhost-cuse usage.

As we have one vhost implementation now, one vhost config option is needed only. Thus, CONFIG_RTE_LIBRTE_VHOST_USER is removed.

---
 config/common_base                            |   6 +-
 lib/librte_vhost/Makefile                     |  13 +-
 lib/librte_vhost/eventfd_link/Makefile        |  41 ---
 lib/librte_vhost/eventfd_link/eventfd_link.c  | 277 ----------------
 lib/librte_vhost/eventfd_link/eventfd_link.h  |  94 ------
 lib/librte_vhost/libvirt/qemu-wrap.py         | 387 -----------------------
 lib/librte_vhost/vhost_cuse/eventfd_copy.c    | 104 -------
 lib/librte_vhost/vhost_cuse/eventfd_copy.h    |  45 ---
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 431 -------------------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 433 --------------------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  56 ----
 mk/rte.app.mk                                 |   3 -
 12 files changed, 4 insertions(+), 1886 deletions(-)
 delete mode 100644 lib/librte_vhost/eventfd_link/Makefile
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h
 delete mode 100755 lib/librte_vhost/libvirt/qemu-wrap.py
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.h
 delete mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
config/common_base +1 -5
index 7830535..c703908 100644
@@ -546,13 +546,9 @@ CONFIG_RTE_KNI_VHOST_DEBUG_TX=n
 CONFIG_RTE_LIBRTE_PDUMP=y
 
 #
-# Compile vhost library
-# fuse-devel is needed to run vhost-cuse.
-# fuse-devel enables user space char driver development
-# vhost-user is turned on by default.
+# Compile vhost user library
 #
 CONFIG_RTE_LIBRTE_VHOST=n
-CONFIG_RTE_LIBRTE_VHOST_USER=y
 CONFIG_RTE_LIBRTE_VHOST_NUMA=n
 CONFIG_RTE_LIBRTE_VHOST_DEBUG=n
 
lib/librte_vhost/Makefile +3 -10
index 538adb0..fb4e7f8 100644
@@ -39,13 +39,8 @@ EXPORT_MAP := rte_vhost_version.map
 LIBABIVER := 3
 
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -D_FILE_OFFSET_BITS=64
-ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y)
 CFLAGS += -I vhost_user
 LDLIBS += -lpthread
-else
-CFLAGS += -I vhost_cuse
-LDLIBS += -lfuse
-endif
 
 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
 LDLIBS += -lnuma
@@ -53,11 +48,9 @@ endif
 
 # all source are stored in SRCS-y
 SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c
-ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),y)
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/vhost-net-user.c vhost_user/virtio-net-user.c vhost_user/fd_man.c
-else
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_cuse/vhost-net-cdev.c vhost_cuse/virtio-net-cdev.c vhost_cuse/eventfd_copy.c
-endif
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/vhost-net-user.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/virtio-net-user.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/fd_man.c
 
 # install includes
 SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h
lib/librte_vhost/eventfd_link/Makefile deleted +0 -41

41 lines not on this page · raw message

lib/librte_vhost/eventfd_link/eventfd_link.c deleted +0 -277

277 lines not on this page · raw message

lib/librte_vhost/eventfd_link/eventfd_link.h deleted +0 -94

94 lines not on this page · raw message

lib/librte_vhost/libvirt/qemu-wrap.py deleted +0 -387

387 lines not on this page · raw message

lib/librte_vhost/vhost_cuse/eventfd_copy.c deleted +0 -104

104 lines not on this page · raw message

lib/librte_vhost/vhost_cuse/eventfd_copy.h deleted +0 -45

45 lines not on this page · raw message

lib/librte_vhost/vhost_cuse/vhost-net-cdev.c deleted +0 -431

431 lines not on this page · raw message

lib/librte_vhost/vhost_cuse/virtio-net-cdev.c deleted +0 -433

433 lines not on this page · raw message

lib/librte_vhost/vhost_cuse/virtio-net-cdev.h deleted +0 -56

56 lines not on this page · raw message

mk/rte.app.mk +0 -3
index eb28e11..f00de7a 100644
@@ -158,9 +158,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lm
 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lnuma
 endif
-ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n)
-_LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lfuse
-endif
 _LDLIBS-$(CONFIG_RTE_PORT_PCAP)             += -lpcap
 endif # !CONFIG_RTE_BUILD_SHARED_LIBS
 
Signature · 1 line
1.9.0
#2 lore raw

Re: [PATCH 1/7] vhost: remove vhost-cuse

2016-08-18 16:48, Yuanhan Liu:

Quoted 2 lines

remove vhost-cuse code, including the eventfd_link kernel module that is for vhost-cuse only.

Please, remove also the deprecation notice. Thanks

#3 lore raw

Re: [PATCH 1/7] vhost: remove vhost-cuse

Quoted 5 lines · Thomas Monjalon

2016-08-18 16:48, Yuanhan Liu:

Quoted 2 lines

remove vhost-cuse code, including the eventfd_link kernel module that is for vhost-cuse only.

Please, remove also the deprecation notice. Thanks

Yes, David also reminded me about that soon when I sent it out. Will fix it.

	--yliu
author Applied
#4 lore raw

Re: [PATCH 1/7] vhost: remove vhost-cuse

In reply to Thomas Monjalon
Quoted 5 lines · Thomas Monjalon

2016-08-18 16:48, Yuanhan Liu:

Quoted 2 lines

remove vhost-cuse code, including the eventfd_link kernel module that is for vhost-cuse only.

Please, remove also the deprecation notice. Thanks

Applied to dpdk-next-virtio, with the deprecation notic removal included.

BTW, thanks Maxime for the review!

	--yliu
Reviewed-by on v1 1/7
#5 lore raw

Re: [PATCH 1/7] vhost: remove vhost-cuse

In reply to Yuanhan Liu
Quoted 25 lines · Yuanhan Liu

remove vhost-cuse code, including the eventfd_link kernel module that is for vhost-cuse only.

The lib/virt/qemu-wrap.py is also removed, as it's mainly for vhost-cuse usage.

As we have one vhost implementation now, one vhost config option is needed only. Thus, CONFIG_RTE_LIBRTE_VHOST_USER is removed.

---
 config/common_base                            |   6 +-
 lib/librte_vhost/Makefile                     |  13 +-
 lib/librte_vhost/eventfd_link/Makefile        |  41 ---
 lib/librte_vhost/eventfd_link/eventfd_link.c  | 277 ----------------
 lib/librte_vhost/eventfd_link/eventfd_link.h  |  94 ------
 lib/librte_vhost/libvirt/qemu-wrap.py         | 387 -----------------------
 lib/librte_vhost/vhost_cuse/eventfd_copy.c    | 104 -------
 lib/librte_vhost/vhost_cuse/eventfd_copy.h    |  45 ---
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c  | 431 -------------------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 433 --------------------------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h |  56 ----
 mk/rte.app.mk                                 |   3 -
 12 files changed, 4 insertions(+), 1886 deletions(-)
 delete mode 100644 lib/librte_vhost/eventfd_link/Makefile
Quoted 8 lines
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h
 delete mode 100755 lib/librte_vhost/libvirt/qemu-wrap.py
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.h
 delete mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h

Looks good to me:

Thanks,
Maxime

#6 lore raw

PATCH 2/7 vhost: remove sub source dir

In reply to Yuanhan Liu

We now have one vhost implementation; no sub source dir is needed. Rmove it by move them to upper dir.

---
 lib/librte_vhost/Makefile                           | 6 +++---
 lib/librte_vhost/{vhost_user => }/fd_man.c          | 0
 lib/librte_vhost/{vhost_user => }/fd_man.h          | 0
 lib/librte_vhost/{vhost_user => }/vhost-net-user.c  | 0
 lib/librte_vhost/{vhost_user => }/vhost-net-user.h  | 0
 lib/librte_vhost/{vhost_user => }/virtio-net-user.c | 0
 lib/librte_vhost/{vhost_user => }/virtio-net-user.h | 0
 7 files changed, 3 insertions(+), 3 deletions(-)
 rename lib/librte_vhost/{vhost_user => }/fd_man.c (100%)
 rename lib/librte_vhost/{vhost_user => }/fd_man.h (100%)
 rename lib/librte_vhost/{vhost_user => }/vhost-net-user.c (100%)
 rename lib/librte_vhost/{vhost_user => }/vhost-net-user.h (100%)
 rename lib/librte_vhost/{vhost_user => }/virtio-net-user.c (100%)
 rename lib/librte_vhost/{vhost_user => }/virtio-net-user.h (100%)
lib/librte_vhost/Makefile +3 -3
index fb4e7f8..277390f 100644
@@ -48,9 +48,9 @@ endif
 
 # all source are stored in SRCS-y
 SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/vhost-net-user.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/virtio-net-user.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost_user/fd_man.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost-net-user.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += virtio-net-user.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += fd_man.c
 
 # install includes
 SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h
lib/librte_vhost/fd_man.c renamed from lib/librte_vhost/vhost_user/fd_man.c +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/fd_man.c
rename to lib/librte_vhost/fd_man.c
lib/librte_vhost/fd_man.h renamed from lib/librte_vhost/vhost_user/fd_man.h +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/fd_man.h
rename to lib/librte_vhost/fd_man.h
lib/librte_vhost/vhost-net-user.c renamed from lib/librte_vhost/vhost_user/vhost-net-user.c +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/vhost-net-user.c
rename to lib/librte_vhost/vhost-net-user.c
lib/librte_vhost/vhost-net-user.h renamed from lib/librte_vhost/vhost_user/vhost-net-user.h +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/vhost-net-user.h
rename to lib/librte_vhost/vhost-net-user.h
lib/librte_vhost/virtio-net-user.c renamed from lib/librte_vhost/vhost_user/virtio-net-user.c +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/virtio-net-user.c
rename to lib/librte_vhost/virtio-net-user.c
lib/librte_vhost/virtio-net-user.h renamed from lib/librte_vhost/vhost_user/virtio-net-user.h +0 -0
similarity index 100%
rename from lib/librte_vhost/vhost_user/virtio-net-user.h
rename to lib/librte_vhost/virtio-net-user.h
Signature · 1 line
1.9.0
Reviewed-by on v1 2/7
#7 lore raw

Re: [PATCH 2/7] vhost: remove sub source dir

Quoted 2 lines · Yuanhan Liu

We now have one vhost implementation; no sub source dir is needed. Rmove it by move them to upper dir.

s/Rmove/Remove/

Quoted 17 lines
---
 lib/librte_vhost/Makefile                           | 6 +++---
 lib/librte_vhost/{vhost_user => }/fd_man.c          | 0
 lib/librte_vhost/{vhost_user => }/fd_man.h          | 0
 lib/librte_vhost/{vhost_user => }/vhost-net-user.c  | 0
 lib/librte_vhost/{vhost_user => }/vhost-net-user.h  | 0
 lib/librte_vhost/{vhost_user => }/virtio-net-user.c | 0
 lib/librte_vhost/{vhost_user => }/virtio-net-user.h | 0
 7 files changed, 3 insertions(+), 3 deletions(-)
 rename lib/librte_vhost/{vhost_user => }/fd_man.c (100%)
 rename lib/librte_vhost/{vhost_user => }/fd_man.h (100%)
 rename lib/librte_vhost/{vhost_user => }/vhost-net-user.c (100%)
 rename lib/librte_vhost/{vhost_user => }/vhost-net-user.h (100%)
 rename lib/librte_vhost/{vhost_user => }/virtio-net-user.c (100%)
 rename lib/librte_vhost/{vhost_user => }/virtio-net-user.h (100%)

Other than this typo:

Thanks,
Maxime

#8 lore raw

PATCH 3/7 vhost: refactor source code structure

In reply to Yuanhan Liu

The code structure is a bit messy now. For example, vhost-user message handling is spread to three different files:

vhost-net-user.c virtio-net.c virtio-net-user.c

Where, vhost-net-user.c is the entrance to handle all those messages and then invoke the right method for a specific message. Some of them are stored at virtio-net.c, while others are stored at virtio-net-user.c.

The truth is all of them should be in one file, vhost_user.c.

So this patch refactors the source code structure: mainly on renaming files and moving code from one file to another file that is more suitable for storing it. Thus, no functional changes are made.

After the refactor, the code structure becomes to:

- socket.c handles all vhost-user socket file related stuff, such
as, socket file creation for server mode, reconnection for client mode.

- vhost.c mainly on stuff like vhost device creation/destroy/reset.
Most of the vhost API implementation are there, too.

- vhost_user.c all stuff about vhost-user messages handling goes there.

- virtio_net.c all stuff about virtio-net should go there. It has virtio net Rx/Tx implementation only so far: it's just a rename from vhost_rxtx.c

---
 lib/librte_vhost/Makefile                          |    6 +-
 lib/librte_vhost/{vhost-net-user.c => socket.c}    |  209 +---
 lib/librte_vhost/vhost.c                           |  409 ++++++++
 lib/librte_vhost/{vhost-net.h => vhost.h}          |   24 +-
 lib/librte_vhost/vhost_user.c                      | 1040 ++++++++++++++++++++
 .../{vhost-net-user.h => vhost_user.h}             |   17 +-
 lib/librte_vhost/virtio-net-user.c                 |  470 ---------
 lib/librte_vhost/virtio-net-user.h                 |   62 --
 lib/librte_vhost/virtio-net.c                      |  847 ----------------
 lib/librte_vhost/{vhost_rxtx.c => virtio_net.c}    |    4 +-
 10 files changed, 1489 insertions(+), 1599 deletions(-)
 rename lib/librte_vhost/{vhost-net-user.c => socket.c} (71%)
 create mode 100644 lib/librte_vhost/vhost.c
 rename lib/librte_vhost/{vhost-net.h => vhost.h} (92%)
 create mode 100644 lib/librte_vhost/vhost_user.c
 rename lib/librte_vhost/{vhost-net-user.h => vhost_user.h} (87%)
 delete mode 100644 lib/librte_vhost/virtio-net-user.c
 delete mode 100644 lib/librte_vhost/virtio-net-user.h
 delete mode 100644 lib/librte_vhost/virtio-net.c
 rename lib/librte_vhost/{vhost_rxtx.c => virtio_net.c} (99%)
lib/librte_vhost/Makefile +2 -4
index 277390f..415ffc6 100644
@@ -47,10 +47,8 @@ LDLIBS += -lnuma
 endif
 
 # all source are stored in SRCS-y
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := virtio-net.c vhost_rxtx.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += vhost-net-user.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += virtio-net-user.c
-SRCS-$(CONFIG_RTE_LIBRTE_VHOST) += fd_man.c
+SRCS-$(CONFIG_RTE_LIBRTE_VHOST) := fd_man.c socket.c vhost.c vhost_user.c \
+				   virtio_net.c
 
 # install includes
 SYMLINK-$(CONFIG_RTE_LIBRTE_VHOST)-include += rte_virtio_net.h
lib/librte_vhost/socket.c renamed from lib/librte_vhost/vhost-net-user.c +12 -197

272 lines not on this page · raw message

lib/librte_vhost/vhost.c new file +409 -0

409 lines not on this page · raw message

lib/librte_vhost/vhost.h renamed from lib/librte_vhost/vhost-net.h +8 -16
similarity index 92%
rename from lib/librte_vhost/vhost-net.h
rename to lib/librte_vhost/vhost.h
index 38593a2..c2dfc3c 100644
@@ -196,6 +196,10 @@ struct virtio_memory {
 #define PRINT_PACKET(device, addr, size, header) do {} while (0)
 #endif
 
+extern uint64_t VHOST_FEATURES;
+#define MAX_VHOST_DEVICE	1024
+extern struct virtio_net *vhost_devices[MAX_VHOST_DEVICE];
+
 /**
  * Function to convert guest physical addresses to vhost virtual addresses.
  * This is used to convert guest virtio buffer addresses.
@@ -222,25 +226,13 @@ struct virtio_net_device_ops const *notify_ops;
 struct virtio_net *get_device(int vid);
 
 int vhost_new_device(void);
+void cleanup_device(struct virtio_net *dev, int destroy);
+void reset_device(struct virtio_net *dev);
 void vhost_destroy_device(int);
 
-void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
-
-int vhost_get_features(int, uint64_t *);
-int vhost_set_features(int, uint64_t *);
-
-int vhost_set_vring_num(int, struct vhost_vring_state *);
-int vhost_set_vring_addr(int, struct vhost_vring_addr *);
-int vhost_set_vring_base(int, struct vhost_vring_state *);
-int vhost_get_vring_base(int, uint32_t, struct vhost_vring_state *);
+int alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx);
 
-int vhost_set_vring_kick(int, struct vhost_vring_file *);
-int vhost_set_vring_call(int, struct vhost_vring_file *);
-
-int vhost_set_backend(int, struct vhost_vring_file *);
-
-int vhost_set_owner(int);
-int vhost_reset_owner(int);
+void vhost_set_ifname(int, const char *if_name, unsigned int if_len);
 
 /*
  * Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
lib/librte_vhost/vhost_user.c new file +1040 -0

1,040 lines not on this page · raw message

lib/librte_vhost/vhost_user.h renamed from lib/librte_vhost/vhost-net-user.h +16 -1
similarity index 87%
rename from lib/librte_vhost/vhost-net-user.h
rename to lib/librte_vhost/vhost_user.h
index f533239..ba78d32 100644
@@ -43,6 +43,14 @@
 
 #define VHOST_MEMORY_MAX_NREGIONS 8
 
+#define VHOST_USER_PROTOCOL_F_MQ	0
+#define VHOST_USER_PROTOCOL_F_LOG_SHMFD	1
+#define VHOST_USER_PROTOCOL_F_RARP	2
+
+#define VHOST_USER_PROTOCOL_FEATURES	((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
+					 (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
+					 (1ULL << VHOST_USER_PROTOCOL_F_RARP))
+
 typedef enum VhostUserRequest {
 	VHOST_USER_NONE = 0,
 	VHOST_USER_GET_FEATURES = 1,
@@ -109,5 +117,12 @@ typedef struct VhostUserMsg {
 /* The version of the protocol we support */
 #define VHOST_USER_VERSION    0x1
 
-/*****************************************************************************/
+
+/* vhost_user.c */
+int vhost_user_msg_handler(int vid, int fd);
+
+/* socket.c */
+int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
+
 #endif
lib/librte_vhost/virtio-net-user.c deleted +0 -470

470 lines not on this page · raw message

lib/librte_vhost/virtio-net-user.h deleted +0 -62

62 lines not on this page · raw message

lib/librte_vhost/virtio-net.c deleted +0 -847

669 lines not on this page · raw message

lib/librte_vhost/virtio_net.c renamed from lib/librte_vhost/vhost_rxtx.c +2 -2
similarity index 99%
rename from lib/librte_vhost/vhost_rxtx.c
rename to lib/librte_vhost/virtio_net.c
index 08a73fd..8a151af 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.0

Part of the diff is not shown here. View the raw message.

Reviewed-by on v1 3/7
#9 lore raw

Re: [PATCH 3/7] vhost: refactor source code structure

Quoted 44 lines · Yuanhan Liu

The code structure is a bit messy now. For example, vhost-user message handling is spread to three different files:

vhost-net-user.c virtio-net.c virtio-net-user.c

Where, vhost-net-user.c is the entrance to handle all those messages and then invoke the right method for a specific message. Some of them are stored at virtio-net.c, while others are stored at virtio-net-user.c.

The truth is all of them should be in one file, vhost_user.c.

So this patch refactors the source code structure: mainly on renaming files and moving code from one file to another file that is more suitable for storing it. Thus, no functional changes are made.

After the refactor, the code structure becomes to:

- socket.c handles all vhost-user socket file related stuff, such
as, socket file creation for server mode, reconnection for client mode.

- vhost.c mainly on stuff like vhost device creation/destroy/reset.
Most of the vhost API implementation are there, too.

- vhost_user.c all stuff about vhost-user messages handling goes there.

- virtio_net.c all stuff about virtio-net should go there. It has virtio net Rx/Tx implementation only so far: it's just a rename from vhost_rxtx.c

---
 lib/librte_vhost/Makefile                          |    6 +-
 lib/librte_vhost/{vhost-net-user.c => socket.c}    |  209 +---
 lib/librte_vhost/vhost.c                           |  409 ++++++++
 lib/librte_vhost/{vhost-net.h => vhost.h}          |   24 +-
 lib/librte_vhost/vhost_user.c                      | 1040 ++++++++++++++++++++
 .../{vhost-net-user.h => vhost_user.h}             |   17 +-
 lib/librte_vhost/virtio-net-user.c                 |  470 ---------
 lib/librte_vhost/virtio-net-user.h                 |   62 --
 lib/librte_vhost/virtio-net.c                      |  847 ----------------
 lib/librte_vhost/{vhost_rxtx.c => virtio_net.c}    |    4 +-
 10 files changed, 1489 insertions(+), 1599 deletions(-)
 rename lib/librte_vhost/{vhost-net-user.c => socket.c} (71%)
Quoted 8 lines
 create mode 100644 lib/librte_vhost/vhost.c
 rename lib/librte_vhost/{vhost-net.h => vhost.h} (92%)
 create mode 100644 lib/librte_vhost/vhost_user.c
 rename lib/librte_vhost/{vhost-net-user.h => vhost_user.h} (87%)
 delete mode 100644 lib/librte_vhost/virtio-net-user.c
 delete mode 100644 lib/librte_vhost/virtio-net-user.h
 delete mode 100644 lib/librte_vhost/virtio-net.c
 rename lib/librte_vhost/{vhost_rxtx.c => virtio_net.c} (99%)

The structure is much cleaner now, and thanks for the detailed information.

I didn't catch any error, and agree on the change:

Thanks,
Maxime

#10 lore raw

PATCH 4/7 vhost: fold common message handlers

In reply to Yuanhan Liu

Due to history reason (that we have 2 vhost implementations), some messages are handled in two calls: vhost specific implementation handles it first and then invoke the common one to do another handling.

We have one implementation only now, we could write one method for each message. Here fold those common handles to corresponding vhost user handler.

---
 lib/librte_vhost/vhost_user.c | 115 ++++++++++++------------------------------
 1 file changed, 31 insertions(+), 84 deletions(-)
lib/librte_vhost/vhost_user.c +31 -84
index c4714b7..ada0a63 100644
@@ -426,87 +426,6 @@ vhost_set_vring_base(int vid, struct vhost_vring_state *state)
 	return 0;
 }
 
-/*
- * We send the virtio device our available ring last used index.
- */
-static int
-vhost_get_vring_base(int vid, uint32_t index,
-	struct vhost_vring_state *state)
-{
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	state->index = index;
-	/* State->index refers to the queue index. The txq is 1, rxq is 0. */
-	state->num = dev->virtqueue[state->index]->last_used_idx;
-
-	return 0;
-}
-
-/*
- * The virtio device sends an eventfd to interrupt the guest. This fd gets
- * copied into our process space.
- */
-static int
-vhost_set_vring_call(int vid, struct vhost_vring_file *file)
-{
-	struct virtio_net *dev;
-	struct vhost_virtqueue *vq;
-	uint32_t cur_qp_idx = file->index / VIRTIO_QNUM;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	/*
-	 * FIXME: VHOST_SET_VRING_CALL is the first per-vring message
-	 * we get, so we do vring queue pair allocation here.
-	 */
-	if (cur_qp_idx + 1 > dev->virt_qp_nb) {
-		if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0)
-			return -1;
-	}
-
-	/* file->index refers to the queue index. The txq is 1, rxq is 0. */
-	vq = dev->virtqueue[file->index];
-	assert(vq != NULL);
-
-	if (vq->callfd >= 0)
-		close(vq->callfd);
-
-	vq->callfd = file->fd;
-
-	return 0;
-}
-
-/*
- * The virtio device sends an eventfd that it can use to notify us.
- * This fd gets copied into our process space.
- */
-static int
-vhost_set_vring_kick(int vid, struct vhost_vring_file *file)
-{
-	struct virtio_net *dev;
-	struct vhost_virtqueue *vq;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	/* file->index refers to the queue index. The txq is 1, rxq is 0. */
-	vq = dev->virtqueue[file->index];
-
-	if (vq->kickfd >= 0)
-		close(vq->kickfd);
-
-	vq->kickfd = file->fd;
-
-	return 0;
-}
-
 static int
 user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 {
@@ -671,6 +590,12 @@ static void
 user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
+	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
+	uint32_t cur_qp_idx;
+
+	if (!dev)
+		return;
 
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
@@ -679,7 +604,24 @@ user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring call idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_call(vid, &file);
+
+	/*
+	 * FIXME: VHOST_SET_VRING_CALL is the first per-vring message
+	 * we get, so we do vring queue pair allocation here.
+	 */
+	cur_qp_idx = file.index / VIRTIO_QNUM;
+	if (cur_qp_idx + 1 > dev->virt_qp_nb) {
+		if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0)
+			return;
+	}
+
+	vq = dev->virtqueue[file.index];
+	assert(vq != NULL);
+
+	if (vq->callfd >= 0)
+		close(vq->callfd);
+
+	vq->callfd = file.fd;
 }
 
 /*
@@ -691,6 +633,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
+	struct vhost_virtqueue *vq;
 
 	if (!dev)
 		return;
@@ -702,7 +645,11 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 		file.fd = pmsg->fds[0];
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring kick idx:%d file:%d\n", file.index, file.fd);
-	vhost_set_vring_kick(vid, &file);
+
+	vq = dev->virtqueue[file.index];
+	if (vq->kickfd >= 0)
+		close(vq->kickfd);
+	vq->kickfd = file.fd;
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
 		if (notify_ops->new_device(vid) == 0)
@@ -727,7 +674,7 @@ user_get_vring_base(int vid, struct vhost_vring_state *state)
 	}
 
 	/* Here we are safe to get the last used index */
-	vhost_get_vring_base(vid, state->index, state);
+	state->num = dev->virtqueue[state->index]->last_used_idx;
 
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"vring base idx:%d file:%d\n", state->index, state->num);
Signature · 1 line
1.9.0
Reviewed-by on v1 4/7
#11 lore raw

Re: [PATCH 4/7] vhost: fold common message handlers

Quoted 4 lines · Yuanhan Liu

Due to history reason (that we have 2 vhost implementations), some messages are handled in two calls: vhost specific implementation handles it first and then invoke the common one to do another handling.

Quoted 9 lines

We have one implementation only now, we could write one method for each message. Here fold those common handles to corresponding vhost user handler.

---
 lib/librte_vhost/vhost_user.c | 115 ++++++++++++------------------------------
 1 file changed, 31 insertions(+), 84 deletions(-)

Thanks,
Maxime

#12 lore raw

PATCH 5/7 vhost: unify function names

In reply to Yuanhan Liu

Some functions are with prefix "user_", while others with "vhost_". Making them all starting with "vhost_user_" to unify the function names.

---
 lib/librte_vhost/vhost_user.c | 60 +++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 30 deletions(-)
lib/librte_vhost/vhost_user.c +30 -30
index ada0a63..de3048c 100644
@@ -134,7 +134,7 @@ vhost_backend_cleanup(struct virtio_net *dev)
  * the device hasn't been initialised.
  */
 static int
-vhost_set_owner(int vid)
+vhost_user_set_owner(int vid)
 {
 	struct virtio_net *dev;
 
@@ -146,7 +146,7 @@ vhost_set_owner(int vid)
 }
 
 static int
-vhost_reset_owner(int vid)
+vhost_user_reset_owner(int vid)
 {
 	struct virtio_net *dev;
 
@@ -168,7 +168,7 @@ vhost_reset_owner(int vid)
  * The features that we support are requested.
  */
 static int
-vhost_get_features(int vid, uint64_t *pu)
+vhost_user_get_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 
@@ -185,7 +185,7 @@ vhost_get_features(int vid, uint64_t *pu)
  * We receive the negotiated features supported by us and the virtio device.
  */
 static int
-vhost_set_features(int vid, uint64_t *pu)
+vhost_user_set_features(int vid, uint64_t *pu)
 {
 	struct virtio_net *dev;
 
@@ -215,7 +215,7 @@ vhost_set_features(int vid, uint64_t *pu)
  * The virtio device sends us the size of the descriptor ring.
  */
 static int
-vhost_set_vring_num(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_num(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
@@ -343,7 +343,7 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
  * This function then converts these to our address space.
  */
 static int
-vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr)
+vhost_user_set_vring_addr(int vid, struct vhost_vring_addr *addr)
 {
 	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
@@ -412,7 +412,7 @@ vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr)
  * The virtio device sends us the available ring last used index.
  */
 static int
-vhost_set_vring_base(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_base(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 
@@ -427,7 +427,7 @@ vhost_set_vring_base(int vid, struct vhost_vring_state *state)
 }
 
 static int
-user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
 {
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct virtio_memory_regions *pregion;
@@ -587,7 +587,7 @@ virtio_is_ready(struct virtio_net *dev)
 }
 
 static void
-user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
@@ -629,7 +629,7 @@ user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
  *  device is ready for packet processing.
  */
 static void
-user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
 	struct virtio_net *dev = get_device(vid);
@@ -661,7 +661,7 @@ user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
  * when virtio is stopped, qemu will send us the GET_VRING_BASE message.
  */
 static int
-user_get_vring_base(int vid, struct vhost_vring_state *state)
+vhost_user_get_vring_base(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev = get_device(vid);
 
@@ -696,7 +696,7 @@ user_get_vring_base(int vid, struct vhost_vring_state *state)
  * enable the virtio queue pair.
  */
 static int
-user_set_vring_enable(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_enable(int vid, struct vhost_vring_state *state)
 {
 	struct virtio_net *dev;
 	int enable = (int)state->num;
@@ -718,7 +718,7 @@ user_set_vring_enable(int vid, struct vhost_vring_state *state)
 }
 
 static void
-user_set_protocol_features(int vid, uint64_t protocol_features)
+vhost_user_set_protocol_features(int vid, uint64_t protocol_features)
 {
 	struct virtio_net *dev;
 
@@ -730,7 +730,7 @@ user_set_protocol_features(int vid, uint64_t protocol_features)
 }
 
 static int
-user_set_log_base(int vid, struct VhostUserMsg *msg)
+vhost_user_set_log_base(int vid, struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
 	int fd = msg->fds[0];
@@ -793,7 +793,7 @@ user_set_log_base(int vid, struct VhostUserMsg *msg)
  * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it.
  */
 static int
-user_send_rarp(int vid, struct VhostUserMsg *msg)
+vhost_user_send_rarp(int vid, struct VhostUserMsg *msg)
 {
 	struct virtio_net *dev;
 	uint8_t *mac = (uint8_t *)&msg->payload.u64;
@@ -894,14 +894,14 @@ vhost_user_msg_handler(int vid, int fd)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_get_features(vid, &features);
+		ret = vhost_user_get_features(vid, &features);
 		msg.payload.u64 = features;
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(fd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
 		features = msg.payload.u64;
-		vhost_set_features(vid, &features);
+		vhost_user_set_features(vid, &features);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -910,22 +910,22 @@ vhost_user_msg_handler(int vid, int fd)
 		send_vhost_message(fd, &msg);
 		break;
 	case VHOST_USER_SET_PROTOCOL_FEATURES:
-		user_set_protocol_features(vid, msg.payload.u64);
+		vhost_user_set_protocol_features(vid, msg.payload.u64);
 		break;
 
 	case VHOST_USER_SET_OWNER:
-		vhost_set_owner(vid);
+		vhost_user_set_owner(vid);
 		break;
 	case VHOST_USER_RESET_OWNER:
-		vhost_reset_owner(vid);
+		vhost_user_reset_owner(vid);
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		user_set_mem_table(vid, &msg);
+		vhost_user_set_mem_table(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-		user_set_log_base(vid, &msg);
+		vhost_user_set_log_base(vid, &msg);
 
 		/* it needs a reply */
 		msg.size = sizeof(msg.payload.u64);
@@ -937,26 +937,26 @@ vhost_user_msg_handler(int vid, int fd)
 		break;
 
 	case VHOST_USER_SET_VRING_NUM:
-		vhost_set_vring_num(vid, &msg.payload.state);
+		vhost_user_set_vring_num(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SET_VRING_ADDR:
-		vhost_set_vring_addr(vid, &msg.payload.addr);
+		vhost_user_set_vring_addr(vid, &msg.payload.addr);
 		break;
 	case VHOST_USER_SET_VRING_BASE:
-		vhost_set_vring_base(vid, &msg.payload.state);
+		vhost_user_set_vring_base(vid, &msg.payload.state);
 		break;
 
 	case VHOST_USER_GET_VRING_BASE:
-		ret = user_get_vring_base(vid, &msg.payload.state);
+		ret = vhost_user_get_vring_base(vid, &msg.payload.state);
 		msg.size = sizeof(msg.payload.state);
 		send_vhost_message(fd, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_KICK:
-		user_set_vring_kick(vid, &msg);
+		vhost_user_set_vring_kick(vid, &msg);
 		break;
 	case VHOST_USER_SET_VRING_CALL:
-		user_set_vring_call(vid, &msg);
+		vhost_user_set_vring_call(vid, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_ERR:
@@ -972,10 +972,10 @@ vhost_user_msg_handler(int vid, int fd)
 		break;
 
 	case VHOST_USER_SET_VRING_ENABLE:
-		user_set_vring_enable(vid, &msg.payload.state);
+		vhost_user_set_vring_enable(vid, &msg.payload.state);
 		break;
 	case VHOST_USER_SEND_RARP:
-		user_send_rarp(vid, &msg);
+		vhost_user_send_rarp(vid, &msg);
 		break;
 
 	default:
Signature · 1 line
1.9.0
Reviewed-by on v1 5/7
#13 lore raw

Re: [PATCH 5/7] vhost: unify function names

Quoted 8 lines · Yuanhan Liu

Some functions are with prefix "user_", while others with "vhost_". Making them all starting with "vhost_user_" to unify the function names.

---
 lib/librte_vhost/vhost_user.c | 60 +++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 30 deletions(-)

Thanks,
Maxime

#14 lore raw

PATCH 6/7 vhost: get device once

In reply to Yuanhan Liu

Invoke get_device() at the beginning of vhost_user_msg_handler, so that we could check the return value once. Which could save tons of duplicate get-and-check device.

---
 lib/librte_vhost/vhost_user.c | 160 +++++++++++++-----------------------------
 1 file changed, 47 insertions(+), 113 deletions(-)
lib/librte_vhost/vhost_user.c +47 -113
index de3048c..ef4a0c1 100644
@@ -134,29 +134,17 @@ vhost_backend_cleanup(struct virtio_net *dev)
  * the device hasn't been initialised.
  */
 static int
-vhost_user_set_owner(int vid)
+vhost_user_set_owner(void)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
 	return 0;
 }
 
 static int
-vhost_user_reset_owner(int vid)
+vhost_user_reset_owner(struct virtio_net *dev)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(vid);
+		notify_ops->destroy_device(dev->vid);
 	}
 
 	cleanup_device(dev, 0);
@@ -168,15 +156,8 @@ vhost_user_reset_owner(int vid)
  * The features that we support are requested.
  */
 static int
-vhost_user_get_features(int vid, uint64_t *pu)
+vhost_user_get_features(uint64_t *pu)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	/* Send our supported features. */
 	*pu = VHOST_FEATURES;
 	return 0;
 }
@@ -185,13 +166,8 @@ vhost_user_get_features(int vid, uint64_t *pu)
  * We receive the negotiated features supported by us and the virtio device.
  */
 static int
-vhost_user_set_features(int vid, uint64_t *pu)
+vhost_user_set_features(struct virtio_net *dev, uint64_t *pu)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
 	if (*pu & ~VHOST_FEATURES)
 		return -1;
 
@@ -215,15 +191,9 @@ vhost_user_set_features(int vid, uint64_t *pu)
  * The virtio device sends us the size of the descriptor ring.
  */
 static int
-vhost_user_set_vring_num(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_num(struct virtio_net *dev,
+			 struct vhost_vring_state *state)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	/* State->index refers to the queue index. The txq is 1, rxq is 0. */
 	dev->virtqueue[state->index]->size = state->num;
 
 	return 0;
@@ -343,13 +313,11 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va)
  * This function then converts these to our address space.
  */
 static int
-vhost_user_set_vring_addr(int vid, struct vhost_vring_addr *addr)
+vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
 {
-	struct virtio_net *dev;
 	struct vhost_virtqueue *vq;
 
-	dev = get_device(vid);
-	if ((dev == NULL) || (dev->mem == NULL))
+	if (dev->mem == NULL)
 		return -1;
 
 	/* addr->index refers to the queue index. The txq 1, rxq is 0. */
@@ -412,40 +380,28 @@ vhost_user_set_vring_addr(int vid, struct vhost_vring_addr *addr)
  * The virtio device sends us the available ring last used index.
  */
 static int
-vhost_user_set_vring_base(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_base(struct virtio_net *dev,
+			  struct vhost_vring_state *state)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
-	/* State->index refers to the queue index. The txq is 1, rxq is 0. */
 	dev->virtqueue[state->index]->last_used_idx = state->num;
 
 	return 0;
 }
 
 static int
-vhost_user_set_mem_table(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_mem_table(struct virtio_net *dev, struct VhostUserMsg *pmsg)
 {
 	struct VhostUserMemory memory = pmsg->payload.memory;
 	struct virtio_memory_regions *pregion;
 	uint64_t mapped_address, mapped_size;
-	struct virtio_net *dev;
 	unsigned int idx = 0;
 	struct orig_region_map *pregion_orig;
 	uint64_t alignment;
 
-	/* unmap old memory regions one by one*/
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
 	/* Remove from the data plane. */
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(vid);
+		notify_ops->destroy_device(dev->vid);
 	}
 
 	if (dev->mem) {
@@ -587,16 +543,12 @@ virtio_is_ready(struct virtio_net *dev)
 }
 
 static void
-vhost_user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
-	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
 	uint32_t cur_qp_idx;
 
-	if (!dev)
-		return;
-
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
 		file.fd = VIRTIO_INVALID_EVENTFD;
@@ -629,15 +581,11 @@ vhost_user_set_vring_call(int vid, struct VhostUserMsg *pmsg)
  *  device is ready for packet processing.
  */
 static void
-vhost_user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
+vhost_user_set_vring_kick(struct virtio_net *dev, struct VhostUserMsg *pmsg)
 {
 	struct vhost_vring_file file;
-	struct virtio_net *dev = get_device(vid);
 	struct vhost_virtqueue *vq;
 
-	if (!dev)
-		return;
-
 	file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK;
 	if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)
 		file.fd = VIRTIO_INVALID_EVENTFD;
@@ -652,7 +600,7 @@ vhost_user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
 	vq->kickfd = file.fd;
 
 	if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) {
-		if (notify_ops->new_device(vid) == 0)
+		if (notify_ops->new_device(dev->vid) == 0)
 			dev->flags |= VIRTIO_DEV_RUNNING;
 	}
 }
@@ -661,16 +609,13 @@ vhost_user_set_vring_kick(int vid, struct VhostUserMsg *pmsg)
  * when virtio is stopped, qemu will send us the GET_VRING_BASE message.
  */
 static int
-vhost_user_get_vring_base(int vid, struct vhost_vring_state *state)
+vhost_user_get_vring_base(struct virtio_net *dev,
+			  struct vhost_vring_state *state)
 {
-	struct virtio_net *dev = get_device(vid);
-
-	if (dev == NULL)
-		return -1;
 	/* We have to stop the queue (virtio) if it is running. */
 	if (dev->flags & VIRTIO_DEV_RUNNING) {
 		dev->flags &= ~VIRTIO_DEV_RUNNING;
-		notify_ops->destroy_device(vid);
+		notify_ops->destroy_device(dev->vid);
 	}
 
 	/* Here we are safe to get the last used index */
@@ -696,21 +641,17 @@ vhost_user_get_vring_base(int vid, struct vhost_vring_state *state)
  * enable the virtio queue pair.
  */
 static int
-vhost_user_set_vring_enable(int vid, struct vhost_vring_state *state)
+vhost_user_set_vring_enable(struct virtio_net *dev,
+			    struct vhost_vring_state *state)
 {
-	struct virtio_net *dev;
 	int enable = (int)state->num;
 
-	dev = get_device(vid);
-	if (dev == NULL)
-		return -1;
-
 	RTE_LOG(INFO, VHOST_CONFIG,
 		"set queue enable: %d to qp idx: %d\n",
 		enable, state->index);
 
 	if (notify_ops->vring_state_changed)
-		notify_ops->vring_state_changed(vid, state->index, enable);
+		notify_ops->vring_state_changed(dev->vid, state->index, enable);
 
 	dev->virtqueue[state->index]->enabled = enable;
 
@@ -718,29 +659,22 @@ vhost_user_set_vring_enable(int vid, struct vhost_vring_state *state)
 }
 
 static void
-vhost_user_set_protocol_features(int vid, uint64_t protocol_features)
+vhost_user_set_protocol_features(struct virtio_net *dev,
+				 uint64_t protocol_features)
 {
-	struct virtio_net *dev;
-
-	dev = get_device(vid);
-	if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
+	if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES)
 		return;
 
 	dev->protocol_features = protocol_features;
 }
 
 static int
-vhost_user_set_log_base(int vid, struct VhostUserMsg *msg)
+vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg)
 {
-	struct virtio_net *dev;
 	int fd = msg->fds[0];
 	uint64_t size, off;
 	void *addr;
 
-	dev = get_device(vid);
-	if (!dev)
-		return -1;
-
 	if (fd < 0) {
 		RTE_LOG(ERR, VHOST_CONFIG, "invalid log fd: %d\n", fd);
 		return -1;
@@ -793,15 +727,10 @@ vhost_user_set_log_base(int vid, struct VhostUserMsg *msg)
  * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it.
  */
 static int
-vhost_user_send_rarp(int vid, struct VhostUserMsg *msg)
+vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg)
 {
-	struct virtio_net *dev;
 	uint8_t *mac = (uint8_t *)&msg->payload.u64;
 
-	dev = get_device(vid);
-	if (!dev)
-		return -1;
-
 	RTE_LOG(DEBUG, VHOST_CONFIG,
 		":: mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
 		mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
@@ -871,10 +800,15 @@ send_vhost_message(int sockfd, struct VhostUserMsg *msg)
 int
 vhost_user_msg_handler(int vid, int fd)
 {
+	struct virtio_net *dev;
 	struct VhostUserMsg msg;
 	uint64_t features = 0;
 	int ret;
 
+	dev = get_device(vid);
+	if (dev == NULL)
+		return -1;
+
 	ret = read_vhost_message(fd, &msg);
 	if (ret <= 0 || msg.request >= VHOST_USER_MAX) {
 		if (ret < 0)
@@ -894,14 +828,14 @@ vhost_user_msg_handler(int vid, int fd)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_user_get_features(vid, &features);
+		ret = vhost_user_get_features(&features);
 		msg.payload.u64 = features;
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(fd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
 		features = msg.payload.u64;
-		vhost_user_set_features(vid, &features);
+		vhost_user_set_features(dev, &features);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -910,22 +844,22 @@ vhost_user_msg_handler(int vid, int fd)
 		send_vhost_message(fd, &msg);
 		break;
 	case VHOST_USER_SET_PROTOCOL_FEATURES:
-		vhost_user_set_protocol_features(vid, msg.payload.u64);
+		vhost_user_set_protocol_features(dev, msg.payload.u64);
 		break;
 
 	case VHOST_USER_SET_OWNER:
-		vhost_user_set_owner(vid);
+		vhost_user_set_owner();
 		break;
 	case VHOST_USER_RESET_OWNER:
-		vhost_user_reset_owner(vid);
+		vhost_user_reset_owner(dev);
 		break;
 
 	case VHOST_USER_SET_MEM_TABLE:
-		vhost_user_set_mem_table(vid, &msg);
+		vhost_user_set_mem_table(dev, &msg);
 		break;
 
 	case VHOST_USER_SET_LOG_BASE:
-		vhost_user_set_log_base(vid, &msg);
+		vhost_user_set_log_base(dev, &msg);
 
 		/* it needs a reply */
 		msg.size = sizeof(msg.payload.u64);
@@ -937,26 +871,26 @@ vhost_user_msg_handler(int vid, int fd)
 		break;
 
 	case VHOST_USER_SET_VRING_NUM:
-		vhost_user_set_vring_num(vid, &msg.payload.state);
+		vhost_user_set_vring_num(dev, &msg.payload.state);
 		break;
 	case VHOST_USER_SET_VRING_ADDR:
-		vhost_user_set_vring_addr(vid, &msg.payload.addr);
+		vhost_user_set_vring_addr(dev, &msg.payload.addr);
 		break;
 	case VHOST_USER_SET_VRING_BASE:
-		vhost_user_set_vring_base(vid, &msg.payload.state);
+		vhost_user_set_vring_base(dev, &msg.payload.state);
 		break;
 
 	case VHOST_USER_GET_VRING_BASE:
-		ret = vhost_user_get_vring_base(vid, &msg.payload.state);
+		ret = vhost_user_get_vring_base(dev, &msg.payload.state);
 		msg.size = sizeof(msg.payload.state);
 		send_vhost_message(fd, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_KICK:
-		vhost_user_set_vring_kick(vid, &msg);
+		vhost_user_set_vring_kick(dev, &msg);
 		break;
 	case VHOST_USER_SET_VRING_CALL:
-		vhost_user_set_vring_call(vid, &msg);
+		vhost_user_set_vring_call(dev, &msg);
 		break;
 
 	case VHOST_USER_SET_VRING_ERR:
@@ -972,10 +906,10 @@ vhost_user_msg_handler(int vid, int fd)
 		break;
 
 	case VHOST_USER_SET_VRING_ENABLE:
-		vhost_user_set_vring_enable(vid, &msg.payload.state);
+		vhost_user_set_vring_enable(dev, &msg.payload.state);
 		break;
 	case VHOST_USER_SEND_RARP:
-		vhost_user_send_rarp(vid, &msg);
+		vhost_user_send_rarp(dev, &msg);
 		break;
 
 	default:
Signature · 1 line
1.9.0
Reviewed-by on v1 6/7
#15 lore raw

Re: [PATCH 6/7] vhost: get device once

Quoted 8 lines · Yuanhan Liu

Invoke get_device() at the beginning of vhost_user_msg_handler, so that we could check the return value once. Which could save tons of duplicate get-and-check device.

---
 lib/librte_vhost/vhost_user.c | 160 +++++++++++++-----------------------------
 1 file changed, 47 insertions(+), 113 deletions(-)

Makes sense:

Thanks,
Maxime

#16 lore raw

PATCH 7/7 vhost: simplify features set/get

In reply to Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
 lib/librte_vhost/vhost_user.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_vhost/vhost_user.c +8 -12
index ef4a0c1..eee99e9 100644
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
  * The features that we support are requested.
  */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
 {
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }
 
 /*
  * We receive the negotiated features supported by us and the virtio device.
  */
 static int
-vhost_user_set_features(struct virtio_net *dev, uint64_t *pu)
+vhost_user_set_features(struct virtio_net *dev, uint64_t features)
 {
-	if (*pu & ~VHOST_FEATURES)
+	if (features & ~VHOST_FEATURES)
 		return -1;
 
-	dev->features = *pu;
+	dev->features = features;
 	if (dev->features &
 		((1 << VIRTIO_NET_F_MRG_RXBUF) | (1ULL << VIRTIO_F_VERSION_1))) {
 		dev->vhost_hlen = sizeof(struct virtio_net_hdr_mrg_rxbuf);
@@ -802,7 +801,6 @@ vhost_user_msg_handler(int vid, int fd)
 {
 	struct virtio_net *dev;
 	struct VhostUserMsg msg;
-	uint64_t features = 0;
 	int ret;
 
 	dev = get_device(vid);
@@ -828,14 +826,12 @@ vhost_user_msg_handler(int vid, int fd)
 		vhost_message_str[msg.request]);
 	switch (msg.request) {
 	case VHOST_USER_GET_FEATURES:
-		ret = vhost_user_get_features(&features);
-		msg.payload.u64 = features;
+		msg.payload.u64 = vhost_user_get_features();
 		msg.size = sizeof(msg.payload.u64);
 		send_vhost_message(fd, &msg);
 		break;
 	case VHOST_USER_SET_FEATURES:
-		features = msg.payload.u64;
-		vhost_user_set_features(dev, &features);
+		vhost_user_set_features(dev, msg.payload.u64);
 		break;
 
 	case VHOST_USER_GET_PROTOCOL_FEATURES:
Signature · 1 line
1.9.0
Reviewed-by on v1 7/7
#17 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

Quoted 14 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
 lib/librte_vhost/vhost_user.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_vhost/vhost_user.c +0 -0
index ef4a0c1..eee99e9 100644
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
  * The features that we support are requested.

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 10 lines
lib/librte_vhost/vhost_user.c +3 -4
  */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
 {
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

It may not match with the orignal purpose of supported features, but could be useful at least for testing without recompilation.

For this patch:

Thanks,
Maxime

#18 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

Quoted 23 lines · Maxime Coquelin
Quoted 20 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
lib/librte_vhost/vhost_user.c | 20 ++++++++------------

1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_vhost/vhost_user.c +2 -2
index ef4a0c1..eee99e9 100644
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
 * The features that we support are requested.
 */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
 {
Quoted 8 lines

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 4 lines
lib/librte_vhost/vhost_user.c +1 -2
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

Not quite sure I understood it correctly: is rte_vhost_feature_disable() the answer you are looking for?

Quoted 5 lines

It may not match with the orignal purpose of supported features, but could be useful at least for testing without recompilation.

For this patch:

Again, appreicate your time on review!

	--yliu
#19 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

Quoted 33 lines · Yuanhan Liu
Quoted 23 lines · Maxime Coquelin
Quoted 20 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
lib/librte_vhost/vhost_user.c | 20 ++++++++------------

1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_vhost/vhost_user.c +2 -2
index ef4a0c1..eee99e9 100644
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
 * The features that we support are requested.
 */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
 {
Quoted 8 lines

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 4 lines
lib/librte_vhost/vhost_user.c +1 -2
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

Quoted 2 lines

Not quite sure I understood it correctly: is rte_vhost_feature_disable() the answer you are looking for?

Not really.

I meant a per-device supported features, and something you could set also via the vhost PMD options, without needing to recompile.

But maybe it would make more sense to do it a guest level?

Maxime

#20 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Maxime Coquelin
Sent: Thursday, August 25, 2016 3:19 PM
To: Yuanhan Liu <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH 7/7] vhost: simplify features set/get

Quoted 32 lines · Yuanhan Liu
Quoted 22 lines · Maxime Coquelin
Quoted 19 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
lib/librte_vhost/vhost_user.c | 20 ++++++++------------

1 file changed, 8 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_user.c index ef4a0c1..eee99e9 100644

lib/librte_vhost/vhost_user.c +2 -2
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
 * The features that we support are requested.
 */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
Quoted 8 lines

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 5 lines
lib/librte_vhost/vhost_user.c +1 -2
 {
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

Quoted 2 lines

Not quite sure I understood it correctly: is rte_vhost_feature_disable() the answer you are looking for?

Not really.

I meant a per-device supported features, and something you could set also via the vhost PMD options, without needing to recompile.

But maybe it would make more sense to do it a guest level?

Maxime

-------Agreed, as you know we have the vhost PMD port and virtio-user PMD port and we can launch both vhost/virtio on the host, but we Can't set the mergeable in the command line, we may need add some feature settings for virtio-user interface. It will be much easier to Run tests or application.

Qian

#21 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

Quoted 50 lines · Qian Q

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Maxime Coquelin
Sent: Thursday, August 25, 2016 3:19 PM
To: Yuanhan Liu <[email protected]>
Cc: [email protected]
Subject: Re: [dpdk-dev] [PATCH 7/7] vhost: simplify features set/get

Quoted 32 lines · Yuanhan Liu
Quoted 22 lines · Maxime Coquelin
Quoted 19 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
lib/librte_vhost/vhost_user.c | 20 ++++++++------------

1 file changed, 8 insertions(+), 12 deletions(-)
(quoted diff) +0 -0

b/lib/librte_vhost/vhost_user.c index ef4a0c1..eee99e9 100644

lib/librte_vhost/vhost_user.c +2 -2
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
 * The features that we support are requested.
 */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
Quoted 8 lines

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 5 lines
lib/librte_vhost/vhost_user.c +1 -2
 {
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

Quoted 2 lines

Not quite sure I understood it correctly: is rte_vhost_feature_disable() the answer you are looking for?

Not really.

I meant a per-device supported features, and something you could set also via the vhost PMD options, without needing to recompile.

Quoted 7 lines

But maybe it would make more sense to do it a guest level?

Maxime

-------Agreed, as you know we have the vhost PMD port and virtio-user PMD port and we can launch both vhost/virtio on the host, but we Can't set the mergeable in the command line, we may need add some feature settings for virtio-user interface. It will be much easier to Run tests or application.

I never tried virtio-user PMD on host, but my proposal should be applicable there too.

Regards,
Maxime

#22 lore raw

Re: [PATCH 7/7] vhost: simplify features set/get

In reply to Maxime Coquelin
Quoted 36 lines · Maxime Coquelin
Quoted 33 lines · Yuanhan Liu
Quoted 31 lines · Maxime Coquelin
Quoted 14 lines · Yuanhan Liu

No need to use a pointer to store/retrieve features.

---
lib/librte_vhost/vhost_user.c | 20 ++++++++------------

1 file changed, 8 insertions(+), 12 deletions(-)
lib/librte_vhost/vhost_user.c +0 -0
index ef4a0c1..eee99e9 100644
@@ -155,23 +155,22 @@ vhost_user_reset_owner(struct virtio_net *dev)
 /*
 * The features that we support are requested.

lib/librte_vhost/vhost_user.c vhost_user_reset_owner(struct virtio_net *dev) · line 162

Quoted 10 lines
lib/librte_vhost/vhost_user.c +3 -4
 */
-static int
-vhost_user_get_features(uint64_t *pu)
+static uint64_t
+vhost_user_get_features(void)
 {
-	*pu = VHOST_FEATURES;
-	return 0;
+	return VHOST_FEATURES;
 }

This is not the topic of this series, but I wonder if it could make sense to be able to override supported features at device init time.

Quoted 6 lines
Quoted 2 lines

Not quite sure I understood it correctly: is rte_vhost_feature_disable() the answer you are looking for?

Not really.

I meant a per-device supported features, and something you could set also via the vhost PMD options, without needing to recompile.

I see. I think my following proposal would fix it then.

    http://dpdk.org/ml/archives/dev/2016-June/040021.html

Note you might want to follow the discussion, as it mentioned per-device config later.

Another note, it lacked a fancy name at last discussion. For now, I think I come up with a better one: --dpdk-env :)

	--yliu
Quoted 4 lines

But maybe it would make more sense to do it a guest level?

Maxime

#23 lore raw
In reply to Yuanhan Liu

I think you need also update vhost sample guide and vhost library in the programmer guide for this release.

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Thursday, August 18, 2016 4:49 PM
To: [email protected]
Cc: Yuanhan Liu <[email protected]>
Subject: [dpdk-dev] [PATCH 0/7] vhost: vhost-cuse removal and code path refactoring

The first patch removes the vhost-cuse (see following link for the deprecate note)

    http://dpdk.org/ml/archives/dev/2016-July/044080.html

After the removal, there is no reason to keep the vhost_user sub source dir any more. This also brings a chance to rename all those files in a more proper way (see patch 3 for details).

---
Yuanhan Liu (7):
vhost: remove vhost-cuse
vhost: remove sub source dir
vhost: refactor source code structure
vhost: fold common message handlers
vhost: unify function names
vhost: get device once
vhost: simplify features set/get

 config/common_base                                 |   6 +-
 lib/librte_vhost/Makefile                          |  13 +-
 lib/librte_vhost/eventfd_link/Makefile             |  41 -
 lib/librte_vhost/eventfd_link/eventfd_link.c       | 277 -------
 lib/librte_vhost/eventfd_link/eventfd_link.h       |  94 ---
 lib/librte_vhost/{vhost_user => }/fd_man.c         |   0
 lib/librte_vhost/{vhost_user => }/fd_man.h         |   0
 lib/librte_vhost/libvirt/qemu-wrap.py              | 387 ---------
 .../{vhost_user/vhost-net-user.c => socket.c}      | 209 +----
 lib/librte_vhost/vhost.c                           | 409 +++++++++
 lib/librte_vhost/{vhost-net.h => vhost.h}          |  24 +-
 lib/librte_vhost/vhost_cuse/eventfd_copy.c         | 104 ---
 lib/librte_vhost/vhost_cuse/eventfd_copy.h         |  45 -
 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c       | 431 ----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c      | 433 ----------
 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h      |  56 --
 lib/librte_vhost/vhost_user.c                      | 917 +++++++++++++++++++++
 .../{vhost_user/vhost-net-user.h => vhost_user.h}  |  17 +-
 lib/librte_vhost/vhost_user/virtio-net-user.c      | 470 -----------
 lib/librte_vhost/vhost_user/virtio-net-user.h      |  62 --
 lib/librte_vhost/virtio-net.c                      | 847 -------------------
 lib/librte_vhost/{vhost_rxtx.c => virtio_net.c}    |   4 +-
 mk/rte.app.mk                                      |   3 -
 23 files changed, 1367 insertions(+), 3482 deletions(-)  delete mode 100644 lib/librte_vhost/eventfd_link/Makefile
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.c
 delete mode 100644 lib/librte_vhost/eventfd_link/eventfd_link.h
 rename lib/librte_vhost/{vhost_user => }/fd_man.c (100%)  rename lib/librte_vhost/{vhost_user => }/fd_man.h (100%)  delete mode 100755 lib/librte_vhost/libvirt/qemu-wrap.py
 rename lib/librte_vhost/{vhost_user/vhost-net-user.c => socket.c} (71%)  create mode 100644 lib/librte_vhost/vhost.c  rename lib/librte_vhost/{vhost-net.h => vhost.h} (92%)  delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/eventfd_copy.h
 delete mode 100644 lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
 delete mode 100644 lib/librte_vhost/vhost_cuse/virtio-net-cdev.h
 create mode 100644 lib/librte_vhost/vhost_user.c  rename lib/librte_vhost/{vhost_user/vhost-net-user.h => vhost_user.h} (87%)  delete mode 100644 lib/librte_vhost/vhost_user/virtio-net-user.c
 delete mode 100644 lib/librte_vhost/vhost_user/virtio-net-user.h
 delete mode 100644 lib/librte_vhost/virtio-net.c  rename lib/librte_vhost/{vhost_rxtx.c => virtio_net.c} (99%)

--
1.9.0

#24 lore raw
Quoted 1 line · Qian Q

I think you need also update vhost sample guide and vhost library in the programmer guide for this release.

Yes, updating vhost lib programmer would be easy, while updating the vhost sample requires a rewrite, that I will defer it later to some where that I have time for it.

	--yliu