From patchwork Sat Sep 15 05:20:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 146751 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1445928ljw; Fri, 14 Sep 2018 22:20:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ7O50cim4mbn4LC0laZLQHk5vZm6loRCHo2I5WDH4Ww2rcSeMOAWn5aceg69ObLQwZW62u X-Received: by 2002:a1c:ef0f:: with SMTP id n15-v6mr4274602wmh.116.1536988833762; Fri, 14 Sep 2018 22:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536988833; cv=none; d=google.com; s=arc-20160816; b=jjrzWQoi/9euYC4mJeqRShul9Gjf4Fnx0glY27eygi335+KpwcxCyodI+/ksUBV+7+ ccqx52EKjfg5jALLJjvXT710zFFrvXVdeoiKlfKJbh0bi0+ZvQ1EtNUMRM3IsZEIgoDF 6rdSaHBep8anbf/dSevnm7cBwmyQW8qkPpOUykhku1aq+0QrAkvgYauT1Hn5mujqHWEa RKKUGzyR0TPt3xqunkW7ifO9csXEWVrneKfPUN/GuP0K/jj+VTu7hNlBUgAVBcLNQSz7 X4ff3zXHxMVYzz8e6fF4lPLEcuAcCa5fX1i5qVNqUtN9f+r7kr1Mpx2obYW9Knkyj9Kc dLsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=8taa9XgI5YYGxpKLquS4UvJx3nBqTBYDZP5xcINngKE=; b=JPL7EfmSA5FF1LpxJwIDivBaLjOxFf/aNGpiLft1Zhb3prkXhl6ggd31NHlu0C9KYs 1EooaBKp6ZruYN3BECvubt7z8ObVdX38UlczyTNFf2z7U8RVxClWy5fp2QWGw55LLLzm MydRRgQHPyIvKW/XALOQPBSLKMPXt1a/cah6OXgfbqJGunseHn2u7W77b5BhEm/y185C OsOB9YuXt25BIcuY9SDaSg5B/M/CRuHKH+BIFzg39OcXxSe5AJg1TbcQP2A2cLHd5XJR VvGvnRX4zseLLHBiQ5zW++DTfRaE6oVpb4uQ7Jho/FZc8Ajd2BjsP1UcN6vwapTtxBl5 KEQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pufiPCIp; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id y84-v6si903498wmc.76.2018.09.14.22.20.33; Fri, 14 Sep 2018 22:20:33 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pufiPCIp; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EAF024C94; Sat, 15 Sep 2018 07:20:30 +0200 (CEST) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by dpdk.org (Postfix) with ESMTP id 7CB1F2BD5 for ; Sat, 15 Sep 2018 07:20:29 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id n11-v6so3940820wmc.2 for ; Fri, 14 Sep 2018 22:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=8taa9XgI5YYGxpKLquS4UvJx3nBqTBYDZP5xcINngKE=; b=pufiPCIpTBazefzzOv6RfY9REzjo0cXa9GAQeI2kjnvRNJV6PHYXA8XL3bfTqcVFfM TsSsoaDeSaREZAQGxmLoj/Ch/Rbq5ZbjWArQTDXEfqSFAKUvlRVaMjm6I7210KGKNWBf iQ6uk+AZYfsU59TmPOMFxiIP+70uj1cHk7NRne1YD3Hf6xEanCEgTxC3yBQus55YQ0tF r/UDEiVbfVxBukWtKIc7hO3j65EFgMjwSdAW3D9GqeSzNPXMmOd0m+qNlx+9aq7LEr0j ggXpxea4qRYjBorK+oYBI3km2khrAVnLUDEdPg6Ztqo7O6jRf2mF/GXOmwOr+PIC1Z55 JiQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=8taa9XgI5YYGxpKLquS4UvJx3nBqTBYDZP5xcINngKE=; b=i1qvYrJbRnLk2EDWyKwnycpInMllMMROLccqBj8+AowbOObPiC7cLocBoUzldqUohY akDqmlhhkzYa65eELL7NCY+8IcFvgDmP7qxM8cDqE9ys8WdLHEltN7pX5iykujjGB3zX nEQd89W2RYmt1Dq2VdRF6JTO9DGx6QfRBcuP0B6RG0zOFY9ltbvZ0d5ichsQoot7Qps8 aXzjxbkExZ8b67ZuhnH4dw+2/VwostoZDOCvjJdwgpQpDPqXPd2pADffyUHAKFw8vbs1 jPm4Y9KPf43LbmfCHrTemjyAX5enGV/02O0hhR6k8s/f9DqP5S04DauJH7GknEF7fhHO C55Q== X-Gm-Message-State: APzg51C/DHLPuNMWh1mWPOS297PCSzg8WaqJLJoIBY+J8vR9X8pj4YKD zX/5pMqLNU7Fzddh5STXjvBOkoDGKPG/cg== X-Received: by 2002:a1c:578a:: with SMTP id l132-v6mr4455588wmb.16.1536988828892; Fri, 14 Sep 2018 22:20:28 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id f6-v6sm6323398wrr.68.2018.09.14.22.20.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:20:28 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Sat, 15 Sep 2018 08:20:26 +0300 Message-ID: <153698882681.23049.10483393218056672951.stgit@T460> In-Reply-To: <153698873346.23049.10966616323159180622.stgit@T460> References: <153698873346.23049.10966616323159180622.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/5] vhost: unify VhostUserMsg usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use the typedef version of struct VhostUserMsg. Also unify the related parameter name. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 50 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 63d145b2d..b05b57670 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -780,10 +780,10 @@ vhost_memory_changed(struct VhostUserMemory *new, } static int -vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg) +vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) { struct virtio_net *dev = *pdev; - struct VhostUserMemory memory = pmsg->payload.memory; + struct VhostUserMemory memory = msg->payload.memory; struct rte_vhost_mem_region *reg; void *mmap_addr; uint64_t mmap_size; @@ -804,7 +804,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg) "(%d) memory regions not changed\n", dev->vid); for (i = 0; i < memory.nregions; i++) - close(pmsg->fds[i]); + close(msg->fds[i]); return 0; } @@ -845,7 +845,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, struct VhostUserMsg *pmsg) dev->mem->nregions = memory.nregions; for (i = 0; i < memory.nregions; i++) { - fd = pmsg->fds[i]; + fd = msg->fds[i]; reg = &dev->mem->regions[i]; reg->guest_phys_addr = memory.regions[i].guest_phys_addr; @@ -994,16 +994,16 @@ virtio_is_ready(struct virtio_net *dev) } static void -vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) +vhost_user_set_vring_call(struct virtio_net *dev, VhostUserMsg *msg) { struct vhost_vring_file file; struct vhost_virtqueue *vq; - file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; - if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) + file.index = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + if (msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; else - file.fd = pmsg->fds[0]; + file.fd = msg->fds[0]; RTE_LOG(INFO, VHOST_CONFIG, "vring call idx:%d file:%d\n", file.index, file.fd); @@ -1015,17 +1015,17 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) } static int -vhost_user_set_vring_kick(struct virtio_net **pdev, struct VhostUserMsg *pmsg) +vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) { struct vhost_vring_file file; struct vhost_virtqueue *vq; struct virtio_net *dev = *pdev; - file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; - if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) + file.index = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + if (msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) file.fd = VIRTIO_INVALID_EVENTFD; else - file.fd = pmsg->fds[0]; + file.fd = msg->fds[0]; RTE_LOG(INFO, VHOST_CONFIG, "vring kick idx:%d file:%d\n", file.index, file.fd); @@ -1153,7 +1153,7 @@ vhost_user_set_vring_enable(struct virtio_net *dev, static void vhost_user_get_protocol_features(struct virtio_net *dev, - struct VhostUserMsg *msg) + VhostUserMsg *msg) { uint64_t features, protocol_features; @@ -1189,7 +1189,7 @@ vhost_user_set_protocol_features(struct virtio_net *dev, } static int -vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg) +vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) { int fd = msg->fds[0]; uint64_t size, off; @@ -1256,7 +1256,7 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg) * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ static int -vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg) +vhost_user_send_rarp(struct virtio_net *dev, VhostUserMsg *msg) { uint8_t *mac = (uint8_t *)&msg->payload.u64; struct rte_vdpa_device *vdpa_dev; @@ -1285,7 +1285,7 @@ vhost_user_send_rarp(struct virtio_net *dev, struct VhostUserMsg *msg) } static int -vhost_user_net_set_mtu(struct virtio_net *dev, struct VhostUserMsg *msg) +vhost_user_net_set_mtu(struct virtio_net *dev, VhostUserMsg *msg) { if (msg->payload.u64 < VIRTIO_MIN_MTU || msg->payload.u64 > VIRTIO_MAX_MTU) { @@ -1301,7 +1301,7 @@ vhost_user_net_set_mtu(struct virtio_net *dev, struct VhostUserMsg *msg) } static int -vhost_user_set_req_fd(struct virtio_net *dev, struct VhostUserMsg *msg) +vhost_user_set_req_fd(struct virtio_net *dev, VhostUserMsg *msg) { int fd = msg->fds[0]; @@ -1367,7 +1367,7 @@ is_vring_iotlb_invalidate(struct vhost_virtqueue *vq, } static int -vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg) +vhost_user_iotlb_msg(struct virtio_net **pdev, VhostUserMsg *msg) { struct virtio_net *dev = *pdev; struct vhost_iotlb_msg *imsg = &msg->payload.iotlb; @@ -1413,7 +1413,7 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg) /* return bytes# of read on success or negative val on failure. */ static int -read_vhost_message(int sockfd, struct VhostUserMsg *msg) +read_vhost_message(int sockfd, VhostUserMsg *msg) { int ret; @@ -1442,7 +1442,7 @@ read_vhost_message(int sockfd, struct VhostUserMsg *msg) } static int -send_vhost_message(int sockfd, struct VhostUserMsg *msg, int *fds, int fd_num) +send_vhost_message(int sockfd, VhostUserMsg *msg, int *fds, int fd_num) { if (!msg) return 0; @@ -1452,7 +1452,7 @@ send_vhost_message(int sockfd, struct VhostUserMsg *msg, int *fds, int fd_num) } static int -send_vhost_reply(int sockfd, struct VhostUserMsg *msg) +send_vhost_reply(int sockfd, VhostUserMsg *msg) { if (!msg) return 0; @@ -1466,7 +1466,7 @@ send_vhost_reply(int sockfd, struct VhostUserMsg *msg) } static int -send_vhost_slave_message(struct virtio_net *dev, struct VhostUserMsg *msg, +send_vhost_slave_message(struct virtio_net *dev, VhostUserMsg *msg, int *fds, int fd_num) { int ret; @@ -1557,7 +1557,7 @@ int vhost_user_msg_handler(int vid, int fd) { struct virtio_net *dev; - struct VhostUserMsg msg; + VhostUserMsg msg; struct rte_vdpa_device *vdpa_dev; int did = -1; int ret; @@ -1850,7 +1850,7 @@ int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm) { int ret; - struct VhostUserMsg msg = { + VhostUserMsg msg = { .request.slave = VHOST_USER_SLAVE_IOTLB_MSG, .flags = VHOST_USER_VERSION, .size = sizeof(msg.payload.iotlb), @@ -1880,7 +1880,7 @@ static int vhost_user_slave_set_vring_host_notifier(struct virtio_net *dev, int *fdp = NULL; size_t fd_num = 0; int ret; - struct VhostUserMsg msg = { + VhostUserMsg msg = { .request.slave = VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG, .flags = VHOST_USER_VERSION | VHOST_USER_NEED_REPLY, .size = sizeof(msg.payload.area), From patchwork Sat Sep 15 05:20:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 146752 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1445985ljw; Fri, 14 Sep 2018 22:20:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYLOC0oa3TBU30DLs3eIoPxyBFtJD4qxXRTjs/6xh+cQcYOZU3prudSgkuUSM2tftKs5DLg X-Received: by 2002:a1c:3d07:: with SMTP id k7-v6mr4722567wma.146.1536988841154; Fri, 14 Sep 2018 22:20:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536988841; cv=none; d=google.com; s=arc-20160816; b=EIGej+pZEdfQbMvBshSkO8eyysj5R7/D5/xBtMRoiHESkfveoZun1MN+OlWLfnLPcS FFR9LFYz1/WQ+2i8Ftgm6pRg92fs/W4H6hRP5dnpxB2DXlzqIe5UTxpSJT4mUoYncjFw /lPVj+VjZeiSdFvV2sKXdWWIwwD1Mg40sITyZDnrQG6f2PwWkLCjti163kTbRK2pfGAT bPAR9+/oM1n9ki95u7pbExbTgFF5pn32xpO4T1mgFRq+AgRmjogLxsVz4ix2zgjOkm/L AuCFl8YEd2qeDhB1oHf2niPhQNKM8SNMChepoebp59YeFgezCrhqlwF1WhPNqIw9PstW Zj3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=YC7apfpVWRkYONJLYzDkVxmsBll9SrTnBZv3hr3PiPo=; b=umIewNvBJuDZ+Me4KOcT6FHvG5oObamabFkrkVWAjzMHr33/pG4wBw58cDBEBIEgNT 9riOS3UmPA+ERvEtC/3wadpcLRIJ9QP8wItfSXHIOilM7OEecVCenoAzw55kKbZTcdkF Ay/qfGOsmtiQxxERfbQw1gJqHRU1nrFgrUvNQ85hfujGj7LXJnO/W5hHF0XnZtdAf/jf v1hv98yxw8izw2SYRj2ZCmxSAxSECjh2KLTgApmzzwgMwadwnyvjwaInj/yS8NNhMsNe 2YNiK6LoS703lCAnsxF1oNxBnY3fcV65rfcII0TVoIbkH8QC5EyqVv0eAnIkI+7N9dBa Oa6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gv9AHwN9; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id o5-v6si9677841wre.145.2018.09.14.22.20.40; Fri, 14 Sep 2018 22:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=gv9AHwN9; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7DE0C4D27; Sat, 15 Sep 2018 07:20:37 +0200 (CEST) Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by dpdk.org (Postfix) with ESMTP id 721A44C92 for ; Sat, 15 Sep 2018 07:20:36 +0200 (CEST) Received: by mail-wm1-f65.google.com with SMTP id o18-v6so3960256wmc.0 for ; Fri, 14 Sep 2018 22:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=YC7apfpVWRkYONJLYzDkVxmsBll9SrTnBZv3hr3PiPo=; b=gv9AHwN9n6VDox4ESFY59zoHyJ3VJiDHzQ+Uf1UkhGb8xJOD5xRt+YN86NUPgCa5Oc jndjiPFyY+V8yTEHq6Rz8MHZEofOAGSlpxc7BDXc9ltmj0efbdlMx69Ly4TApCWYstOT 56FFRG9lkBXBZiQnWz5sumbgTRv2qH4CMNgp13euvhkL0RL9FsAgQd/mHLsjXpYVhhYo C0gENrDrAEKmoqdOTD6CQYecaCF/jLPz70Fd3NR6XBSi82yehBR4lREAxOtRnhf2gbzp 8cnpN3GuPr/8BEWCfDQZjfXWfitn220Ph682R2AjDm3YRGz3zoWaSOW6lQEI9twMOuM+ pZdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=YC7apfpVWRkYONJLYzDkVxmsBll9SrTnBZv3hr3PiPo=; b=WRmRW9RYLoYR4KN9KMyy+mGScdWPS3P9pgcyU8F8sakdMhv/bsKeHmduBwqJtRKSE+ iP7C0gWpNhfmwsNuibKJa1L2tooWi6EMXMVgBq/n4bXEcTfZW4k5/1bafJsow0AYWsai 6jVZJXRn6fpk2C5R3pKklaD8GmpRFqulmN1+Nx3MzISKoZcfPgEbRDTBo1ogsuTqR8zD r1d1VNlnm/YPUNKxJIp/O4kz8t6SnN4j1Ykq3T7EfFbns2fC/OAi1iV0gzkEqzGS2ovn B0dZyNi9ZzvgYbXM41mmTZXIxt7zkbPxW6t0v8olPqtr1khLoILn3vY8V3zDc0Yitmxx JxPw== X-Gm-Message-State: APzg51D/nyIGF7XqzxbMQOXJkHmFybiMj8jPytKwvA8HU2DjeDP6ImU9 h/8Wzuc6bW1oqOPlR0scISZmbma+nu9bAw== X-Received: by 2002:a1c:8587:: with SMTP id h129-v6mr4688882wmd.105.1536988835983; Fri, 14 Sep 2018 22:20:35 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id t4-v6sm9992573wrb.45.2018.09.14.22.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:20:35 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Sat, 15 Sep 2018 08:20:33 +0300 Message-ID: <153698883388.23049.2819933386635765768.stgit@T460> In-Reply-To: <153698873346.23049.10966616323159180622.stgit@T460> References: <153698873346.23049.10966616323159180622.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/5] vhost: make message handling functions prepare the reply X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" As VhostUserMsg structure is reused to generate the reply, move the relevant fields update into the respective message handling functions. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index b05b57670..3a00d53cf 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -146,11 +146,15 @@ vhost_user_reset_owner(struct virtio_net *dev) * The features that we support are requested. */ static uint64_t -vhost_user_get_features(struct virtio_net *dev) +vhost_user_get_features(struct virtio_net *dev, VhostUserMsg *msg) { uint64_t features = 0; rte_vhost_driver_get_features(dev->ifname, &features); + + msg->payload.u64 = features; + msg->size = sizeof(msg->payload.u64); + return features; } @@ -158,11 +162,15 @@ vhost_user_get_features(struct virtio_net *dev) * The queue number that we support are requested. */ static uint32_t -vhost_user_get_queue_num(struct virtio_net *dev) +vhost_user_get_queue_num(struct virtio_net *dev, VhostUserMsg *msg) { uint32_t queue_num = 0; rte_vhost_driver_get_queue_num(dev->ifname, &queue_num); + + msg->payload.u64 = (uint64_t)queue_num; + msg->size = sizeof(msg->payload.u64); + return queue_num; } @@ -1117,6 +1125,8 @@ vhost_user_get_vring_base(struct virtio_net *dev, rte_free(vq->batch_copy_elems); vq->batch_copy_elems = NULL; + msg->size = sizeof(msg->payload.state); + return 0; } @@ -1244,6 +1254,8 @@ vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) dev->log_base = dev->log_addr + off; dev->log_size = size; + msg->size = sizeof(msg->payload.u64); + return 0; } @@ -1657,8 +1669,7 @@ vhost_user_msg_handler(int vid, int fd) switch (msg.request.master) { case VHOST_USER_GET_FEATURES: - msg.payload.u64 = vhost_user_get_features(dev); - msg.size = sizeof(msg.payload.u64); + vhost_user_get_features(dev, &msg); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_FEATURES: @@ -1689,7 +1700,6 @@ vhost_user_msg_handler(int vid, int fd) if (ret) goto skip_to_reply; /* it needs a reply */ - msg.size = sizeof(msg.payload.u64); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_LOG_FD: @@ -1711,7 +1721,6 @@ vhost_user_msg_handler(int vid, int fd) ret = vhost_user_get_vring_base(dev, &msg); if (ret) goto skip_to_reply; - msg.size = sizeof(msg.payload.state); send_vhost_reply(fd, &msg); break; @@ -1729,8 +1738,7 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_GET_QUEUE_NUM: - msg.payload.u64 = (uint64_t)vhost_user_get_queue_num(dev); - msg.size = sizeof(msg.payload.u64); + vhost_user_get_queue_num(dev, &msg); send_vhost_reply(fd, &msg); break; From patchwork Sat Sep 15 05:20:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 146753 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1446176ljw; Fri, 14 Sep 2018 22:21:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdalvSDT8RTsqYhAWBTv3dgdSY4w0tkEaXX4FrOZgoeKgff487IF7qcM6zMHvk8xJAqaBj2s X-Received: by 2002:a5d:434c:: with SMTP id u12-v6mr11846040wrr.189.1536988859969; Fri, 14 Sep 2018 22:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536988859; cv=none; d=google.com; s=arc-20160816; b=LE5Zz1b5CjEr5EqtUQckXbdAuwhQM0d6sZNmHIwAOyI7iYkL6LnJaZzxlgnsRtvqj8 fNR0ji128Da6Dy6qx5cyNkXcNACMK7lKEpcrXhdywNGIDA42zxvO2IgfAE7D18pYaC+k j7/A74nKV5ZCCdzlwtVorNh7+NpaZcqcPDRFOwsCNl2E44v8L3E0pRZnaao6zbyijMxV AYCxIylzQKWML0K54wRkv5RhNaB/Mw/Pa0Uni3awAT77j35v6iAHFqxz/vyyD5iDIvsz eNkVQsekhg5VMa6AWWVK9cu0yClZffJQUHckQoxcZAKtWuDYmRtv45Ti9KGNIjEr9ZSU E98g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=wSyLR66ibmeohSkyjhR+kIs69sar6ev7WV4Pnz8Oy5Y=; b=GZ+6sRAu3ll9ekk5fCLHznyuZbssd339yOvd9Sb7vQ/17l8GHdcPUdTkqUHKau/QBs lBej0HJ/XNhoUEEuHTAvwYcFV+BtEaOedi2G4oXThdw3sIL2ge7QTfCnP4b12auBVxs2 txcHMsw1d3eQdscBCGyj5E3T62zlDc+uzDjnYiWKTt3YNxvs2VjUPddIretc7g5mkcMO 4nUZ3eZMxRmTRqZGJEHboU6JDmVcUjkfDkPUJZcZEgyhd6WlYQP8W3gVffyZyCbd9OuA BuEq3nsU5L4YHtMZOOUurmUANvHJTW3u8K+YC/vp39u6y0mAU/FcIXBnegsuYJzgkClc Gvag== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OHayr3e1; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id a85-v6si859648wme.181.2018.09.14.22.20.59; Fri, 14 Sep 2018 22:20:59 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=OHayr3e1; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 461D55689; Sat, 15 Sep 2018 07:20:47 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 4C996532C for ; Sat, 15 Sep 2018 07:20:43 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id 20-v6so12339905wrb.12 for ; Fri, 14 Sep 2018 22:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=wSyLR66ibmeohSkyjhR+kIs69sar6ev7WV4Pnz8Oy5Y=; b=OHayr3e1ejOlHnAsCRH91rZUob31mx9Ulc/2UT9KoE9s7mOUByjJUbUbkouexeK4q/ HzZd1DiHdOX7ylUCmZqZYEI5IjAzrvCJ3y85tl/dbEuG6xjFREdLVSa8RZsrJBazyKNM JIi4jTbANWSBFPCVDsBoqBb/+pevHfsL8tm3L6BJ/w+OGbpmHZHq3ha3P6iQMBh4oRi2 8TWgPM3VRlGxwkha7nuXfcffPaXC5Imx2d1M2TcH8yBO1tM0dVE6S5OqSDYHgDfAWLbP 2yhP1lWofWKkyx4PVNln9bd2AayA+x8YjNeOnktO7eeQY/1CnfnBodZQ5NvaPgzJ7B1c frJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=wSyLR66ibmeohSkyjhR+kIs69sar6ev7WV4Pnz8Oy5Y=; b=oKXKihcmkSMCDgDdZ2t6lNKNpTfjxQ9BZKKxT5pRCB1TuiJhpYjZZ4PzAkP6q94YRG NFVCN+TNmDVRvlCZRqQN/HGr1G0ddKNpqs/IiNS/CPVx9ZT/KAqyDBMQH+b3EdOuqJrV Q90ILJea90XVzGuKJMLJBaoXKXMpQnhbgbwSZMzDSsRvzsJkFQ7xkoO8w/OBjKYFeXP5 EQAJXEol2rVVfEy2Pfwmz3szl4GQw+9DNT6jKk5hsZFGAC5ZXZ+ax45m8gbPni1AUy9V PdT3n2e3H8NM7Gmya6uGooOGjq3yTOs0XAcdi9U5ha3Kv2U3GAlUAw0xZjrbG2uEQnX9 YcQg== X-Gm-Message-State: APzg51BpBjM6mPa5A4/noPZ/qUfAfGSIaj/E/ESnlgyNhsAyKSmDhzSh J+yEwse2UaBsqU8jCxIOPwTCpmXIExrn3Q== X-Received: by 2002:adf:add0:: with SMTP id w74-v6mr12399288wrc.73.1536988842801; Fri, 14 Sep 2018 22:20:42 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id j133-v6sm1996725wmd.12.2018.09.14.22.20.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:20:42 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Sat, 15 Sep 2018 08:20:40 +0300 Message-ID: <153698884084.23049.3225944257155202776.stgit@T460> In-Reply-To: <153698873346.23049.10966616323159180622.stgit@T460> References: <153698873346.23049.10966616323159180622.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/5] vhost: handle unsupported message types in functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add new functions to handle the unsupported vhost message types: - vhost_user_set_vring_err - vhost_user_set_log_fd Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 3a00d53cf..c38b0fd70 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1022,6 +1022,14 @@ vhost_user_set_vring_call(struct virtio_net *dev, VhostUserMsg *msg) vq->callfd = file.fd; } +static void vhost_user_set_vring_err(struct virtio_net *dev __rte_unused, + VhostUserMsg *msg) +{ + if (!(msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)) + close(msg->fds[0]); + RTE_LOG(INFO, VHOST_CONFIG, "not implemented\n"); +} + static int vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) { @@ -1259,6 +1267,13 @@ vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) return 0; } +static void +vhost_user_set_log_fd(struct virtio_net *dev __rte_unused, VhostUserMsg *msg) +{ + close(msg->fds[0]); + RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n"); +} + /* * An rarp packet is constructed and broadcasted to notify switches about * the new location of the migrated VM, so that packets from outside will @@ -1703,8 +1718,7 @@ vhost_user_msg_handler(int vid, int fd) send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_LOG_FD: - close(msg.fds[0]); - RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n"); + vhost_user_set_log_fd(dev, &msg); break; case VHOST_USER_SET_VRING_NUM: @@ -1732,9 +1746,7 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_VRING_ERR: - if (!(msg.payload.u64 & VHOST_USER_VRING_NOFD_MASK)) - close(msg.fds[0]); - RTE_LOG(INFO, VHOST_CONFIG, "not implemented\n"); + vhost_user_set_vring_err(dev, &msg); break; case VHOST_USER_GET_QUEUE_NUM: From patchwork Sat Sep 15 05:20:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 146754 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1446243ljw; Fri, 14 Sep 2018 22:21:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYMWcwP2EyH9dB5IrIoYdAqCItNoBMbVh9KyhXPuUC6dfEXoA0M7wEsY0u/VkSYqYfNxAGu X-Received: by 2002:adf:a789:: with SMTP id j9-v6mr12359871wrc.277.1536988868277; Fri, 14 Sep 2018 22:21:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536988868; cv=none; d=google.com; s=arc-20160816; b=FVQURncfc2mQopFI0/JvMXWSu6esDMEIB82rMS/oB1os8IdMv4nsaDu1ia1c2A+Bpd QJ5iERi/Cg4l6EZa7ACnxe8h7qK0ILmIBWYCkBUcpF7oEA/9a2MPRZ7khEqy23ua2EGM fl6EkvoHSP+sa6ngm0ZpFpaxV0MtKUloJ4GOwzcKafmTt4sEBpueKnQwoJ1lneWdIf+c UUX7USpX5CA+ObJpIU54LtaDFcuKNc47AeDI0L+tlxYtSLEKaO9LEegRzHvScFug5LuV uWLEpaHnLO2/n6ZEsyqwtQjmQke6tp60mTin46Mi8i92MsT2DsOLEzCIkbLWF5aAa2H5 kIFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=Y7XyZoRaej7A3nO9T0xVv+zTMfdGqqY2JO5N2SDsuVU=; b=Tm+EViN3JJmWUKzIoyfygFusyp+GbfrN0k6CwVGudKtDRBDEv2YwWDn+G71ql2cDNN bP8xlN8Ay0ZaYhxvWOGfgVTlKr8QHrgMkYvRbVpbuEpXVPshJ+kT5f1cMzQX5UAsoB6n D3/PPUe6olPI88FyVfefTzsJaXndfceVRL8znqWHwODQ+iuq8xwMmw/uc2mWVtWES7gB s4yGO1kbYs9rFSPoL/KzbUk+Bc5XdUGzBpqZVWVISRuA0jF4oyPOio17PszbTFnJO1SK bGnIMMCOMMGs9cG0PVtsIkH3O9I4l4aZ0h9FOPZ6FzD8ImcFGtn/rXjxmfvHVWnUSw93 +Qhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vHcFLO4C; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id 36-v6si8816200wrg.248.2018.09.14.22.21.08; Fri, 14 Sep 2018 22:21:08 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vHcFLO4C; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 141385592; Sat, 15 Sep 2018 07:20:51 +0200 (CEST) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id 649DA4D3A for ; Sat, 15 Sep 2018 07:20:50 +0200 (CEST) Received: by mail-wr1-f65.google.com with SMTP id n2-v6so12393198wrw.7 for ; Fri, 14 Sep 2018 22:20:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Y7XyZoRaej7A3nO9T0xVv+zTMfdGqqY2JO5N2SDsuVU=; b=vHcFLO4ChSmm10Vbk2V9Fcu4tHGJ1O2+bFIXnMwdUIi2JgjdhdKtHTpSTEGnHfLWtv PdoLyBdP23V5bdmK91ranfMIGPPOLFkQW5mw9dQF5/Mab1EvWztFBL1l9gOdumVtIG5h QOY54Dg3/oWORdJFykbllhMl2g7YZd8BYME0vKOiN8pJvUYdOYaE/OUC0MA5xrR6veoH JD49xvCGytwhsBx3cAAxJtpoGTanScYUNDIaXM1CawGNjYiqQBxQrcvHEb+ThFwfP4sL AntTO5bvaD4Z+GmvxcTX34XwJ7B+gRA5RUoDYLdGPrLNp6a+BSlyIfmAcuIH+CzHwc2H Jrxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Y7XyZoRaej7A3nO9T0xVv+zTMfdGqqY2JO5N2SDsuVU=; b=jVZh+kPyq8wCqaOT3y2A9c3FrPGnyk/SAJv5Uy+VbQS73AoZpgrgj0mQFGsM+O9MGQ hR/lCIe852KfVxHfA/nu9i0FQt8Lc7tq/dfKe4F0ZJFsuNBrFP2jXTjmam0AB9a0fdf4 oBn44OLr9O9/WmlvPEqpesL7IXIaZoTnKiNydJcsBi0aDTBiH3p5ncOczLfOagOo3l0b 9l3OsWzesaMYCcsbY5HIb9IZ2s/ajJaAOPfSuLW5p58hmfnyiLOnJe9EvzqEbrtT65bx fYOU3ilTmuBhwsj0Izu/7D5xW1NmdY3t4r47yyU2PQ0GkxW2Mn4zyxaiS6FuphutibmJ /7uw== X-Gm-Message-State: APzg51CK6TKprVUqG50f6vV+j9UuStgLEyyLutxgg1vNe/C02YCJEGM/ LYBc00YIYIq6hmL3QvoL9w9qmopg1XrXwQ== X-Received: by 2002:adf:9c12:: with SMTP id f18-v6mr12606648wrc.93.1536988849715; Fri, 14 Sep 2018 22:20:49 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id w3-v6sm9335840wrn.16.2018.09.14.22.20.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:20:49 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Sat, 15 Sep 2018 08:20:47 +0300 Message-ID: <153698884769.23049.2698007589975452166.stgit@T460> In-Reply-To: <153698873346.23049.10966616323159180622.stgit@T460> References: <153698873346.23049.10966616323159180622.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 4/5] vhost: unify message handling function signature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Each vhost-user message handling function will return an int result which is described in the new enum vh_result: error, OK and reply. All functions will now have two arguments, virtio_net double pointer and VhostUserMsg pointer. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 213 ++++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 87 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index c38b0fd70..81c0396de 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -71,6 +71,16 @@ static const char *vhost_message_str[VHOST_USER_MAX] = { [VHOST_USER_CRYPTO_CLOSE_SESS] = "VHOST_USER_CRYPTO_CLOSE_SESS", }; +/* The possible results of a message handling function */ +enum vh_result { + /* Message handling failed */ + VH_RESULT_ERR = -1, + /* Message handling successful */ + VH_RESULT_OK = 0, + /* Message handling successful and reply prepared */ + VH_RESULT_REPLY = 1, +}; + static uint64_t get_blk_size(int fd) { @@ -127,27 +137,31 @@ vhost_backend_cleanup(struct virtio_net *dev) * the device hasn't been initialised. */ static int -vhost_user_set_owner(void) +vhost_user_set_owner(struct virtio_net **pdev __rte_unused, + VhostUserMsg * msg __rte_unused) { - return 0; + return VH_RESULT_OK; } static int -vhost_user_reset_owner(struct virtio_net *dev) +vhost_user_reset_owner(struct virtio_net **pdev, + VhostUserMsg * msg __rte_unused) { + struct virtio_net *dev = *pdev; vhost_destroy_device_notify(dev); cleanup_device(dev, 0); reset_device(dev); - return 0; + return VH_RESULT_OK; } /* * The features that we support are requested. */ -static uint64_t -vhost_user_get_features(struct virtio_net *dev, VhostUserMsg *msg) +static int +vhost_user_get_features(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; uint64_t features = 0; rte_vhost_driver_get_features(dev->ifname, &features); @@ -155,15 +169,16 @@ vhost_user_get_features(struct virtio_net *dev, VhostUserMsg *msg) msg->payload.u64 = features; msg->size = sizeof(msg->payload.u64); - return features; + return VH_RESULT_REPLY; } /* * The queue number that we support are requested. */ -static uint32_t -vhost_user_get_queue_num(struct virtio_net *dev, VhostUserMsg *msg) +static int +vhost_user_get_queue_num(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; uint32_t queue_num = 0; rte_vhost_driver_get_queue_num(dev->ifname, &queue_num); @@ -171,15 +186,17 @@ vhost_user_get_queue_num(struct virtio_net *dev, VhostUserMsg *msg) msg->payload.u64 = (uint64_t)queue_num; msg->size = sizeof(msg->payload.u64); - return queue_num; + return VH_RESULT_REPLY; } /* * We receive the negotiated features supported by us and the virtio device. */ static int -vhost_user_set_features(struct virtio_net *dev, uint64_t features) +vhost_user_set_features(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; + uint64_t features = msg->payload.u64; uint64_t vhost_features = 0; struct rte_vdpa_device *vdpa_dev; int did = -1; @@ -189,12 +206,12 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) RTE_LOG(ERR, VHOST_CONFIG, "(%d) received invalid negotiated features.\n", dev->vid); - return -1; + return VH_RESULT_ERR; } if (dev->flags & VIRTIO_DEV_RUNNING) { if (dev->features == features) - return 0; + return VH_RESULT_OK; /* * Error out if master tries to change features while device is @@ -205,7 +222,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) RTE_LOG(ERR, VHOST_CONFIG, "(%d) features changed while device is running.\n", dev->vid); - return -1; + return VH_RESULT_ERR; } if (dev->notify_ops->features_changed) @@ -250,16 +267,17 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) if (vdpa_dev && vdpa_dev->ops->set_features) vdpa_dev->ops->set_features(dev->vid); - return 0; + return VH_RESULT_OK; } /* * The virtio device sends us the size of the descriptor ring. */ static int -vhost_user_set_vring_num(struct virtio_net *dev, +vhost_user_set_vring_num(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index]; vq->size = msg->payload.state.num; @@ -272,7 +290,7 @@ vhost_user_set_vring_num(struct virtio_net *dev, if ((vq->size & (vq->size - 1)) || vq->size > 32768) { RTE_LOG(ERR, VHOST_CONFIG, "invalid virtqueue size %u\n", vq->size); - return -1; + return VH_RESULT_ERR; } if (dev->dequeue_zero_copy) { @@ -298,7 +316,7 @@ vhost_user_set_vring_num(struct virtio_net *dev, if (!vq->shadow_used_packed) { RTE_LOG(ERR, VHOST_CONFIG, "failed to allocate memory for shadow used ring.\n"); - return -1; + return VH_RESULT_ERR; } } else { @@ -308,7 +326,7 @@ vhost_user_set_vring_num(struct virtio_net *dev, if (!vq->shadow_used_split) { RTE_LOG(ERR, VHOST_CONFIG, "failed to allocate memory for shadow used ring.\n"); - return -1; + return VH_RESULT_ERR; } } @@ -318,10 +336,10 @@ vhost_user_set_vring_num(struct virtio_net *dev, if (!vq->batch_copy_elems) { RTE_LOG(ERR, VHOST_CONFIG, "failed to allocate memory for batching copy.\n"); - return -1; + return VH_RESULT_ERR; } - return 0; + return VH_RESULT_OK; } /* @@ -621,12 +639,12 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) static int vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; struct vhost_virtqueue *vq; struct vhost_vring_addr *addr = &msg->payload.addr; - struct virtio_net *dev = *pdev; if (dev->mem == NULL) - return -1; + return VH_RESULT_ERR; /* addr->index refers to the queue index. The txq 1, rxq is 0. */ vq = dev->virtqueue[msg->payload.addr.index]; @@ -643,27 +661,28 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) (1ULL << VHOST_USER_F_PROTOCOL_FEATURES))) { dev = translate_ring_addresses(dev, msg->payload.addr.index); if (!dev) - return -1; + return VH_RESULT_ERR; *pdev = dev; } - return 0; + return VH_RESULT_OK; } /* * The virtio device sends us the available ring last used index. */ static int -vhost_user_set_vring_base(struct virtio_net *dev, +vhost_user_set_vring_base(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; dev->virtqueue[msg->payload.state.index]->last_used_idx = msg->payload.state.num; dev->virtqueue[msg->payload.state.index]->last_avail_idx = msg->payload.state.num; - return 0; + return VH_RESULT_OK; } static int @@ -804,7 +823,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) if (memory.nregions > VHOST_MEMORY_MAX_NREGIONS) { RTE_LOG(ERR, VHOST_CONFIG, "too many memory regions (%u)\n", memory.nregions); - return -1; + return VH_RESULT_ERR; } if (dev->mem && !vhost_memory_changed(&memory, dev->mem)) { @@ -814,7 +833,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) for (i = 0; i < memory.nregions; i++) close(msg->fds[i]); - return 0; + return VH_RESULT_OK; } if (dev->mem) { @@ -838,7 +857,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) "(%d) failed to allocate memory " "for dev->guest_pages\n", dev->vid); - return -1; + return VH_RESULT_ERR; } } @@ -848,7 +867,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) RTE_LOG(ERR, VHOST_CONFIG, "(%d) failed to allocate memory for dev->mem\n", dev->vid); - return -1; + return VH_RESULT_ERR; } dev->mem->nregions = memory.nregions; @@ -945,7 +964,7 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) dev = translate_ring_addresses(dev, i); if (!dev) - return -1; + return VH_RESULT_ERR; *pdev = dev; } @@ -953,13 +972,13 @@ vhost_user_set_mem_table(struct virtio_net **pdev, VhostUserMsg *msg) dump_guest_pages(dev); - return 0; + return VH_RESULT_OK; err_mmap: free_mem_region(dev); rte_free(dev->mem); dev->mem = NULL; - return -1; + return VH_RESULT_ERR; } static bool @@ -1001,9 +1020,10 @@ virtio_is_ready(struct virtio_net *dev) return 1; } -static void -vhost_user_set_vring_call(struct virtio_net *dev, VhostUserMsg *msg) +static int +vhost_user_set_vring_call(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; struct vhost_vring_file file; struct vhost_virtqueue *vq; @@ -1020,22 +1040,26 @@ vhost_user_set_vring_call(struct virtio_net *dev, VhostUserMsg *msg) close(vq->callfd); vq->callfd = file.fd; + + return VH_RESULT_OK; } -static void vhost_user_set_vring_err(struct virtio_net *dev __rte_unused, +static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, VhostUserMsg *msg) { if (!(msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK)) close(msg->fds[0]); RTE_LOG(INFO, VHOST_CONFIG, "not implemented\n"); + + return VH_RESULT_OK; } static int vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; struct vhost_vring_file file; struct vhost_virtqueue *vq; - struct virtio_net *dev = *pdev; file.index = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (msg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) @@ -1048,7 +1072,7 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) /* Interpret ring addresses only when ring is started. */ dev = translate_ring_addresses(dev, file.index); if (!dev) - return -1; + return VH_RESULT_ERR; *pdev = dev; @@ -1065,7 +1089,8 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) if (vq->kickfd >= 0) close(vq->kickfd); vq->kickfd = file.fd; - return 0; + + return VH_RESULT_OK; } static void @@ -1088,9 +1113,10 @@ free_zmbufs(struct vhost_virtqueue *vq) * when virtio is stopped, qemu will send us the GET_VRING_BASE message. */ static int -vhost_user_get_vring_base(struct virtio_net *dev, +vhost_user_get_vring_base(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index]; /* We have to stop the queue (virtio) if it is running. */ @@ -1135,7 +1161,7 @@ vhost_user_get_vring_base(struct virtio_net *dev, msg->size = sizeof(msg->payload.state); - return 0; + return VH_RESULT_OK; } /* @@ -1143,9 +1169,10 @@ vhost_user_get_vring_base(struct virtio_net *dev, * enable the virtio queue pair. */ static int -vhost_user_set_vring_enable(struct virtio_net *dev, +vhost_user_set_vring_enable(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; int enable = (int)msg->payload.state.num; int index = (int)msg->payload.state.index; struct rte_vdpa_device *vdpa_dev; @@ -1166,13 +1193,14 @@ vhost_user_set_vring_enable(struct virtio_net *dev, dev->virtqueue[index]->enabled = enable; - return 0; + return VH_RESULT_OK; } -static void -vhost_user_get_protocol_features(struct virtio_net *dev, +static int +vhost_user_get_protocol_features(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; uint64_t features, protocol_features; rte_vhost_driver_get_features(dev->ifname, &features); @@ -1189,40 +1217,46 @@ vhost_user_get_protocol_features(struct virtio_net *dev, msg->payload.u64 = protocol_features; msg->size = sizeof(msg->payload.u64); + + return VH_RESULT_OK; } static int -vhost_user_set_protocol_features(struct virtio_net *dev, - uint64_t protocol_features) +vhost_user_set_protocol_features(struct virtio_net **pdev, + VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; + uint64_t protocol_features = msg->payload.u64; if (protocol_features & ~VHOST_USER_PROTOCOL_FEATURES) { RTE_LOG(ERR, VHOST_CONFIG, "(%d) received invalid protocol features.\n", dev->vid); - return -1; + return VH_RESULT_ERR; } dev->protocol_features = protocol_features; - return 0; + + return VH_RESULT_OK; } static int -vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) +vhost_user_set_log_base(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; int fd = msg->fds[0]; uint64_t size, off; void *addr; if (fd < 0) { RTE_LOG(ERR, VHOST_CONFIG, "invalid log fd: %d\n", fd); - return -1; + return VH_RESULT_ERR; } if (msg->size != sizeof(VhostUserLog)) { RTE_LOG(ERR, VHOST_CONFIG, "invalid log base msg size: %"PRId32" != %d\n", msg->size, (int)sizeof(VhostUserLog)); - return -1; + return VH_RESULT_ERR; } size = msg->payload.log.mmap_size; @@ -1233,7 +1267,7 @@ vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) RTE_LOG(ERR, VHOST_CONFIG, "log offset %#"PRIx64" exceeds log size %#"PRIx64"\n", off, size); - return -1; + return VH_RESULT_ERR; } RTE_LOG(INFO, VHOST_CONFIG, @@ -1248,7 +1282,7 @@ vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) close(fd); if (addr == MAP_FAILED) { RTE_LOG(ERR, VHOST_CONFIG, "mmap log base failed!\n"); - return -1; + return VH_RESULT_ERR; } /* @@ -1264,14 +1298,16 @@ vhost_user_set_log_base(struct virtio_net *dev, VhostUserMsg *msg) msg->size = sizeof(msg->payload.u64); - return 0; + return VH_RESULT_OK; } -static void -vhost_user_set_log_fd(struct virtio_net *dev __rte_unused, VhostUserMsg *msg) +static int +vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused, VhostUserMsg *msg) { close(msg->fds[0]); RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n"); + + return VH_RESULT_OK; } /* @@ -1283,8 +1319,9 @@ vhost_user_set_log_fd(struct virtio_net *dev __rte_unused, VhostUserMsg *msg) * a flag 'broadcast_rarp' to let rte_vhost_dequeue_burst() inject it. */ static int -vhost_user_send_rarp(struct virtio_net *dev, VhostUserMsg *msg) +vhost_user_send_rarp(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; uint8_t *mac = (uint8_t *)&msg->payload.u64; struct rte_vdpa_device *vdpa_dev; int did = -1; @@ -1308,40 +1345,42 @@ vhost_user_send_rarp(struct virtio_net *dev, VhostUserMsg *msg) if (vdpa_dev && vdpa_dev->ops->migration_done) vdpa_dev->ops->migration_done(dev->vid); - return 0; + return VH_RESULT_OK; } static int -vhost_user_net_set_mtu(struct virtio_net *dev, VhostUserMsg *msg) +vhost_user_net_set_mtu(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; if (msg->payload.u64 < VIRTIO_MIN_MTU || msg->payload.u64 > VIRTIO_MAX_MTU) { RTE_LOG(ERR, VHOST_CONFIG, "Invalid MTU size (%"PRIu64")\n", msg->payload.u64); - return -1; + return VH_RESULT_ERR; } dev->mtu = msg->payload.u64; - return 0; + return VH_RESULT_OK; } static int -vhost_user_set_req_fd(struct virtio_net *dev, VhostUserMsg *msg) +vhost_user_set_req_fd(struct virtio_net **pdev, VhostUserMsg *msg) { + struct virtio_net *dev = *pdev; int fd = msg->fds[0]; if (fd < 0) { RTE_LOG(ERR, VHOST_CONFIG, "Invalid file descriptor for slave channel (%d)\n", fd); - return -1; + return VH_RESULT_ERR; } dev->slave_req_fd = fd; - return 0; + return VH_RESULT_OK; } static int @@ -1406,7 +1445,7 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, VhostUserMsg *msg) len = imsg->size; vva = qva_to_vva(dev, imsg->uaddr, &len); if (!vva) - return -1; + return VH_RESULT_ERR; for (i = 0; i < dev->nr_vring; i++) { struct vhost_virtqueue *vq = dev->virtqueue[i]; @@ -1432,10 +1471,10 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, VhostUserMsg *msg) default: RTE_LOG(ERR, VHOST_CONFIG, "Invalid IOTLB message type (%d)\n", imsg->type); - return -1; + return VH_RESULT_ERR; } - return 0; + return VH_RESULT_OK; } /* return bytes# of read on success or negative val on failure. */ @@ -1684,26 +1723,26 @@ vhost_user_msg_handler(int vid, int fd) switch (msg.request.master) { case VHOST_USER_GET_FEATURES: - vhost_user_get_features(dev, &msg); + ret = vhost_user_get_features(&dev, &msg); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_FEATURES: - ret = vhost_user_set_features(dev, msg.payload.u64); + ret = vhost_user_set_features(&dev, &msg); break; case VHOST_USER_GET_PROTOCOL_FEATURES: - vhost_user_get_protocol_features(dev, &msg); + ret = vhost_user_get_protocol_features(&dev, &msg); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_PROTOCOL_FEATURES: - ret = vhost_user_set_protocol_features(dev, msg.payload.u64); + ret = vhost_user_set_protocol_features(&dev, &msg); break; case VHOST_USER_SET_OWNER: - ret = vhost_user_set_owner(); + ret = vhost_user_set_owner(&dev, &msg); break; case VHOST_USER_RESET_OWNER: - ret = vhost_user_reset_owner(dev); + ret = vhost_user_reset_owner(&dev, &msg); break; case VHOST_USER_SET_MEM_TABLE: @@ -1711,28 +1750,28 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_LOG_BASE: - ret = vhost_user_set_log_base(dev, &msg); + ret = vhost_user_set_log_base(&dev, &msg); if (ret) goto skip_to_reply; /* it needs a reply */ send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_LOG_FD: - vhost_user_set_log_fd(dev, &msg); + ret = vhost_user_set_log_fd(&dev, &msg); break; case VHOST_USER_SET_VRING_NUM: - ret = vhost_user_set_vring_num(dev, &msg); + ret = vhost_user_set_vring_num(&dev, &msg); break; case VHOST_USER_SET_VRING_ADDR: ret = vhost_user_set_vring_addr(&dev, &msg); break; case VHOST_USER_SET_VRING_BASE: - ret = vhost_user_set_vring_base(dev, &msg); + ret = vhost_user_set_vring_base(&dev, &msg); break; case VHOST_USER_GET_VRING_BASE: - ret = vhost_user_get_vring_base(dev, &msg); + ret = vhost_user_get_vring_base(&dev, &msg); if (ret) goto skip_to_reply; send_vhost_reply(fd, &msg); @@ -1742,31 +1781,31 @@ vhost_user_msg_handler(int vid, int fd) ret = vhost_user_set_vring_kick(&dev, &msg); break; case VHOST_USER_SET_VRING_CALL: - vhost_user_set_vring_call(dev, &msg); + ret = vhost_user_set_vring_call(&dev, &msg); break; case VHOST_USER_SET_VRING_ERR: - vhost_user_set_vring_err(dev, &msg); + ret = vhost_user_set_vring_err(&dev, &msg); break; case VHOST_USER_GET_QUEUE_NUM: - vhost_user_get_queue_num(dev, &msg); + ret = vhost_user_get_queue_num(&dev, &msg); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_VRING_ENABLE: - ret = vhost_user_set_vring_enable(dev, &msg); + ret = vhost_user_set_vring_enable(&dev, &msg); break; case VHOST_USER_SEND_RARP: - ret = vhost_user_send_rarp(dev, &msg); + ret = vhost_user_send_rarp(&dev, &msg); break; case VHOST_USER_NET_SET_MTU: - ret = vhost_user_net_set_mtu(dev, &msg); + ret = vhost_user_net_set_mtu(&dev, &msg); break; case VHOST_USER_SET_SLAVE_REQ_FD: - ret = vhost_user_set_req_fd(dev, &msg); + ret = vhost_user_set_req_fd(&dev, &msg); break; case VHOST_USER_IOTLB_MSG: From patchwork Sat Sep 15 05:20:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 146755 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1446325ljw; Fri, 14 Sep 2018 22:21:16 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY6FaDlORiVPtT0kdtzUC2/ierYPQr7oatKy8EaQplkUs2a+C3ag8MF4VIMwxTgln6gaAZk X-Received: by 2002:a1c:b54b:: with SMTP id e72-v6mr4523511wmf.117.1536988876766; Fri, 14 Sep 2018 22:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536988876; cv=none; d=google.com; s=arc-20160816; b=NpORy7szCGhcikVXlchl2XX4yGQIKMsT63XBAksdrF4Y1AeATcwErl4yQhpITVkrGV kBcNlL3c2b+FwjU7lMFOJL+dkDn9h6Rh07YET+alfcnB5knFwvLotGACHUutklIkbvSZ b3KRbYFTvf097eST0sbZn07q4nZ635CueyMX7c37k1PQQ+UKAih2n7i6iZ8vTtNogXwj nRunDyhgVqCGMyrKPP97Ubca8c5eOytIqxeI5G6WQSxbyJ0l+ORmkBYHsMfdVWIGtSJP kP8JPVQM2fmzk7OdxBvU1U1DkNprBJ+l5Et8znxynpyhWkqns6h0x2Nm32mK5kHNiAa9 9GDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=Yv236JZO8MBwNudwgeRbvCz9ijAwsid6llq78vrEdfI=; b=GOMVxdyYpRbwG8gNg016gY1oyntYKZgnsI3urO+aJAxE4Hx7OIwRRYt0SdCyK3ZlRx sBVmNhm5VkWoWoMTz7F6JqT/8Ph2AEKPGUfDa5Kxzs7UcK0Jk4kWo+RU/3W+hzruXwhP k4DMiVSm5ZCn1Xk35BbUJf8dZ5Iyh3jaFWhOOMUfegGzHReWys9x/z1bz7k2hoQXvlWG W/S2CLyVCtj+Dhw/ECpU2L6+fdrBF4jyNWVt0wXQyb5ht47/SoTBveucNUu0uJgZU204 ko5/TGYW51b2sl3ckrZ5AuW0Wo7Trk5a9bk0B81ALnOp8kVv+6PE5vBMS+bjr3zFmtoC 8gwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=M41PSF13; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id f6-v6si958261wmf.1.2018.09.14.22.21.16; Fri, 14 Sep 2018 22:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=M41PSF13; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B5AA94D3A; Sat, 15 Sep 2018 07:20:58 +0200 (CEST) Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 26C2E4F9B for ; Sat, 15 Sep 2018 07:20:57 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id w11-v6so12386070wrc.5 for ; Fri, 14 Sep 2018 22:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Yv236JZO8MBwNudwgeRbvCz9ijAwsid6llq78vrEdfI=; b=M41PSF1384aSFyIeQmnyTLwZhfgtpePKAq68cWu2AmkFanCMs6ev5tCIUW5R/sYKVz QLSXOZrszJch5yrAWAzLJRlcnemgR9a2vh9W5OBogVZB2QdtsO8/J2uoGQFnxyQ4ihMV 4hCh6e3DzllOEJ7U7PjN6f/xwc3HJRaG0T5HGL2joMI1KWQNLmlg/PoLqBS3xF3/0pk5 iHPAY/YmdecJR5nv4GlzGmB5Lg5jc44wq8qIJLMCLfSm+AvU2FAu6hFXi92ucQ5Fwnnc VtSjC1nfmlcT7ZKmUg79iEkpM6KdRmYDjEQow8X4fUyeDT6UbWS5re6UcOX8KAQ1PTIp lQiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Yv236JZO8MBwNudwgeRbvCz9ijAwsid6llq78vrEdfI=; b=V/2y2YZdKPRYHNnHfN3x+IVXQ3hyh4Cnnx03DjOUtkNyfm8vMbvz3TOyzOcVjeMV+0 5WotHn3AKNuxDZiTSjeC2EBtdy/9vqB0YpYPkKm9E3pEffBjkpr8fzX+WsNDquH2u3Zt ie/9RB6ZrRAf7KjeWRvW7n4AdPKkUlwJ8NMaHbIdLFZaD4CkVSQJFu+f3KxtEukcJMNs AY1h3pgKjZ0qQ3ykl6SiHNw1kdXizbi3be1A3xT9sCyP0uaSy26P5a5ek8rL7MvVt/Oy LJl6kHXle4gEQW+L0keGQMbgTw/ttYomqyEWhgjQAZzzi1UGBoGoE2YuMQqJjHbzfbiR mbZA== X-Gm-Message-State: APzg51CzKP1RdUfCCOtypRqY8LkDDvV+hh8MV1AHKIJBG55FyPSOX3bh IxkkHXZpP2sG9bUceRpd0AjY3K133EitbA== X-Received: by 2002:a5d:50cf:: with SMTP id f15-v6mr12415525wrt.128.1536988856596; Fri, 14 Sep 2018 22:20:56 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id 60-v6sm9827382wre.82.2018.09.14.22.20.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 22:20:56 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Sat, 15 Sep 2018 08:20:54 +0300 Message-ID: <153698885466.23049.5627861471035122455.stgit@T460> In-Reply-To: <153698873346.23049.10966616323159180622.stgit@T460> References: <153698873346.23049.10966616323159180622.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 5/5] vhost: message handling implemented as a callback array X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Introduce vhost_message_handlers, which maps the message request type to the message handler. Then replace the switch construct with a map and call. Failing vhost_user_set_features is fatal and all processing should stop immediately and propagate the error to the upper layers. Change the code accordingly to reflect that. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 161 +++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 95 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 81c0396de..9004e1ac8 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -73,6 +73,8 @@ static const char *vhost_message_str[VHOST_USER_MAX] = { /* The possible results of a message handling function */ enum vh_result { + /* Message handling failed with an unrecoverable error */ + VH_RESULT_FATAL = -2, /* Message handling failed */ VH_RESULT_ERR = -1, /* Message handling successful */ @@ -206,7 +208,7 @@ vhost_user_set_features(struct virtio_net **pdev, VhostUserMsg *msg) RTE_LOG(ERR, VHOST_CONFIG, "(%d) received invalid negotiated features.\n", dev->vid); - return VH_RESULT_ERR; + return VH_RESULT_FATAL; } if (dev->flags & VIRTIO_DEV_RUNNING) { @@ -222,7 +224,7 @@ vhost_user_set_features(struct virtio_net **pdev, VhostUserMsg *msg) RTE_LOG(ERR, VHOST_CONFIG, "(%d) features changed while device is running.\n", dev->vid); - return VH_RESULT_ERR; + return VH_RESULT_FATAL; } if (dev->notify_ops->features_changed) @@ -1477,6 +1479,34 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, VhostUserMsg *msg) return VH_RESULT_OK; } +typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, VhostUserMsg * msg); +static vhost_message_handler_t vhost_message_handlers[VHOST_USER_MAX] = { + [VHOST_USER_NONE] = NULL, + [VHOST_USER_GET_FEATURES] = vhost_user_get_features, + [VHOST_USER_SET_FEATURES] = vhost_user_set_features, + [VHOST_USER_SET_OWNER] = vhost_user_set_owner, + [VHOST_USER_RESET_OWNER] = vhost_user_reset_owner, + [VHOST_USER_SET_MEM_TABLE] = vhost_user_set_mem_table, + [VHOST_USER_SET_LOG_BASE] = vhost_user_set_log_base, + [VHOST_USER_SET_LOG_FD] = vhost_user_set_log_fd, + [VHOST_USER_SET_VRING_NUM] = vhost_user_set_vring_num, + [VHOST_USER_SET_VRING_ADDR] = vhost_user_set_vring_addr, + [VHOST_USER_SET_VRING_BASE] = vhost_user_set_vring_base, + [VHOST_USER_GET_VRING_BASE] = vhost_user_get_vring_base, + [VHOST_USER_SET_VRING_KICK] = vhost_user_set_vring_kick, + [VHOST_USER_SET_VRING_CALL] = vhost_user_set_vring_call, + [VHOST_USER_SET_VRING_ERR] = vhost_user_set_vring_err, + [VHOST_USER_GET_PROTOCOL_FEATURES] = vhost_user_get_protocol_features, + [VHOST_USER_SET_PROTOCOL_FEATURES] = vhost_user_set_protocol_features, + [VHOST_USER_GET_QUEUE_NUM] = vhost_user_get_queue_num, + [VHOST_USER_SET_VRING_ENABLE] = vhost_user_set_vring_enable, + [VHOST_USER_SEND_RARP] = vhost_user_send_rarp, + [VHOST_USER_NET_SET_MTU] = vhost_user_net_set_mtu, + [VHOST_USER_SET_SLAVE_REQ_FD] = vhost_user_set_req_fd, + [VHOST_USER_IOTLB_MSG] = vhost_user_iotlb_msg, +}; + + /* return bytes# of read on success or negative val on failure. */ static int read_vhost_message(int sockfd, VhostUserMsg *msg) @@ -1629,6 +1659,7 @@ vhost_user_msg_handler(int vid, int fd) int ret; int unlock_required = 0; uint32_t skip_master = 0; + int request; dev = get_device(vid); if (dev == NULL) @@ -1721,100 +1752,40 @@ vhost_user_msg_handler(int vid, int fd) goto skip_to_post_handle; } - switch (msg.request.master) { - case VHOST_USER_GET_FEATURES: - ret = vhost_user_get_features(&dev, &msg); - send_vhost_reply(fd, &msg); - break; - case VHOST_USER_SET_FEATURES: - ret = vhost_user_set_features(&dev, &msg); - break; - - case VHOST_USER_GET_PROTOCOL_FEATURES: - ret = vhost_user_get_protocol_features(&dev, &msg); - send_vhost_reply(fd, &msg); - break; - case VHOST_USER_SET_PROTOCOL_FEATURES: - ret = vhost_user_set_protocol_features(&dev, &msg); - break; - - case VHOST_USER_SET_OWNER: - ret = vhost_user_set_owner(&dev, &msg); - break; - case VHOST_USER_RESET_OWNER: - ret = vhost_user_reset_owner(&dev, &msg); - break; - - case VHOST_USER_SET_MEM_TABLE: - ret = vhost_user_set_mem_table(&dev, &msg); - break; - - case VHOST_USER_SET_LOG_BASE: - ret = vhost_user_set_log_base(&dev, &msg); - if (ret) - goto skip_to_reply; - /* it needs a reply */ - send_vhost_reply(fd, &msg); - break; - case VHOST_USER_SET_LOG_FD: - ret = vhost_user_set_log_fd(&dev, &msg); - break; - - case VHOST_USER_SET_VRING_NUM: - ret = vhost_user_set_vring_num(&dev, &msg); - break; - case VHOST_USER_SET_VRING_ADDR: - ret = vhost_user_set_vring_addr(&dev, &msg); - break; - case VHOST_USER_SET_VRING_BASE: - ret = vhost_user_set_vring_base(&dev, &msg); - break; - - case VHOST_USER_GET_VRING_BASE: - ret = vhost_user_get_vring_base(&dev, &msg); - if (ret) - goto skip_to_reply; - send_vhost_reply(fd, &msg); - break; - - case VHOST_USER_SET_VRING_KICK: - ret = vhost_user_set_vring_kick(&dev, &msg); - break; - case VHOST_USER_SET_VRING_CALL: - ret = vhost_user_set_vring_call(&dev, &msg); - break; - - case VHOST_USER_SET_VRING_ERR: - ret = vhost_user_set_vring_err(&dev, &msg); - break; - - case VHOST_USER_GET_QUEUE_NUM: - ret = vhost_user_get_queue_num(&dev, &msg); - send_vhost_reply(fd, &msg); - break; - - case VHOST_USER_SET_VRING_ENABLE: - ret = vhost_user_set_vring_enable(&dev, &msg); - break; - case VHOST_USER_SEND_RARP: - ret = vhost_user_send_rarp(&dev, &msg); - break; - - case VHOST_USER_NET_SET_MTU: - ret = vhost_user_net_set_mtu(&dev, &msg); - break; - - case VHOST_USER_SET_SLAVE_REQ_FD: - ret = vhost_user_set_req_fd(&dev, &msg); - break; - - case VHOST_USER_IOTLB_MSG: - ret = vhost_user_iotlb_msg(&dev, &msg); - break; + request = msg.request.master; + if (request > VHOST_USER_NONE && request < VHOST_USER_MAX) { + if (!vhost_message_handlers[request]) + goto skip_to_post_handle; + ret = vhost_message_handlers[request](&dev, &msg); - default: - ret = -1; - break; + switch (ret) { + case VH_RESULT_FATAL: + RTE_LOG(ERR, VHOST_CONFIG, + "Processing %s failed with an unrecoverable error.\n", + vhost_message_str[request]); + /* Propagate the error to the upper layer */ + return -1; + case VH_RESULT_ERR: + RTE_LOG(ERR, VHOST_CONFIG, + "Processing %s failed.\n", + vhost_message_str[request]); + break; + case VH_RESULT_OK: + RTE_LOG(DEBUG, VHOST_CONFIG, + "Processing %s succeeded.\n", + vhost_message_str[request]); + break; + case VH_RESULT_REPLY: + RTE_LOG(INFO, VHOST_CONFIG, + "Processing %s succeeded and needs reply.\n", + vhost_message_str[request]); + send_vhost_reply(fd, &msg); + break; + } + } else { + RTE_LOG(ERR, VHOST_CONFIG, + "Requested invalid message type %d.\n", request); + ret = VH_RESULT_ERR; } skip_to_post_handle: