From patchwork Thu Jul 19 19:13:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 142377 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2093413ljj; Thu, 19 Jul 2018 12:13:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+NmutXVl94tSYjt0FGYdXRFncArXlrIgLZVUWTFUu32OzTq2U078zQWgbNLo+6YFGr01z X-Received: by 2002:a1c:b80c:: with SMTP id i12-v6mr4846879wmf.30.1532027614375; Thu, 19 Jul 2018 12:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532027614; cv=none; d=google.com; s=arc-20160816; b=QUOYMtpZuLObDwBfV+ChE2sXvDRLddS+ViTH5VcCnASFzV+r2sxW55E5rLhjUHuDVN IcVDdq5MjLdDd6gucQvkMRTKIdohX2RjheOBZPU1V7MSCb2J9YNyMyZP7djFEH7SlPJC kDm9XejKunjT9yrVwqy5g77DCqoPkXLKqT79hM2D6ZoNGKokn1248/MKORUfgtXhORFK m7k3fgNwv3ZSltFk0kLFZQrIysSXMZmKZqwjDhmObh+RLRMROsqlzbQ9PfnXxoiX1gwY EFa7PrPKBRHLo7F5ah1Vqw3rRLsns3wbo5amFh5ZaKmK7xoOn3LAEl12tT4sXLX/CIdC BqUA== 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 :arc-authentication-results; bh=LlwHzfaxIoFmiP+qbtyHxok2KSAD9DezgDgcQ0/NNkQ=; b=z/htqdr43gjud7tpaGdse2EqxShsZmjgofzNgSHoSoLtNTWRtgcRoB57YepmJw5l/D lpgo89a+lNTGCv0lRfeEVbKDwT/josJEqSgPlIBLiaFQapd2l6qjY+05KfPTgiiSD/oY 0uvEb8BI6YVNj8+Eqm3cgiYEWAFuU06vjoF31SWxQSuEF5wgGWMQpuktBRPm6pKx1nCj xCELY7glj4rmHUkgZEj7OLDL0CY2Oqnf+6ItkRmtWO/NkaUZGUvSi6wTfMDBo4bK37XK n+vlNtqZPFYAhm6C2wAIRgSER8NwWshV99NMDz7Htywgd801Oh/ddtWooNDQmUNVFcIA CrRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=RaYcZ0Qt; 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 x3-v6si5724884wrb.173.2018.07.19.12.13.34; Thu, 19 Jul 2018 12:13:34 -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=RaYcZ0Qt; 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 834AA5B20; Thu, 19 Jul 2018 21:13:30 +0200 (CEST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 9D10D5B1C for ; Thu, 19 Jul 2018 21:13:29 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id z13-v6so7465194wma.5 for ; Thu, 19 Jul 2018 12:13: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=LlwHzfaxIoFmiP+qbtyHxok2KSAD9DezgDgcQ0/NNkQ=; b=RaYcZ0QtcdoZOdJsB+7ZvReEW//faJzn1ACwQnzUUrvzRSd3vcU5XchBJ5ja14cdZA e6cHI4z9M2liSAyeVGT2uUd6WXN+tYXq0gMzKkXCkx1wQ80f7Sp8jZUyJlPtRWOMtZ3l oKQj0eYioL0is77FJnJH4QgfR468nTJBG6PKm96W889pQTKjOq3uswaSv0+KavLUD1qK eNbp9PmMKjomodOsZfyyy5NwcNpNpH86XMttFSq7wG74rktu7+xuk8NPhzEXA/b+4R9s D918LaQFn7vu+SIY1t8JhZIFtgD+CDUNTycmsYPuS0oWwwjeSo+sz3xhmWBL+3+woftS 6hVA== 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=LlwHzfaxIoFmiP+qbtyHxok2KSAD9DezgDgcQ0/NNkQ=; b=L0vNfTCv3Cfd5UQeqx9D6KKPddEB+NMLHQLjYfWTA5Gn5Eseo43jGJVh5qKRQbe998 b8W+8XqWcF1ZMJEcvVgax2Jtw56dpxvS/8edhNe4bKMRFCSVzA6IK6bLw3JYlLXkP2ux oOfu1GEp+OGmI+85d3fBl60lywwGhqiKQVOlwSU2aY8qORONapn4aE0oXQQX0h/CbdQu aHP29jnQCunso/X56hIGu5dPIJqeZLylyomNu1FgjeSkOeqVd7GkTTahBAjKLgyxsCZ4 nxEo69aWHzZYtSiBGgmQd6GuRfmlVyLx0yQ6qxfkajkntCWJRIuz3IchEeFsbT4MURmf inrw== X-Gm-Message-State: AOUpUlGSLEITRMuWDrLkRRE7pIIkBNor5J7iATXGrMP0bApktqhBAzhD GRBfPOfsvqptU2tZK8JEs6chpijt6FE= X-Received: by 2002:a1c:cbc1:: with SMTP id b184-v6mr5319418wmg.149.1532027609070; Thu, 19 Jul 2018 12:13:29 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id r8-v6sm148056wmh.37.2018.07.19.12.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 12:13:28 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Thu, 19 Jul 2018 22:13:27 +0300 Message-ID: <153202760738.21481.2953475302358332226.stgit@T460> In-Reply-To: <153202755842.21481.1772155561595981441.stgit@T460> References: <153202755842.21481.1772155561595981441.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 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(-) Reviewed-by: Maxime Coquelin diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index dc53ff712..d51616695 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -778,10 +778,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; @@ -802,7 +802,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; } @@ -838,7 +838,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; @@ -987,16 +987,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); @@ -1008,17 +1008,17 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) } static void -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); @@ -1145,7 +1145,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; @@ -1176,7 +1176,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; @@ -1243,7 +1243,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; @@ -1272,7 +1272,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) { @@ -1288,7 +1288,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]; @@ -1354,7 +1354,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; @@ -1400,7 +1400,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; @@ -1429,7 +1429,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; @@ -1439,7 +1439,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; @@ -1453,7 +1453,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; @@ -1544,7 +1544,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; @@ -1832,7 +1832,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), @@ -1862,7 +1862,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 Thu Jul 19 19:13:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 142378 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2093555ljj; Thu, 19 Jul 2018 12:13:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfob2PgnC9/VNTpbZALKCj9V0UgaVqdUyJKjR/bWMS0oalKu/oKyTT3i9RE2n7euFwrYNJX X-Received: by 2002:a1c:30d2:: with SMTP id w201-v6mr4823768wmw.47.1532027623517; Thu, 19 Jul 2018 12:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532027623; cv=none; d=google.com; s=arc-20160816; b=h3O07Uwde/trjLiBfJ24psvHerKu+DCTfGvN6BVWjfk4VpJQzaq+QSZ0R8snnzzRhv wKlouTd0oh/CtzRYhKj8sAsDOf9/9Rfa2SMFjFbYGmdVz714BFkevqHwbfy1AiEXjYeq rjIiNWp5m5jxIcDKepWFoQRzpkCyWd+O0+kSJnBFkP9DUPJTL+rneFkr8fCdDdrBE6qF HP8WKGlUruCjT0IvQ/gyL/FjgJiPgY45PXCjCmXmfx6b9oV9p860W5Pdm7RHixlWXqDM R4P3dj2XuMiEweAVBEzEX+kXh7I4sIz0XyLjszDeIUR3do3jt6GHM7dRxC9xgLJ9A8ND g+YQ== 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 :arc-authentication-results; bh=6cg4XzjXRxCK8ANybJSK+tcCbAgT3r6KNJRCv3E9sqQ=; b=PVG8jNCr0zVSEMAoVqr6N19vrcCxgkK6DzHAR+D9bje4UsH/v+hPWOUg1PB6ge+EXi 7xlANhF61jJ3eO6/vQV3gzx+HF5m/TOqsw2P4isF2PZXn/6Kk8fWrQOx6ICq3vFGX8V7 vOnY31nlNak11cllAcx0Ttq+gkKdsUxL9xJJfUZLGe30+MINo8C9H9f80u+szekdw7xL TFGKc/R0nJdtoieuhAXh+yvTtROn2cT/mid5u5fSL6NpmvBE0OQq0tlujMt2rxLNLUx8 sGuy8zF07Pkcs6rIGY6ZZ78WKl7ZYAdSkVWsxgxAuLGc3cAd+OM9cO24n/M82hgkRUQ+ qM7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Kpl+xXeb; 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 c123-v6si181209wmh.108.2018.07.19.12.13.43; Thu, 19 Jul 2018 12:13:43 -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=Kpl+xXeb; 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 27C445B38; Thu, 19 Jul 2018 21:13:37 +0200 (CEST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 707B65B3C for ; Thu, 19 Jul 2018 21:13:36 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id z6-v6so2491249wma.0 for ; Thu, 19 Jul 2018 12:13: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=6cg4XzjXRxCK8ANybJSK+tcCbAgT3r6KNJRCv3E9sqQ=; b=Kpl+xXebXMSkf9CNMqS7m0nSGO6l1ZWvqYcJO4PWp8v3mWqKZgPqOlzZxMbS5XA1aw YImmE8Utm7fDyzV3C/qhiGIsC5azrJHXRv5uUnDa2QGZ1lm6zn9/aQj1r6VRduSZshcZ /drXzCtmlO9quKYnHt4OcVJtNK+u0gbVC0HDhhROXwHj8P8eK/nGnolFsBySWlZCa+Y6 5TnY49cyZUKkbLA0qpwgVH7SeePKvMpKJmuUr3bCC8kqrMS7F46iCD6vsXkPi8fsm7d0 1bo5kMzraEMYYZUhMCOALMjQfp/mXosLZeD8iAdFsCACP0xLzOaocuJcA8QGq6UA4swO bhkg== 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=6cg4XzjXRxCK8ANybJSK+tcCbAgT3r6KNJRCv3E9sqQ=; b=BYCq8V6H5MbLX6+GnLeUCVjruCTbz/rFwzJH6onMZEX+rGwjgeeo+8Pn07S2sd26mI V10P02De2h3XZoZBP+VQgDLSO/fgKhDKCKtyoeE8ZaorORwkLZzN74cJC0nDzfsA/jCa b24zAtR0t72q/enJFcCYyZYcWC5oyOLEHGQj1NNs2S4mUjreE3V061OjVSeGNT3hTCtU a9vi2DXp2A2AqD+3hhe6NV/IKa2NEMzOldK61WL/D2+ja38NOcv9U/5kMuYY4sUMSs8P HB2W1FAaS7zRs4i6q3iETpIKZ9UzeJ/6GeEShqfghonPaOWiHsV95ylmqSWZ3TylI15G BhTg== X-Gm-Message-State: AOUpUlEwOzALErct5NC7PBKUpxJvw/fM3X2AIyv22bekd8VuUHri9gOl 3+YvOSe7Gsawkw7oljUmfmZpnfVyzhc= X-Received: by 2002:a1c:64d5:: with SMTP id y204-v6mr4900024wmb.14.1532027615896; Thu, 19 Jul 2018 12:13:35 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id m17-v6sm11377480wrg.65.2018.07.19.12.13.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 12:13:35 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Thu, 19 Jul 2018 22:13:34 +0300 Message-ID: <153202761415.21481.4698894052167645234.stgit@T460> In-Reply-To: <153202755842.21481.1772155561595981441.stgit@T460> References: <153202755842.21481.1772155561595981441.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 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 resued 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 | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) Reviewed-by: Maxime Coquelin diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index d51616695..e97b2d563 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; } @@ -1109,6 +1117,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; } @@ -1231,6 +1241,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; } @@ -1644,8 +1656,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: @@ -1675,9 +1686,6 @@ vhost_user_msg_handler(int vid, int fd) case VHOST_USER_SET_LOG_BASE: vhost_user_set_log_base(dev, &msg); - - /* it needs a reply */ - msg.size = sizeof(msg.payload.u64); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_LOG_FD: @@ -1697,7 +1705,6 @@ vhost_user_msg_handler(int vid, int fd) case VHOST_USER_GET_VRING_BASE: vhost_user_get_vring_base(dev, &msg); - msg.size = sizeof(msg.payload.state); send_vhost_reply(fd, &msg); break; @@ -1715,8 +1722,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 Thu Jul 19 19:13:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 142379 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2093712ljj; Thu, 19 Jul 2018 12:13:55 -0700 (PDT) X-Google-Smtp-Source: AAOMgpevJXrR5ILXX3icQhde24NTTPUrU1qcrI/ezF8b1pSyQ8Lo1mogdodUZgl0B8J5X1dq+RtC X-Received: by 2002:a1c:369c:: with SMTP id y28-v6mr4819334wmh.34.1532027635125; Thu, 19 Jul 2018 12:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532027635; cv=none; d=google.com; s=arc-20160816; b=c5jloP0wUKSS9PnGO8gUpO/bTWNBcUa+S4eQ/TyvRtqBurN/gm8bTv9o85zPhKIMl4 TXaI1t9r68ClW+JxKek8HCU7tbRfmSsNQkVVnC57fFmMk4O7E211VFSfx6UwKFZPD0zV NRlahvLw5ITtkRlauXVC/OFgLkrlXVA45q/nuLuM4nm0iJVF1qLJXWbQCF3uXoXb4g0N zZAEp5SP04d16Vm1YJkVZi5GJdkiCue6o5rv8bOoXpM6B8IiSRQS8ebOMBFFUPlrjUBz Shi+nrWJIxjj2lVM01EMZsltJuIrIb84Boyi+ul1kUH5xePCvLI/4jfc8Lxa2ToFl3tP fhSQ== 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 :arc-authentication-results; bh=WCSiwYONcpbm/m1/uhhMkrStdpQpy+aMGCslI1fCi60=; b=Ujphx+o+Mc8L1malW4Mx4wk2+J8xe+LlW244E/Y2eIx5jVKVmKhi5LxJJMQRG9Ahzx 6cKBVeEBQ46cvh5zO8uFoXuwBHn0MZDlYeWvBHHgewy/dm7n/iR0yx2HZn54qJMxWOcf uYGLIMdL6QXrScwDC9YNuu4dj24r7KePCYPRsvVT215ebKNfPapSzlszCwccIKMBTdcy srAbhNJUBRx/hAgvXfyCyCG3WqgMUB7rSle16sb7wA8VutuqznE7SlMFt9HvGdKgF7JQ mPvDpFlxEDYtJtujlUv32+tpTxgInxfAVtqof6rb6haTktKgY47XEqqqS1rn4bcSzZHv 24zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=AAoxIMhG; 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 y124-v6si173761wmy.141.2018.07.19.12.13.54; Thu, 19 Jul 2018 12:13:55 -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=AAoxIMhG; 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 467D65F12; Thu, 19 Jul 2018 21:13:44 +0200 (CEST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 6FFCE5B2A for ; Thu, 19 Jul 2018 21:13:43 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id z13-v6so7465710wma.5 for ; Thu, 19 Jul 2018 12:13: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=WCSiwYONcpbm/m1/uhhMkrStdpQpy+aMGCslI1fCi60=; b=AAoxIMhGKdUATAMcrE9X73y8EizSiCANH7i/MvoWg3oylOHNc7exB0M6I9drGeGdCP Edj9W18mzzQGQJl2vnfYESpJwgVxLwkqvaov+r/nCYYBFTMYYI1UDeJKfNvV0yOCiPQ0 dkqCp2wYOiZS6uMVd5sWxux7HHHJW41sy/75WweEwYrwM21BeoqnP2GfG2lPFuDdXv8J dxJyaTYrgArhMUeidvDhB9IO+KekiMw+sDUZha8MQT9SMR0EVrtva2EuwooVZ4x9pan3 6kmPlDm65TSeWjiz48MMW5SkVqlNz9XmzG9lwntXJebuwb3AXyAang4xQLsqextdVLaF lCxg== 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=WCSiwYONcpbm/m1/uhhMkrStdpQpy+aMGCslI1fCi60=; b=j0Sd7BEbzf/xtD7Yz+WjeUxSe6/ryldPGvJc6VK+M7T1P9QRAlaoJMSY/4BAJ04iMS d97dfC3/a3rqWNFfyH7Ek1y4bgta0EePdvNcykS+OAitteaMlmoUJURnF98X0QIGSN3o Q1Sk61haeKSEJWQVlDNPItOMYlcs20FOxQBAQpKnSNVBRyVWiuuxPOUdIFZ85CLbGYXF HKwkViu2CQHJBvPojFRCeqDUxpCVArSrQO63s1E94zghuYRZbbJxp4pr6d/LgFwwawkM e4L9WIvUcGBvHfQy5vqIzpOtu2t1pVADFjsuT6QEZ/SYwjCfzErRz3b/G6UnJwiiDe/p iMRg== X-Gm-Message-State: AOUpUlEe5iEOTZpsCavqj9S33sjTTxKFa3yArYNQf1N+VAQjdLqONEZm QWuLCUE57J3le0Q6n6PeVIPRhOpG4DQ= X-Received: by 2002:a1c:d607:: with SMTP id n7-v6mr4927274wmg.150.1532027623001; Thu, 19 Jul 2018 12:13:43 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id h14-v6sm9296506wro.15.2018.07.19.12.13.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 12:13:42 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Thu, 19 Jul 2018 22:13:41 +0300 Message-ID: <153202762111.21481.10403768024279892271.stgit@T460> In-Reply-To: <153202755842.21481.1772155561595981441.stgit@T460> References: <153202755842.21481.1772155561595981441.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 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(-) Reviewed-by: Maxime Coquelin diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index e97b2d563..b408460f0 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1015,6 +1015,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 void vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) { @@ -1246,6 +1254,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 @@ -1689,8 +1704,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: @@ -1716,9 +1730,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 Thu Jul 19 19:13:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 142380 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2093880ljj; Thu, 19 Jul 2018 12:14:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpewhbMzlbI9md6PWlqhEno7eEkxLgwy6GV1PK6VX2Mh/RlKypjLZALe82WaaOXTnGqxpUOj X-Received: by 2002:adf:e3c5:: with SMTP id k5-v6mr8646520wrm.94.1532027645565; Thu, 19 Jul 2018 12:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532027645; cv=none; d=google.com; s=arc-20160816; b=Lu+t11QhukBvuiY9dXbow6oCK6L+i0LQz/QwPJ16vTwZY+yvjK5oUQoqacsH/ACbTB ywUDrZqQ8TswV9fBz80sUdJaDSDgjihYxJWeYiTTOtmvVkhf597L6OmpQfwL8DrQ6DKd +q1leykVThMLHwEpwEVPv4rqs6xro/Uks2456VcMRERmNGfbchbQa7lMuD1oikfPh7aM h/xboGLKHm+AQTLaqqwWAMI+LHgeCqE8LI7doyKCoJRt0rcwlni7m9AEZIZGe46QWTw/ 63LVzndsMWGBvMeO6Sgec5YM161ymVHee22rmGbksPZ45XvQN79WJQAyueI8iEP5ibV0 oaRQ== 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 :arc-authentication-results; bh=54IOh5VHBYD03NLbWDjjU6ki9Ig8/ynVaU6fYQSRTWM=; b=wpZVnirrIuKKVNisIOHlBr93GhnyExGcywDO6L6db+FRNf5OP7LoYxL99vjF2IRVO8 2tu7gGguI17Sdd6C0PB5MsZA6mH05u7jL+ASdaGcgyqAySBBQ5iAaXFGvCPEPxJrtiPi MXRcNp9HJv5+Je8w+iNSFGrVq7jc2H5f8ceBIbuhOlJ5DK3sNmJ4jgKYy4zYw6yJ68+u SkO2dDeoDaK9o6r5uLUPl/EbMxqi+fb8loKykvsQWNQx0qYUQOMI2oDwr4QHJ5fR6/+u P5/onF6/2DF+w/WPAgk/mfQzAcg6FQY1a44pUpY2tWOnFnB97ZbIzs08wIxVvf2rDFG0 fbow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=LWeO7ity; 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 c6-v6si159942wmi.227.2018.07.19.12.14.05; Thu, 19 Jul 2018 12:14:05 -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=LWeO7ity; 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 D65B15B3C; Thu, 19 Jul 2018 21:13: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 91BDD5F2F for ; Thu, 19 Jul 2018 21:13:50 +0200 (CEST) Received: by mail-wr1-f65.google.com with SMTP id b15-v6so9087108wrv.10 for ; Thu, 19 Jul 2018 12:13: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=54IOh5VHBYD03NLbWDjjU6ki9Ig8/ynVaU6fYQSRTWM=; b=LWeO7ityu0CyDb8Aqn17GOGaEgCtbQqMheloI9Bw0vhoxZ8Vq1wDdTVxd3wyU2wBwX 3+vXVo3DFIzRYEggrzpo8PXNJp8GeUbxsYYiQMT/U6XC+GBZcr/iQ8UVdREh6T5uqkd/ L7mXvT0Pw78uRcWCDAOxnouC6w62udCNPM31d0JF1xHcGhd74z5rCU34MVVFTRbZiRK8 RJEh4bjvhhV7Xwr7OnoEZEP3rpYhEKCoTjqMcDtGAX1X5PEWK5hIFjcwu/Mbr/IxyNpN 6+g8/cSTdmlcu66yOlOruVmccuJawy5lKsr59//Jhz3uicJhTcQJvXLyw/FJlizN6Snf 76aA== 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=54IOh5VHBYD03NLbWDjjU6ki9Ig8/ynVaU6fYQSRTWM=; b=aIQk2TBFwExWtXnYUx8+YL25gahfNlcZxW1OKbv6GAcy3QITFd2AP/qRpLCu6iLu0E Rlr3e8LtCsQ6es3zLI7MwHjoA5W7fwz0WxjMV25wc+/ufKjBM0CX64tQ/tNahA85ZE2v OdMenP3VYOG5Dqq/HfVFgbbYbUE+2LzjsHkJP8OQPKvup8vksGQjEiRIIbybJQMAUBCp mdDpvMkNYy+rh9UTDkG+4JgYhEqf9jDiQOEll2teg5p/eXq1XQ5vZIhyhnikbkSvhecY O7ccT6EIN3nsmtpuCACljoyZWNB+eqYx/WEi3Th04m/YIxxaygRJ/KbcITzX5evBZSrk RrbQ== X-Gm-Message-State: AOUpUlGnvw+VVNg6Q8luCXigTwIqaQ2DAmV9N3nL0bvLM6OQEEB2DNk7 xnmrWm61G7QLhcKjYTlpx8UOV71mjT8= X-Received: by 2002:adf:ffc7:: with SMTP id x7-v6mr8658347wrs.137.1532027629910; Thu, 19 Jul 2018 12:13:49 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id f20-v6sm488578wmd.3.2018.07.19.12.13.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 12:13:49 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Thu, 19 Jul 2018 22:13:48 +0300 Message-ID: <153202762812.21481.4897742465873945718.stgit@T460> In-Reply-To: <153202755842.21481.1772155561595981441.stgit@T460> References: <153202755842.21481.1772155561595981441.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 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 | 219 ++++++++++++++++++++++++----------------- 1 file changed, 130 insertions(+), 89 deletions(-) Reviewed-by: Maxime Coquelin diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index b408460f0..6b39d1e30 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; } /* @@ -619,12 +637,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]; @@ -641,27 +659,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 @@ -802,7 +821,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)) { @@ -812,7 +831,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) { @@ -831,7 +850,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; } } @@ -841,7 +860,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; @@ -938,7 +957,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; } @@ -946,13 +965,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 @@ -994,9 +1013,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; @@ -1013,22 +1033,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 void +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) @@ -1041,7 +1065,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; + return VH_RESULT_OK; *pdev = dev; @@ -1058,6 +1082,8 @@ vhost_user_set_vring_kick(struct virtio_net **pdev, VhostUserMsg *msg) if (vq->kickfd >= 0) close(vq->kickfd); vq->kickfd = file.fd; + + return VH_RESULT_OK; } static void @@ -1080,9 +1106,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. */ @@ -1127,7 +1154,7 @@ vhost_user_get_vring_base(struct virtio_net *dev, msg->size = sizeof(msg->payload.state); - return 0; + return VH_RESULT_OK; } /* @@ -1135,9 +1162,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; @@ -1158,13 +1186,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); @@ -1181,35 +1210,42 @@ 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 void -vhost_user_set_protocol_features(struct virtio_net *dev, - uint64_t protocol_features) +static int +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) - return; + return VH_RESULT_OK; dev->protocol_features = protocol_features; + + 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; @@ -1220,7 +1256,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, @@ -1235,7 +1271,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; } /* @@ -1251,14 +1287,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; } /* @@ -1270,8 +1308,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; @@ -1295,40 +1334,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 @@ -1393,7 +1434,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]; @@ -1419,10 +1460,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. */ @@ -1671,28 +1712,28 @@ 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); if (ret) return -1; 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: - vhost_user_set_protocol_features(dev, msg.payload.u64); + ret = vhost_user_set_protocol_features(&dev, &msg); break; case VHOST_USER_SET_OWNER: - vhost_user_set_owner(); + ret = vhost_user_set_owner(&dev, &msg); break; case VHOST_USER_RESET_OWNER: - vhost_user_reset_owner(dev); + ret = vhost_user_reset_owner(&dev, &msg); break; case VHOST_USER_SET_MEM_TABLE: @@ -1700,57 +1741,57 @@ vhost_user_msg_handler(int vid, int fd) break; case VHOST_USER_SET_LOG_BASE: - vhost_user_set_log_base(dev, &msg); + ret = vhost_user_set_log_base(&dev, &msg); 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: - vhost_user_set_vring_num(dev, &msg); + ret = vhost_user_set_vring_num(&dev, &msg); break; case VHOST_USER_SET_VRING_ADDR: - vhost_user_set_vring_addr(&dev, &msg); + ret = vhost_user_set_vring_addr(&dev, &msg); break; case VHOST_USER_SET_VRING_BASE: - vhost_user_set_vring_base(dev, &msg); + ret = vhost_user_set_vring_base(&dev, &msg); break; case VHOST_USER_GET_VRING_BASE: - vhost_user_get_vring_base(dev, &msg); + ret = vhost_user_get_vring_base(&dev, &msg); send_vhost_reply(fd, &msg); break; case VHOST_USER_SET_VRING_KICK: - vhost_user_set_vring_kick(&dev, &msg); + 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: - vhost_user_set_vring_enable(dev, &msg); + ret = vhost_user_set_vring_enable(&dev, &msg); break; case VHOST_USER_SEND_RARP: - 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 Thu Jul 19 19:13:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 142381 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2094026ljj; Thu, 19 Jul 2018 12:14:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd5cUHntQ6ipidaPsmTEqy5XXlbXDaFXo0NfFHCsJ25rYdyngQHnkz3B8aj25xgKmhMcj+L X-Received: by 2002:a1c:b84e:: with SMTP id i75-v6mr4700847wmf.158.1532027655983; Thu, 19 Jul 2018 12:14:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532027655; cv=none; d=google.com; s=arc-20160816; b=XjTEvc1DKAl4V0q9fwQjAwn6eYWSE/FcFmb6usWZSm2yPPjR6x3OmUkbMwwpW/G4KU hVw0zI4/wZcaDk9pAk1575kPhkXlg2yKBp5vexF+krKd1fSgGG9R7FL7IHfF5pEXk7+8 59DfV2bteqCWe8joHkfAckYLGk3FSRiy2ZwbrBnSHIa/P5Zkm+9mSaRUHiy9OklMJ12N +/K+ORPz0STeEUxLnzG/fn6f4ogiNbgjXn9R7hMwY+V+BFPPH+N1+MLYI/9CtMJi6PKv 5Tl99znSjJsN2RiG7xVpbpH2pE6JgQGBBql0/xwQ2fQeWK54/SOpnWUJoVXNHuJftCDo nfcQ== 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 :arc-authentication-results; bh=KhfDSsoQpeIb857jFSN9TRCgwg/w+w61ixZV4X4+GjU=; b=stqH8B1tPa0v+8XwLg4/Ui1mD6mv70xb3rOkTHvKm2a8hK6lVgo6NB95lBnVnodycq sA9giyhqaUxok5HYs0sFW2xzT8jOH+f7W5fuFYPbQYaT6zU2+JHDpBhzw8c4B5hJr/pg u3nTKX+b/JQotdfDlQrp4cvZini7dNxMadPHgGJD6JoYXmp9WkWnvz7S4X1ovNJiTn9e yKn24Qo4cfI88JORv+gVoPPFJ53UXONEYBWFmIJ4L6yagnHq8UZ1+/+HpAg7Wfb9v5TX RTUkrCqtfSLoqPMbgWFjDeH0rbj3RAJEhv9WhwRKb8vkB9rGHOFemnTLTfVa8gcQ/oSb g/Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=mlE+6Br9; 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 y3-v6si5800100wra.59.2018.07.19.12.14.15; Thu, 19 Jul 2018 12:14:15 -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=mlE+6Br9; 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 A3A675F33; Thu, 19 Jul 2018 21:13:58 +0200 (CEST) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 496405F30 for ; Thu, 19 Jul 2018 21:13:57 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id c13-v6so9110708wrt.1 for ; Thu, 19 Jul 2018 12:13: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=KhfDSsoQpeIb857jFSN9TRCgwg/w+w61ixZV4X4+GjU=; b=mlE+6Br9bp5MOeRlRLyksQRAA9ZUErv7VE8CMreCwb9UDuEiPuWJe7nGSNJ5IYgAEe xUJnATKH+493O2AjKn7zllwTpDjSlutxSVRju5IboRC5nD3E7IM2fewW6TgFcoSAb4QI J5jRT/s0XixgYUBTUUVcPIARXefKpFHRfoS2ucAv+QO/VOgqNwWMXjLydlcG3PNzsxa4 OJE7aLtnujWCmP1IqeJfF7wcBlnqZvv4EuD0WJRQwOpFGTiS4NseVzc0H+fLZmivQBZE XF4PMq6BqzkEmjPaa7uvUu+3C7p5s2ge3EC4VkbPLo6HGaohUUoLInHGIPZ2r/lWy55O ZgkQ== 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=KhfDSsoQpeIb857jFSN9TRCgwg/w+w61ixZV4X4+GjU=; b=lFfk/haPlQJOzYiW308Sec8ORTZzznHqrjN7LwX4iMoMXHrqp0rYyPE2VAc3xgXPpT H7DMyYiAV5hh8dTTdatiWJ+nCizHaxhq3hPZKzZHgyRQU2v//shDIFR2YlemxCo3B6xE 9LPFVhqLmu0jQNlwziScWBVfY5rYF8LV1pZa0J3M2wgFoGGWumyV4FzIC7znjDCNLhsm 3Ny0Fs+inpRhdf6hXU7XIdenuhTdGaIlKbnPxXPjjFhR1FUvfSYe2PaKaX0S7R0gmuGL V3IaMsXnL2D5vedhx7yYJ43jpquyXC2NBzIadga3TtSf3cH85qu5/lsLeSnAt4HzoL0A hu9w== X-Gm-Message-State: AOUpUlEyt9g5X+gIIwkmUEaArCQsbE0rcThtcIcCUbk4EngDeYq0r6wI p9TGan09rLPGCnzNAHQWhJsUcWJcy6M= X-Received: by 2002:adf:9aeb:: with SMTP id a98-v6mr8104300wrc.110.1532027636822; Thu, 19 Jul 2018 12:13:56 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id y191-v6sm467188wmy.4.2018.07.19.12.13.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 12:13:56 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Thu, 19 Jul 2018 22:13:55 +0300 Message-ID: <153202763503.21481.6074577075024787339.stgit@T460> In-Reply-To: <153202755842.21481.1772155561595981441.stgit@T460> References: <153202755842.21481.1772155561595981441.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 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. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 143 +++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 89 deletions(-) Reviewed-by: Maxime Coquelin diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 6b39d1e30..1b164df27 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1466,6 +1466,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) @@ -1618,6 +1646,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) @@ -1710,97 +1739,33 @@ 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); - if (ret) - return -1; - 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); - 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); - 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: + switch (ret) { + case VH_RESULT_ERR: + RTE_LOG(ERR, VHOST_CONFIG, + "Processing %s failed.\n", + vhost_message_str[request]); + 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 = -1; - break; } skip_to_post_handle: