Show a patch.

GET /api/patches/43223/
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 43223,
    "url": "http://patches.dpdk.org/api/patches/43223/",
    "web_url": "http://patches.dpdk.org/patch/43223/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<153202763503.21481.6074577075024787339.stgit@T460>",
    "date": "2018-07-19T19:13:55",
    "name": "[v2,5/5] vhost: message handling implemented as a callback array",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "74920ca24d5d74a1da4787d9749042464fc5eb1e",
    "submitter": {
        "id": 1062,
        "url": "http://patches.dpdk.org/api/people/1062/",
        "name": "Nikolay Nikolaev",
        "email": "nicknickolaev@gmail.com"
    },
    "delegate": {
        "id": 2642,
        "url": "http://patches.dpdk.org/api/users/2642/",
        "username": "mcoquelin",
        "first_name": "Maxime",
        "last_name": "Coquelin",
        "email": "maxime.coquelin@redhat.com"
    },
    "mbox": "http://patches.dpdk.org/patch/43223/mbox/",
    "series": [
        {
            "id": 681,
            "url": "http://patches.dpdk.org/api/series/681/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=681",
            "date": "2018-07-19T19:13:20",
            "name": "vhost_user.c code cleanup",
            "version": 2,
            "mbox": "http://patches.dpdk.org/series/681/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/43223/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/43223/checks/",
    "tags": {},
    "headers": {
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "To": "maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com",
        "X-Google-Smtp-Source": "AAOMgpfHAU7UY5zdqgTyU2cPZDvi1wuk0dpixn0Be/X2HTm/yCmTOUoLf3fsELStOJXyuCz7KRK88g==",
        "X-Gm-Message-State": "AOUpUlEyt9g5X+gIIwkmUEaArCQsbE0rcThtcIcCUbk4EngDeYq0r6wI\n\tp9TGan09rLPGCnzNAHQWhJsUcWJcy6M=",
        "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=KhfDSsoQpeIb857jFSN9TRCgwg/w+w61ixZV4X4+GjU=;\n\tb=mlE+6Br9bp5MOeRlRLyksQRAA9ZUErv7VE8CMreCwb9UDuEiPuWJe7nGSNJ5IYgAEe\n\txUJnATKH+493O2AjKn7zllwTpDjSlutxSVRju5IboRC5nD3E7IM2fewW6TgFcoSAb4QI\n\tJ5jRT/s0XixgYUBTUUVcPIARXefKpFHRfoS2ucAv+QO/VOgqNwWMXjLydlcG3PNzsxa4\n\tOJE7aLtnujWCmP1IqeJfF7wcBlnqZvv4EuD0WJRQwOpFGTiS4NseVzc0H+fLZmivQBZE\n\tXF4PMq6BqzkEmjPaa7uvUu+3C7p5s2ge3EC4VkbPLo6HGaohUUoLInHGIPZ2r/lWy55O\n\tZgkQ==",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Message-ID": "<153202763503.21481.6074577075024787339.stgit@T460>",
        "X-BeenThere": "dev@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A3A675F33;\n\tThu, 19 Jul 2018 21:13:58 +0200 (CEST)",
            "from mail-wr1-f68.google.com (mail-wr1-f68.google.com\n\t[209.85.221.68]) by dpdk.org (Postfix) with ESMTP id 496405F30\n\tfor <dev@dpdk.org>; Thu, 19 Jul 2018 21:13:57 +0200 (CEST)",
            "by mail-wr1-f68.google.com with SMTP id c13-v6so9110708wrt.1\n\tfor <dev@dpdk.org>; Thu, 19 Jul 2018 12:13:57 -0700 (PDT)",
            "from [127.0.1.1] ([82.146.27.14]) by smtp.gmail.com with ESMTPSA id\n\ty191-v6sm467188wmy.4.2018.07.19.12.13.55\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 19 Jul 2018 12:13:56 -0700 (PDT)"
        ],
        "Subject": "[dpdk-dev] [PATCH v2 5/5] vhost: message handling implemented as a\n\tcallback array",
        "In-Reply-To": "<153202755842.21481.1772155561595981441.stgit@T460>",
        "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-Post": "<mailto:dev@dpdk.org>",
        "Cc": "dev@dpdk.org",
        "Precedence": "list",
        "From": "Nikolay Nikolaev <nicknickolaev@gmail.com>",
        "X-Received": "by 2002:adf:9aeb:: with SMTP id\n\ta98-v6mr8104300wrc.110.1532027636822; \n\tThu, 19 Jul 2018 12:13:56 -0700 (PDT)",
        "Content-Transfer-Encoding": "7bit",
        "MIME-Version": "1.0",
        "References": "<153202755842.21481.1772155561595981441.stgit@T460>",
        "X-Original-To": "patchwork@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "Errors-To": "dev-bounces@dpdk.org",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Delivered-To": "patchwork@dpdk.org",
        "Date": "Thu, 19 Jul 2018 22:13:55 +0300",
        "X-Mailman-Version": "2.1.15",
        "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=KhfDSsoQpeIb857jFSN9TRCgwg/w+w61ixZV4X4+GjU=;\n\tb=lFfk/haPlQJOzYiW308Sec8ORTZzznHqrjN7LwX4iMoMXHrqp0rYyPE2VAc3xgXPpT\n\tH7DMyYiAV5hh8dTTdatiWJ+nCizHaxhq3hPZKzZHgyRQU2v//shDIFR2YlemxCo3B6xE\n\t9LPFVhqLmu0jQNlwziScWBVfY5rYF8LV1pZa0J3M2wgFoGGWumyV4FzIC7znjDCNLhsm\n\t3Ny0Fs+inpRhdf6hXU7XIdenuhTdGaIlKbnPxXPjjFhR1FUvfSYe2PaKaX0S7R0gmuGL\n\tV3IaMsXnL2D5vedhx7yYJ43jpquyXC2NBzIadga3TtSf3cH85qu5/lsLeSnAt4HzoL0A\n\thu9w==",
        "User-Agent": "StGit/0.17.1-dirty"
    },
    "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\nSigned-off-by: Nikolay Nikolaev <nicknickolaev@gmail.com>\n---\n lib/librte_vhost/vhost_user.c |  143 +++++++++++++++--------------------------\n 1 file changed, 54 insertions(+), 89 deletions(-)",
    "diff": "diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c\nindex 6b39d1e30..1b164df27 100644\n--- a/lib/librte_vhost/vhost_user.c\n+++ b/lib/librte_vhost/vhost_user.c\n@@ -1466,6 +1466,34 @@ vhost_user_iotlb_msg(struct virtio_net **pdev, 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, VhostUserMsg *msg)\n@@ -1618,6 +1646,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@@ -1710,97 +1739,33 @@ 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\tif (ret)\n-\t\t\treturn -1;\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\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\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\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\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 = -1;\n-\t\tbreak;\n \t}\n \n skip_to_post_handle:\n",
    "prefixes": [
        "v2",
        "5/5"
    ]
}