From patchwork Tue Jun 26 16:19:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 140005 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5441109lji; Tue, 26 Jun 2018 09:19:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcOKsRtvj6mZU/NKSfOhAGsP46ihbxYyGAZVkRNz5EvVAkPk70i8e+0oTRBCVN2BHSnwQcn X-Received: by 2002:a1c:1983:: with SMTP id 125-v6mr1914811wmz.79.1530029953853; Tue, 26 Jun 2018 09:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029953; cv=none; d=google.com; s=arc-20160816; b=C89OMWEd0LXa8kP2c0/FY3MFK+QHujgYYRr2ZyegwQiZ1MEpoKpdh6e9UDauH2NcLV nIZojF0c2SAXRoSMiYSXJktKytmbMZNTfwy2oh25yC8HfTDhyiQVDV3jJX3qJFVCNDJt AHtDc9I36JQfVy3KF+RkJx1itEXHH7s4ZhYMEgpeVpV8rojfhaVidmy3wJ6so5DnjVx3 nwHlEQFv17HdUOZYFBU2QsV26BMqS0so+/PoDK0wThZOdHUtzmCYDHLkeQdsoivUGy1b CPwkdyp4XqxB1qmB/V6Jlnqy/taFMjrHeZ7YUc7uHGAbcg1lTT479r/shlCnBeYmlTGE CHcQ== 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=S2hfINd+0OaSELPa37VybVZgVCvJixS7nuHCjLSxeu0=; b=PSXuw38UTj2Se+hFr0NTUmaA9clWYrfh9yQLIAKsbBXTIbM3Dg37YKg+z0QSDDEw5F 6PP0Q7tRgo7rpWM9MEsX1o4qjwzI4fNypSRUmjNGjXo164bmLfA0KaOWvre3lNGhuEK+ 8US1rlouBM62b6aI/lGzQG5ZYaba0zUCgA2DkRDJKTuyJSwthVrxiFB1n3qYjuz1u8oB JYg77Oy6gyQ96x8FLjtrc0Me3tk6U+KzL4QXjQ6DrOyUw1ySXZdW0S8HLWKvyulsGf8C YWeJ08EJFJlYeAbkhAKDwl+dW5MEEaTPoy1lO5iphVDaW4YFAlUWaDDaTGtGJ6EPhe7s gPGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=kLPAF0QH; 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 b6-v6si1750839wrm.331.2018.06.26.09.19.13; Tue, 26 Jun 2018 09:19:13 -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=kLPAF0QH; 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 3BEDF1BB09; Tue, 26 Jun 2018 18:19:13 +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 A92371B60B for ; Tue, 26 Jun 2018 18:19:12 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id z137-v6so2497608wmc.0 for ; Tue, 26 Jun 2018 09:19:12 -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=S2hfINd+0OaSELPa37VybVZgVCvJixS7nuHCjLSxeu0=; b=kLPAF0QHAl0hw1We6jRuoBoMUl2LlyrnsiF5EJOMvTP1kiZIZJdYKYQDR4C1eQutBY INd35IFERthUgB3G3i+oXHyc4F/RDEV7GjZDqkKRqSQxx7Sk1qbq2qaHvsy4vfg3mnSQ tmxDC5zUzzfR0LYV8ouA/I+Kr0fbybtpt6T95E1Mc3F2vA2jET21frAV3FiJAfo72hZt 1cZzCOyM+X6SWs7m+Yc2fprFo3pbAQqvX+laUpeYQP/i646IfqJ3Pfdu4p+3urnnqYpA W53EYg6fU++YTooa5Nl7TObUfv3MgHoKC6U2NpT7mzSq9aBFS6nqAl5SrE8+s0+whxmq y5TA== 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=S2hfINd+0OaSELPa37VybVZgVCvJixS7nuHCjLSxeu0=; b=UqVXN/Gs6+TuG+K4yO3rPJexx87Dml3hyjPEZmwHde18J4PVm2EkJQQwv3LbepzXQz uOLyeu1ekkE3+dDZTfZRjuqLkdywqztmbpC6XhIIHGlEz0ahCreyM555G5NmQmrFR58W lr3S2RVggIyk3tJebljtsYNesFpu6cVyl9Cvb0Z94oqS2jo2jLXf1yUa05tetLu09X/d gQ3fX4OiDBVtifC+Lk2CjdD/HnGUvbyBs2LDGdeYeKyhzEsVUn3MfxxJ58+yPJVA9ZZO zy5QyuDXFAVheygtt7xovY3b5t2g9mM49C7wG/jLGL95TyjdtkO+N4hhjIV7ipqnYU44 vdnw== X-Gm-Message-State: APt69E0zO8PTxHXOR44+ZfxH3osiLGUwmyUJ3ALHxx0ump1Ozc81T6t3 UOZ4fh+O7Q6eESM9RfVcE1oIy6cq X-Received: by 2002:a1c:8312:: with SMTP id f18-v6mr2231801wmd.127.1530029951942; Tue, 26 Jun 2018 09:19:11 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id x5-v6sm2617425wrr.3.2018.06.26.09.19.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:19:11 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Tue, 26 Jun 2018 19:19:09 +0300 Message-ID: <153002994991.22089.16713275746085839135.stgit@T460> In-Reply-To: <153002988259.22089.8523468795459281187.stgit@T460> References: <153002988259.22089.8523468795459281187.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 1/5] vhost: unify VhostUserMsg usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Use the typedef version of struct VhostUserMsg. Also unify the related parameter name. Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 50 +++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 26cfebec0..9b5598871 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -706,10 +706,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; @@ -730,7 +730,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; } @@ -766,7 +766,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; @@ -905,16 +905,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); @@ -926,17 +926,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); @@ -1058,7 +1058,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; @@ -1089,7 +1089,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; @@ -1156,7 +1156,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; @@ -1185,7 +1185,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) { @@ -1201,7 +1201,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]; @@ -1267,7 +1267,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; @@ -1313,7 +1313,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; @@ -1342,7 +1342,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; @@ -1352,7 +1352,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; @@ -1366,7 +1366,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; @@ -1457,7 +1457,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; @@ -1745,7 +1745,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), @@ -1775,7 +1775,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 Tue Jun 26 16:19:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 140006 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5441295lji; Tue, 26 Jun 2018 09:19:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfThfcF3W9GBDdEbHgzU8vndVzxTcnx2UTCZrrQXesC820FJl5mlvUz5pa2ntUIDB4xANk8 X-Received: by 2002:a1c:8cc8:: with SMTP id o191-v6mr2193081wmd.75.1530029963369; Tue, 26 Jun 2018 09:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029963; cv=none; d=google.com; s=arc-20160816; b=TTK2QwGTzsfyJ18UQweu9Y2dh6zSBRCyl6ZfxMs9VcGR76UaWtNzovG4ID0BlqJLJ4 SuKvTno5S24PN2JGORVL+pm67qWNYxjZY5qN+o6hvKHaUGzOG3S5Ejc0dnThfir47cPy NAIhH95jRszB2zMNQXTsmqV6vDuEyTyMC4hGfW8/F+3mQoL9ca/ebZNSGMMU+hE4GiWy /197YbFxb6wObd7wieGmGUR8eb2JS4yBObRLb7DCIzzx/GVTwb5JI4LwNtYDh5YVNQ5K Q3Nwwgqlcnu7k9zEweO3eoRfoGKgYE9Tc0i0n03/E+/bHUp9zyldP1IuOPO8wPehuYCt gQfw== 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=of+2Ji+OknmxObvfuCoPCYZwA7RB2jj3EFPLZN0ePgY=; b=JOHGQnzGsXN+ESCh9orlfpgQNeij+/iDda1AEWhldYtUsH79nlr1b8GRzmkvraicpa VookzELwBOhcqoAdsaDczrRXltWbIqviiDz0Yc4p8rvN+0CJSF1rkWbhqVPZpALch2mE eup84r+50PUQ0TL7fnvfe0n8tzaV2ByJjXANYGJ4b9DV0KQruI3NI2UvkDTTYL00qyoH O3yTo8/S7xCXyT0I74JNLrzSw9pQsieEQvoagFgeljMt7k4TU/k2p82cpJPTZqk3yOzh oIJRdf0KsGqxf1syiIDQTqA74FB8wsI8yT2lCBiAUrOJQAIDO9Ks6rUjrWfho7C8hNIQ 00Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=O3w0fyCJ; 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 k82-v6si1335425wmh.214.2018.06.26.09.19.23; Tue, 26 Jun 2018 09:19: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=O3w0fyCJ; 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 0D5071BB37; Tue, 26 Jun 2018 18:19:21 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 4C52D1B901 for ; Tue, 26 Jun 2018 18:19:19 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id u18-v6so2488102wmc.1 for ; Tue, 26 Jun 2018 09:19:19 -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=of+2Ji+OknmxObvfuCoPCYZwA7RB2jj3EFPLZN0ePgY=; b=O3w0fyCJYfuoPcBK+lvvzV5iDsB4B7SgkJcuKmKQ6AD/JZVWznDwHnHt53FzbC4EK+ OCZAOZFiMvx1FFGcJlXCJIsuahosidneRk5bUZskW1aJseg4QoYZ1MtkX4U1K26ll/+i r5XiiOW05xJE9qIC2YgRJ11xC0bApqOwtubUlwSDPeqBofFBWBLRl3HmqnZwI4ZJUkXI oTM4MG3qlcu4f032mgpEH2/kviHswf3Dzu8LEFrim8mdkUQRnW5POO6nUQEkyIUFDQwK RsFSYa/5uXvmXjA+7H2+4Bsikb7m1Y/uriJJFPJ95rIjKXrmykDyul+zvBr9QCrkYrx8 OFKw== 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=of+2Ji+OknmxObvfuCoPCYZwA7RB2jj3EFPLZN0ePgY=; b=Bkkvyvh/8H4jaylGeilOpScxHZQcuR2GA1UpV3Sp47cSbTqsEvAUtIRe5xfq6DWQ4l Yz1/ICqCJ5y0PsCuwqjMe0SiHEretDE6/q7ZYAhC2xj0qqVDTrURMxfGaQbtXutcWxHh MJ+ZQH3klVXeqzG4TtQr+eBRCxl4PMntjkJH2tn2rg6NJEP975Exo/z+oNKGXO0Fg6Xx gI9P2nQwvh/3KFauzL28IkCmKQ3gMuwNyLBJ9Jz+PJ8p92NwJbPHcc6OS9aDiduC8TDs UlEhEmJXQXHsFD51IJIAvRKHuayNKvvmPQfcACuz6ALV+95NgO6x4Fps4kCwi7AAbhYw ja8A== X-Gm-Message-State: APt69E3oVMNxFIIfYEc5tCkjvTmFNEBnsGAa4C3DOJUJPnLJSMVJS211 Uy7ti7vzJeJgUkEsVyhc6A3X0Qme X-Received: by 2002:a1c:6b56:: with SMTP id g83-v6mr2191407wmc.143.1530029958757; Tue, 26 Jun 2018 09:19:18 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id n10-v6sm2973138wrs.64.2018.06.26.09.19.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:19:18 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Tue, 26 Jun 2018 19:19:17 +0300 Message-ID: <153002995700.22089.6499516015793208840.stgit@T460> In-Reply-To: <153002988259.22089.8523468795459281187.stgit@T460> References: <153002988259.22089.8523468795459281187.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 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(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 9b5598871..1bc3d1629 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; } @@ -1022,6 +1030,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; } @@ -1144,6 +1154,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; } @@ -1557,8 +1569,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: @@ -1588,9 +1599,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: @@ -1610,7 +1618,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; @@ -1628,8 +1635,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 Tue Jun 26 16:19:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 140007 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5441479lji; Tue, 26 Jun 2018 09:19:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeJuYgR2kAcbHaaUjurM+d201ZgjUXOutzYnMZRq5qo/vwko+ROci/KH0gn3gzBK4ZDv8eD X-Received: by 2002:adf:992d:: with SMTP id x42-v6mr2068839wrb.81.1530029975361; Tue, 26 Jun 2018 09:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029975; cv=none; d=google.com; s=arc-20160816; b=vhAlXLQMljy2sS+cI2TNApKsqALi/pn/5urMgt35SoOxMU+y3zFFbXSx+CnoPeBYR0 eFW/G544e3rvCKGx1+/kmqhuvKuKmGE0i4Mcjbb9IHSE053R+JFtGVBjY+fLb/kq0K13 GkDvxS2TAFoAcpBcaMfg+IFiqVtvLPB6ieOZA12VT7fVfy+4Xn0aAPNY0kcP2akZ+nQ/ W6P5NNVeOZmtLazPHsku2BnK3glsTtAFHE13wo/65DG9Lxw621W9eWGeyVMx4HROxwcS VwZbUeTrtz2JYcYXhjo5ISdLJq5DWRlinb2YJuZO6Yo3bQ+mQCfDUxa0X2CnGemb6tm2 cgBw== 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=WzeEikkS80TprZ9F+UfoT9sblGO6MIMj3Pz5V7Hryus=; b=kt3BsXe3rYiwEFJMvLMrmxR+rYjIfZSIQew7RxthuCawl5c0OZUPER3wH72XyppcEh FMKDfS1oIfvwThnHLFD8qej13+IRHD2nS2wDmoa7xUgSHk4ekCfH2d9dkUjvYbWiIloF ZAqsukvvHpQ45MAkuNxWiONNVPcw/rBJ6lUhgAfRZzHSlr1NFUpBTEgHOvKZd1JWQONN nssNLTufpEFWwWAb3BSKbq/B2rlZHYNtAP0XWm2SAhJssHJEsnH7nZdgtgSex2P6nEz1 fChVca41fZInveWL+WAYhaSPa8raPEr0EBhzCOOryME2MV5iU3xT06DXDMFKWOog7r+4 h+kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=rTf7SoH9; 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 6-v6si2158337wmv.67.2018.06.26.09.19.35; Tue, 26 Jun 2018 09:19:35 -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=rTf7SoH9; 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 7E0A21BB40; Tue, 26 Jun 2018 18:19:27 +0200 (CEST) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id 9F4751BB32 for ; Tue, 26 Jun 2018 18:19:26 +0200 (CEST) Received: by mail-wr0-f194.google.com with SMTP id p1-v6so2269206wrs.9 for ; Tue, 26 Jun 2018 09:19:26 -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=WzeEikkS80TprZ9F+UfoT9sblGO6MIMj3Pz5V7Hryus=; b=rTf7SoH9QjMX/APEoHL7n41c//E53bcM/5W+bl5mGIg76yBmwX0HpXJrkoLT6lP7JE A4XdKxGdvfYXEeZNFTwOXpLrS3Ezaj5FXGn2c0kHAjSoekNrrdO4SpC1OY3EagGJ0sfM kCJMMjRxJDCrkT4duZxVVH08a6eJJxv3qLl+VNOJk28Jhyq53RVEjXwkHNk+BkEeNzX5 iMvVF9Nj1qEj22BiLd754dZROjDmEm8BN6A7W3UymyyuPQuF7CZVrghSXfQzHryZFYD5 WwfBeVx1q/VDrLmPMnj2HoEePKj4ZWoAZlw7Tmsj12abd0q0oTsibByP3RO+uDFfmnLQ bCZA== 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=WzeEikkS80TprZ9F+UfoT9sblGO6MIMj3Pz5V7Hryus=; b=mB+admVMrW2l/rXuINzUg/uMYl/S5pFQiqC/9dmSBdW9jeaVPK28C6NZPt9IAPz9o5 3M0qKF2MWydNFYgUoI6lXLl7oWd77goGmPVFzLOjzkf2UwkRp8Z6RCYh532/EDDo4Bsi pOE3ZBvCbxR4KM7Hcd+e+qX4UA/49J+uEqgFyW1lrpW6v7MJnSswgceQzMwEYyLg6WVY plXRhY7zfws3AyoBav8361SaQrKvYcyNg/q4DZyf+MIICSz8QA1aj5f9Wl0vqCsPADtb d+cCBqD4HyWxbIPRmoX7OdhuZXzTdfegzhew1M4S3n2H6EDFdBkyZ9OlDKGweS/pPi4y IuDQ== X-Gm-Message-State: APt69E1Uky5++rarti4GFuXHPIZnY5RjzkH3Q5nUtG8qFuVuaEAkSjMn div5f/aPxVvJskLib5k/RyvUZwNW X-Received: by 2002:adf:87f1:: with SMTP id c46-v6mr2076265wrc.246.1530029966093; Tue, 26 Jun 2018 09:19:26 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id q70-v6sm2859618wmd.45.2018.06.26.09.19.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:19:25 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Tue, 26 Jun 2018 19:19:23 +0300 Message-ID: <153002996384.22089.7999103657201130704.stgit@T460> In-Reply-To: <153002988259.22089.8523468795459281187.stgit@T460> References: <153002988259.22089.8523468795459281187.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 3/5] vhost: handle unsupported message types in functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add new functions to handle the unsupported vhost message types: - vhost_user_set_vring_err - vhost_user_set_log_fd Signed-off-by: Nikolay Nikolaev --- lib/librte_vhost/vhost_user.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 1bc3d1629..d999c80ed 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -933,6 +933,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) { @@ -1159,6 +1167,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 @@ -1602,8 +1617,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: @@ -1629,9 +1643,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 Tue Jun 26 16:19:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 140008 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5441682lji; Tue, 26 Jun 2018 09:19:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdQtonug3PZbzAgvgNDKFru8uMKOKJfhzeiEOPTc25Qmb1o+/snVoEww2tsXCNQRAFHeHnT X-Received: by 2002:a1c:8410:: with SMTP id g16-v6mr2175125wmd.26.1530029986406; Tue, 26 Jun 2018 09:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029986; cv=none; d=google.com; s=arc-20160816; b=xUhBKEHCVBboILbNI/aMYoe+Xoy8k6Xu08B7A2Mb+I9aV1FpgPl2ndKzD2FJZxk9je Vkg+MvLLoWno2IQ05TDoJ6ebo/56QlTox8BKmi2b/IhhS0skuNqGr9ESzPMmVbBxGee1 NTgh2KiJsOUjnPMJQrdfTT+9GmnYq/nCluAnUlk07O9PFIAzwwnh8pGSKwzrd/xha23Y ZUakii0dOfDhSSIF83RKJNDSqkZMorOhHrjcWAP2E9Q4wyw+FK1S6mB/lspkF7nfDGhb obyHtSP6hIHqZefgxSfWTt9J9CYWFtqjuNRybyvRdxdyHucPn6HRYvFaO8BkVNxS+3JU l/qg== 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=2/Q+KCq8Y+0J4uCKiF8BZJgg2rZiU7VnNRV4rS167Kg=; b=AJCRsuhATiMAL+PVzqwC6EYu6L7UHBkU0Us38plzAJym+FmywVpaIT1ZVGsKpaaoe4 NH7ucY4zkiitb+69TLCeAzB/K/qyjXu0JipyHQm/DQtrt+ZapsDxXTAifeSQ/hPtlajb OoRQN+l819mRe6JxYRqJgqfwAXL3IrH300BwExvJI5/QEZULLrL2haUfCuL2/MBJKh02 Vf9ljFJ57rMfJP3PB8SGM3tOWpXz7WKqwuy8H2OQYqiTKkuaL1MZv9xmdMf4wnDHdd60 Up8vE/vglwcr6Qm5x2whI8x6JV1Hr4vkputOp5u1Qt4efHxWIyngD0EFIkQ0ySJSdjW2 hmMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=EyPNqFuu; 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 6-v6si2158649wmv.67.2018.06.26.09.19.46; Tue, 26 Jun 2018 09:19:46 -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=EyPNqFuu; 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 321791BB7F; Tue, 26 Jun 2018 18:19:35 +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 EF6831BB7A for ; Tue, 26 Jun 2018 18:19:33 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id e16-v6so2633949wmd.0 for ; Tue, 26 Jun 2018 09:19:33 -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=2/Q+KCq8Y+0J4uCKiF8BZJgg2rZiU7VnNRV4rS167Kg=; b=EyPNqFuulhXozjayjKbSWEAh9nWNPfwPJaRC5b9ujiTDIcBS6fTj/Y7TC9fkysnwRz u7ZS15WBOlTWsGGsngp5CSWQFyYRYc6c5l3r8795orNo0vkeWdrwTrlL5jq4nqWRZ4Pu VFY79erZIgGsOgAKngA+VHDi8GB/gOcPXKiL1aA89XoZ2wFky0y+YHCdz6RZr8I9NRTA zCedvBl9Lkekjn1218bCTvVj6ChAzX0CSQq00BF7TeKE9qdKmOqcGfBawtav/YbhZnvg S5wiGMeR4ldOTLwPCNHTBSk1iHg013uG61YR0f2sexsyLYkXfz6LfpA9vzuR65P0l6wB 5Wlg== 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=2/Q+KCq8Y+0J4uCKiF8BZJgg2rZiU7VnNRV4rS167Kg=; b=EAfSK7NUWfzr08aw4YfTBZX/LszzUOeZLTRKk5ppKZnjwiMzvsiRnCSx1icBCkhvak e1zuFywtq1RnHuKm2yZ27v+s18kSq8CO3d9r72c2tkuWwIiX1BulmZbjTbLHIWNv00wq ZWQNQXVXIkMn152B3wHyyy75WFwKX2Eq02xCTVZV4D+OB9jCCwpg8uPRk46A4iIX4BjG T8/ph1wMh4xiztcHipkQpeCsA6gnIAqOQMGEOVfZSQJYrHBH1quO4ihv0rtbsrZaKsNZ PXCxtpSZydR7LSXHT84X6xi//LPSBqpEBXmkdRrIPekr8GQHM35YH5FxzX/KCqQ08Mlr qFpQ== X-Gm-Message-State: APt69E2ny3/S/pvf1eiEQxscKNQOx7E5pcHF5Yi3MJekQUxXRIFL+gpM ZZsNO5IR1RK/efgWnMYuuibFvF9c X-Received: by 2002:a1c:d004:: with SMTP id h4-v6mr2116043wmg.151.1530029973145; Tue, 26 Jun 2018 09:19:33 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id r15-v6sm2228097wro.21.2018.06.26.09.19.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:19:32 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Tue, 26 Jun 2018 19:19:31 +0300 Message-ID: <153002997115.22089.11268165694203279446.stgit@T460> In-Reply-To: <153002988259.22089.8523468795459281187.stgit@T460> References: <153002988259.22089.8523468795459281187.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 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 handlign 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 | 217 ++++++++++++++++++++++++----------------- 1 file changed, 129 insertions(+), 88 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index d999c80ed..dd47d84c7 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 handlig failed */ + VH_RESULT_ERR = -1, + /* Message handlig successful */ + VH_RESULT_OK = 0, + /* Message handlig 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) { @@ -296,7 +314,7 @@ vhost_user_set_vring_num(struct virtio_net *dev, if (!vq->shadow_used_ring) { RTE_LOG(ERR, VHOST_CONFIG, "failed to allocate memory for shadow used ring.\n"); - return -1; + return VH_RESULT_ERR; } vq->batch_copy_elems = rte_malloc(NULL, @@ -305,10 +323,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; } /* @@ -547,12 +565,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]; @@ -569,27 +587,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 @@ -730,7 +749,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)) { @@ -740,7 +759,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) { @@ -759,7 +778,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; } } @@ -769,7 +788,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; @@ -866,7 +885,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; } @@ -874,13 +893,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 int @@ -912,9 +931,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; @@ -931,22 +951,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) @@ -959,7 +983,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; @@ -976,6 +1000,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 @@ -998,9 +1024,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. */ @@ -1040,7 +1067,7 @@ vhost_user_get_vring_base(struct virtio_net *dev, msg->size = sizeof(msg->payload.state); - return 0; + return VH_RESULT_OK; } /* @@ -1048,9 +1075,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; @@ -1071,13 +1099,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); @@ -1094,35 +1123,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; @@ -1133,7 +1169,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, @@ -1148,7 +1184,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; } /* @@ -1164,14 +1200,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; } /* @@ -1183,8 +1221,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; @@ -1208,40 +1247,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 @@ -1306,7 +1347,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]; @@ -1332,10 +1373,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. */ @@ -1584,28 +1625,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: @@ -1613,57 +1654,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 Tue Jun 26 16:19:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 140009 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp5441901lji; Tue, 26 Jun 2018 09:19:58 -0700 (PDT) X-Google-Smtp-Source: AAOMgpecmjg1RKccfEZvONcNaf9yPpWDzMvyUgrJBJtshN7wvSh75C/2Um8LuOMVPhywseDsYDtJ X-Received: by 2002:a1c:b54a:: with SMTP id e71-v6mr2210891wmf.154.1530029997952; Tue, 26 Jun 2018 09:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530029997; cv=none; d=google.com; s=arc-20160816; b=F5KscZBwhvwLI1aVE6r2grRP/PPCZv3jCFevciIxRBUAF5Eo1leJ0HvvG2D8LkQtSC 2xOjNnJ+DxReQeItqH5utaMB/cSxGgFicp3oBty/1PEuT3Ib7qbuSf/J+dcRlMNK0NlR fSBpjKlfv98I2eod0q1hGsC9iCY7qJgevJ9NeyNtx6lV5xBc7kewfZ+dpTM0evOWRwEh x9ZFIJkuqySGMAnutvmZvmyrRbP+LWAWpV00NHHeq4jNAaCjFRhXASVPqlfYXS0wleV1 pOKy3OdA4l3K2DmLfHnk1eL3VqPUcs2lpvoHaH6w3iES35YCPcVvReYJl6iN9l+S8WEX 3e+w== 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=DeHYl6S+qE/deqeKTsfPvmsfGNhx2ikapv2wcW5uuvQ=; b=YnFVgNd9IH51nW9rp5K5plYY6F8+qq+nPEdXT8kUDp/JvLLwyX1Hut2xSdtr+lgZCH uEVusymzn6Enmlti53xWKh2/8nXiLQfVUplGqV5nL85qlcmNld9/bsBWEENNZIbE2EFD DfKw3eUNCb95Dx94vBKc+QzKLAj3wrH7cRrtKKAB97PCQv9TvnLQty41Uw6Ru5xMw0sY GkCsGhVVNVA8ulzdeZE9+EJdeyIou3TjMn4KNohbqVec1nuxbfnWwMCANF++ZvBF8Kz8 nTZ2ZKe3U37mZXDqEgqbrqa07mvGlYMZ9rR5cu+nM4XNvnt/2mfxYu+YC+hnwT7JiLHI 5FTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="cuX/DrAM"; 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 w82-v6si2149022wme.183.2018.06.26.09.19.57; Tue, 26 Jun 2018 09:19:57 -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="cuX/DrAM"; 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 019BB4C97; Tue, 26 Jun 2018 18:19:42 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id B1F391BB92 for ; Tue, 26 Jun 2018 18:19:40 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id p12-v6so16224645wrn.11 for ; Tue, 26 Jun 2018 09:19:40 -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=DeHYl6S+qE/deqeKTsfPvmsfGNhx2ikapv2wcW5uuvQ=; b=cuX/DrAMiAuETJTy89+IJpeTHqvXD+mdtCmEoHytw2iNqfqBmHYWbV3mI/iKX02J4a N/0IuNEmfRSJ3DUxAJ/5z/APoYIhjYK0J5WqRF7Uh0FX3iJpiiz0xNIT/wTrwhYw41ja XYuyV1L6GGNHz7b6gLRw24REk0oxCpwrTDyfUiH5my05VfC/tg1eCif4G6LFJQTUUweE ZFCaZFELsq42CGXx1PnA4NFJzKNZje9TVN5U1PJhHvcMQEvMLpjKBiC5dWF7Kh8slRA9 QPTGuJvEyjvU+TKtmobJyKPwqR5TYiSDyJMS23WRoOclJ7dr5A8DC+iIuLmH+1RXAUC4 6WJw== 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=DeHYl6S+qE/deqeKTsfPvmsfGNhx2ikapv2wcW5uuvQ=; b=ihIQMnUdU0EkrTSrsgBy7+NaVZO5edJ9IQNs2QP8PtUNfmcbDVpkwd9X1oLOL2pgXj 2yIlwFPLOGpPaQ17k8kEj0xsvpQCGroXSkv8Uh1BnK3wcp0JUU87kZUVv1QPh+Zn3IK6 OZ7dp8IajuOzgGJlZcYhK8i7OyHVCVVnCBULiSPsSTLNXU8FalnpsebuxWpXQ6JBh3KU UxwoOm6BRDk8wbG9K/acQlOFsIl92uacF+5fZ2gAZvidv6f1V+9fr4yywpU10ucQUdMm 91ul9mvL+M4fZe4xQia9G7MTLxsSVIZRj8xuC3A5dT2ywe/B2DoHd1gHC3rVg7Z95qkI k8cQ== X-Gm-Message-State: APt69E3/jT+xtrFyCZBT7wxedU2UxOKbFsfQpJk2ftWnnZc1s69sYeVp fznZLSoAkXMGmm4OoYl9/of2bKiS X-Received: by 2002:adf:8446:: with SMTP id 64-v6mr2207082wrf.138.1530029980092; Tue, 26 Jun 2018 09:19:40 -0700 (PDT) Received: from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id w67-v6sm2687951wmw.0.2018.06.26.09.19.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:19:39 -0700 (PDT) From: Nikolay Nikolaev To: maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com Cc: dev@dpdk.org Date: Tue, 26 Jun 2018 19:19:38 +0300 Message-ID: <153002997827.22089.15583649737397622971.stgit@T460> In-Reply-To: <153002988259.22089.8523468795459281187.stgit@T460> References: <153002988259.22089.8523468795459281187.stgit@T460> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v1 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 | 144 ++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 89 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index dd47d84c7..e62164d63 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -1379,6 +1379,36 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, VhostUserMsg *msg) return VH_RESULT_OK; } +typedef int (*message_handler)(struct virtio_net **pdev, VhostUserMsg * msg); +static message_handler 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, + [VHOST_USER_CRYPTO_CREATE_SESS] = NULL, + [VHOST_USER_CRYPTO_CLOSE_SESS] = NULL, +}; + + /* return bytes# of read on success or negative val on failure. */ static int read_vhost_message(int sockfd, VhostUserMsg *msg) @@ -1623,97 +1653,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; + int request = msg.request.master; + if (vhost_message_handlers[request]) { + ret = vhost_message_handlers[request](&dev, &msg); - 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; - - default: - ret = -1; - break; + switch (ret) { + case VH_RESULT_ERR: + RTE_LOG(ERR, VHOST_CONFIG, + "Processing %s failed.\n", + vhost_message_str[request]); + return -1; + 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); + return -1; } skip_to_post_handle: