virtio/user: minor cleanup

Make struct vhost_user_msg match the format defined in
the vhost-user spec. The custom additions were inhereted
from DPDK, but SPDK never made use of them. Also replace
direct sizeof(*msg) usages with a handy macro that was
already there. Finally add a VHOST_USER prefix to the
VHOST_MEMORY_MAX_NREGIONS #define.

Change-Id: Idef60fdc62a9e96f076059d60aad796fcc9d3e1c
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446083
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-02-25 08:44:21 +01:00 committed by Jim Harris
parent 2b846acc49
commit e67743162f

View File

@ -40,13 +40,13 @@
/* The version of the protocol we support */
#define VHOST_USER_VERSION 0x1
#define VHOST_MEMORY_MAX_NREGIONS 8
#define VHOST_USER_MEMORY_MAX_NREGIONS 8
/** Fixed-size vhost_memory struct */
struct vhost_memory_padded {
uint32_t nregions;
uint32_t padding;
struct vhost_memory_region regions[VHOST_MEMORY_MAX_NREGIONS];
struct vhost_memory_region regions[VHOST_USER_MEMORY_MAX_NREGIONS];
};
struct vhost_user_msg {
@ -65,7 +65,6 @@ struct vhost_user_msg {
struct vhost_memory_padded memory;
struct vhost_user_config cfg;
} payload;
int fds[VHOST_MEMORY_MAX_NREGIONS];
} __attribute((packed));
#define VHOST_USER_HDR_SIZE offsetof(struct vhost_user_msg, payload.u64)
@ -142,9 +141,9 @@ vhost_user_read(int fd, struct vhost_user_msg *msg)
sz_payload = msg->size;
if (sizeof(*msg) - sz_hdr < sz_payload) {
if (sz_payload > VHOST_USER_PAYLOAD_SIZE) {
SPDK_WARNLOG("Received oversized msg: payload size %zu > available space %zu\n",
sz_payload, sizeof(*msg) - sz_hdr);
sz_payload, VHOST_USER_PAYLOAD_SIZE);
return -EIO;
}
@ -263,9 +262,9 @@ static int
prepare_vhost_memory_user(struct vhost_user_msg *msg, int fds[])
{
int i, num;
struct hugepage_file_info huges[VHOST_MEMORY_MAX_NREGIONS];
struct hugepage_file_info huges[VHOST_USER_MEMORY_MAX_NREGIONS];
num = get_hugepage_file_info(huges, VHOST_MEMORY_MAX_NREGIONS);
num = get_hugepage_file_info(huges, VHOST_USER_MEMORY_MAX_NREGIONS);
if (num < 0) {
SPDK_ERRLOG("Failed to prepare memory for vhost-user\n");
return num;
@ -312,7 +311,7 @@ vhost_user_sock(struct virtio_user_dev *dev,
struct vhost_user_msg msg;
struct vhost_vring_file *file = 0;
int need_reply = 0;
int fds[VHOST_MEMORY_MAX_NREGIONS];
int fds[VHOST_USER_MEMORY_MAX_NREGIONS];
int fd_num = 0;
int i, len, rc;
int vhostfd = dev->vhostfd;