void (* destroy_device) (volatile struct virtio_net *); /* Remove device. */
};
-struct vhost_net_device_ops const * get_virtio_net_callbacks(void);
-
#endif
#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
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.
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
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;
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);
}
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:
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:
}
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);
}
}
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)
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",
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
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;
return;
}
- fh = ops->new_device(vdev_ctx);
+ fh = vhost_new_device(vdev_ctx);
if (fh == -1) {
free(ctx);
close(conn_fd);
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);
close(connfd);
*remove = 1;
free(cfd_ctx);
- ops->destroy_device(ctx);
+ vhost_destroy_device(ctx);
return;
}
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:
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:
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:
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,
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);
}
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))
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);
* 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;
* 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;
}
}
-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;
* 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;
/*
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
* 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;
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)
{