* [dpdk-dev] [PATCH] vhost: remove vhost_net_device_ops
@ 2016-02-10 19:27 Rich Lane
2016-02-15 5:57 ` Yuanhan Liu
2016-02-16 22:45 ` [dpdk-dev] [PATCH v2] " Rich Lane
0 siblings, 2 replies; 7+ messages in thread
From: Rich Lane @ 2016-02-10 19:27 UTC (permalink / raw)
To: dev
The indirection is unnecessary because there is only one implementation of the
vhost common code. Removing it makes the code more readable.
Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
examples/vhost_xen/virtio-net.h | 2 -
lib/librte_vhost/vhost-net.h | 40 +++++-------
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 27 ++++----
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 4 +-
lib/librte_vhost/vhost_user/vhost-net-user.c | 23 +++----
lib/librte_vhost/vhost_user/virtio-net-user.c | 6 +-
lib/librte_vhost/virtio-net.c | 92 ++++++++-------------------
7 files changed, 70 insertions(+), 124 deletions(-)
diff --git a/examples/vhost_xen/virtio-net.h b/examples/vhost_xen/virtio-net.h
index c8c5a7a..ab69726 100644
--- a/examples/vhost_xen/virtio-net.h
+++ b/examples/vhost_xen/virtio-net.h
@@ -110,6 +110,4 @@ struct virtio_net_device_ops {
void (* destroy_device) (volatile struct virtio_net *); /* Remove device. */
};
-struct vhost_net_device_ops const * get_virtio_net_callbacks(void);
-
#endif
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index c69b60b..81274df 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,8 +43,6 @@
#include "rte_virtio_net.h"
-extern struct vhost_net_device_ops const *ops;
-
/* Macros for printing using RTE_LOG */
#define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -85,34 +83,26 @@ struct vhost_device_ctx {
uint64_t fh; /* Populated with fi->fh to track the device index. */
};
-/*
- * Structure contains function pointers to be defined in virtio-net.c. These
- * functions are called in CUSE context and are used to configure devices.
- */
-struct vhost_net_device_ops {
- int (*new_device)(struct vhost_device_ctx);
- void (*destroy_device)(struct vhost_device_ctx);
+int vhost_new_device(struct vhost_device_ctx);
+void vhost_destroy_device(struct vhost_device_ctx);
- void (*set_ifname)(struct vhost_device_ctx,
- const char *if_name, unsigned int if_len);
+void vhost_set_ifname(struct vhost_device_ctx,
+ const char *if_name, unsigned int if_len);
- int (*get_features)(struct vhost_device_ctx, uint64_t *);
- int (*set_features)(struct vhost_device_ctx, uint64_t *);
+int vhost_get_features(struct vhost_device_ctx, uint64_t *);
+int vhost_set_features(struct vhost_device_ctx, uint64_t *);
- int (*set_vring_num)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*set_vring_addr)(struct vhost_device_ctx, struct vhost_vring_addr *);
- int (*set_vring_base)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*get_vring_base)(struct vhost_device_ctx, uint32_t, struct vhost_vring_state *);
+int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
+int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_get_vring_base(struct vhost_device_ctx, uint32_t, struct vhost_vring_state *);
- int (*set_vring_kick)(struct vhost_device_ctx, struct vhost_vring_file *);
- int (*set_vring_call)(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
- int (*set_backend)(struct vhost_device_ctx, struct vhost_vring_file *);
-
- int (*set_owner)(struct vhost_device_ctx);
- int (*reset_owner)(struct vhost_device_ctx);
-};
+int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_owner(struct vhost_device_ctx);
+int vhost_reset_owner(struct vhost_device_ctx);
-struct vhost_net_device_ops const *get_virtio_net_callbacks(void);
#endif /* _VHOST_NET_CDEV_H_ */
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index ae7ad8d..c613e68 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -58,7 +58,6 @@ static const char cuse_device_name[] = "/dev/cuse";
static const char default_cdev[] = "vhost-net";
static struct fuse_session *session;
-struct vhost_net_device_ops const *ops;
/*
* Returns vhost_device_ctx from given fuse_req_t. The index is populated later
@@ -86,7 +85,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
int err = 0;
- err = ops->new_device(ctx);
+ err = vhost_new_device(ctx);
if (err == -1) {
fuse_reply_err(req, EPERM);
return;
@@ -108,7 +107,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
int err = 0;
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
fuse_reply_err(req, err);
}
@@ -208,25 +207,25 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
case VHOST_GET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_W(uint64_t, features, ops->get_features);
+ VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
break;
case VHOST_SET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_R(uint64_t, features, ops->set_features);
+ VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
break;
case VHOST_RESET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->reset_owner);
+ VHOST_IOCTL(vhost_reset_owner);
break;
case VHOST_SET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->set_owner);
+ VHOST_IOCTL(vhost_set_owner);
break;
case VHOST_SET_MEM_TABLE:
@@ -267,28 +266,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_num);
+ vhost_set_vring_num);
break;
case VHOST_SET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_base);
+ vhost_set_vring_base);
break;
case VHOST_GET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_RW(uint32_t, index,
- struct vhost_vring_state, state, ops->get_vring_base);
+ struct vhost_vring_state, state, vhost_get_vring_base);
break;
case VHOST_SET_VRING_ADDR:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_addr, addr,
- ops->set_vring_addr);
+ vhost_set_vring_addr);
break;
case VHOST_SET_VRING_KICK:
@@ -316,10 +315,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
}
file.fd = fd;
if (cmd == VHOST_SET_VRING_KICK) {
- result = ops->set_vring_kick(ctx, &file);
+ result = vhost_set_vring_kick(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
} else {
- result = ops->set_vring_call(ctx, &file);
+ result = vhost_set_vring_call(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
}
}
@@ -397,8 +396,6 @@ rte_vhost_driver_register(const char *dev_name)
cuse_info.dev_info_argv = device_argv;
cuse_info.flags = CUSE_UNRESTRICTED_IOCTL;
- ops = get_virtio_net_callbacks();
-
session = cuse_lowlevel_setup(3, fuse_argv,
&cuse_info, &vhost_net_ops, 0, NULL);
if (session == NULL)
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index ae2c3fa..2d3a4da 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -399,7 +399,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
if (ret >= 0) {
ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
- ops->set_ifname(ctx, ifr.ifr_name, ifr_size);
+ vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
} else
RTE_LOG(ERR, VHOST_CONFIG,
"(%"PRIu64") TUNGETIFF ioctl failed\n",
@@ -419,5 +419,5 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
get_ifname(ctx, dev, file->fd, ctx.pid);
- return ops->set_backend(ctx, file);
+ return vhost_set_backend(ctx, file);
}
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 8b7a448..da322d9 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -55,7 +55,6 @@
static void vserver_new_vq_conn(int fd, void *data, int *remove);
static void vserver_message_handler(int fd, void *dat, int *remove);
-struct vhost_net_device_ops const *ops;
struct connfd_ctx {
struct vhost_server *vserver;
@@ -301,7 +300,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
return;
}
- fh = ops->new_device(vdev_ctx);
+ fh = vhost_new_device(vdev_ctx);
if (fh == -1) {
free(ctx);
close(conn_fd);
@@ -310,7 +309,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
vdev_ctx.fh = fh;
size = strnlen(vserver->path, PATH_MAX);
- ops->set_ifname(vdev_ctx, vserver->path,
+ vhost_set_ifname(vdev_ctx, vserver->path,
size);
RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
@@ -348,7 +347,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
*remove = 1;
free(cfd_ctx);
user_destroy_device(ctx);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
return;
}
@@ -357,14 +356,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
vhost_message_str[msg.request]);
switch (msg.request) {
case VHOST_USER_GET_FEATURES:
- ret = ops->get_features(ctx, &features);
+ ret = vhost_get_features(ctx, &features);
msg.payload.u64 = features;
msg.size = sizeof(msg.payload.u64);
send_vhost_message(connfd, &msg);
break;
case VHOST_USER_SET_FEATURES:
features = msg.payload.u64;
- ops->set_features(ctx, &features);
+ vhost_set_features(ctx, &features);
break;
case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -377,10 +376,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_OWNER:
- ops->set_owner(ctx);
+ vhost_set_owner(ctx);
break;
case VHOST_USER_RESET_OWNER:
- ops->reset_owner(ctx);
+ vhost_reset_owner(ctx);
break;
case VHOST_USER_SET_MEM_TABLE:
@@ -397,13 +396,13 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_VRING_NUM:
- ops->set_vring_num(ctx, &msg.payload.state);
+ vhost_set_vring_num(ctx, &msg.payload.state);
break;
case VHOST_USER_SET_VRING_ADDR:
- ops->set_vring_addr(ctx, &msg.payload.addr);
+ vhost_set_vring_addr(ctx, &msg.payload.addr);
break;
case VHOST_USER_SET_VRING_BASE:
- ops->set_vring_base(ctx, &msg.payload.state);
+ vhost_set_vring_base(ctx, &msg.payload.state);
break;
case VHOST_USER_GET_VRING_BASE:
@@ -450,8 +449,6 @@ rte_vhost_driver_register(const char *path)
struct vhost_server *vserver;
pthread_mutex_lock(&g_vhost_server.server_mutex);
- if (ops == NULL)
- ops = get_virtio_net_callbacks();
if (g_vhost_server.vserver_cnt == MAX_VHOST_SERVER) {
RTE_LOG(ERR, VHOST_CONFIG,
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 2934d1c..fa74c39 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -253,7 +253,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring call idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_call(ctx, &file);
+ vhost_set_vring_call(ctx, &file);
}
@@ -274,7 +274,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring kick idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_kick(ctx, &file);
+ vhost_set_vring_kick(ctx, &file);
if (virtio_is_ready(dev) &&
!(dev->flags & VIRTIO_DEV_RUNNING))
@@ -297,7 +297,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
notify_ops->destroy_device(dev);
/* Here we are safe to get the last used index */
- ops->get_vring_base(ctx, state->index, state);
+ vhost_get_vring_base(ctx, state->index, state);
RTE_LOG(INFO, VHOST_CONFIG,
"vring base idx:%d file:%d\n", state->index, state->num);
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index de78a0f..545e26d 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -348,8 +348,8 @@ reset_device(struct virtio_net *dev)
* initialised and a new entry is added to the device configuration linked
* list.
*/
-static int
-new_device(struct vhost_device_ctx ctx)
+int
+vhost_new_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *new_ll_dev;
@@ -374,8 +374,8 @@ new_device(struct vhost_device_ctx ctx)
* Function is called from the CUSE release function. This function will
* cleanup the device and remove it from device configuration linked list.
*/
-static void
-destroy_device(struct vhost_device_ctx ctx)
+void
+vhost_destroy_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last = NULL;
struct virtio_net_config_ll *ll_dev_cur = ll_root;
@@ -403,8 +403,8 @@ destroy_device(struct vhost_device_ctx ctx)
}
}
-static void
-set_ifname(struct vhost_device_ctx ctx,
+void
+vhost_set_ifname(struct vhost_device_ctx ctx,
const char *if_name, unsigned int if_len)
{
struct virtio_net *dev;
@@ -426,8 +426,8 @@ set_ifname(struct vhost_device_ctx ctx,
* This function just returns success at the moment unless
* the device hasn't been initialised.
*/
-static int
-set_owner(struct vhost_device_ctx ctx)
+int
+vhost_set_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -441,8 +441,8 @@ set_owner(struct vhost_device_ctx ctx)
/*
* Called from CUSE IOCTL: VHOST_RESET_OWNER
*/
-static int
-reset_owner(struct vhost_device_ctx ctx)
+int
+vhost_reset_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -462,8 +462,8 @@ reset_owner(struct vhost_device_ctx ctx)
* Called from CUSE IOCTL: VHOST_GET_FEATURES
* The features that we support are requested.
*/
-static int
-get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
@@ -480,8 +480,8 @@ get_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_FEATURES
* We receive the negotiated features supported by us and the virtio device.
*/
-static int
-set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
uint16_t vhost_hlen;
@@ -520,8 +520,8 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_VRING_NUM
* The virtio device sends us the size of the descriptor ring.
*/
-static int
-set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -622,8 +622,8 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
* The virtio device sends us the desc, used and avail ring addresses.
* This function then converts these to our address space.
*/
-static int
-set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+int
+vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -680,8 +680,8 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
* Called from CUSE IOCTL: VHOST_SET_VRING_BASE
* The virtio device sends us the available ring last used index.
*/
-static int
-set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -700,8 +700,8 @@ set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
* Called from CUSE IOCTL: VHOST_GET_VRING_BASE
* We send the virtio device our available ring last used index.
*/
-static int
-get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+int
+vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -723,8 +723,8 @@ get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
* The virtio device sends an eventfd to interrupt the guest. This fd gets
* copied into our process space.
*/
-static int
-set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -760,8 +760,8 @@ set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* The virtio device sends an eventfd that it can use to notify us.
* This fd gets copied into our process space.
*/
-static int
-set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -790,8 +790,8 @@ set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* At that point we remove the device from the data core.
* The device will still exist in the device configuration linked list.
*/
-static int
-set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
@@ -818,42 +818,6 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
return 0;
}
-/*
- * Function pointers are set for the device operations to allow CUSE to call
- * functions when an IOCTL, device_add or device_release is received.
- */
-static const struct vhost_net_device_ops vhost_device_ops = {
- .new_device = new_device,
- .destroy_device = destroy_device,
-
- .set_ifname = set_ifname,
-
- .get_features = get_features,
- .set_features = set_features,
-
- .set_vring_num = set_vring_num,
- .set_vring_addr = set_vring_addr,
- .set_vring_base = set_vring_base,
- .get_vring_base = get_vring_base,
-
- .set_vring_kick = set_vring_kick,
- .set_vring_call = set_vring_call,
-
- .set_backend = set_backend,
-
- .set_owner = set_owner,
- .reset_owner = reset_owner,
-};
-
-/*
- * Called by main to setup callbacks when registering CUSE device.
- */
-struct vhost_net_device_ops const *
-get_virtio_net_callbacks(void)
-{
- return &vhost_device_ops;
-}
-
int rte_vhost_enable_guest_notification(struct virtio_net *dev,
uint16_t queue_id, int enable)
{
--
1.9.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH] vhost: remove vhost_net_device_ops
2016-02-10 19:27 [dpdk-dev] [PATCH] vhost: remove vhost_net_device_ops Rich Lane
@ 2016-02-15 5:57 ` Yuanhan Liu
2016-02-16 22:45 ` [dpdk-dev] [PATCH v2] " Rich Lane
1 sibling, 0 replies; 7+ messages in thread
From: Yuanhan Liu @ 2016-02-15 5:57 UTC (permalink / raw)
To: Rich Lane; +Cc: dev
On Wed, Feb 10, 2016 at 11:27:08AM -0800, Rich Lane wrote:
> The indirection is unnecessary because there is only one implementation of the
> vhost common code. Removing it makes the code more readable.
This is a good cleanup! A minor nit is that I saw few long lines
exceeding 80 chars.
--yliu
^ permalink raw reply [flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH v2] vhost: remove vhost_net_device_ops
2016-02-10 19:27 [dpdk-dev] [PATCH] vhost: remove vhost_net_device_ops Rich Lane
2016-02-15 5:57 ` Yuanhan Liu
@ 2016-02-16 22:45 ` Rich Lane
2016-02-17 12:58 ` Yuanhan Liu
2016-02-19 18:10 ` [dpdk-dev] [PATCH v3] " Rich Lane
1 sibling, 2 replies; 7+ messages in thread
From: Rich Lane @ 2016-02-16 22:45 UTC (permalink / raw)
To: dev
The indirection is unnecessary because there is only one implementation
of the vhost common code. Removing it makes the code more readable.
Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
v1->v2:
- Fix long lines.
examples/vhost_xen/virtio-net.h | 2 -
lib/librte_vhost/vhost-net.h | 41 +++++-------
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 27 ++++----
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 4 +-
lib/librte_vhost/vhost_user/vhost-net-user.c | 23 +++----
lib/librte_vhost/vhost_user/virtio-net-user.c | 6 +-
lib/librte_vhost/virtio-net.c | 94 +++++++++------------------
7 files changed, 73 insertions(+), 124 deletions(-)
diff --git a/examples/vhost_xen/virtio-net.h b/examples/vhost_xen/virtio-net.h
index c8c5a7a..ab69726 100644
--- a/examples/vhost_xen/virtio-net.h
+++ b/examples/vhost_xen/virtio-net.h
@@ -110,6 +110,4 @@ struct virtio_net_device_ops {
void (* destroy_device) (volatile struct virtio_net *); /* Remove device. */
};
-struct vhost_net_device_ops const * get_virtio_net_callbacks(void);
-
#endif
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index c69b60b..afa9829 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,8 +43,6 @@
#include "rte_virtio_net.h"
-extern struct vhost_net_device_ops const *ops;
-
/* Macros for printing using RTE_LOG */
#define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -85,34 +83,27 @@ struct vhost_device_ctx {
uint64_t fh; /* Populated with fi->fh to track the device index. */
};
-/*
- * Structure contains function pointers to be defined in virtio-net.c. These
- * functions are called in CUSE context and are used to configure devices.
- */
-struct vhost_net_device_ops {
- int (*new_device)(struct vhost_device_ctx);
- void (*destroy_device)(struct vhost_device_ctx);
+int vhost_new_device(struct vhost_device_ctx);
+void vhost_destroy_device(struct vhost_device_ctx);
- void (*set_ifname)(struct vhost_device_ctx,
- const char *if_name, unsigned int if_len);
+void vhost_set_ifname(struct vhost_device_ctx,
+ const char *if_name, unsigned int if_len);
- int (*get_features)(struct vhost_device_ctx, uint64_t *);
- int (*set_features)(struct vhost_device_ctx, uint64_t *);
+int vhost_get_features(struct vhost_device_ctx, uint64_t *);
+int vhost_set_features(struct vhost_device_ctx, uint64_t *);
- int (*set_vring_num)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*set_vring_addr)(struct vhost_device_ctx, struct vhost_vring_addr *);
- int (*set_vring_base)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*get_vring_base)(struct vhost_device_ctx, uint32_t, struct vhost_vring_state *);
+int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
+int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_get_vring_base(struct vhost_device_ctx,
+ uint32_t, struct vhost_vring_state *);
- int (*set_vring_kick)(struct vhost_device_ctx, struct vhost_vring_file *);
- int (*set_vring_call)(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
- int (*set_backend)(struct vhost_device_ctx, struct vhost_vring_file *);
-
- int (*set_owner)(struct vhost_device_ctx);
- int (*reset_owner)(struct vhost_device_ctx);
-};
+int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_owner(struct vhost_device_ctx);
+int vhost_reset_owner(struct vhost_device_ctx);
-struct vhost_net_device_ops const *get_virtio_net_callbacks(void);
#endif /* _VHOST_NET_CDEV_H_ */
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index ae7ad8d..c613e68 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -58,7 +58,6 @@ static const char cuse_device_name[] = "/dev/cuse";
static const char default_cdev[] = "vhost-net";
static struct fuse_session *session;
-struct vhost_net_device_ops const *ops;
/*
* Returns vhost_device_ctx from given fuse_req_t. The index is populated later
@@ -86,7 +85,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
int err = 0;
- err = ops->new_device(ctx);
+ err = vhost_new_device(ctx);
if (err == -1) {
fuse_reply_err(req, EPERM);
return;
@@ -108,7 +107,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
int err = 0;
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
fuse_reply_err(req, err);
}
@@ -208,25 +207,25 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
case VHOST_GET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_W(uint64_t, features, ops->get_features);
+ VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
break;
case VHOST_SET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_R(uint64_t, features, ops->set_features);
+ VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
break;
case VHOST_RESET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->reset_owner);
+ VHOST_IOCTL(vhost_reset_owner);
break;
case VHOST_SET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->set_owner);
+ VHOST_IOCTL(vhost_set_owner);
break;
case VHOST_SET_MEM_TABLE:
@@ -267,28 +266,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_num);
+ vhost_set_vring_num);
break;
case VHOST_SET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_base);
+ vhost_set_vring_base);
break;
case VHOST_GET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_RW(uint32_t, index,
- struct vhost_vring_state, state, ops->get_vring_base);
+ struct vhost_vring_state, state, vhost_get_vring_base);
break;
case VHOST_SET_VRING_ADDR:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_addr, addr,
- ops->set_vring_addr);
+ vhost_set_vring_addr);
break;
case VHOST_SET_VRING_KICK:
@@ -316,10 +315,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
}
file.fd = fd;
if (cmd == VHOST_SET_VRING_KICK) {
- result = ops->set_vring_kick(ctx, &file);
+ result = vhost_set_vring_kick(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
} else {
- result = ops->set_vring_call(ctx, &file);
+ result = vhost_set_vring_call(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
}
}
@@ -397,8 +396,6 @@ rte_vhost_driver_register(const char *dev_name)
cuse_info.dev_info_argv = device_argv;
cuse_info.flags = CUSE_UNRESTRICTED_IOCTL;
- ops = get_virtio_net_callbacks();
-
session = cuse_lowlevel_setup(3, fuse_argv,
&cuse_info, &vhost_net_ops, 0, NULL);
if (session == NULL)
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index ae2c3fa..2d3a4da 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -399,7 +399,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
if (ret >= 0) {
ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
- ops->set_ifname(ctx, ifr.ifr_name, ifr_size);
+ vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
} else
RTE_LOG(ERR, VHOST_CONFIG,
"(%"PRIu64") TUNGETIFF ioctl failed\n",
@@ -419,5 +419,5 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
get_ifname(ctx, dev, file->fd, ctx.pid);
- return ops->set_backend(ctx, file);
+ return vhost_set_backend(ctx, file);
}
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 8b7a448..da322d9 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -55,7 +55,6 @@
static void vserver_new_vq_conn(int fd, void *data, int *remove);
static void vserver_message_handler(int fd, void *dat, int *remove);
-struct vhost_net_device_ops const *ops;
struct connfd_ctx {
struct vhost_server *vserver;
@@ -301,7 +300,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
return;
}
- fh = ops->new_device(vdev_ctx);
+ fh = vhost_new_device(vdev_ctx);
if (fh == -1) {
free(ctx);
close(conn_fd);
@@ -310,7 +309,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
vdev_ctx.fh = fh;
size = strnlen(vserver->path, PATH_MAX);
- ops->set_ifname(vdev_ctx, vserver->path,
+ vhost_set_ifname(vdev_ctx, vserver->path,
size);
RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
@@ -348,7 +347,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
*remove = 1;
free(cfd_ctx);
user_destroy_device(ctx);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
return;
}
@@ -357,14 +356,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
vhost_message_str[msg.request]);
switch (msg.request) {
case VHOST_USER_GET_FEATURES:
- ret = ops->get_features(ctx, &features);
+ ret = vhost_get_features(ctx, &features);
msg.payload.u64 = features;
msg.size = sizeof(msg.payload.u64);
send_vhost_message(connfd, &msg);
break;
case VHOST_USER_SET_FEATURES:
features = msg.payload.u64;
- ops->set_features(ctx, &features);
+ vhost_set_features(ctx, &features);
break;
case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -377,10 +376,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_OWNER:
- ops->set_owner(ctx);
+ vhost_set_owner(ctx);
break;
case VHOST_USER_RESET_OWNER:
- ops->reset_owner(ctx);
+ vhost_reset_owner(ctx);
break;
case VHOST_USER_SET_MEM_TABLE:
@@ -397,13 +396,13 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_VRING_NUM:
- ops->set_vring_num(ctx, &msg.payload.state);
+ vhost_set_vring_num(ctx, &msg.payload.state);
break;
case VHOST_USER_SET_VRING_ADDR:
- ops->set_vring_addr(ctx, &msg.payload.addr);
+ vhost_set_vring_addr(ctx, &msg.payload.addr);
break;
case VHOST_USER_SET_VRING_BASE:
- ops->set_vring_base(ctx, &msg.payload.state);
+ vhost_set_vring_base(ctx, &msg.payload.state);
break;
case VHOST_USER_GET_VRING_BASE:
@@ -450,8 +449,6 @@ rte_vhost_driver_register(const char *path)
struct vhost_server *vserver;
pthread_mutex_lock(&g_vhost_server.server_mutex);
- if (ops == NULL)
- ops = get_virtio_net_callbacks();
if (g_vhost_server.vserver_cnt == MAX_VHOST_SERVER) {
RTE_LOG(ERR, VHOST_CONFIG,
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 2934d1c..fa74c39 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -253,7 +253,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring call idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_call(ctx, &file);
+ vhost_set_vring_call(ctx, &file);
}
@@ -274,7 +274,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring kick idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_kick(ctx, &file);
+ vhost_set_vring_kick(ctx, &file);
if (virtio_is_ready(dev) &&
!(dev->flags & VIRTIO_DEV_RUNNING))
@@ -297,7 +297,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
notify_ops->destroy_device(dev);
/* Here we are safe to get the last used index */
- ops->get_vring_base(ctx, state->index, state);
+ vhost_get_vring_base(ctx, state->index, state);
RTE_LOG(INFO, VHOST_CONFIG,
"vring base idx:%d file:%d\n", state->index, state->num);
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index de78a0f..ddbd47f 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -348,8 +348,8 @@ reset_device(struct virtio_net *dev)
* initialised and a new entry is added to the device configuration linked
* list.
*/
-static int
-new_device(struct vhost_device_ctx ctx)
+int
+vhost_new_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *new_ll_dev;
@@ -374,8 +374,8 @@ new_device(struct vhost_device_ctx ctx)
* Function is called from the CUSE release function. This function will
* cleanup the device and remove it from device configuration linked list.
*/
-static void
-destroy_device(struct vhost_device_ctx ctx)
+void
+vhost_destroy_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last = NULL;
struct virtio_net_config_ll *ll_dev_cur = ll_root;
@@ -403,8 +403,8 @@ destroy_device(struct vhost_device_ctx ctx)
}
}
-static void
-set_ifname(struct vhost_device_ctx ctx,
+void
+vhost_set_ifname(struct vhost_device_ctx ctx,
const char *if_name, unsigned int if_len)
{
struct virtio_net *dev;
@@ -426,8 +426,8 @@ set_ifname(struct vhost_device_ctx ctx,
* This function just returns success at the moment unless
* the device hasn't been initialised.
*/
-static int
-set_owner(struct vhost_device_ctx ctx)
+int
+vhost_set_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -441,8 +441,8 @@ set_owner(struct vhost_device_ctx ctx)
/*
* Called from CUSE IOCTL: VHOST_RESET_OWNER
*/
-static int
-reset_owner(struct vhost_device_ctx ctx)
+int
+vhost_reset_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -462,8 +462,8 @@ reset_owner(struct vhost_device_ctx ctx)
* Called from CUSE IOCTL: VHOST_GET_FEATURES
* The features that we support are requested.
*/
-static int
-get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
@@ -480,8 +480,8 @@ get_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_FEATURES
* We receive the negotiated features supported by us and the virtio device.
*/
-static int
-set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
uint16_t vhost_hlen;
@@ -520,8 +520,9 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_VRING_NUM
* The virtio device sends us the size of the descriptor ring.
*/
-static int
-set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_num(struct vhost_device_ctx ctx,
+ struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -622,8 +623,8 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
* The virtio device sends us the desc, used and avail ring addresses.
* This function then converts these to our address space.
*/
-static int
-set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+int
+vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -680,8 +681,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
* Called from CUSE IOCTL: VHOST_SET_VRING_BASE
* The virtio device sends us the available ring last used index.
*/
-static int
-set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_base(struct vhost_device_ctx ctx,
+ struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -700,8 +702,8 @@ set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
* Called from CUSE IOCTL: VHOST_GET_VRING_BASE
* We send the virtio device our available ring last used index.
*/
-static int
-get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+int
+vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -723,8 +725,8 @@ get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
* The virtio device sends an eventfd to interrupt the guest. This fd gets
* copied into our process space.
*/
-static int
-set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -760,8 +762,8 @@ set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* The virtio device sends an eventfd that it can use to notify us.
* This fd gets copied into our process space.
*/
-static int
-set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -790,8 +792,8 @@ set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* At that point we remove the device from the data core.
* The device will still exist in the device configuration linked list.
*/
-static int
-set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
@@ -818,42 +820,6 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
return 0;
}
-/*
- * Function pointers are set for the device operations to allow CUSE to call
- * functions when an IOCTL, device_add or device_release is received.
- */
-static const struct vhost_net_device_ops vhost_device_ops = {
- .new_device = new_device,
- .destroy_device = destroy_device,
-
- .set_ifname = set_ifname,
-
- .get_features = get_features,
- .set_features = set_features,
-
- .set_vring_num = set_vring_num,
- .set_vring_addr = set_vring_addr,
- .set_vring_base = set_vring_base,
- .get_vring_base = get_vring_base,
-
- .set_vring_kick = set_vring_kick,
- .set_vring_call = set_vring_call,
-
- .set_backend = set_backend,
-
- .set_owner = set_owner,
- .reset_owner = reset_owner,
-};
-
-/*
- * Called by main to setup callbacks when registering CUSE device.
- */
-struct vhost_net_device_ops const *
-get_virtio_net_callbacks(void)
-{
- return &vhost_device_ops;
-}
-
int rte_vhost_enable_guest_notification(struct virtio_net *dev,
uint16_t queue_id, int enable)
{
--
1.9.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH v2] vhost: remove vhost_net_device_ops
2016-02-16 22:45 ` [dpdk-dev] [PATCH v2] " Rich Lane
@ 2016-02-17 12:58 ` Yuanhan Liu
2016-02-19 15:12 ` Thomas Monjalon
2016-02-19 18:10 ` [dpdk-dev] [PATCH v3] " Rich Lane
1 sibling, 1 reply; 7+ messages in thread
From: Yuanhan Liu @ 2016-02-17 12:58 UTC (permalink / raw)
To: Rich Lane; +Cc: dev
On Tue, Feb 16, 2016 at 02:45:04PM -0800, Rich Lane wrote:
> The indirection is unnecessary because there is only one implementation
> of the vhost common code. Removing it makes the code more readable.
>
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Thanks.
--yliu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH v2] vhost: remove vhost_net_device_ops
2016-02-17 12:58 ` Yuanhan Liu
@ 2016-02-19 15:12 ` Thomas Monjalon
0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2016-02-19 15:12 UTC (permalink / raw)
To: Rich Lane; +Cc: dev
2016-02-17 20:58, Yuanhan Liu:
> On Tue, Feb 16, 2016 at 02:45:04PM -0800, Rich Lane wrote:
> > The indirection is unnecessary because there is only one implementation
> > of the vhost common code. Removing it makes the code more readable.
> >
> > Signed-off-by: Rich Lane <rlane@bigswitch.com>
>
> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Please Rich, may I ask a rebased v3? Thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
* [dpdk-dev] [PATCH v3] vhost: remove vhost_net_device_ops
2016-02-16 22:45 ` [dpdk-dev] [PATCH v2] " Rich Lane
2016-02-17 12:58 ` Yuanhan Liu
@ 2016-02-19 18:10 ` Rich Lane
2016-02-19 18:34 ` Thomas Monjalon
1 sibling, 1 reply; 7+ messages in thread
From: Rich Lane @ 2016-02-19 18:10 UTC (permalink / raw)
To: dev
The indirection is unnecessary because there is only one implementation
of the vhost common code. Removing it makes the code more readable.
Signed-off-by: Rich Lane <rlane@bigswitch.com>
Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
v2->v3:
- Rebased.
v1->v2:
- Fix long lines.
examples/vhost_xen/virtio-net.h | 2 -
lib/librte_vhost/vhost-net.h | 42 +++++-------
lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 27 ++++----
lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 4 +-
lib/librte_vhost/vhost_user/vhost-net-user.c | 23 +++----
lib/librte_vhost/vhost_user/virtio-net-user.c | 6 +-
lib/librte_vhost/virtio-net.c | 94 +++++++++------------------
7 files changed, 73 insertions(+), 125 deletions(-)
diff --git a/examples/vhost_xen/virtio-net.h b/examples/vhost_xen/virtio-net.h
index c8c5a7a..ab69726 100644
--- a/examples/vhost_xen/virtio-net.h
+++ b/examples/vhost_xen/virtio-net.h
@@ -110,6 +110,4 @@ struct virtio_net_device_ops {
void (* destroy_device) (volatile struct virtio_net *); /* Remove device. */
};
-struct vhost_net_device_ops const * get_virtio_net_callbacks(void);
-
#endif
diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h
index affbd1a..f193a1f 100644
--- a/lib/librte_vhost/vhost-net.h
+++ b/lib/librte_vhost/vhost-net.h
@@ -43,8 +43,6 @@
#include "rte_virtio_net.h"
-extern struct vhost_net_device_ops const *ops;
-
/* Macros for printing using RTE_LOG */
#define RTE_LOGTYPE_VHOST_CONFIG RTE_LOGTYPE_USER1
#define RTE_LOGTYPE_VHOST_DATA RTE_LOGTYPE_USER1
@@ -85,36 +83,28 @@ struct vhost_device_ctx {
uint64_t fh; /* Populated with fi->fh to track the device index. */
};
-/*
- * Structure contains function pointers to be defined in virtio-net.c. These
- * functions are called in CUSE context and are used to configure devices.
- */
-struct vhost_net_device_ops {
- int (*new_device)(struct vhost_device_ctx);
- void (*destroy_device)(struct vhost_device_ctx);
-
- void (*set_ifname)(struct vhost_device_ctx,
- const char *if_name, unsigned int if_len);
-
- int (*get_features)(struct vhost_device_ctx, uint64_t *);
- int (*set_features)(struct vhost_device_ctx, uint64_t *);
+int vhost_new_device(struct vhost_device_ctx);
+void vhost_destroy_device(struct vhost_device_ctx);
- int (*set_vring_num)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*set_vring_addr)(struct vhost_device_ctx, struct vhost_vring_addr *);
- int (*set_vring_base)(struct vhost_device_ctx, struct vhost_vring_state *);
- int (*get_vring_base)(struct vhost_device_ctx, uint32_t, struct vhost_vring_state *);
+void vhost_set_ifname(struct vhost_device_ctx,
+ const char *if_name, unsigned int if_len);
- int (*set_vring_kick)(struct vhost_device_ctx, struct vhost_vring_file *);
- int (*set_vring_call)(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_get_features(struct vhost_device_ctx, uint64_t *);
+int vhost_set_features(struct vhost_device_ctx, uint64_t *);
- int (*set_backend)(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_num(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_set_vring_addr(struct vhost_device_ctx, struct vhost_vring_addr *);
+int vhost_set_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
+int vhost_get_vring_base(struct vhost_device_ctx,
+ uint32_t, struct vhost_vring_state *);
- int (*set_owner)(struct vhost_device_ctx);
- int (*reset_owner)(struct vhost_device_ctx);
-};
+int vhost_set_vring_kick(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_vring_call(struct vhost_device_ctx, struct vhost_vring_file *);
+int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *);
-struct vhost_net_device_ops const *get_virtio_net_callbacks(void);
+int vhost_set_owner(struct vhost_device_ctx);
+int vhost_reset_owner(struct vhost_device_ctx);
/*
* Backend-specific cleanup. Defined by vhost-cuse and vhost-user.
diff --git a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
index ae7ad8d..c613e68 100644
--- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c
@@ -58,7 +58,6 @@ static const char cuse_device_name[] = "/dev/cuse";
static const char default_cdev[] = "vhost-net";
static struct fuse_session *session;
-struct vhost_net_device_ops const *ops;
/*
* Returns vhost_device_ctx from given fuse_req_t. The index is populated later
@@ -86,7 +85,7 @@ vhost_net_open(fuse_req_t req, struct fuse_file_info *fi)
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
int err = 0;
- err = ops->new_device(ctx);
+ err = vhost_new_device(ctx);
if (err == -1) {
fuse_reply_err(req, EPERM);
return;
@@ -108,7 +107,7 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi)
int err = 0;
struct vhost_device_ctx ctx = fuse_req_to_vhost_ctx(req, fi);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
RTE_LOG(INFO, VHOST_CONFIG, "(%"PRIu64") Device released\n", ctx.fh);
fuse_reply_err(req, err);
}
@@ -208,25 +207,25 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
case VHOST_GET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_W(uint64_t, features, ops->get_features);
+ VHOST_IOCTL_W(uint64_t, features, vhost_get_features);
break;
case VHOST_SET_FEATURES:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_FEATURES\n", ctx.fh);
- VHOST_IOCTL_R(uint64_t, features, ops->set_features);
+ VHOST_IOCTL_R(uint64_t, features, vhost_set_features);
break;
case VHOST_RESET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_RESET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->reset_owner);
+ VHOST_IOCTL(vhost_reset_owner);
break;
case VHOST_SET_OWNER:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_OWNER\n", ctx.fh);
- VHOST_IOCTL(ops->set_owner);
+ VHOST_IOCTL(vhost_set_owner);
break;
case VHOST_SET_MEM_TABLE:
@@ -267,28 +266,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_NUM\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_num);
+ vhost_set_vring_num);
break;
case VHOST_SET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_state, state,
- ops->set_vring_base);
+ vhost_set_vring_base);
break;
case VHOST_GET_VRING_BASE:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_GET_VRING_BASE\n", ctx.fh);
VHOST_IOCTL_RW(uint32_t, index,
- struct vhost_vring_state, state, ops->get_vring_base);
+ struct vhost_vring_state, state, vhost_get_vring_base);
break;
case VHOST_SET_VRING_ADDR:
LOG_DEBUG(VHOST_CONFIG,
"(%"PRIu64") IOCTL: VHOST_SET_VRING_ADDR\n", ctx.fh);
VHOST_IOCTL_R(struct vhost_vring_addr, addr,
- ops->set_vring_addr);
+ vhost_set_vring_addr);
break;
case VHOST_SET_VRING_KICK:
@@ -316,10 +315,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg,
}
file.fd = fd;
if (cmd == VHOST_SET_VRING_KICK) {
- result = ops->set_vring_kick(ctx, &file);
+ result = vhost_set_vring_kick(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
} else {
- result = ops->set_vring_call(ctx, &file);
+ result = vhost_set_vring_call(ctx, &file);
fuse_reply_ioctl(req, result, NULL, 0);
}
}
@@ -397,8 +396,6 @@ rte_vhost_driver_register(const char *dev_name)
cuse_info.dev_info_argv = device_argv;
cuse_info.flags = CUSE_UNRESTRICTED_IOCTL;
- ops = get_virtio_net_callbacks();
-
session = cuse_lowlevel_setup(3, fuse_argv,
&cuse_info, &vhost_net_ops, 0, NULL);
if (session == NULL)
diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
index 374c884..a68a8bd 100644
--- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
+++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c
@@ -399,7 +399,7 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int
if (ret >= 0) {
ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name));
- ops->set_ifname(ctx, ifr.ifr_name, ifr_size);
+ vhost_set_ifname(ctx, ifr.ifr_name, ifr_size);
} else
RTE_LOG(ERR, VHOST_CONFIG,
"(%"PRIu64") TUNGETIFF ioctl failed\n",
@@ -419,7 +419,7 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED)
get_ifname(ctx, dev, file->fd, ctx.pid);
- return ops->set_backend(ctx, file);
+ return vhost_set_backend(ctx, file);
}
void
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 6ed7669..de7eecb 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -55,7 +55,6 @@
static void vserver_new_vq_conn(int fd, void *data, int *remove);
static void vserver_message_handler(int fd, void *dat, int *remove);
-struct vhost_net_device_ops const *ops;
struct connfd_ctx {
struct vhost_server *vserver;
@@ -302,7 +301,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
return;
}
- fh = ops->new_device(vdev_ctx);
+ fh = vhost_new_device(vdev_ctx);
if (fh == -1) {
free(ctx);
close(conn_fd);
@@ -311,7 +310,7 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove)
vdev_ctx.fh = fh;
size = strnlen(vserver->path, PATH_MAX);
- ops->set_ifname(vdev_ctx, vserver->path,
+ vhost_set_ifname(vdev_ctx, vserver->path,
size);
RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", fh);
@@ -348,7 +347,7 @@ vserver_message_handler(int connfd, void *dat, int *remove)
close(connfd);
*remove = 1;
free(cfd_ctx);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
return;
}
@@ -357,14 +356,14 @@ vserver_message_handler(int connfd, void *dat, int *remove)
vhost_message_str[msg.request]);
switch (msg.request) {
case VHOST_USER_GET_FEATURES:
- ret = ops->get_features(ctx, &features);
+ ret = vhost_get_features(ctx, &features);
msg.payload.u64 = features;
msg.size = sizeof(msg.payload.u64);
send_vhost_message(connfd, &msg);
break;
case VHOST_USER_SET_FEATURES:
features = msg.payload.u64;
- ops->set_features(ctx, &features);
+ vhost_set_features(ctx, &features);
break;
case VHOST_USER_GET_PROTOCOL_FEATURES:
@@ -377,10 +376,10 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_OWNER:
- ops->set_owner(ctx);
+ vhost_set_owner(ctx);
break;
case VHOST_USER_RESET_OWNER:
- ops->reset_owner(ctx);
+ vhost_reset_owner(ctx);
break;
case VHOST_USER_SET_MEM_TABLE:
@@ -400,13 +399,13 @@ vserver_message_handler(int connfd, void *dat, int *remove)
break;
case VHOST_USER_SET_VRING_NUM:
- ops->set_vring_num(ctx, &msg.payload.state);
+ vhost_set_vring_num(ctx, &msg.payload.state);
break;
case VHOST_USER_SET_VRING_ADDR:
- ops->set_vring_addr(ctx, &msg.payload.addr);
+ vhost_set_vring_addr(ctx, &msg.payload.addr);
break;
case VHOST_USER_SET_VRING_BASE:
- ops->set_vring_base(ctx, &msg.payload.state);
+ vhost_set_vring_base(ctx, &msg.payload.state);
break;
case VHOST_USER_GET_VRING_BASE:
@@ -456,8 +455,6 @@ rte_vhost_driver_register(const char *path)
struct vhost_server *vserver;
pthread_mutex_lock(&g_vhost_server.server_mutex);
- if (ops == NULL)
- ops = get_virtio_net_callbacks();
if (g_vhost_server.vserver_cnt == MAX_VHOST_SERVER) {
RTE_LOG(ERR, VHOST_CONFIG,
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index ffce0d6..68b24f4 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -269,7 +269,7 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring call idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_call(ctx, &file);
+ vhost_set_vring_call(ctx, &file);
}
@@ -290,7 +290,7 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg)
file.fd = pmsg->fds[0];
RTE_LOG(INFO, VHOST_CONFIG,
"vring kick idx:%d file:%d\n", file.index, file.fd);
- ops->set_vring_kick(ctx, &file);
+ vhost_set_vring_kick(ctx, &file);
if (virtio_is_ready(dev) &&
!(dev->flags & VIRTIO_DEV_RUNNING))
@@ -313,7 +313,7 @@ user_get_vring_base(struct vhost_device_ctx ctx,
notify_ops->destroy_device(dev);
/* Here we are safe to get the last used index */
- ops->get_vring_base(ctx, state->index, state);
+ vhost_get_vring_base(ctx, state->index, state);
RTE_LOG(INFO, VHOST_CONFIG,
"vring base idx:%d file:%d\n", state->index, state->num);
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 196e1cf..e189c74 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -350,8 +350,8 @@ reset_device(struct virtio_net *dev)
* initialised and a new entry is added to the device configuration linked
* list.
*/
-static int
-new_device(struct vhost_device_ctx ctx)
+int
+vhost_new_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *new_ll_dev;
@@ -376,8 +376,8 @@ new_device(struct vhost_device_ctx ctx)
* Function is called from the CUSE release function. This function will
* cleanup the device and remove it from device configuration linked list.
*/
-static void
-destroy_device(struct vhost_device_ctx ctx)
+void
+vhost_destroy_device(struct vhost_device_ctx ctx)
{
struct virtio_net_config_ll *ll_dev_cur_ctx, *ll_dev_last = NULL;
struct virtio_net_config_ll *ll_dev_cur = ll_root;
@@ -405,8 +405,8 @@ destroy_device(struct vhost_device_ctx ctx)
}
}
-static void
-set_ifname(struct vhost_device_ctx ctx,
+void
+vhost_set_ifname(struct vhost_device_ctx ctx,
const char *if_name, unsigned int if_len)
{
struct virtio_net *dev;
@@ -428,8 +428,8 @@ set_ifname(struct vhost_device_ctx ctx,
* This function just returns success at the moment unless
* the device hasn't been initialised.
*/
-static int
-set_owner(struct vhost_device_ctx ctx)
+int
+vhost_set_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -443,8 +443,8 @@ set_owner(struct vhost_device_ctx ctx)
/*
* Called from CUSE IOCTL: VHOST_RESET_OWNER
*/
-static int
-reset_owner(struct vhost_device_ctx ctx)
+int
+vhost_reset_owner(struct vhost_device_ctx ctx)
{
struct virtio_net *dev;
@@ -464,8 +464,8 @@ reset_owner(struct vhost_device_ctx ctx)
* Called from CUSE IOCTL: VHOST_GET_FEATURES
* The features that we support are requested.
*/
-static int
-get_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
@@ -482,8 +482,8 @@ get_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_FEATURES
* We receive the negotiated features supported by us and the virtio device.
*/
-static int
-set_features(struct vhost_device_ctx ctx, uint64_t *pu)
+int
+vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu)
{
struct virtio_net *dev;
uint16_t vhost_hlen;
@@ -522,8 +522,9 @@ set_features(struct vhost_device_ctx ctx, uint64_t *pu)
* Called from CUSE IOCTL: VHOST_SET_VRING_NUM
* The virtio device sends us the size of the descriptor ring.
*/
-static int
-set_vring_num(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_num(struct vhost_device_ctx ctx,
+ struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -624,8 +625,8 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused)
* The virtio device sends us the desc, used and avail ring addresses.
* This function then converts these to our address space.
*/
-static int
-set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
+int
+vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -686,8 +687,9 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr)
* Called from CUSE IOCTL: VHOST_SET_VRING_BASE
* The virtio device sends us the available ring last used index.
*/
-static int
-set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
+int
+vhost_set_vring_base(struct vhost_device_ctx ctx,
+ struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -706,8 +708,8 @@ set_vring_base(struct vhost_device_ctx ctx, struct vhost_vring_state *state)
* Called from CUSE IOCTL: VHOST_GET_VRING_BASE
* We send the virtio device our available ring last used index.
*/
-static int
-get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
+int
+vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
struct vhost_vring_state *state)
{
struct virtio_net *dev;
@@ -729,8 +731,8 @@ get_vring_base(struct vhost_device_ctx ctx, uint32_t index,
* The virtio device sends an eventfd to interrupt the guest. This fd gets
* copied into our process space.
*/
-static int
-set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -766,8 +768,8 @@ set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* The virtio device sends an eventfd that it can use to notify us.
* This fd gets copied into our process space.
*/
-static int
-set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;
@@ -796,8 +798,8 @@ set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
* At that point we remove the device from the data core.
* The device will still exist in the device configuration linked list.
*/
-static int
-set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
+int
+vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
{
struct virtio_net *dev;
@@ -824,42 +826,6 @@ set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
return 0;
}
-/*
- * Function pointers are set for the device operations to allow CUSE to call
- * functions when an IOCTL, device_add or device_release is received.
- */
-static const struct vhost_net_device_ops vhost_device_ops = {
- .new_device = new_device,
- .destroy_device = destroy_device,
-
- .set_ifname = set_ifname,
-
- .get_features = get_features,
- .set_features = set_features,
-
- .set_vring_num = set_vring_num,
- .set_vring_addr = set_vring_addr,
- .set_vring_base = set_vring_base,
- .get_vring_base = get_vring_base,
-
- .set_vring_kick = set_vring_kick,
- .set_vring_call = set_vring_call,
-
- .set_backend = set_backend,
-
- .set_owner = set_owner,
- .reset_owner = reset_owner,
-};
-
-/*
- * Called by main to setup callbacks when registering CUSE device.
- */
-struct vhost_net_device_ops const *
-get_virtio_net_callbacks(void)
-{
- return &vhost_device_ops;
-}
-
int rte_vhost_enable_guest_notification(struct virtio_net *dev,
uint16_t queue_id, int enable)
{
--
1.9.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [dpdk-dev] [PATCH v3] vhost: remove vhost_net_device_ops
2016-02-19 18:10 ` [dpdk-dev] [PATCH v3] " Rich Lane
@ 2016-02-19 18:34 ` Thomas Monjalon
0 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2016-02-19 18:34 UTC (permalink / raw)
To: Rich Lane; +Cc: dev
2016-02-19 10:10, Rich Lane:
> The indirection is unnecessary because there is only one implementation
> of the vhost common code. Removing it makes the code more readable.
>
> Signed-off-by: Rich Lane <rlane@bigswitch.com>
> Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Applied, thanks
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-02-19 18:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10 19:27 [dpdk-dev] [PATCH] vhost: remove vhost_net_device_ops Rich Lane
2016-02-15 5:57 ` Yuanhan Liu
2016-02-16 22:45 ` [dpdk-dev] [PATCH v2] " Rich Lane
2016-02-17 12:58 ` Yuanhan Liu
2016-02-19 15:12 ` Thomas Monjalon
2016-02-19 18:10 ` [dpdk-dev] [PATCH v3] " Rich Lane
2016-02-19 18:34 ` Thomas Monjalon
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).