From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 776036CB8 for ; Tue, 7 Jun 2016 05:51:31 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 06 Jun 2016 20:51:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,431,1459839600"; d="scan'208";a="992411086" Received: from yliu-dev.sh.intel.com ([10.239.67.162]) by orsmga002.jf.intel.com with ESMTP; 06 Jun 2016 20:51:29 -0700 From: Yuanhan Liu To: dev@dpdk.org Cc: huawei.xie@intel.com, Thomas Monjalon , Panu Matilainen , Traynor Kevin , Rich Lane , Tetsuya Mukawa , Yuanhan Liu Date: Tue, 7 Jun 2016 11:51:56 +0800 Message-Id: <1465271530-27878-7-git-send-email-yuanhan.liu@linux.intel.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com> References: <1463117111-27050-1-git-send-email-yuanhan.liu@linux.intel.com> <1465271530-27878-1-git-send-email-yuanhan.liu@linux.intel.com> Subject: [dpdk-dev] [PATCH v3 06/20] vhost: get device by vid only X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jun 2016 03:51:32 -0000 get_device() just needs vid, so pass vid as the parameter only. Signed-off-by: Yuanhan Liu Tested-by: Rich Lane Acked-by: Rich Lane --- lib/librte_vhost/vhost-net.h | 30 ++++++------ lib/librte_vhost/vhost_cuse/vhost-net-cdev.c | 64 ++++++++++++------------- lib/librte_vhost/vhost_cuse/virtio-net-cdev.c | 18 ++++--- lib/librte_vhost/vhost_user/vhost-net-user.c | 43 ++++++++--------- lib/librte_vhost/vhost_user/virtio-net-user.c | 36 +++++++------- lib/librte_vhost/vhost_user/virtio-net-user.h | 18 ++++--- lib/librte_vhost/virtio-net.c | 68 +++++++++++++-------------- lib/librte_vhost/virtio-net.h | 2 +- 8 files changed, 132 insertions(+), 147 deletions(-) diff --git a/lib/librte_vhost/vhost-net.h b/lib/librte_vhost/vhost-net.h index b63ea6f..4de3aa0 100644 --- a/lib/librte_vhost/vhost-net.h +++ b/lib/librte_vhost/vhost-net.h @@ -83,28 +83,26 @@ struct vhost_device_ctx { int vid; /* Virtio-net device ID */ }; -int vhost_new_device(struct vhost_device_ctx); -void vhost_destroy_device(struct vhost_device_ctx); +int vhost_new_device(void); +void vhost_destroy_device(int); -void vhost_set_ifname(struct vhost_device_ctx, - const char *if_name, unsigned int if_len); +void vhost_set_ifname(int, const char *if_name, unsigned int if_len); -int vhost_get_features(struct vhost_device_ctx, uint64_t *); -int vhost_set_features(struct vhost_device_ctx, uint64_t *); +int vhost_get_features(int, uint64_t *); +int vhost_set_features(int, uint64_t *); -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 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 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_vring_kick(int, struct vhost_vring_file *); +int vhost_set_vring_call(int, struct vhost_vring_file *); -int vhost_set_backend(struct vhost_device_ctx, struct vhost_vring_file *); +int vhost_set_backend(int, struct vhost_vring_file *); -int vhost_set_owner(struct vhost_device_ctx); -int vhost_reset_owner(struct vhost_device_ctx); +int vhost_set_owner(int); +int vhost_reset_owner(int); /* * 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 3a9b33d..45a9a91 100644 --- a/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c +++ b/lib/librte_vhost/vhost_cuse/vhost-net-cdev.c @@ -82,19 +82,18 @@ fuse_req_to_vhost_ctx(fuse_req_t req, struct fuse_file_info *fi) static void 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; + int vid = 0; - err = vhost_new_device(ctx); - if (err == -1) { + vid = vhost_new_device(); + if (vid == -1) { fuse_reply_err(req, EPERM); return; } - fi->fh = err; + fi->fh = vid; RTE_LOG(INFO, VHOST_CONFIG, - "(%d) device configuration started\n", err); + "(%d) device configuration started\n", vid); fuse_reply_open(req, fi); } @@ -107,17 +106,17 @@ 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); - vhost_destroy_device(ctx); + vhost_destroy_device(ctx.vid); RTE_LOG(INFO, VHOST_CONFIG, "(%d) device released\n", ctx.vid); fuse_reply_err(req, err); } /* * Boilerplate code for CUSE IOCTL - * Implicit arguments: ctx, req, result. + * Implicit arguments: vid, req, result. */ #define VHOST_IOCTL(func) do { \ - result = (func)(ctx); \ + result = (func)(vid); \ fuse_reply_ioctl(req, result, NULL, 0); \ } while (0) @@ -134,41 +133,41 @@ vhost_net_release(fuse_req_t req, struct fuse_file_info *fi) /* * Boilerplate code for CUSE Read IOCTL - * Implicit arguments: ctx, req, result, in_bufsz, in_buf. + * Implicit arguments: vid, req, result, in_bufsz, in_buf. */ #define VHOST_IOCTL_R(type, var, func) do { \ if (!in_bufsz) { \ VHOST_IOCTL_RETRY(sizeof(type), 0);\ } else { \ (var) = *(const type*)in_buf; \ - result = func(ctx, &(var)); \ + result = func(vid, &(var)); \ fuse_reply_ioctl(req, result, NULL, 0);\ } \ } while (0) /* * Boilerplate code for CUSE Write IOCTL - * Implicit arguments: ctx, req, result, out_bufsz. + * Implicit arguments: vid, req, result, out_bufsz. */ #define VHOST_IOCTL_W(type, var, func) do { \ if (!out_bufsz) { \ VHOST_IOCTL_RETRY(0, sizeof(type));\ } else { \ - result = (func)(ctx, &(var));\ + result = (func)(vid, &(var));\ fuse_reply_ioctl(req, result, &(var), sizeof(type));\ } \ } while (0) /* * Boilerplate code for CUSE Read/Write IOCTL - * Implicit arguments: ctx, req, result, in_bufsz, in_buf. + * Implicit arguments: vid, req, result, in_bufsz, in_buf. */ #define VHOST_IOCTL_RW(type1, var1, type2, var2, func) do { \ if (!in_bufsz) { \ VHOST_IOCTL_RETRY(sizeof(type1), sizeof(type2));\ } else { \ (var1) = *(const type1*) (in_buf); \ - result = (func)(ctx, (var1), &(var2)); \ + result = (func)(vid, (var1), &(var2)); \ fuse_reply_ioctl(req, result, &(var2), sizeof(type2));\ } \ } while (0) @@ -190,6 +189,7 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, uint64_t features; uint32_t index; int result = 0; + int vid = ctx.vid; switch (cmd) { case VHOST_NET_SET_BACKEND: @@ -206,32 +206,32 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, case VHOST_GET_FEATURES: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_GET_FEATURES\n", ctx.vid); + "(%d) IOCTL: VHOST_GET_FEATURES\n", vid); VHOST_IOCTL_W(uint64_t, features, vhost_get_features); break; case VHOST_SET_FEATURES: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_FEATURES\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_FEATURES\n", vid); VHOST_IOCTL_R(uint64_t, features, vhost_set_features); break; case VHOST_RESET_OWNER: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_RESET_OWNER\n", ctx.vid); + "(%d) IOCTL: VHOST_RESET_OWNER\n", vid); VHOST_IOCTL(vhost_reset_owner); break; case VHOST_SET_OWNER: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_OWNER\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_OWNER\n", vid); VHOST_IOCTL(vhost_set_owner); break; case VHOST_SET_MEM_TABLE: /*TODO fix race condition.*/ LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_MEM_TABLE\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_MEM_TABLE\n", vid); static struct vhost_memory mem_temp; switch (in_bufsz) { @@ -264,28 +264,28 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, case VHOST_SET_VRING_NUM: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_VRING_NUM\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_VRING_NUM\n", vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_num); break; case VHOST_SET_VRING_BASE: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_VRING_BASE\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_VRING_BASE\n", vid); VHOST_IOCTL_R(struct vhost_vring_state, state, vhost_set_vring_base); break; case VHOST_GET_VRING_BASE: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_GET_VRING_BASE\n", ctx.vid); + "(%d) IOCTL: VHOST_GET_VRING_BASE\n", vid); VHOST_IOCTL_RW(uint32_t, index, struct vhost_vring_state, state, vhost_get_vring_base); break; case VHOST_SET_VRING_ADDR: LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_VRING_ADDR\n", ctx.vid); + "(%d) IOCTL: VHOST_SET_VRING_ADDR\n", vid); VHOST_IOCTL_R(struct vhost_vring_addr, addr, vhost_set_vring_addr); break; @@ -294,12 +294,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, case VHOST_SET_VRING_CALL: if (cmd == VHOST_SET_VRING_KICK) LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_VRING_KICK\n", - ctx.vid); + "(%d) IOCTL: VHOST_SET_VRING_KICK\n", vid); else LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: VHOST_SET_VRING_CALL\n", - ctx.vid); + "(%d) IOCTL: VHOST_SET_VRING_CALL\n", vid); if (!in_buf) VHOST_IOCTL_RETRY(sizeof(struct vhost_vring_file), 0); else { @@ -315,10 +313,10 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, } file.fd = fd; if (cmd == VHOST_SET_VRING_KICK) { - result = vhost_set_vring_kick(ctx, &file); + result = vhost_set_vring_kick(vid, &file); fuse_reply_ioctl(req, result, NULL, 0); } else { - result = vhost_set_vring_call(ctx, &file); + result = vhost_set_vring_call(vid, &file); fuse_reply_ioctl(req, result, NULL, 0); } } @@ -326,17 +324,17 @@ vhost_net_ioctl(fuse_req_t req, int cmd, void *arg, default: RTE_LOG(ERR, VHOST_CONFIG, - "(%d) IOCTL: DOESN NOT EXIST\n", ctx.vid); + "(%d) IOCTL: DOESN NOT EXIST\n", vid); result = -1; fuse_reply_ioctl(req, result, NULL, 0); } if (result < 0) LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: FAIL\n", ctx.vid); + "(%d) IOCTL: FAIL\n", vid); else LOG_DEBUG(VHOST_CONFIG, - "(%d) IOCTL: SUCCESS\n", ctx.vid); + "(%d) IOCTL: SUCCESS\n", vid); } /* diff --git a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c index b90dabf..34ee6c9 100644 --- a/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c +++ b/lib/librte_vhost/vhost_cuse/virtio-net-cdev.c @@ -274,7 +274,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, uint64_t base_address = 0, mapped_address, mapped_size; struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(ctx.vid); if (dev == NULL) return -1; @@ -379,7 +379,7 @@ cuse_set_mem_table(struct vhost_device_ctx ctx, * save it in the device structure. */ static int -get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int pid) +get_ifname(int vid, int tap_fd, int pid) { int fd_tap; struct ifreq ifr; @@ -393,16 +393,14 @@ get_ifname(struct vhost_device_ctx ctx, struct virtio_net *dev, int tap_fd, int ret = ioctl(fd_tap, TUNGETIFF, &ifr); if (close(fd_tap) < 0) - RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n", - dev->vid); + RTE_LOG(ERR, VHOST_CONFIG, "(%d) fd close failed\n", vid); if (ret >= 0) { ifr_size = strnlen(ifr.ifr_name, sizeof(ifr.ifr_name)); - vhost_set_ifname(ctx, ifr.ifr_name, ifr_size); + vhost_set_ifname(vid, ifr.ifr_name, ifr_size); } else RTE_LOG(ERR, VHOST_CONFIG, - "(%d) TUNGETIFF ioctl failed\n", - dev->vid); + "(%d) TUNGETIFF ioctl failed\n", vid); return 0; } @@ -411,14 +409,14 @@ int cuse_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(ctx.vid); if (dev == NULL) return -1; if (!(dev->flags & VIRTIO_DEV_RUNNING) && file->fd != VIRTIO_DEV_STOPPED) - get_ifname(ctx, dev, file->fd, ctx.pid); + get_ifname(ctx.vid, file->fd, ctx.pid); - return vhost_set_backend(ctx, file); + return vhost_set_backend(ctx.vid, 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 3498796..68fc9b9 100644 --- a/lib/librte_vhost/vhost_user/vhost-net-user.c +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c @@ -286,7 +286,6 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove) int conn_fd; struct connfd_ctx *ctx; int vid; - struct vhost_device_ctx vdev_ctx = { (pid_t)0, 0 }; unsigned int size; conn_fd = accept(fd, NULL, NULL); @@ -301,17 +300,15 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove) return; } - vid = vhost_new_device(vdev_ctx); + vid = vhost_new_device(); if (vid == -1) { free(ctx); close(conn_fd); return; } - vdev_ctx.vid = vid; size = strnlen(vserver->path, PATH_MAX); - vhost_set_ifname(vdev_ctx, vserver->path, - size); + vhost_set_ifname(vid, vserver->path, size); RTE_LOG(INFO, VHOST_CONFIG, "new device, handle is %d\n", vid); @@ -325,13 +322,13 @@ vserver_new_vq_conn(int fd, void *dat, __rte_unused int *remove) static void vserver_message_handler(int connfd, void *dat, int *remove) { - struct vhost_device_ctx ctx; + int vid; struct connfd_ctx *cfd_ctx = (struct connfd_ctx *)dat; struct VhostUserMsg msg; uint64_t features; int ret; - ctx.vid = cfd_ctx->vid; + vid = cfd_ctx->vid; ret = read_vhost_message(connfd, &msg); if (ret <= 0 || msg.request >= VHOST_USER_MAX) { if (ret < 0) @@ -347,7 +344,7 @@ vserver_message_handler(int connfd, void *dat, int *remove) close(connfd); *remove = 1; free(cfd_ctx); - vhost_destroy_device(ctx); + vhost_destroy_device(vid); return; } @@ -356,14 +353,14 @@ vserver_message_handler(int connfd, void *dat, int *remove) vhost_message_str[msg.request]); switch (msg.request) { case VHOST_USER_GET_FEATURES: - ret = vhost_get_features(ctx, &features); + ret = vhost_get_features(vid, &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; - vhost_set_features(ctx, &features); + vhost_set_features(vid, &features); break; case VHOST_USER_GET_PROTOCOL_FEATURES: @@ -372,22 +369,22 @@ vserver_message_handler(int connfd, void *dat, int *remove) send_vhost_message(connfd, &msg); break; case VHOST_USER_SET_PROTOCOL_FEATURES: - user_set_protocol_features(ctx, msg.payload.u64); + user_set_protocol_features(vid, msg.payload.u64); break; case VHOST_USER_SET_OWNER: - vhost_set_owner(ctx); + vhost_set_owner(vid); break; case VHOST_USER_RESET_OWNER: - vhost_reset_owner(ctx); + vhost_reset_owner(vid); break; case VHOST_USER_SET_MEM_TABLE: - user_set_mem_table(ctx, &msg); + user_set_mem_table(vid, &msg); break; case VHOST_USER_SET_LOG_BASE: - user_set_log_base(ctx, &msg); + user_set_log_base(vid, &msg); /* it needs a reply */ msg.size = sizeof(msg.payload.u64); @@ -399,26 +396,26 @@ vserver_message_handler(int connfd, void *dat, int *remove) break; case VHOST_USER_SET_VRING_NUM: - vhost_set_vring_num(ctx, &msg.payload.state); + vhost_set_vring_num(vid, &msg.payload.state); break; case VHOST_USER_SET_VRING_ADDR: - vhost_set_vring_addr(ctx, &msg.payload.addr); + vhost_set_vring_addr(vid, &msg.payload.addr); break; case VHOST_USER_SET_VRING_BASE: - vhost_set_vring_base(ctx, &msg.payload.state); + vhost_set_vring_base(vid, &msg.payload.state); break; case VHOST_USER_GET_VRING_BASE: - ret = user_get_vring_base(ctx, &msg.payload.state); + ret = user_get_vring_base(vid, &msg.payload.state); msg.size = sizeof(msg.payload.state); send_vhost_message(connfd, &msg); break; case VHOST_USER_SET_VRING_KICK: - user_set_vring_kick(ctx, &msg); + user_set_vring_kick(vid, &msg); break; case VHOST_USER_SET_VRING_CALL: - user_set_vring_call(ctx, &msg); + user_set_vring_call(vid, &msg); break; case VHOST_USER_SET_VRING_ERR: @@ -434,10 +431,10 @@ vserver_message_handler(int connfd, void *dat, int *remove) break; case VHOST_USER_SET_VRING_ENABLE: - user_set_vring_enable(ctx, &msg.payload.state); + user_set_vring_enable(vid, &msg.payload.state); break; case VHOST_USER_SEND_RARP: - user_send_rarp(ctx, &msg); + user_send_rarp(vid, &msg); break; default: diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index 1568c9f..9385af1 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -99,7 +99,7 @@ vhost_backend_cleanup(struct virtio_net *dev) } int -user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) +user_set_mem_table(int vid, struct VhostUserMsg *pmsg) { struct VhostUserMemory memory = pmsg->payload.memory; struct virtio_memory_regions *pregion; @@ -110,7 +110,7 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) uint64_t alignment; /* unmap old memory regions one by one*/ - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -254,7 +254,7 @@ virtio_is_ready(struct virtio_net *dev) } void -user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) +user_set_vring_call(int vid, struct VhostUserMsg *pmsg) { struct vhost_vring_file file; @@ -265,7 +265,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); - vhost_set_vring_call(ctx, &file); + vhost_set_vring_call(vid, &file); } @@ -274,10 +274,10 @@ user_set_vring_call(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) * device is ready for packet processing. */ void -user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) +user_set_vring_kick(int vid, struct VhostUserMsg *pmsg) { struct vhost_vring_file file; - struct virtio_net *dev = get_device(ctx); + struct virtio_net *dev = get_device(vid); file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) @@ -286,7 +286,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); - vhost_set_vring_kick(ctx, &file); + vhost_set_vring_kick(vid, &file); if (virtio_is_ready(dev) && !(dev->flags & VIRTIO_DEV_RUNNING)) { if (notify_ops->new_device(dev) == 0) @@ -298,10 +298,10 @@ user_set_vring_kick(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) * when virtio is stopped, qemu will send us the GET_VRING_BASE message. */ int -user_get_vring_base(struct vhost_device_ctx ctx, +user_get_vring_base(int vid, struct vhost_vring_state *state) { - struct virtio_net *dev = get_device(ctx); + struct virtio_net *dev = get_device(vid); if (dev == NULL) return -1; @@ -310,7 +310,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 */ - vhost_get_vring_base(ctx, state->index, state); + vhost_get_vring_base(vid, state->index, state); RTE_LOG(INFO, VHOST_CONFIG, "vring base idx:%d file:%d\n", state->index, state->num); @@ -332,10 +332,10 @@ user_get_vring_base(struct vhost_device_ctx ctx, * enable the virtio queue pair. */ int -user_set_vring_enable(struct vhost_device_ctx ctx, +user_set_vring_enable(int vid, struct vhost_vring_state *state) { - struct virtio_net *dev = get_device(ctx); + struct virtio_net *dev = get_device(vid); int enable = (int)state->num; RTE_LOG(INFO, VHOST_CONFIG, @@ -352,12 +352,12 @@ user_set_vring_enable(struct vhost_device_ctx ctx, } void -user_set_protocol_features(struct vhost_device_ctx ctx, +user_set_protocol_features(int vid, uint64_t protocol_features) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL || protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) return; @@ -365,7 +365,7 @@ user_set_protocol_features(struct vhost_device_ctx ctx, } int -user_set_log_base(struct vhost_device_ctx ctx, +user_set_log_base(int vid, struct VhostUserMsg *msg) { struct virtio_net *dev; @@ -373,7 +373,7 @@ user_set_log_base(struct vhost_device_ctx ctx, uint64_t size, off; void *addr; - dev = get_device(ctx); + dev = get_device(vid); if (!dev) return -1; @@ -421,12 +421,12 @@ user_set_log_base(struct vhost_device_ctx ctx, * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ int -user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *msg) +user_send_rarp(int vid, struct VhostUserMsg *msg) { struct virtio_net *dev; uint8_t *mac = (uint8_t *)&msg->payload.u64; - dev = get_device(ctx); + dev = get_device(vid); if (!dev) return -1; diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h index cefec16..e1b967b 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.h +++ b/lib/librte_vhost/vhost_user/virtio-net-user.h @@ -45,20 +45,18 @@ (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\ (1ULL << VHOST_USER_PROTOCOL_F_RARP)) -int user_set_mem_table(struct vhost_device_ctx, struct VhostUserMsg *); +int user_set_mem_table(int, struct VhostUserMsg *); -void user_set_vring_call(struct vhost_device_ctx, struct VhostUserMsg *); +void user_set_vring_call(int, struct VhostUserMsg *); -void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *); +void user_set_vring_kick(int, struct VhostUserMsg *); -void user_set_protocol_features(struct vhost_device_ctx ctx, - uint64_t protocol_features); -int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *); -int user_send_rarp(struct vhost_device_ctx ctx, struct VhostUserMsg *); +void user_set_protocol_features(int vid, uint64_t protocol_features); +int user_set_log_base(int vid, struct VhostUserMsg *); +int user_send_rarp(int vid, struct VhostUserMsg *); -int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *); +int user_get_vring_base(int, struct vhost_vring_state *); -int user_set_vring_enable(struct vhost_device_ctx ctx, - struct vhost_vring_state *state); +int user_set_vring_enable(int vid, struct vhost_vring_state *state); #endif diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 0a13150..c6d3829 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -108,15 +108,14 @@ qva_to_vva(struct virtio_net *dev, uint64_t qemu_va) return vhost_va; } - struct virtio_net * -get_device(struct vhost_device_ctx ctx) +get_device(int vid) { - struct virtio_net *dev = vhost_devices[ctx.vid]; + struct virtio_net *dev = vhost_devices[vid]; if (unlikely(!dev)) { RTE_LOG(ERR, VHOST_CONFIG, - "(%d) device not found.\n", ctx.vid); + "(%d) device not found.\n", vid); } return dev; @@ -255,7 +254,7 @@ reset_device(struct virtio_net *dev) * list. */ int -vhost_new_device(struct vhost_device_ctx ctx) +vhost_new_device(void) { struct virtio_net *dev; int i; @@ -263,7 +262,7 @@ vhost_new_device(struct vhost_device_ctx ctx) dev = rte_zmalloc(NULL, sizeof(struct virtio_net), 0); if (dev == NULL) { RTE_LOG(ERR, VHOST_CONFIG, - "(%d) failed to allocate memory for dev.\n", ctx.vid); + "Failed to allocate memory for new dev.\n"); return -1; } @@ -288,9 +287,9 @@ vhost_new_device(struct vhost_device_ctx ctx) * cleanup the device and remove it from device configuration linked list. */ void -vhost_destroy_device(struct vhost_device_ctx ctx) +vhost_destroy_device(int vid) { - struct virtio_net *dev = get_device(ctx); + struct virtio_net *dev = get_device(vid); if (dev == NULL) return; @@ -303,17 +302,16 @@ vhost_destroy_device(struct vhost_device_ctx ctx) cleanup_device(dev, 1); free_device(dev); - vhost_devices[ctx.vid] = NULL; + vhost_devices[vid] = NULL; } void -vhost_set_ifname(struct vhost_device_ctx ctx, - const char *if_name, unsigned int if_len) +vhost_set_ifname(int vid, const char *if_name, unsigned int if_len) { struct virtio_net *dev; unsigned int len; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return; @@ -331,11 +329,11 @@ vhost_set_ifname(struct vhost_device_ctx ctx, * the device hasn't been initialised. */ int -vhost_set_owner(struct vhost_device_ctx ctx) +vhost_set_owner(int vid) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -346,11 +344,11 @@ vhost_set_owner(struct vhost_device_ctx ctx) * Called from CUSE IOCTL: VHOST_RESET_OWNER */ int -vhost_reset_owner(struct vhost_device_ctx ctx) +vhost_reset_owner(int vid) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -369,11 +367,11 @@ vhost_reset_owner(struct vhost_device_ctx ctx) * The features that we support are requested. */ int -vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu) +vhost_get_features(int vid, uint64_t *pu) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -387,13 +385,13 @@ vhost_get_features(struct vhost_device_ctx ctx, uint64_t *pu) * We receive the negotiated features supported by us and the virtio device. */ int -vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) +vhost_set_features(int vid, uint64_t *pu) { struct virtio_net *dev; uint16_t vhost_hlen; uint16_t i; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; if (*pu & ~VHOST_FEATURES) @@ -427,12 +425,11 @@ vhost_set_features(struct vhost_device_ctx ctx, uint64_t *pu) * The virtio device sends us the size of the descriptor ring. */ int -vhost_set_vring_num(struct vhost_device_ctx ctx, - struct vhost_vring_state *state) +vhost_set_vring_num(int vid, struct vhost_vring_state *state) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -531,12 +528,12 @@ numa_realloc(struct virtio_net *dev, int index __rte_unused) * This function then converts these to our address space. */ int -vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) +vhost_set_vring_addr(int vid, struct vhost_vring_addr *addr) { struct virtio_net *dev; struct vhost_virtqueue *vq; - dev = get_device(ctx); + dev = get_device(vid); if ((dev == NULL) || (dev->mem == NULL)) return -1; @@ -593,12 +590,11 @@ vhost_set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) * The virtio device sends us the available ring last used index. */ int -vhost_set_vring_base(struct vhost_device_ctx ctx, - struct vhost_vring_state *state) +vhost_set_vring_base(int vid, struct vhost_vring_state *state) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -614,12 +610,12 @@ vhost_set_vring_base(struct vhost_device_ctx ctx, * We send the virtio device our available ring last used index. */ int -vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index, +vhost_get_vring_base(int vid, uint32_t index, struct vhost_vring_state *state) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -637,13 +633,13 @@ vhost_get_vring_base(struct vhost_device_ctx ctx, uint32_t index, * copied into our process space. */ int -vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file) +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(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -674,12 +670,12 @@ vhost_set_vring_call(struct vhost_device_ctx ctx, struct vhost_vring_file *file) * This fd gets copied into our process space. */ int -vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file) +vhost_set_vring_kick(int vid, struct vhost_vring_file *file) { struct virtio_net *dev; struct vhost_virtqueue *vq; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; @@ -704,11 +700,11 @@ vhost_set_vring_kick(struct vhost_device_ctx ctx, struct vhost_vring_file *file) * The device will still exist in the device configuration linked list. */ int -vhost_set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file) +vhost_set_backend(int vid, struct vhost_vring_file *file) { struct virtio_net *dev; - dev = get_device(ctx); + dev = get_device(vid); if (dev == NULL) return -1; diff --git a/lib/librte_vhost/virtio-net.h b/lib/librte_vhost/virtio-net.h index 75fb57e..9812545 100644 --- a/lib/librte_vhost/virtio-net.h +++ b/lib/librte_vhost/virtio-net.h @@ -38,6 +38,6 @@ #include "rte_virtio_net.h" struct virtio_net_device_ops const *notify_ops; -struct virtio_net *get_device(struct vhost_device_ctx ctx); +struct virtio_net *get_device(int vid); #endif -- 1.9.0