Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/45178/?format=api
http://patches.dpdk.org/api/patches/45178/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/153765101718.29126.8572479467169372862.stgit@T460/", "project": { "id": 1, "url": "http://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<153765101718.29126.8572479467169372862.stgit@T460>", "list_archive_url": "https://inbox.dpdk.org/dev/153765101718.29126.8572479467169372862.stgit@T460", "date": "2018-09-22T21:16:57", "name": "[v4,5/5] vhost: message handling implemented as a callback array", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "57a5b90e1ab8f657102ae0d3cf82665250577404", "submitter": { "id": 1062, "url": "http://patches.dpdk.org/api/people/1062/?format=api", "name": "Nikolay Nikolaev", "email": "nicknickolaev@gmail.com" }, "delegate": { "id": 2642, "url": "http://patches.dpdk.org/api/users/2642/?format=api", "username": "mcoquelin", "first_name": "Maxime", "last_name": "Coquelin", "email": "maxime.coquelin@redhat.com" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/153765101718.29126.8572479467169372862.stgit@T460/mbox/", "series": [ { "id": 1455, "url": "http://patches.dpdk.org/api/series/1455/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=1455", "date": "2018-09-22T21:16:23", "name": "vhost: vhost_user.c code cleanup", "version": 4, "mbox": "http://patches.dpdk.org/series/1455/mbox/" } ], "comments": "http://patches.dpdk.org/api/patches/45178/comments/", "check": "success", "checks": "http://patches.dpdk.org/api/patches/45178/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A9688532C;\n\tSat, 22 Sep 2018 23:17:00 +0200 (CEST)", "from mail-wm1-f66.google.com (mail-wm1-f66.google.com\n\t[209.85.128.66]) by dpdk.org (Postfix) with ESMTP id 8C3B25323\n\tfor <dev@dpdk.org>; Sat, 22 Sep 2018 23:16:59 +0200 (CEST)", "by mail-wm1-f66.google.com with SMTP id o18-v6so6535869wmc.0\n\tfor <dev@dpdk.org>; Sat, 22 Sep 2018 14:16:59 -0700 (PDT)", "from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id\n\tv21-v6sm62818914wrd.4.2018.09.22.14.16.57\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tSat, 22 Sep 2018 14:16:58 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=subject:from:to:cc:date:message-id:in-reply-to:references\n\t:user-agent:mime-version:content-transfer-encoding;\n\tbh=AZ9DUhrOmKCd/cvdUEPq0e8pvG+izaG3eM8h4+BfO3U=;\n\tb=fAGR4hEYSSsdMGFKKsbwYC5TzrdZ8oLjG/t5K5SgI8aiwxuI2C8pGjUEx2+0bAycde\n\thpfirm0Xneh+h7rvuwOkos74J/OAvj5PwDP+F7yD01tuID71zkZQ3ys36QEg+28fbW7i\n\tXur56nkMR2HvwMrDL8n4DcS/mX1v80ioLSqrI9OeZ467J1lqtj5QDk09MPLU6unpXfA9\n\tBLmmEzEQsSGNJsOV0GolbpCIubInqjhDtp2OBZYhajRBmZmEyPVaflIYqou53IiOwqlk\n\t7CWIRgVaqOmmA7Pc8eDIx4fGPnVd8iQPTaQSjnNzneY6d97E14YS3nJ6tI5H+ZlBF18m\n\tVmkw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to\n\t:references:user-agent:mime-version:content-transfer-encoding;\n\tbh=AZ9DUhrOmKCd/cvdUEPq0e8pvG+izaG3eM8h4+BfO3U=;\n\tb=LfF0HFkj7gC62HI/V81nNfAT5mScGgxvEllC6qbrONh6xCZjoN8pz3FTAJRT5mp6lB\n\tKasWlGkZcTj7BOU/i6hR1xgPfYxQu6h7LheNYf2rz3M6bVIyU7jk3IL4O6XBMZ8Zm0JX\n\tfMJDhdLVotKyORAZaVlNXOGoGgoyvg0/KRiys/rO/l17DBbJfMtEgwllmyJF6Iu7iZkR\n\tH0iQ0QoWvC7esyr+Wvhq53yxlkHOoyfLIk4LtNSGfpyBmXTnXe8476eom+4y7NnbUJIf\n\tqoMZlAHVdEGkoG4aRv3rmjepnh+Rd2PVbGVV4NPtK51uhyl5Ceck4SzkJOUnH65ZKWTg\n\tRnCA==", "X-Gm-Message-State": "APzg51BmjEWEYATcBMofZChAuron+23n+P3oldhqP0xi+vmlUXWY/ANn\n\thAeIFsyMdYjW+6WR20eLgQol26ZIq0s47g==", "X-Google-Smtp-Source": "ACcGV61/ZN7r+R6hXzdlKew9CRBOhwrRr/OGZA40ivdYy3uBlGrxbrk/SrDUz9YkE7BEn5z2/x+yTg==", "X-Received": "by 2002:a1c:b5d3:: with SMTP id\n\te202-v6mr2425633wmf.23.1537651018959; \n\tSat, 22 Sep 2018 14:16:58 -0700 (PDT)", "From": "Nikolay Nikolaev <nicknickolaev@gmail.com>", "To": "maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com", "Cc": "dev@dpdk.org", "Date": "Sun, 23 Sep 2018 00:16:57 +0300", "Message-ID": "<153765101718.29126.8572479467169372862.stgit@T460>", "In-Reply-To": "<153765091094.29126.1031571146095035538.stgit@T460>", "References": "<153765091094.29126.1031571146095035538.stgit@T460>", "User-Agent": "StGit/0.17.1-dirty", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "7bit", "Subject": "[dpdk-dev] [PATCH v4 5/5] vhost: message handling implemented as a\n\tcallback array", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "DPDK patches and discussions <dev.dpdk.org>", "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://mails.dpdk.org/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Introduce vhost_message_handlers, which maps the message request\ntype to the message handler. Then replace the switch construct\nwith a map and call.\n\nFailing vhost_user_set_features is fatal and all processing should\nstop immediately and propagate the error to the upper layers. Change\nthe code accordingly to reflect that.\n\nSigned-off-by: Nikolay Nikolaev <nicknickolaev@gmail.com>\n---\n lib/librte_vhost/vhost_user.c | 149 +++++++++++++++--------------------------\n 1 file changed, 56 insertions(+), 93 deletions(-)", "diff": "diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex 051740477..0c2faa6af 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -1477,6 +1477,34 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, struct VhostUserMsg *msg)\n \treturn VH_RESULT_OK;\n }\n \n+typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, VhostUserMsg * msg);\n+static vhost_message_handler_t vhost_message_handlers[VHOST_USER_MAX] = {\n+\t[VHOST_USER_NONE] = NULL,\n+\t[VHOST_USER_GET_FEATURES] = vhost_user_get_features,\n+\t[VHOST_USER_SET_FEATURES] = vhost_user_set_features,\n+\t[VHOST_USER_SET_OWNER] = vhost_user_set_owner,\n+\t[VHOST_USER_RESET_OWNER] = vhost_user_reset_owner,\n+\t[VHOST_USER_SET_MEM_TABLE] = vhost_user_set_mem_table,\n+\t[VHOST_USER_SET_LOG_BASE] = vhost_user_set_log_base,\n+\t[VHOST_USER_SET_LOG_FD] = vhost_user_set_log_fd,\n+\t[VHOST_USER_SET_VRING_NUM] = vhost_user_set_vring_num,\n+\t[VHOST_USER_SET_VRING_ADDR] = vhost_user_set_vring_addr,\n+\t[VHOST_USER_SET_VRING_BASE] = vhost_user_set_vring_base,\n+\t[VHOST_USER_GET_VRING_BASE] = vhost_user_get_vring_base,\n+\t[VHOST_USER_SET_VRING_KICK] = vhost_user_set_vring_kick,\n+\t[VHOST_USER_SET_VRING_CALL] = vhost_user_set_vring_call,\n+\t[VHOST_USER_SET_VRING_ERR] = vhost_user_set_vring_err,\n+\t[VHOST_USER_GET_PROTOCOL_FEATURES] = vhost_user_get_protocol_features,\n+\t[VHOST_USER_SET_PROTOCOL_FEATURES] = vhost_user_set_protocol_features,\n+\t[VHOST_USER_GET_QUEUE_NUM] = vhost_user_get_queue_num,\n+\t[VHOST_USER_SET_VRING_ENABLE] = vhost_user_set_vring_enable,\n+\t[VHOST_USER_SEND_RARP] = vhost_user_send_rarp,\n+\t[VHOST_USER_NET_SET_MTU] = vhost_user_net_set_mtu,\n+\t[VHOST_USER_SET_SLAVE_REQ_FD] = vhost_user_set_req_fd,\n+\t[VHOST_USER_IOTLB_MSG] = vhost_user_iotlb_msg,\n+};\n+\n+\n /* return bytes# of read on success or negative val on failure. */\n static int\n read_vhost_message(int sockfd, struct VhostUserMsg *msg)\n@@ -1630,6 +1658,7 @@ vhost_user_msg_handler(int vid, int fd)\n \tint ret;\n \tint unlock_required = 0;\n \tuint32_t skip_master = 0;\n+\tint request;\n \n \tdev = get_device(vid);\n \tif (dev == NULL)\n@@ -1722,100 +1751,34 @@ vhost_user_msg_handler(int vid, int fd)\n \t\t\tgoto skip_to_post_handle;\n \t}\n \n-\tswitch (msg.request.master) {\n-\tcase VHOST_USER_GET_FEATURES:\n-\t\tret = vhost_user_get_features(&dev, &msg);\n-\t\tsend_vhost_reply(fd, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_FEATURES:\n-\t\tret = vhost_user_set_features(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_GET_PROTOCOL_FEATURES:\n-\t\tret = vhost_user_get_protocol_features(&dev, &msg);\n-\t\tsend_vhost_reply(fd, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_PROTOCOL_FEATURES:\n-\t\tret = vhost_user_set_protocol_features(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_OWNER:\n-\t\tret = vhost_user_set_owner(&dev, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_RESET_OWNER:\n-\t\tret = vhost_user_reset_owner(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_MEM_TABLE:\n-\t\tret = vhost_user_set_mem_table(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_LOG_BASE:\n-\t\tret = vhost_user_set_log_base(&dev, &msg);\n-\t\tif (ret)\n-\t\t\tgoto skip_to_reply;\n-\t\t/* it needs a reply */\n-\t\tsend_vhost_reply(fd, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_LOG_FD:\n-\t\tret = vhost_user_set_log_fd(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_VRING_NUM:\n-\t\tret = vhost_user_set_vring_num(&dev, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_VRING_ADDR:\n-\t\tret = vhost_user_set_vring_addr(&dev, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_VRING_BASE:\n-\t\tret = vhost_user_set_vring_base(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_GET_VRING_BASE:\n-\t\tret = vhost_user_get_vring_base(&dev, &msg);\n-\t\tif (ret)\n-\t\t\tgoto skip_to_reply;\n-\t\tsend_vhost_reply(fd, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_VRING_KICK:\n-\t\tret = vhost_user_set_vring_kick(&dev, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SET_VRING_CALL:\n-\t\tret = vhost_user_set_vring_call(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_VRING_ERR:\n-\t\tret = vhost_user_set_vring_err(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_GET_QUEUE_NUM:\n-\t\tret = vhost_user_get_queue_num(&dev, &msg);\n-\t\tsend_vhost_reply(fd, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_VRING_ENABLE:\n-\t\tret = vhost_user_set_vring_enable(&dev, &msg);\n-\t\tbreak;\n-\tcase VHOST_USER_SEND_RARP:\n-\t\tret = vhost_user_send_rarp(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_NET_SET_MTU:\n-\t\tret = vhost_user_net_set_mtu(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_SET_SLAVE_REQ_FD:\n-\t\tret = vhost_user_set_req_fd(&dev, &msg);\n-\t\tbreak;\n-\n-\tcase VHOST_USER_IOTLB_MSG:\n-\t\tret = vhost_user_iotlb_msg(&dev, &msg);\n-\t\tbreak;\n+\trequest = msg.request.master;\n+\tif (request > VHOST_USER_NONE && request < VHOST_USER_MAX) {\n+\t\tif (!vhost_message_handlers[request])\n+\t\t\tgoto skip_to_post_handle;\n+\t\tret = vhost_message_handlers[request](&dev, &msg);\n \n-\tdefault:\n-\t\tret = -1;\n-\t\tbreak;\n+\t\tswitch (ret) {\n+\t\tcase VH_RESULT_ERR:\n+\t\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\t\"Processing %s failed.\\n\",\n+\t\t\t\tvhost_message_str[request]);\n+\t\t\tbreak;\n+\t\tcase VH_RESULT_OK:\n+\t\t\tRTE_LOG(DEBUG, VHOST_CONFIG,\n+\t\t\t\t\"Processing %s succeeded.\\n\",\n+\t\t\t\tvhost_message_str[request]);\n+\t\t\tbreak;\n+\t\tcase VH_RESULT_REPLY:\n+\t\t\tRTE_LOG(INFO, VHOST_CONFIG,\n+\t\t\t\t\"Processing %s succeeded and needs reply.\\n\",\n+\t\t\t\tvhost_message_str[request]);\n+\t\t\tsend_vhost_reply(fd, &msg);\n+\t\t\tbreak;\n+\t\t}\n+\t} else {\n+\t\tRTE_LOG(ERR, VHOST_CONFIG,\n+\t\t\t\"Requested invalid message type %d.\\n\", request);\n+\t\tret = VH_RESULT_ERR;\n \t}\n \n skip_to_post_handle:\n", "prefixes": [ "v4", "5/5" ] }{ "id": 45178, "url": "