From patchwork Mon Sep 24 20:17:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 147382 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1129510lji; Mon, 24 Sep 2018 13:17:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV62RExZtl+t/GfPi35oMpg1BnlphwRSbeZaVhbksEmiqVzz4XATI7q0+/TAMioVEJbgUezTj X-Received: by 2002:a50:e40d:: with SMTP id d13-v6mr19736911edm.263.1537820228556; Mon, 24 Sep 2018 13:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537820228; cv=none; d=google.com; s=arc-20160816; b=U7b928iHf4jbQF6pESQQ+J7uLeDD4ONAQ0zDjqQq781WfsAScZAqRDuUBX9n+yfgDy jLxmtVxsgHi/WJFC3ppVzLOcQ9oB1u33+ZCzuXWwjF0To4kReumIv++20tFT5IlQorHi XSZ1+3wBLM16fkFdzMr+BCiWKvH58mymxYGfONN/TCbUUmbYP4lYMFKOu0I5becpNBrJ D29CZSmKk8NsnGC/2FaOtMrO2ySLm+uYP69k+T8y8Cse26CkOtAJSNdla4UhOby0F+CE wqUXLl7g1pdkdNo8ZnvJpK7OW/RZuxyCWZu/0hqDZ0KQNVGrtVsTm+7G3NqD9YBHoO08 18PQ== 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=pUfkQVMKM2Fv1RqwcmlLcUmN3XeXvKMFDpnlfeDA+38=; b=bNcUuByhgKHVemhiZt/pQtQarc16bEsakF5z87ubY+5AasPbZXPW/PAx7WBAq1mvoB F990QL/R36QkegN/Y4heY54woz+M1ZOCxxxBtcp1zdOtnJbtrM7oznqIZEgVF2ECiVlC 1kr/4xVmkeQ4lfvZpRUje5+l28i0STYSv4WmfEGy3pKTT1AGV5+zYSIQW4c35x/qw0jN gFfg5EWQs2Z15m+e7as/aQKipT9/AGGDPMUca/UsovcLFCxeZhZ/F81rDECL+ThHcsYU lARPA3EtrrsYqcYg8fv5VYQ0YqoXXovYSq5jLJXDILD7QZXtW+SEoaeiev2JkX/3AonY 8Sng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=O4o55Sol; 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 n6-v6si2898370edn.294.2018.09.24.13.17.08; Mon, 24 Sep 2018 13:17: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=O4o55Sol; 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 CE2031B17F; Mon, 24 Sep 2018 22:17:07 +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 08D751B170 for ; Mon, 24 Sep 2018 22:17:07 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id t15so13077749wrx.1 for ; Mon, 24 Sep 2018 13:17:07 -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=pUfkQVMKM2Fv1RqwcmlLcUmN3XeXvKMFDpnlfeDA+38=; b=O4o55Solmb9InpE1cl+vBX40UfjfelKHd3Sz12hnt9OHaZrLjCKA23/0MUKYKnKvKU W2b3e5G2D4NDQ9qylEXgLAapQNm0EWZsWXk/j1fXR4rFrA4j+3ssdSaqLJIWiJhXzKpB axjGIMJOPI8MKEGjwWwmfsbVyFX0uwa3ybZSFA5d9Xr8iN3RxWi1jpkMwL9y9qTYp0EN 7WhIl0TdUoNNZQKvC7ovySXD9nDwf55CVyGRiXIJpaHi04kas19ohoHQ3yUKWGT6fTBp pzoqPSrGqrAOvQ1trbD+ncTguBh/U9xGpzN5NXyZUzrwvDAfxcDCK5i9mEQIR1kyeWyh 6PuQ== 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=pUfkQVMKM2Fv1RqwcmlLcUmN3XeXvKMFDpnlfeDA+38=; b=GbgkguAkT3N4WtOsNDjTwr4Ykkp2Rm4ojZf9jgRM+9iz2OCyf15hRw7eXNvEid8nL5 F9h2gel6+4aT8nu+Ojg4WT7kbx66vb3AgMGy+15sjbkQvnHFephWikgsISLx+VDimYqx 0e4fojF0sIxNRvxIcVpY2f6FOyS2ESN0UqUlx1ITikkgQgHW1pd6gz2t2ThU4kL5mtLg tiRHtF71SOW1bb5c1QX7zHdianP9a2geSAbMQzOfKDPZbUYElD559h0kJC6gtdqWdXbV rdp7EzFKY7FwtGSz0VKsnZJvXpw0gRaxxRahPV8AediSTKxboWNGO7AkiCo5XBYWKwtD ffDA== X-Gm-Message-State: ABuFfogGlbJGt9eEZTZe7dd4MyqzcXzPcmoRhY7czmVWr2dq5ZcBMVYe MWpyaJy0YeV7+wP82aX65LGMyYxHOFUQsQ== X-Received: by 2002:a5d:6a46:: with SMTP id t6-v6mr333024wrw.192.1537820226410; Mon, 24 Sep 2018 13:17:06 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id e7-v6sm431977wrs.25.2018.09.24.13.17.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 13:17:05 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, anatoly.burakov@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Mon, 24 Sep 2018 23:17:04 +0300 Message-ID: <153782022417.27450.3107419616649123360.stgit@T460> In-Reply-To: <153782013094.27450.17651924330876922486.stgit@T460> References: <153782013094.27450.17651924330876922486.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 1/5] vhost: unify struct 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" Do not use the typedef version of struct VhostUserMsg. Also unify the related parameter name. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) Reviewed-by: Anatoly Burakov diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 63d145b2d..505db3bfc 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -250,7 +250,7 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features) */ static int vhost_user_set_vring_num(struct virtio_net *dev, - VhostUserMsg *msg) + struct VhostUserMsg *msg) { struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index]; @@ -611,7 +611,7 @@ translate_ring_addresses(struct virtio_net *dev, int vq_index) * This function then converts these to our address space. */ static int -vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) +vhost_user_set_vring_addr(struct virtio_net **pdev, struct VhostUserMsg *msg) { struct vhost_virtqueue *vq; struct vhost_vring_addr *addr = &msg->payload.addr; @@ -648,7 +648,7 @@ vhost_user_set_vring_addr(struct virtio_net **pdev, VhostUserMsg *msg) */ static int vhost_user_set_vring_base(struct virtio_net *dev, - VhostUserMsg *msg) + struct VhostUserMsg *msg) { dev->virtqueue[msg->payload.state.index]->last_used_idx = msg->payload.state.num; @@ -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, struct 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, struct 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, struct 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); @@ -1073,7 +1073,7 @@ free_zmbufs(struct vhost_virtqueue *vq) */ static int vhost_user_get_vring_base(struct virtio_net *dev, - VhostUserMsg *msg) + struct VhostUserMsg *msg) { struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index]; @@ -1126,7 +1126,7 @@ vhost_user_get_vring_base(struct virtio_net *dev, */ static int vhost_user_set_vring_enable(struct virtio_net *dev, - VhostUserMsg *msg) + struct VhostUserMsg *msg) { int enable = (int)msg->payload.state.num; int index = (int)msg->payload.state.index; @@ -1485,7 +1485,8 @@ send_vhost_slave_message(struct virtio_net *dev, struct VhostUserMsg *msg, * Allocate a queue pair if it hasn't been allocated yet */ static int -vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) +vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, + struct VhostUserMsg *msg) { uint16_t vring_idx; @@ -1818,9 +1819,9 @@ vhost_user_msg_handler(int vid, int fd) } static int process_slave_message_reply(struct virtio_net *dev, - const VhostUserMsg *msg) + const struct VhostUserMsg *msg) { - VhostUserMsg msg_reply; + struct VhostUserMsg msg_reply; int ret; if ((msg->flags & VHOST_USER_NEED_REPLY) == 0) From patchwork Mon Sep 24 20:17:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 147383 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1129601lji; Mon, 24 Sep 2018 13:17:16 -0700 (PDT) X-Google-Smtp-Source: ACcGV63SzsqeRUmOSu/4oBH3Ajx45kcEreTd2Hn6My1vgcoRVi3ur3etiri3QF/0GBD4XlG/p4OU X-Received: by 2002:a50:86f0:: with SMTP id 45-v6mr19055776edu.52.1537820236373; Mon, 24 Sep 2018 13:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537820236; cv=none; d=google.com; s=arc-20160816; b=ZRPK/MnwdIJVAFmCpRgBhzqVcmqXX2ew9ihi3eQTCWLOWmp794/Ln/jyazUIB2QlLZ BVpklsYZlRVfxCRVYscSol2X17Pe2S8g4zrUP5Or97vh34AMC/eJ7f3XxREZWFlApPpF oLsikVOtOrkLVXHyy2sjAoQUF6wd//4eKaUq9wWXj7NIhxhtX4FabO5X6MCdYzxJtwNW p+O9o3V0os8hM0MukaasjTCughQ6sutqBQkomCE3R1yp8XpyNDcsgBAd8OBZnzKLaFKS h/H0OdUj4MbGh5ft1RIduPoJs93ZjJ12Y93NL0LUHkwrisJAmK/BjLKobPqW+izwsxgj ldCQ== 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=KlqevEpVE/LgiA1Ie+DmN7/5IIg5yXavGQgJ7mPQScY=; b=a9fqhZvMHghecxs4iqLpAmSgF+9oeehcuKCNnrTrJgVVCt7s/nvndFp8cUr47i3T8u gY48ivMzYp8UqcfD8Rkx2YQvZYBghwyeQBAfWAePrwUMfrG5LgLtAmMQVhglDZ+2IClV slolUA2j+iLMKOgJ5vDxpjGbTQGQbsQmHdzyGLi0xpVxE0I4m5m3ZPkHLK/7BD1nAiss LccBZPXDshBlbQaohzoNwXL3QiheGqul2W4Pk5hLGBo1kkDuHHG0qvImtzINluyjRl85 EcvojctNq3G/ghDCjKuY2Np7NrChrLAsJptXjaVEXdUurv+E/52TiW2h6e/6RroI/Bo4 3ipw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=HD4C2xZs; 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 f46-v6si2547115edd.409.2018.09.24.13.17.16; Mon, 24 Sep 2018 13:17: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=HD4C2xZs; 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 D40731B192; Mon, 24 Sep 2018 22:17:15 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 4FF7E1B192 for ; Mon, 24 Sep 2018 22:17:14 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id q8-v6so11319949wmq.4 for ; Mon, 24 Sep 2018 13:17:14 -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=KlqevEpVE/LgiA1Ie+DmN7/5IIg5yXavGQgJ7mPQScY=; b=HD4C2xZsibUk+axWXQlouqRmPSbD6GFM+VpRTkvheaAeThlYExHiCloF8MDqqAr1ru +KgrQpM2PgvAZaufmzr6pL61xQMqgogn0BOquUvOtZlyrKXKwj3HMQ53J1MAsO4sxaQV p/j0RIfc0ofLJhHt1Pf6sZVAXeEEDOqS/yBMDZ/bRihFAWLwF5Qwv81vKJqPn960jz7Q Tnrr98w5BM8SZ62JSyouKjMutx3WM6Guclsx1QXmUMTas7EaEQ75ib+oLA7n8SNNWce1 zACdW33+xvgy8sq6eNCwa7AQsYBTqoTfU4aWYcWd2Mq4DJ8/Y6D+bLfI/jK0YY9C9j0p 7qCA== 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=KlqevEpVE/LgiA1Ie+DmN7/5IIg5yXavGQgJ7mPQScY=; b=H3sHTnke4XAEO5XJ8SmG0oZLo1vnrVkhl/nfeMhGmz77Ls5fqHkTtzibVdpSzN+RBp YRmIrfyqmA+j/ZzOAih50TZQfVT1G8rrg9OG+aaJ3iZWBeb/Q3DwWqL6naVU3/EYov4s K0fpMmUEUdJgtFWMlvfcuVDMr++mUM/0c241WRFiAYjgkxGcNMeIOu/AJwSFpyrAwMbH V5bKVuKt4cw/eK3oIe9HFt5haQeNwiEmyRorerZNOEtc4OaZLgSJhRw2Yb1tvEPh8S4p rR8+pWo4lRXvzorGj0vRUtnfu3hNK1miWmeXYTbmBEnVcPc6S6alBxiFZhUxMrMtMSgW A2og== X-Gm-Message-State: ABuFfogkO7nQkH3koIEgELWgPP2qQMKY1Ynmj8xrdBLERqa+vKbD4s9S hh3HGYqmmbvw3/+WOvSBqNBq0FcrgrYqeQ== X-Received: by 2002:a1c:1609:: with SMTP id 9-v6mr54404wmw.12.1537820233425; Mon, 24 Sep 2018 13:17:13 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id z80-v6sm511924wrb.1.2018.09.24.13.17.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 13:17:12 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, anatoly.burakov@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Mon, 24 Sep 2018 23:17:11 +0300 Message-ID: <153782023114.27450.13792732999240312966.stgit@T460> In-Reply-To: <153782013094.27450.17651924330876922486.stgit@T460> References: <153782013094.27450.17651924330876922486.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 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(-) Reviewed-by: Anatoly Burakov diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 505db3bfc..4ae7b9346 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, struct 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, struct 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, struct VhostUserMsg *msg) dev->log_base = dev->log_addr + off; dev->log_size = size; + msg->size = sizeof(msg->payload.u64); + return 0; } @@ -1658,8 +1670,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: @@ -1690,7 +1701,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: @@ -1712,7 +1722,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; @@ -1730,8 +1739,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 Mon Sep 24 20:17:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 147384 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1129708lji; Mon, 24 Sep 2018 13:17:23 -0700 (PDT) X-Google-Smtp-Source: ACcGV60zgokqTaZ/nIWLAUiJn4z3hqttFOlOp8/zq5dlc19hVFnldr1CpXrrG3IxSQ7sEXALEjgN X-Received: by 2002:adf:a708:: with SMTP id c8-v6mr350642wrd.56.1537820243850; Mon, 24 Sep 2018 13:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537820243; cv=none; d=google.com; s=arc-20160816; b=lgpReByvf9xhLlppIXZ7tf99V4Q/V4Au7ZbOX0rucKXoJeV/+98RmxeWLYCsEuetNx LDmQZhVN5GuafJpU/Xx0HvMHjHTxbedc8yzyVQoIN1a+4j6HXwHN04q+10bXZRNPyUyH z2+8EDoe/pGysuowKHxRt6TTHhr/un7ytIDlRcbVjnVukqwWdvnKoz7LlYFJZ6lItB89 mFtDZpLYCJwxYRQfHi8UUKC1JSioKpFyn9fzYAl2hxXcxob5E3u9n1rcUk7e5MXjdXBi A0kqVE/gdLu6tsduNRlg5Yg7TaTp1g5CUnX3uHbIaL4o8IV0cxHO3xh0jc/X8boC/T4A BFzg== 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=02phtoPLKMhvw1pfeICuDg0OkVyxO3opBE13Pyie90Y=; b=O4ga6LyTxJ4tcbyFPeMdd/jzHOvPTZ4K/kH8HEySz/zGzvsqYvaWQ6eoAcHWh4BR2E L6CzT+x7ModHFp1IVvP6TSkJPW54vpizHwSRaMV1PqTt9yA2Pn5o47U9OBs9jOiRwfyO 6fHr1E9OtED9d7+Q6USn0PdiFqFLl5e7RcPLPS855BKExqKu4jrE0C3RTr5AqTwMEYRv VJGFftoYB0KvBeDEboTbQ4HfifoeQhn638LhpZsCO/wywNVPZKtEmAW179JM+ap6x8Qk PrDYKYP0JUmVaGNScpT9nnrbPlORW8VjSlkgf3e4dYnykjBxML0kn0vBYRHfYHvQcELa N4ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=j9U9yDtt; 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 o14-v6si270073wrs.141.2018.09.24.13.17.23; Mon, 24 Sep 2018 13:17:23 -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=j9U9yDtt; 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 1EB091B19F; Mon, 24 Sep 2018 22:17:23 +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 5A13F1B194 for ; Mon, 24 Sep 2018 22:17:21 +0200 (CEST) Received: by mail-wr1-f68.google.com with SMTP id z14-v6so3491460wrs.10 for ; Mon, 24 Sep 2018 13:17:21 -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=02phtoPLKMhvw1pfeICuDg0OkVyxO3opBE13Pyie90Y=; b=j9U9yDttZjlEu/eMdQr0JLzw24AJOT2eqT0DNniDNDdgFjbUj4Y79xtvKWhqZ6DOgk 4PbQsraYqlqi7lwkNt11RERDaZGUbrLleBk5JArunzsolr1awhlMBVDtY7XSbp5FaP18 FrOlVIs20n8Vt4Ko7zxIAp8HH66GmbSD4oPObHdtg11Ra2LMhMn4MfKRlIUCq/sfA82M YrHcuXRxxNkrUdfvnorxhaPjre/fyi/t/9e3a065xpQUPjXCSGrLd4h+P51QOWRKtRUt MMwnFKmcerI9XqpG1sDWXNXKLvSMZU5pMeuMyhxo5DBO+VzqflvJPBVpr8HCThn3a2Go r+hQ== 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=02phtoPLKMhvw1pfeICuDg0OkVyxO3opBE13Pyie90Y=; b=FT+BF782gZ7Bh6XcGxJ0Ci2XYOyyGK9PpCQyz+dP57+l2CD3ujEM+5BA+AfrTUJ8VV dptJwSl8E11CAmbwWGRqydUTAoBvjmR5sNmZ29UEaoLklWp7SUx8O5VfNQdISBhzZTx9 ls/0FoCsKsFwzjteCd1xkNcu8PwjURJ9nBZ1V2CGxSd+ELa8tcQhm37v2FCY+YrzPiar gQuApxZ1nSOACTJFABA4nR3FSyZZF3ez+kV2GIjxm6RHQQcZfMw+3vPVGmGuIvNMhz9Q hsOZp+e1CldfOf7uK9gKohGpyFnGJRcqv4q/kdrUFaW/dh+GW1usgfuJMcb8rlvenrlQ HuAQ== X-Gm-Message-State: ABuFfojdLSsM/d5drehZUP12ZG37GKbQDefPJ97RNSm73HvIQtnukI70 6Ut4+SU0UulWyvj6d1O/zdXzEOPCUcWZzg== X-Received: by 2002:a5d:5248:: with SMTP id p8-v6mr344894wrv.198.1537820240798; Mon, 24 Sep 2018 13:17:20 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id j66-v6sm443681wrj.28.2018.09.24.13.17.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 13:17:19 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, anatoly.burakov@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Mon, 24 Sep 2018 23:17:18 +0300 Message-ID: <153782023810.27450.1072870890780678375.stgit@T460> In-Reply-To: <153782013094.27450.17651924330876922486.stgit@T460> References: <153782013094.27450.17651924330876922486.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 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: Anatoly Burakov diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 4ae7b9346..77905dda0 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, struct VhostUserMsg *msg) vq->callfd = file.fd; } +static void vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, + struct 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, struct VhostUserMsg *msg) { @@ -1259,6 +1267,13 @@ vhost_user_set_log_base(struct virtio_net *dev, struct VhostUserMsg *msg) return 0; } +static void vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused, + struct 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 @@ -1704,8 +1719,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: @@ -1733,9 +1747,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 Mon Sep 24 20:17:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 147385 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1129834lji; Mon, 24 Sep 2018 13:17:32 -0700 (PDT) X-Google-Smtp-Source: ACcGV60OIwMQcfsEnXJ0xnlcRSDX0hVGd+EaSxv/pwldRtC3dqDD84PY+/4LzsuycxBpqDWr6cbe X-Received: by 2002:a50:d54a:: with SMTP id f10-v6mr859264edj.151.1537820252192; Mon, 24 Sep 2018 13:17:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537820252; cv=none; d=google.com; s=arc-20160816; b=xlGWm8uVCaMp+TE+lMp45JQ3ji8FHu2N/HO3E4p5TrwWOsG3HcPFw+hYYmXPtUyhSM X+d83UwSkXPrRBS2xHK+OWe21ZgFHZpishsj52GKNnQv72Ysxmc3e3PJPbHko2IpZ+zt 948kRN22FStISWNFH6VkLLPCeRnPJfLRR6Z+S6fVj/vchHfjuUx/BD5ltnH4JRtCc808 PWKQhuZLkIGswLTy1A2breVJP0BJmWRM77ej9rFLlj0NjUzvhCz017FLd0enW+WYs1JJ 2zhgnl0XWb+pReFQxapo/kpzcCJatjskHvTTauwIJdrHLZ+J2lCF9oWd1dmDC4RjgzjI aEBQ== 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=XRyfiLGoxysYc9oToMoxmqk8stjCdt4k31mRy/vHTcU=; b=YCzN156U3fwdlVMNNEd1VuGPjo1HsGeJVWn9KX/SwdQ7Bwhd0TPAvcpl8N53rwm70z c49InpAXjM9LDY2sV1hlhcxa6XkHkroZtJSqZXU5vBksi4sT99+hufDJJWg+4PecMyD7 82IYCcykW29xeKWzf4MM3RoUx6UKIdsI+73+DpyGME+v44JJRMnRItX5K1hHXb4gkHtp wYyH4uBi39n0DTAraHPqRr9OtBvf64K2wAiJjodODdxLe486c22+lvJ6xW/akRz0PnMd vzeiE01nLIXfvvnysETY7qLu9xurgqPbB0bWLw4Phm/ufbcu+IqCmtUJDy+Gs8E9t7pq G8xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=quOPIyOd; 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 e12-v6si2632951eds.18.2018.09.24.13.17.31; Mon, 24 Sep 2018 13:17:32 -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=quOPIyOd; 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 3B8ED1B1AD; Mon, 24 Sep 2018 22:17:30 +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 B3C861B1C6 for ; Mon, 24 Sep 2018 22:17:28 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id u12-v6so20965711wrr.4 for ; Mon, 24 Sep 2018 13:17:28 -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=XRyfiLGoxysYc9oToMoxmqk8stjCdt4k31mRy/vHTcU=; b=quOPIyOd4viQiZdSk3jKwMuKW/htTQnef8DuheS/Vgr6ViuYT3NlVb8+eD5+8rGonR uDajBtyH0t70LXiDg7jGbPdmxhWclXvtgzWyg7qMWwfm45Z22SAQ+wzTqtcUcimeDMUD EBSTuVZ8IACaUJ+pN6S1No9BKtY2JnBvLvdczB6LovWHqUMqL6IDetZu4hBlPRRQ+vE4 em1n6hQdICYyuu7LSI3tIbahTr4Klc0Ba0CB0gmy0fyuwfyLmi9DMxwuQUABa7h+M8Cy dE7gbGEqYvboSkT+3Q11HWVUYeR2zSuFu46QUAZezCcXWZPbaP6sQyHbTiczAkbiBdz0 5dZw== 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=XRyfiLGoxysYc9oToMoxmqk8stjCdt4k31mRy/vHTcU=; b=Pe1NTEQMGioUoRjVL48HPPT/SURq8+DtrLN0yJ83+T8QAhzamTtJMziyQr4thNYzm9 sZVa6jBfBJVCTa9A3V3MMh++48X+iwM5gYw9FXoxchAq/G/qfL7YRDhBuM4/7318OGrx ciJP81HoNDEUmHZaxS/sKQhoOOTP6RpHVgwYLwRNIpra2AMZTm4C4IkIcr3fACm11/dm P7mEekR0FVDaBN6nrz1MsTRjPM7E2j8dSP8/zXyfQ/uA5bapQ8cnDmZ+w6nlrCGAmGBY rQhVv+7P4SeR3I2XOZNSXrWSCp9rc7xoRF/k8aPmziJ5Dg8ltPVLY0GfEg1/zuH9pYXM qK4Q== X-Gm-Message-State: ABuFfogQ41ayXj/2XIv9yHnFbVq2gcyuC+gwK7DOHsdT+77JgSon038X Uho0OMSKh5paCEHUq4Okcj/8/K6ToRb8yA== X-Received: by 2002:adf:e6c9:: with SMTP id y9-v6mr326376wrm.35.1537820248052; Mon, 24 Sep 2018 13:17:28 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id z13sm415040wrw.19.2018.09.24.13.17.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 13:17:27 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, anatoly.burakov@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Mon, 24 Sep 2018 23:17:25 +0300 Message-ID: <153782024547.27450.17763956133344046123.stgit@T460> In-Reply-To: <153782013094.27450.17651924330876922486.stgit@T460> References: <153782013094.27450.17651924330876922486.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 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 | 211 ++++++++++++++++++++++++----------------- 1 file changed, 125 insertions(+), 86 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 77905dda0..e1b705fa7 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, + struct 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, + struct 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, struct VhostUserMsg *msg) +static int +vhost_user_get_features(struct virtio_net **pdev, struct 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, struct 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, struct VhostUserMsg *msg) +static int +vhost_user_get_queue_num(struct virtio_net **pdev, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct VhostUserMsg *msg) +static int +vhost_user_set_vring_call(struct virtio_net **pdev, struct 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, struct VhostUserMsg *msg) close(vq->callfd); vq->callfd = file.fd; + + return VH_RESULT_OK; } -static void vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, +static int vhost_user_set_vring_err(struct virtio_net **pdev __rte_unused, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, struct 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, + struct 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, struct VhostUserMsg *msg) +vhost_user_set_log_base(struct virtio_net **pdev, struct 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, struct 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, struct 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, struct VhostUserMsg *msg) msg->size = sizeof(msg->payload.u64); - return 0; + return VH_RESULT_OK; } -static void vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused, +static int vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused, struct VhostUserMsg *msg) { close(msg->fds[0]); RTE_LOG(INFO, VHOST_CONFIG, "not implemented.\n"); + + return VH_RESULT_OK; } /* @@ -1283,8 +1319,9 @@ static void vhost_user_set_log_fd(struct virtio_net **pdev __rte_unused, * 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 **pdev, struct 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, struct 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, struct VhostUserMsg *msg) +vhost_user_net_set_mtu(struct virtio_net **pdev, struct 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, struct VhostUserMsg *msg) +vhost_user_set_req_fd(struct virtio_net **pdev, struct 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, struct 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, struct 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. */ @@ -1685,26 +1724,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: @@ -1712,28 +1751,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); @@ -1743,31 +1782,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 Mon Sep 24 20:17:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 147386 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1129988lji; Mon, 24 Sep 2018 13:17:44 -0700 (PDT) X-Google-Smtp-Source: ACcGV62d12/DHsEGkOEGQxLr+0bknpAaMR2E7I4FeE+iXFRXfRmJImlm7ppqSDDbQuhanzZwUpt3 X-Received: by 2002:a5d:6848:: with SMTP id o8-v6mr338380wrw.159.1537820264663; Mon, 24 Sep 2018 13:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537820264; cv=none; d=google.com; s=arc-20160816; b=RJvoLcVuvuWIbhH7UFpXkDa0O1tuE5rhObbfkUwdlBkQd2nYSn6+Mod2ybk3KcM9N0 884lhWHy9Qh7WHQYC3dVU8H2mqFy3Uuv5YY4HHUiPz0UOPHmaLD2Vglz5i1ksRYVQo4p AvZvmrfRjnYbhqD0BQeglPVbfAGwWTPAA2IikgRK57gyrdVGRIrVorXZTyuNuads34cF D2ICkOo0JXNKuFnkFU7aF+xBUWQzTrLe2iwUG8uyakKO3gnSi9ryNTT/ICeAQosKsOiA eT07qXbdi+KT7dVWXGQzPCbiuqcjIgTDCurK2DwKSLPy7Vd72yZLXx9fpZFNImm2X+hG IgBA== 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=6L6TFG9CJRyfCU1b2adXr4gdWYR/ITSHhhJH6E2O/OY=; b=WIbG5ZOVoL9tXX+1kLYWb78kHc9mYIuxlABEZ7hmDNgxKihHppIWz1pV8mPoqFLAIj Pqd3msjSCG7EBU4a4574eOUbhzakNfHebSkRJktn/5IsJIsl8p0HWHcjMfg+XzNZlCEN I72Rxu5GE3GGQLodk+EtXoHw1rsHa79Q9DGjCgi6lUfjdIBEWyA7itTW3kgA4ct2UUDQ ZoR/DCmuFOzsptFvBjc7XgqouBN89cOyydTmQoUVadV5xr/++HyUYHJO5yB+7bGmPwPC lldjVOpBRZrfB4tBX5FH4zrxdQMYOEp89r3vOG902a6MvChuXzm4NQoM3XVHWNa7PQJB 70Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="jBJ3e/7s"; 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 18-v6si48138wmv.27.2018.09.24.13.17.44; Mon, 24 Sep 2018 13:17:44 -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="jBJ3e/7s"; 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 5E4A01B1DA; Mon, 24 Sep 2018 22:17:38 +0200 (CEST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by dpdk.org (Postfix) with ESMTP id 27BA91B1D6 for ; Mon, 24 Sep 2018 22:17:36 +0200 (CEST) Received: by mail-wm1-f67.google.com with SMTP id r1-v6so10803101wmh.0 for ; Mon, 24 Sep 2018 13:17: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=6L6TFG9CJRyfCU1b2adXr4gdWYR/ITSHhhJH6E2O/OY=; b=jBJ3e/7sC8cxiCc19ooy+/YBGnNNn0HafYE3N0g8IsQE8nRCzPIGeOYzKIjcl4Z5aj w3qD/ksx90qNHG1Y7Ctcg262yO3a0JxQZ9jMqCkO8dHDOogKVRwSVPEPzKVyTs3/roYj lnwfH6+fkI8/ygsfbZGh9o+l0J+kSLNo4hmwCI0V6uWXP9CEmYnd7geoUKVhZlmwuz3d zMDdcGb7k0CyHLXndrQkPt/nbpOBnm+eSzQHdz+OvilyvV4PGiFDkHRPgpvG3N5FfQ+G 5gkuy8pcV9IvzSokA+CroKJ1IXTHULE5jpS/RrALwnNAv2G4XfFWKzYGBuC6MggxNEUX ZOWQ== 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=6L6TFG9CJRyfCU1b2adXr4gdWYR/ITSHhhJH6E2O/OY=; b=DQSHnHQZzdz7RRVbK4vlDMhJPyT4kRSC6gtCk/1Is7xqXrOuwpNTWWdEF2qOJbG403 Qh31TTO8dXk4lTlZ2wz/yhGcxIqEPmcH8JipNevLFERM2Ar+E2BjmGt/1WtKJIy+8/Cf Vw76Ff//wf4uxVyvoMbKKDMUP3ozQ0GbrrD7SI0xDl9RWZaCR7cbFr7ES7rjMB0Mkd/p ncKLyZqQ8KJho8k+pUJiJAApSSL2QXUPP5XPjTDNQUJc8PFPwxUEQOsn955capnp8s// o8Y9avgTCuepQ5ntT6WO3lsDHfAg+F8LkXA2urrIYIvtRsPJhMugZYBNXu2JD8mKTk0r d9eg== X-Gm-Message-State: ABuFfog1Bzujyzi+5Aq0Axov3ZwwT0BUEiow1ocgEJ+Tex7dJ4VaxWyt ghfQPHGPD+eCvzCQCgJJnXnU9cjJFFqvRg== X-Received: by 2002:a1c:1748:: with SMTP id 69-v6mr24907wmx.75.1537820255544; Mon, 24 Sep 2018 13:17:35 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id j20-v6sm30535wmh.9.2018.09.24.13.17.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Sep 2018 13:17:34 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, anatoly.burakov@intel.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Mon, 24 Sep 2018 23:17:32 +0300 Message-ID: <153782025279.27450.1954681982875165882.stgit@T460> In-Reply-To: <153782013094.27450.17651924330876922486.stgit@T460> References: <153782013094.27450.17651924330876922486.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v6 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 | 150 ++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 93 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index e1b705fa7..f6ce8e092 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1477,6 +1477,35 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg) return VH_RESULT_OK; } +typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, + struct 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, struct VhostUserMsg *msg) @@ -1630,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) @@ -1722,100 +1752,34 @@ 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_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: