get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 11264,
    "url": "http://patches.dpdk.org/api/patches/11264/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1457512409-24403-6-git-send-email-mukawa@igel.co.jp/",
    "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": "<1457512409-24403-6-git-send-email-mukawa@igel.co.jp>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1457512409-24403-6-git-send-email-mukawa@igel.co.jp",
    "date": "2016-03-09T08:33:22",
    "name": "[dpdk-dev,v4,05/12] virtio, qtest: Add QTest utility basic functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "ffb11722c3f1a17a55d125af73da6c21b56b7a9b",
    "submitter": {
        "id": 64,
        "url": "http://patches.dpdk.org/api/people/64/?format=api",
        "name": "Tetsuya Mukawa",
        "email": "mukawa@igel.co.jp"
    },
    "delegate": {
        "id": 355,
        "url": "http://patches.dpdk.org/api/users/355/?format=api",
        "username": "yliu",
        "first_name": "Yuanhan",
        "last_name": "Liu",
        "email": "yuanhan.liu@linux.intel.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1457512409-24403-6-git-send-email-mukawa@igel.co.jp/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/11264/comments/",
    "check": "pending",
    "checks": "http://patches.dpdk.org/api/patches/11264/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 [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 12B2537B8;\n\tWed,  9 Mar 2016 09:33:58 +0100 (CET)",
            "from mail-pa0-f49.google.com (mail-pa0-f49.google.com\n\t[209.85.220.49]) by dpdk.org (Postfix) with ESMTP id BC77E37A4\n\tfor <dev@dpdk.org>; Wed,  9 Mar 2016 09:33:55 +0100 (CET)",
            "by mail-pa0-f49.google.com with SMTP id fe3so18041100pab.1\n\tfor <dev@dpdk.org>; Wed, 09 Mar 2016 00:33:55 -0800 (PST)",
            "from localhost.localdomain (napt.igel.co.jp. [219.106.231.132])\n\tby smtp.gmail.com with ESMTPSA id\n\tqh8sm10350238pac.40.2016.03.09.00.33.53\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 09 Mar 2016 00:33:54 -0800 (PST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=igel-co-jp.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:in-reply-to:references;\n\tbh=fSsmha5ARp5U8AAu7VMWajJ/vYuImrtb5NE4qwjCf1w=;\n\tb=Q1w3h16Y8kIM++DU7FWFzOZu+VkB5lT+DJWGI7PmWT7c1Y57ippDpzxt4MJw2MntDU\n\tFQtVrDLi7V6/0VGw2YGjc2C6bjr/uaphc9+vwt5Z4H+UfTONNZQqRGDi+oKAWeCEsXmz\n\tu/qQgfXIgp8Zk2ZHIL2DJRFuj9/ay0Tz4I5hBMagoB7W4K5JSirh65v5MbTES7JavkAk\n\tZh9iV75zuHvQYsGnVDajoj2u+yDkLisNiqAFjXPLwiZpPRLqM+xE9BRLXyOssfaqWcBv\n\tZdsbfnn0s2w6duTbFT9QfdhxnJL35PmifO3jjns5aeMuCe2waiIp97Cm3CEW7HhXIwX2\n\trARA==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20130820;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:in-reply-to:references;\n\tbh=fSsmha5ARp5U8AAu7VMWajJ/vYuImrtb5NE4qwjCf1w=;\n\tb=GlXhqD6cUpe/UKHN2NbgcszxJliw4kNk/BBrQJ2AcrP6nFuf5Kajs5Fq9IeBv5XSVZ\n\th0vYqDj0KZ2T4lGUd9w4Il2m0HBONm4URQSr+9D4XWQ7QVrDQWQ9skI4DRtZ1FlhgYvc\n\tG2QgLGcdEdxEtgKMkU3pPNOfXxTEDPqtmrVXDnSKZmSEZN9TEJCk5BQS57PGGRfspQTV\n\tEh7I6V8lIQQoqbiQqfZfPIWoeNOiLNOu6Fwqlb4iVwnmd/zVBd6HFqWN/FGVrUemOiFH\n\t+O2GzTB06QkVIX2S1qdf22J/2GcIrb8XtTcV7Gw4iWoega1vQhsJWvxdcuLemYySUgzj\n\tnPQQ==",
        "X-Gm-Message-State": "AD7BkJJ2O45nZeJkNAjzBDmUo0657+52h2fZcKjs15+yPadjK7OtblpmG83c41j/DlQQvg==",
        "X-Received": "by 10.66.129.130 with SMTP id nw2mr48545839pab.80.1457512435206; \n\tWed, 09 Mar 2016 00:33:55 -0800 (PST)",
        "From": "Tetsuya Mukawa <mukawa@igel.co.jp>",
        "To": "dev@dpdk.org, jianfeng.tan@intel.com, huawei.xie@intel.com,\n\tyuanhan.liu@linux.intel.com",
        "Date": "Wed,  9 Mar 2016 17:33:22 +0900",
        "Message-Id": "<1457512409-24403-6-git-send-email-mukawa@igel.co.jp>",
        "X-Mailer": "git-send-email 2.1.4",
        "In-Reply-To": [
            "<1457512409-24403-1-git-send-email-mukawa@igel.co.jp>",
            "<1456129075-14909-4-git-send-email-mukawa@igel.co.jp>"
        ],
        "References": [
            "<1457512409-24403-1-git-send-email-mukawa@igel.co.jp>",
            "<1456129075-14909-4-git-send-email-mukawa@igel.co.jp>"
        ],
        "Subject": "[dpdk-dev] [PATCH v4 05/12] virtio,\n\tqtest: Add QTest utility basic functions",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "patches and discussions about DPDK <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "The patch adds basic functions for accessing to QEMU quest that runs in\nQTest mode. The functions will be used by virtio container extension\nthat can access to the above guest.\n\nSigned-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>\n---\n config/common_base               |   1 +\n drivers/net/virtio/Makefile      |   4 +\n drivers/net/virtio/qtest_utils.c | 480 +++++++++++++++++++++++++++++++++++++++\n drivers/net/virtio/qtest_utils.h | 119 ++++++++++\n 4 files changed, 604 insertions(+)\n create mode 100644 drivers/net/virtio/qtest_utils.c\n create mode 100644 drivers/net/virtio/qtest_utils.h",
    "diff": "diff --git a/config/common_base b/config/common_base\nindex 340feaf..b19cb59 100644\n--- a/config/common_base\n+++ b/config/common_base\n@@ -260,6 +260,7 @@ CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n\n # Enable virtio support for container\n #\n CONFIG_RTE_VIRTIO_VDEV=n\n+CONFIG_RTE_VIRTIO_VDEV_QTEST=n\n \n #\n # Compile burst-oriented VMXNET3 PMD driver\ndiff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile\nindex 9e83852..e6d5a04 100644\n--- a/drivers/net/virtio/Makefile\n+++ b/drivers/net/virtio/Makefile\n@@ -59,6 +59,10 @@ ifeq ($(CONFIG_RTE_VIRTIO_VDEV),y)\n \tSRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += vhost_embedded.c\n endif\n \n+ifeq ($(CONFIG_RTE_VIRTIO_VDEV_QTEST),y)\n+\tSRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += qtest_utils.c\n+endif\n+\n # this lib depends upon:\n DEPDIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += lib/librte_eal lib/librte_ether\n DEPDIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += lib/librte_mempool lib/librte_mbuf\ndiff --git a/drivers/net/virtio/qtest_utils.c b/drivers/net/virtio/qtest_utils.c\nnew file mode 100644\nindex 0000000..f4cd6af\n--- /dev/null\n+++ b/drivers/net/virtio/qtest_utils.c\n@@ -0,0 +1,480 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 IGEL Co., Ltd. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of IGEL Co., Ltd. nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <unistd.h>\n+#include <sys/socket.h>\n+#include <sys/un.h>\n+#include <pthread.h>\n+#include <fcntl.h>\n+\n+#include <rte_malloc.h>\n+\n+#include \"virtio_logs.h\"\n+#include \"virtio_ethdev.h\"\n+#include \"qtest_utils.h\"\n+\n+union qtest_pipefds {\n+\tstruct {\n+\t\tint pipefd[2];\n+\t};\n+\tstruct {\n+\t\tint readfd;\n+\t\tint writefd;\n+\t};\n+};\n+\n+struct qtest_session {\n+\tint qtest_socket;\n+\tpthread_mutex_t qtest_session_lock;\n+\n+\tpthread_t event_th;\n+\tint event_th_started;\n+\tchar *evq;\n+\tchar *evq_dequeue_ptr;\n+\tsize_t evq_total_len;\n+\n+\tunion qtest_pipefds msgfds;\n+};\n+\n+static int\n+qtest_raw_send(int fd, char *buf, size_t count)\n+{\n+\tsize_t len = count;\n+\tsize_t total_len = 0;\n+\tint ret = 0;\n+\n+\twhile (len > 0) {\n+\t\tret = write(fd, buf, len);\n+\t\tif (ret == -1) {\n+\t\t\tif (errno == EINTR)\n+\t\t\t\tcontinue;\n+\t\t\treturn ret;\n+\t\t}\n+\t\tif (ret == (int)len)\n+\t\t\tbreak;\n+\t\ttotal_len += ret;\n+\t\tbuf += ret;\n+\t\tlen -= ret;\n+\t}\n+\treturn total_len + ret;\n+}\n+\n+static int\n+qtest_raw_recv(int fd, char *buf, size_t count)\n+{\n+\tsize_t len = count;\n+\tsize_t total_len = 0;\n+\tint ret = 0;\n+\n+\twhile (len > 0) {\n+\t\tret = read(fd, buf, len);\n+\t\tif (ret <= 0) {\n+\t\t\tif (errno == EINTR) {\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t\treturn ret;\n+\t\t}\n+\t\tif (ret == (int)len)\n+\t\t\tbreak;\n+\t\tif (*(buf + ret - 1) == '\\n')\n+\t\t\tbreak;\n+\t\ttotal_len += ret;\n+\t\tbuf += ret;\n+\t\tlen -= ret;\n+\t}\n+\treturn total_len + ret;\n+}\n+\n+/*\n+ * To know QTest protocol specification, see below QEMU source code.\n+ *  - qemu/qtest.c\n+ * If qtest socket is closed, qtest_raw_in and qtest_raw_read will return 0.\n+ */\n+static uint32_t\n+qtest_raw_in(struct qtest_session *s, uint16_t addr, char type)\n+{\n+\tchar buf[64];\n+\tint ret;\n+\n+\tif ((type != 'l') && (type != 'w') && (type != 'b'))\n+\t\trte_panic(\"Invalid value\\n\");\n+\n+\tsnprintf(buf, sizeof(buf), \"in%c 0x%x\\n\", type, addr);\n+\t/* write to qtest socket */\n+\tret = qtest_raw_send(s->qtest_socket, buf, strlen(buf));\n+\t/* read reply from event handler */\n+\tret = qtest_raw_recv(s->msgfds.readfd, buf, sizeof(buf));\n+\tif (ret < 0)\n+\t\treturn 0;\n+\n+\tbuf[ret] = '\\0';\n+\treturn strtoul(buf + strlen(\"OK \"), NULL, 16);\n+}\n+\n+static void\n+qtest_raw_out(struct qtest_session *s, uint16_t addr, uint32_t val, char type)\n+{\n+\tchar buf[64];\n+\tint ret __rte_unused;\n+\n+\tif ((type != 'l') && (type != 'w') && (type != 'b'))\n+\t\trte_panic(\"Invalid value\\n\");\n+\n+\tsnprintf(buf, sizeof(buf), \"out%c 0x%x 0x%x\\n\", type, addr, val);\n+\t/* write to qtest socket */\n+\tret = qtest_raw_send(s->qtest_socket, buf, strlen(buf));\n+\t/* read reply from event handler */\n+\tret = qtest_raw_recv(s->msgfds.readfd, buf, sizeof(buf));\n+}\n+\n+static uint32_t\n+qtest_raw_read(struct qtest_session *s, uint64_t addr, char type)\n+{\n+\tchar buf[64];\n+\tint ret;\n+\n+\tif ((type != 'l') && (type != 'w') && (type != 'b'))\n+\t\trte_panic(\"Invalid value\\n\");\n+\n+\tsnprintf(buf, sizeof(buf), \"read%c 0x%lx\\n\", type, addr);\n+\t/* write to qtest socket */\n+\tret = qtest_raw_send(s->qtest_socket, buf, strlen(buf));\n+\t/* read reply from event handler */\n+\tret = qtest_raw_recv(s->msgfds.readfd, buf, sizeof(buf));\n+\tif (ret < 0)\n+\t\treturn 0;\n+\n+\tbuf[ret] = '\\0';\n+\treturn strtoul(buf + strlen(\"OK \"), NULL, 16);\n+}\n+\n+static void\n+qtest_raw_write(struct qtest_session *s, uint64_t addr, uint32_t val, char type)\n+{\n+\tchar buf[64];\n+\tint ret __rte_unused;\n+\n+\tif ((type != 'l') && (type != 'w') && (type != 'b'))\n+\t\trte_panic(\"Invalid value\\n\");\n+\n+\tsnprintf(buf, sizeof(buf), \"write%c 0x%lx 0x%x\\n\", type, addr, val);\n+\t/* write to qtest socket */\n+\tret = qtest_raw_send(s->qtest_socket, buf, strlen(buf));\n+\t/* read reply from event handler */\n+\tret = qtest_raw_recv(s->msgfds.readfd, buf, sizeof(buf));\n+}\n+\n+/*\n+ * qtest_in/out are used for accessing ioport of qemu guest.\n+ * qtest_read/write are used for accessing memory of qemu guest.\n+ */\n+uint32_t\n+qtest_in(struct qtest_session *s, uint16_t addr, char type)\n+{\n+\tuint32_t val;\n+\n+\tif (pthread_mutex_lock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\tval = qtest_raw_in(s, addr, type);\n+\n+\tif (pthread_mutex_unlock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\treturn val;\n+}\n+\n+void\n+qtest_out(struct qtest_session *s, uint16_t addr, uint64_t val, char type)\n+{\n+\tif (pthread_mutex_lock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\tqtest_raw_out(s, addr, val, type);\n+\n+\tif (pthread_mutex_unlock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+}\n+\n+uint32_t\n+qtest_read(struct qtest_session *s, uint64_t addr, char type)\n+{\n+\tuint32_t val;\n+\n+\tif (pthread_mutex_lock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\tval = qtest_raw_read(s, addr, type);\n+\n+\tif (pthread_mutex_unlock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\treturn val;\n+}\n+\n+void\n+qtest_write(struct qtest_session *s, uint64_t addr, uint64_t val, char type)\n+{\n+\tif (pthread_mutex_lock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+\n+\tqtest_raw_write(s, addr, val, type);\n+\n+\tif (pthread_mutex_unlock(&s->qtest_session_lock) < 0)\n+\t\trte_panic(\"Cannot lock mutex\\n\");\n+}\n+\n+static void\n+qtest_event_send(struct qtest_session *s, char *buf)\n+{\n+\tint ret;\n+\n+\t/* relay normal message to pipe */\n+\tret = qtest_raw_send(s->msgfds.writefd, buf, strlen(buf));\n+\tif (ret < 0)\n+\t\trte_panic(\"cannot relay normal message\\n\");\n+}\n+\n+static void\n+qtest_close_one_socket(int *fd)\n+{\n+\tif (*fd > 0) {\n+\t\tclose(*fd);\n+\t\t*fd = -1;\n+\t}\n+}\n+\n+static void\n+qtest_close_sockets(struct qtest_session *s)\n+{\n+\tqtest_close_one_socket(&s->qtest_socket);\n+\tqtest_close_one_socket(&s->msgfds.readfd);\n+\tqtest_close_one_socket(&s->msgfds.writefd);\n+}\n+\n+static void\n+qtest_event_enqueue(struct qtest_session *s, char *buf)\n+{\n+\tsize_t len = strlen(buf);\n+\tchar *dest;\n+\n+\tif (s->evq == NULL) {\n+\t\t/* allocate one more byte for '\\0' */\n+\t\ts->evq = malloc(len + 1);\n+\t\tif (s->evq == NULL)\n+\t\t\trte_panic(\"Cannot allocate memory\\n\");\n+\n+\t\ts->evq_dequeue_ptr = s->evq;\n+\t\ts->evq_total_len = len + 1;\n+\t\tdest = s->evq;\n+\t} else {\n+\t\tsize_t offset = s->evq_dequeue_ptr - s->evq;\n+\n+\t\ts->evq = realloc(s->evq, s->evq_total_len + len);\n+\t\tif (s->evq == NULL)\n+\t\t\trte_panic(\"Cannot re-allocate memory\\n\");\n+\n+\t\ts->evq_dequeue_ptr = s->evq + offset;\n+\t\tdest = s->evq + s->evq_total_len - 1;\n+\t\ts->evq_total_len += len;\n+\t}\n+\n+\tstrncpy(dest, buf, len);\n+\tdest[len] = '\\0';\n+}\n+\n+static char *\n+qtest_event_dequeue(struct qtest_session *s)\n+{\n+\tchar *head, *next_head;\n+\n+\thead = s->evq_dequeue_ptr;\n+\n+\t/* make sure message is terminated by '\\n' */\n+\tnext_head = strchr(s->evq_dequeue_ptr, '\\n');\n+\tif (next_head == NULL)\n+\t\treturn NULL;\n+\n+\t/* set next dequeue pointer */\n+\ts->evq_dequeue_ptr = next_head + 1;\n+\n+\treturn head;\n+}\n+\n+static void\n+qtest_event_flush(struct qtest_session *s)\n+{\n+\tif (s->evq) {\n+\t\tfree(s->evq);\n+\t\ts->evq = NULL;\n+\t\ts->evq_dequeue_ptr = NULL;\n+\t\ts->evq_total_len = 0;\n+\t}\n+}\n+\n+/*\n+ * This thread relays QTest response using pipe and eventfd.\n+ * The function is needed because we need to separate IRQ message from others.\n+ */\n+static void *\n+qtest_event_handler(void *data) {\n+\tstruct qtest_session *s = (struct qtest_session *)data;\n+\tchar buf[64];\n+\tchar *p;\n+\tint ret;\n+\n+\tfor (;;) {\n+\t\tmemset(buf, 0, sizeof(buf));\n+\t\tret = qtest_raw_recv(s->qtest_socket, buf, sizeof(buf));\n+\t\tif (ret <= 0) {\n+\t\t\tPMD_DRV_LOG(EMERG,\n+\t\t\t\t\"QTest connection was closed.\\n\"\n+\t\t\t\t\"Please detach the port, then start QEMU \"\n+\t\t\t\t\"and attach the port again.\\n\");\n+\t\t\tqtest_close_sockets(s);\n+\t\t\tqtest_event_flush(s);\n+\t\t\treturn NULL;\n+\t\t}\n+\n+\t\tqtest_event_enqueue(s, buf);\n+\n+\t\t/* in the case of incomplete message, receive again */\n+\t\tp = &buf[sizeof(buf) - 1];\n+\t\tif ((*p != '\\0') && (*p != '\\n'))\n+\t\t\tcontinue;\n+\n+\t\t/* may receive multiple messages at the same time */\n+\t\twhile ((p = qtest_event_dequeue(s)) != NULL)\n+\t\t\tqtest_event_send(s, p);\n+\n+\t\tqtest_event_flush(s);\n+\t}\n+\treturn NULL;\n+}\n+\n+static int\n+qtest_open_socket(char *path)\n+{\n+\tstruct sockaddr_un sa = {0};\n+\tint ret, fd, loop = 100;\n+\n+\tfd = socket(AF_UNIX, SOCK_STREAM, 0);\n+\tif (fd < 0)\n+\t\treturn -1;\n+\n+\tsa.sun_family = AF_UNIX;\n+\tstrncpy(sa.sun_path, path, sizeof(sa.sun_path));\n+\n+\twhile (loop--) {\n+\t\t/*\n+\t\t * If QEMU has multiple sockets needed to be listen, QEMU needs\n+\t\t * some time to start listening a next socket.\n+\t\t * In our case, after connecting ivshmem socket, we may need to wait\n+\t\t * a bit to connect to qtest socket.\n+\t\t */\n+\t\tret = connect(fd, (struct sockaddr *)&sa,\n+\t\t\t\tsizeof(struct sockaddr_un));\n+\t\tif (ret == 0)\n+\t\t\tbreak;\n+\t\telse\n+\t\t\tusleep(100000);\n+\t}\n+\n+\tif (ret != 0) {\n+\t\tclose(fd);\n+\t\treturn -1;\n+\t}\n+\n+\treturn fd;\n+}\n+\n+void\n+qtest_vdev_uninit(struct qtest_session *s)\n+{\n+\tqtest_close_sockets(s);\n+\tqtest_event_flush(s);\n+\n+\tif (s->event_th_started) {\n+\t\tpthread_cancel(s->event_th);\n+\t\tpthread_join(s->event_th, NULL);\n+\t\ts->event_th_started = 0;\n+\t}\n+\n+\tpthread_mutex_destroy(&s->qtest_session_lock);\n+\trte_free(s);\n+}\n+\n+struct qtest_session *\n+qtest_vdev_init(char *qtest_path)\n+{\n+\tstruct qtest_session *s;\n+\tint ret;\n+\n+\ts = rte_zmalloc(NULL, sizeof(*s), RTE_CACHE_LINE_SIZE);\n+\tif (s == NULL) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to allocate memory\\n\");\n+\t\treturn NULL;\n+\t}\n+\n+\tret = pthread_mutex_init(&s->qtest_session_lock, NULL);\n+\tif (ret != 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to initialize mutex\\n\");\n+\t\trte_free(s);\n+\t\treturn NULL;\n+\t}\n+\n+\tret = pipe(s->msgfds.pipefd);\n+\tif (ret != 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to initialize message pipe\\n\");\n+\t\tgoto error;\n+\t}\n+\n+\ts->qtest_socket = qtest_open_socket(qtest_path);\n+\tif (s->qtest_socket < 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to open %s\\n\", qtest_path);\n+\t\tgoto error;\n+\t}\n+\n+\tret = pthread_create(&s->event_th, NULL, qtest_event_handler, s);\n+\tif (ret != 0) {\n+\t\tPMD_DRV_LOG(ERR, \"Failed to create event handler\\n\");\n+\t\tgoto error;\n+\t}\n+\ts->event_th_started = 1;\n+\n+\treturn s;\n+\n+error:\n+\tqtest_vdev_uninit(s);\n+\treturn NULL;\n+}\ndiff --git a/drivers/net/virtio/qtest_utils.h b/drivers/net/virtio/qtest_utils.h\nnew file mode 100644\nindex 0000000..962fc5c\n--- /dev/null\n+++ b/drivers/net/virtio/qtest_utils.h\n@@ -0,0 +1,119 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 IGEL Co., Ltd. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of IGEL Co., Ltd. nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _VIRTIO_QTEST_UTILS_H_\n+#define _VIRTIO_QTEST_UTILS_H_\n+\n+/**\n+ * @internal\n+ * Initialization function of QTest utility.\n+ *\n+ * @param qtest_path\n+ *   Path of qtest socket.\n+ * @return\n+ *   The pointer to qtest session structure.\n+ */\n+struct qtest_session *qtest_vdev_init(char *qtest_path);\n+\n+/**\n+ * @internal\n+ * Finalization function of QTest utility.\n+ *\n+ * @param s\n+ *   The pointer to qtest session structure.\n+ */\n+void qtest_vdev_uninit(struct qtest_session *s);\n+\n+/**\n+ * @internal\n+ * Read a port of QEMU guest.\n+ *\n+ * @param s\n+ *   The pointer to qtest session structure.\n+ * @param addr\n+ *   The port address.\n+ * @param type\n+ *   Size of port. Specify one of 'l', 'w', and 'b'.\n+ * @return\n+ *   Value read from the port.\n+ */\n+uint32_t qtest_in(struct qtest_session *s, uint16_t addr, char type);\n+\n+/**\n+ * @internal\n+ * Write a port of QEMU guest.\n+ *\n+ * @param s\n+ *   The pointer to qtest session structure.\n+ * @param addr\n+ *   The port address.\n+ * @param val\n+ *   Written value.\n+ * @param type\n+ *   Size of port. Specify one of 'l', 'w', and 'b'.\n+ */\n+void qtest_out(struct qtest_session *s, uint16_t addr,\n+\t\t\tuint64_t val, char type);\n+\n+/**\n+ * @internal\n+ * Read memory of QEMU guest.\n+ *\n+ * @param s\n+ *   The pointer to qtest session structure.\n+ * @param addr\n+ *   The memory address.\n+ * @param type\n+ *   Size of port. Specify one of 'l', 'w', and 'b'.\n+ * @return\n+ *   Value read from the memory.\n+ */\n+uint32_t qtest_read(struct qtest_session *s, uint64_t addr, char type);\n+\n+/**\n+ * @internal\n+ * Write memory of QEMU guest.\n+ *\n+ * @param s\n+ *   The pointer to qtest session structure.\n+ * @param addr\n+ *   The memory address.\n+ * @param val\n+ *   Written value.\n+ * @param type\n+ *   Size of memory. Specify one of 'l', 'w', and 'b'.\n+ */\n+void qtest_write(struct qtest_session *s, uint64_t addr,\n+\t\t\tuint64_t val, char type);\n+\n+#endif /* _VIRTIO_QTEST_UTILS_H_ */\n",
    "prefixes": [
        "dpdk-dev",
        "v4",
        "05/12"
    ]
}