get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 42581,
    "url": "http://patches.dpdk.org/api/patches/42581/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180709033706.27858-6-qi.z.zhang@intel.com/",
    "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": "<20180709033706.27858-6-qi.z.zhang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180709033706.27858-6-qi.z.zhang@intel.com",
    "date": "2018-07-09T03:36:52",
    "name": "[v10,05/19] eal: enable hotplug on multi-process",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e974f150cf86f00bf7e13eb9caed4d8426ed4d0f",
    "submitter": {
        "id": 504,
        "url": "http://patches.dpdk.org/api/people/504/?format=api",
        "name": "Qi Zhang",
        "email": "qi.z.zhang@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/20180709033706.27858-6-qi.z.zhang@intel.com/mbox/",
    "series": [
        {
            "id": 467,
            "url": "http://patches.dpdk.org/api/series/467/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=467",
            "date": "2018-07-09T03:36:47",
            "name": "enable hotplug on multi-process",
            "version": 10,
            "mbox": "http://patches.dpdk.org/series/467/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42581/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/42581/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 2FCB91B3A3;\n\tMon,  9 Jul 2018 05:36:52 +0200 (CEST)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby dpdk.org (Postfix) with ESMTP id 85E8B1B05B\n\tfor <dev@dpdk.org>; Mon,  9 Jul 2018 05:36:40 +0200 (CEST)",
            "from fmsmga005.fm.intel.com ([10.253.24.32])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t08 Jul 2018 20:36:39 -0700",
            "from dpdk51.sh.intel.com ([10.67.110.190])\n\tby fmsmga005.fm.intel.com with ESMTP; 08 Jul 2018 20:36:38 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.51,328,1526367600\"; d=\"scan'208\";a=\"243632723\"",
        "From": "Qi Zhang <qi.z.zhang@intel.com>",
        "To": "thomas@monjalon.net,\n\tanatoly.burakov@intel.com",
        "Cc": "konstantin.ananyev@intel.com, dev@dpdk.org, bruce.richardson@intel.com, \n\tferruh.yigit@intel.com, benjamin.h.shelton@intel.com,\n\tnarender.vangati@intel.com, Qi Zhang <qi.z.zhang@intel.com>",
        "Date": "Mon,  9 Jul 2018 11:36:52 +0800",
        "Message-Id": "<20180709033706.27858-6-qi.z.zhang@intel.com>",
        "X-Mailer": "git-send-email 2.13.6",
        "In-Reply-To": "<20180709033706.27858-1-qi.z.zhang@intel.com>",
        "References": "<20180607123849.14439-1-qi.z.zhang@intel.com>\n\t<20180709033706.27858-1-qi.z.zhang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v10 05/19] eal: enable hotplug on multi-process",
        "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": "We are going to introduce the solution to handle hotplug in\nmulti-process, it includes the below scenario:\n\n1. Attach a device from the primary\n2. Detach a device from the primary\n3. Attach a device from a secondary\n4. Detach a device from a secondary\n\nIn the primary-secondary process model, we assume devices are shared\nby default. that means attaches or detaches a device on any process\nwill broadcast to all other processes through mp channel then device\ninformation will be synchronized on all processes.\n\nAny failure during attaching/detaching process will cause inconsistent\nstatus between processes, so proper rollback action should be considered.\n\nThis patch covers the implementation of case 1,2.\nCase 3,4 will be implemented on a separate patch.\n\nIPC scenario for Case 1, 2:\n\nattach a device\na) primary attach the new device if failed goto h).\nb) primary send attach sync request to all secondary.\nc) secondary receive request and attach the device and send a reply.\nd) primary check the reply if all success goes to i).\ne) primary send attach rollback sync request to all secondary.\nf) secondary receive the request and detach the device and send a reply.\ng) primary receive the reply and detach device as rollback action.\nh) attach fail\ni) attach success\n\ndetach a device\na) primary send detach sync request to all secondary\nb) secondary detach the device and send reply\nc) primary check the reply if all success goes to f).\nd) primary send detach rollback sync request to all secondary.\ne) secondary receive the request and attach back device. goto g)\nf) primary detach the device if success goto g), else goto d)\ng) detach fail.\nh) detach success.\n\nSigned-off-by: Qi Zhang <qi.z.zhang@intel.com>\n---\n lib/librte_eal/bsdapp/eal/Makefile      |   1 +\n lib/librte_eal/common/eal_common_dev.c  | 140 +++++++++++++++++++++++-\n lib/librte_eal/common/eal_private.h     |  37 +++++++\n lib/librte_eal/common/hotplug_mp.c      | 181 ++++++++++++++++++++++++++++++++\n lib/librte_eal/common/hotplug_mp.h      |  44 ++++++++\n lib/librte_eal/common/include/rte_bus.h |   3 +\n lib/librte_eal/common/include/rte_dev.h |   9 ++\n lib/librte_eal/common/meson.build       |   1 +\n lib/librte_eal/linuxapp/eal/Makefile    |   1 +\n lib/librte_eal/linuxapp/eal/eal.c       |   6 ++\n 10 files changed, 418 insertions(+), 5 deletions(-)\n create mode 100644 lib/librte_eal/common/hotplug_mp.c\n create mode 100644 lib/librte_eal/common/hotplug_mp.h",
    "diff": "diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile\nindex 3fd33f1e4..4ecc73b42 100644\n--- a/lib/librte_eal/bsdapp/eal/Makefile\n+++ b/lib/librte_eal/bsdapp/eal/Makefile\n@@ -59,6 +59,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_thread.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_proc.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_fbarray.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += rte_malloc.c\n+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += hotplug_mp.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_elem.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_heap.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += malloc_mp.c\ndiff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c\nindex 14c5f05fa..fb1a122ae 100644\n--- a/lib/librte_eal/common/eal_common_dev.c\n+++ b/lib/librte_eal/common/eal_common_dev.c\n@@ -16,8 +16,10 @@\n #include <rte_log.h>\n #include <rte_spinlock.h>\n #include <rte_malloc.h>\n+#include <rte_string_fns.h>\n \n #include \"eal_private.h\"\n+#include \"hotplug_mp.h\"\n \n /**\n  * The device event callback description.\n@@ -102,8 +104,9 @@ int rte_eal_dev_detach(struct rte_device *dev)\n \treturn ret;\n }\n \n-int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devname,\n-\t\t\tconst char *devargs)\n+int\n+do_dev_hotplug_add(const char *busname, const char *devname,\n+\t\tconst char *devargs)\n {\n \tstruct rte_bus *bus;\n \tstruct rte_device *dev;\n@@ -168,8 +171,7 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn\n \treturn ret;\n }\n \n-int __rte_experimental\n-rte_eal_hotplug_remove(const char *busname, const char *devname)\n+int do_dev_hotplug_remove(const char *busname, const char *devname)\n {\n \tstruct rte_bus *bus;\n \tstruct rte_device *dev;\n@@ -197,11 +199,139 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)\n \tif (ret)\n \t\tRTE_LOG(ERR, EAL, \"Driver cannot detach the device (%s)\\n\",\n \t\t\tdev->name);\n-\trte_devargs_remove(busname, devname);\n+\telse\n+\t\trte_devargs_remove(busname, devname);\n+\n \treturn ret;\n }\n \n int __rte_experimental\n+rte_eal_hotplug_add(const char *busname, const char *devname,\n+\t\tconst char *devargs)\n+{\n+\tstruct eal_dev_mp_req req;\n+\tint ret;\n+\n+\tmemset(&req, 0, sizeof(req));\n+\treq.t = EAL_DEV_REQ_TYPE_ATTACH;\n+\tstrlcpy(req.busname, busname, RTE_BUS_NAME_MAX_LEN);\n+\tstrlcpy(req.devname, devname, RTE_DEV_NAME_MAX_LEN);\n+\tstrlcpy(req.devargs, devargs, RTE_DEV_ARGS_MAX_LEN);\n+\n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY)\n+\t\treturn -ENOTSUP;\n+\n+\t/**\n+\t * attach a device from primary start from here:\n+\t *\n+\t * a) primary attach the new device if failed goto h).\n+\t * b) primary send attach sync request to all secondary.\n+\t * c) secondary receive request and attach the device and send a reply.\n+\t * d) primary check the reply if all success goes to i).\n+\t * e) primary send attach rollback sync request to all secondary.\n+\t * f) secondary receive the request and detach the device and send a\n+\t *    reply.\n+\t * g) primary receive the reply and detach device as rollback action.\n+\t * h) attach fail\n+\t * i) attach success\n+\t */\n+\n+\t/* step a) */\n+\tret = do_dev_hotplug_add(busname, devname, devargs);\n+\tif (ret)\n+\t\t/* step h) */\n+\t\treturn ret;\n+\n+\t/* step b), c) */\n+\tret = eal_dev_hotplug_request_to_secondary(&req);\n+\n+\t/* step d) */\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to send hotplug add request to secondary\\n\");\n+\t\tgoto rollback;\n+\t}\n+\n+\tif (req.result)\n+\t\tgoto rollback;\n+\n+\t/* step i */\n+\treturn 0;\n+\n+rollback:\n+\treq.t = EAL_DEV_REQ_TYPE_ATTACH_ROLLBACK;\n+\t/* step e), f) */\n+\teal_dev_hotplug_request_to_secondary(&req);\n+\t/* step g) */\n+\tdo_dev_hotplug_remove(busname, devname);\n+\t/* step h */\n+\treturn -ENODEV;\n+}\n+\n+int __rte_experimental\n+rte_eal_hotplug_remove(const char *busname, const char *devname)\n+{\n+\tstruct eal_dev_mp_req req;\n+\tint ret;\n+\n+\tmemset(&req, 0, sizeof(req));\n+\treq.t = EAL_DEV_REQ_TYPE_DETACH;\n+\tstrlcpy(req.busname, busname, RTE_BUS_NAME_MAX_LEN);\n+\tstrlcpy(req.devname, devname, RTE_DEV_NAME_MAX_LEN);\n+\n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY)\n+\t\treturn -ENOTSUP;\n+\n+\t/**\n+\t * detach a device from primary start from here:\n+\t *\n+\t * a) primary send detach sync request to all secondary\n+\t * b) secondary detach the device and send reply\n+\t * c) primary check the reply if all success goes to f).\n+\t * d) primary send detach rollback sync request to all secondary.\n+\t * e) secondary receive the request and attach back device. goto g)\n+\t * f) primary detach the device if success goto g), else goto d)\n+\t * g) detach fail.\n+\t * h) detach success.\n+\t */\n+\n+\t/* step a), b) */\n+\tret = eal_dev_hotplug_request_to_secondary(&req);\n+\t/* step c) */\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to send device detach request to secondary\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tif (req.result) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to detach device on secondary process\\n\");\n+\t\tgoto rollback;\n+\t}\n+\n+\t/* step f) */\n+\tret = do_dev_hotplug_remove(busname, devname);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to detach device on primary process\\n\");\n+\t\tgoto rollback;\n+\t}\n+\t/* step h */\n+\treturn 0;\n+\n+rollback:\n+\treq.t = EAL_DEV_REQ_TYPE_DETACH_ROLLBACK;\n+\t/* step d), e) */\n+\tif (eal_dev_hotplug_request_to_secondary(&req))\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to attach back device on secondary.\"\n+\t\t\t\"Devices in secondary may not sync with primary\\n\");\n+\t/* step g) */\n+\treturn -ENODEV;\n+}\n+\n+int __rte_experimental\n rte_dev_event_callback_register(const char *device_name,\n \t\t\t\trte_dev_event_cb_fn cb_fn,\n \t\t\t\tvoid *cb_arg)\ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex bdadc4d50..1883b05d1 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -258,4 +258,41 @@ int rte_mp_channel_init(void);\n  */\n void dev_callback_process(char *device_name, enum rte_dev_event_type event);\n \n+/**\n+ * Hotplug add a given device to a specific bus.\n+ *\n+ * @param busname\n+ *   The bus name the device is added to.\n+ * @param devname\n+ *   The device name. Based on this device name, eal will identify a driver\n+ *   capable of handling it and pass it to the driver probing function.\n+ * @param devargs\n+ *   Device arguments to be passed to the driver.\n+ * @return\n+ *   0 on success, negative on error.\n+ */\n+int do_dev_hotplug_add(const char *busname, const char *devname,\n+\t\t\tconst char *devargs);\n+\n+/**\n+ * Hotplug remove a given device from a specific bus.\n+ *\n+ * @param busname\n+ *   The bus name the device is removed from.\n+ * @param devname\n+ *   The device name being removed.\n+ * @return\n+ *   0 on success, negative on error.\n+ */\n+int do_dev_hotplug_remove(const char *busname,\n+\t\t\tconst char *devname);\n+\n+/**\n+ * Register all mp action callbacks for hotplug.\n+ *\n+ * @return\n+ *   0 on success, negative on error.\n+ */\n+int rte_dev_hotplug_mp_init(void);\n+\n #endif /* _EAL_PRIVATE_H_ */\ndiff --git a/lib/librte_eal/common/hotplug_mp.c b/lib/librte_eal/common/hotplug_mp.c\nnew file mode 100644\nindex 000000000..261d17fe6\n--- /dev/null\n+++ b/lib/librte_eal/common/hotplug_mp.c\n@@ -0,0 +1,181 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Intel Corporation\n+ */\n+#include <string.h>\n+\n+#include <rte_eal.h>\n+#include <rte_alarm.h>\n+#include <rte_string_fns.h>\n+\n+#include \"hotplug_mp.h\"\n+#include \"eal_private.h\"\n+\n+#define MP_TIMEOUT_S 5 /**< 5 seconds timeouts */\n+\n+struct mp_reply_bundle {\n+\tstruct rte_mp_msg msg;\n+\tvoid *peer;\n+};\n+\n+static int\n+handle_secondary_request(const struct rte_mp_msg *msg, const void *peer)\n+{\n+\tRTE_SET_USED(msg);\n+\tRTE_SET_USED(peer);\n+\treturn -ENOTSUP;\n+}\n+\n+static void __handle_primary_request(void *param)\n+{\n+\tstruct mp_reply_bundle *bundle = param;\n+\tstruct rte_mp_msg *msg = &bundle->msg;\n+\tconst struct eal_dev_mp_req *req =\n+\t\t(const struct eal_dev_mp_req *)msg->param;\n+\tstruct rte_mp_msg mp_resp;\n+\tstruct eal_dev_mp_req *resp =\n+\t\t(struct eal_dev_mp_req *)mp_resp.param;\n+\tint ret = 0;\n+\n+\tmemset(&mp_resp, 0, sizeof(mp_resp));\n+\n+\tswitch (req->t) {\n+\tcase EAL_DEV_REQ_TYPE_ATTACH:\n+\tcase EAL_DEV_REQ_TYPE_DETACH_ROLLBACK:\n+\t\tret = do_dev_hotplug_add(req->busname, req->devname, \"\");\n+\t\tbreak;\n+\tcase EAL_DEV_REQ_TYPE_DETACH:\n+\tcase EAL_DEV_REQ_TYPE_ATTACH_ROLLBACK:\n+\t\tret = do_dev_hotplug_remove(req->busname, req->devname);\n+\t\tbreak;\n+\tdefault:\n+\t\tret = -EINVAL;\n+\t}\n+\n+\tstrlcpy(mp_resp.name, EAL_DEV_MP_ACTION_REQUEST, sizeof(mp_resp.name));\n+\tmp_resp.len_param = sizeof(*req);\n+\tmemcpy(resp, req, sizeof(*resp));\n+\tresp->result = ret;\n+\tif (rte_mp_reply(&mp_resp, bundle->peer) < 0)\n+\t\tRTE_LOG(ERR, EAL, \"failed to send reply to primary request\\n\");\n+\n+\tfree(bundle->peer);\n+\tfree(bundle);\n+}\n+\n+static int\n+handle_primary_request(const struct rte_mp_msg *msg, const void *peer)\n+{\n+\tstruct rte_mp_msg mp_resp;\n+\tconst struct eal_dev_mp_req *req =\n+\t\t(const struct eal_dev_mp_req *)msg->param;\n+\tstruct eal_dev_mp_req *resp =\n+\t\t(struct eal_dev_mp_req *)mp_resp.param;\n+\tstruct mp_reply_bundle *bundle;\n+\tint ret = 0;\n+\n+\tmemset(&mp_resp, 0, sizeof(mp_resp));\n+\tstrlcpy(mp_resp.name, EAL_DEV_MP_ACTION_REQUEST, sizeof(mp_resp.name));\n+\tmp_resp.len_param = sizeof(*req);\n+\tmemcpy(resp, req, sizeof(*resp));\n+\n+\tbundle = calloc(1, sizeof(*bundle));\n+\tif (bundle == NULL) {\n+\t\tresp->result = -ENOMEM;\n+\t\tret = rte_mp_reply(&mp_resp, peer);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"failed to send reply to primary request\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\tbundle->msg = *msg;\n+\t/**\n+\t * We need to send reply on interrupt thread, but peer can't be\n+\t * parsed directly, so this is a temporal hack, need to be fixed\n+\t * when it is ready.\n+\t */\n+\tbundle->peer = (void *)strdup(peer);\n+\n+\t/**\n+\t * We are at IPC callback thread, sync IPC is not allowed due to\n+\t * dead lock, so we delegate the task to interrupt thread.\n+\t */\n+\tret = rte_eal_alarm_set(1, __handle_primary_request, bundle);\n+\tif (ret) {\n+\t\tresp->result = ret;\n+\t\tret = rte_mp_reply(&mp_resp, peer);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"failed to send reply to primary request\\n\");\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+int eal_dev_hotplug_request_to_primary(struct eal_dev_mp_req *req)\n+{\n+\tRTE_SET_USED(req);\n+\treturn -ENOTSUP;\n+}\n+\n+int eal_dev_hotplug_request_to_secondary(struct eal_dev_mp_req *req)\n+{\n+\tstruct rte_mp_msg mp_req;\n+\tstruct rte_mp_reply mp_reply;\n+\tstruct timespec ts = {.tv_sec = MP_TIMEOUT_S, .tv_nsec = 0};\n+\tint ret;\n+\tint i;\n+\n+\tmemset(&mp_req, 0, sizeof(mp_req));\n+\tmemcpy(mp_req.param, req, sizeof(*req));\n+\tmp_req.len_param = sizeof(*req);\n+\tstrlcpy(mp_req.name, EAL_DEV_MP_ACTION_REQUEST, sizeof(mp_req.name));\n+\n+\tret = rte_mp_request_sync(&mp_req, &mp_reply, &ts);\n+\tif (ret) {\n+\t\tRTE_LOG(ERR, EAL, \"rte_mp_request_sync failed\\n\");\n+\t\treturn ret;\n+\t}\n+\n+\tif (mp_reply.nb_sent != mp_reply.nb_received) {\n+\t\tRTE_LOG(ERR, EAL, \"not all secondary reply\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\treq->result = 0;\n+\tfor (i = 0; i < mp_reply.nb_received; i++) {\n+\t\tstruct eal_dev_mp_req *resp =\n+\t\t\t(struct eal_dev_mp_req *)mp_reply.msgs[i].param;\n+\t\tif (resp->result) {\n+\t\t\treq->result = resp->result;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int rte_dev_hotplug_mp_init(void)\n+{\n+\tint ret;\n+\n+\tif (rte_eal_process_type() == RTE_PROC_PRIMARY) {\n+\t\tret = rte_mp_action_register(EAL_DEV_MP_ACTION_REQUEST,\n+\t\t\t\t\thandle_secondary_request);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"Couldn't register '%s' action\\n\",\n+\t\t\t\tEAL_DEV_MP_ACTION_REQUEST);\n+\t\t\treturn ret;\n+\t\t}\n+\t} else {\n+\t\tret = rte_mp_action_register(EAL_DEV_MP_ACTION_REQUEST,\n+\t\thandle_primary_request);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL, \"Couldn't register '%s' action\\n\",\n+\t\t\t\tEAL_DEV_MP_ACTION_REQUEST);\n+\t\t\treturn ret;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/lib/librte_eal/common/hotplug_mp.h b/lib/librte_eal/common/hotplug_mp.h\nnew file mode 100644\nindex 000000000..f24ba107b\n--- /dev/null\n+++ b/lib/librte_eal/common/hotplug_mp.h\n@@ -0,0 +1,44 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2018 Intel Corporation\n+ */\n+\n+#ifndef _HOTPLUG_MP_H_\n+#define _HOTPLUG_MP_H_\n+\n+#include <rte_dev.h>\n+#include <rte_bus.h>\n+\n+#define EAL_DEV_MP_ACTION_REQUEST      \"eal_dev_mp_request\"\n+#define EAL_DEV_MP_ACTION_RESPONSE     \"eal_dev_mp_response\"\n+\n+enum eal_dev_req_type {\n+\tEAL_DEV_REQ_TYPE_ATTACH,\n+\tEAL_DEV_REQ_TYPE_DETACH,\n+\tEAL_DEV_REQ_TYPE_ATTACH_ROLLBACK,\n+\tEAL_DEV_REQ_TYPE_DETACH_ROLLBACK,\n+};\n+\n+struct eal_dev_mp_req {\n+\tenum eal_dev_req_type t;\n+\tchar busname[RTE_BUS_NAME_MAX_LEN];\n+\tchar devname[RTE_DEV_NAME_MAX_LEN];\n+\tchar devargs[RTE_DEV_ARGS_MAX_LEN];\n+\tint result;\n+};\n+\n+/**\n+ * this is a synchronous wrapper for secondary process send\n+ * request to primary process, this is invoked when an attach\n+ * or detach request issued from primary process.\n+ */\n+int eal_dev_hotplug_request_to_primary(struct eal_dev_mp_req *req);\n+\n+/**\n+ * this is a synchronous wrapper for primary process send\n+ * request to secondary process, this is invoked when an attach\n+ * or detach request issued from secondary process.\n+ */\n+int eal_dev_hotplug_request_to_secondary(struct eal_dev_mp_req *req);\n+\n+\n+#endif /* _HOTPLUG_MP_H_ */\ndiff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h\nindex eb9eded4e..720f7c3c8 100644\n--- a/lib/librte_eal/common/include/rte_bus.h\n+++ b/lib/librte_eal/common/include/rte_bus.h\n@@ -197,6 +197,9 @@ struct rte_bus_conf {\n typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void);\n \n \n+/* Max length for a bus name */\n+#define RTE_BUS_NAME_MAX_LEN 32\n+\n /**\n  * A structure describing a generic bus.\n  */\ndiff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h\nindex 3879ff3ca..667df20f0 100644\n--- a/lib/librte_eal/common/include/rte_dev.h\n+++ b/lib/librte_eal/common/include/rte_dev.h\n@@ -152,6 +152,9 @@ struct rte_driver {\n  */\n #define RTE_DEV_NAME_MAX_LEN 64\n \n+/* Max devargs length be allowed */\n+#define RTE_DEV_ARGS_MAX_LEN 128\n+\n /**\n  * A structure describing a generic device.\n  */\n@@ -193,6 +196,9 @@ int rte_eal_dev_detach(struct rte_device *dev);\n  * @b EXPERIMENTAL: this API may change without prior notice\n  *\n  * Hotplug add a given device to a specific bus.\n+ * In multi-process, this function will inform all other processes\n+ * to hotplug add the same device. Any failure on other process\n+ * will rollback the action.\n  *\n  * @param busname\n  *   The bus name the device is added to.\n@@ -212,6 +218,9 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn\n  * @b EXPERIMENTAL: this API may change without prior notice\n  *\n  * Hotplug remove a given device from a specific bus.\n+ * In multi-process, this function will inform all other processes\n+ * to hotplug remove the same device. Any failure on other process\n+ * will rollback the action.\n  *\n  * @param busname\n  *   The bus name the device is removed from.\ndiff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build\nindex 8a3dcfee0..0f2cf9a1a 100644\n--- a/lib/librte_eal/common/meson.build\n+++ b/lib/librte_eal/common/meson.build\n@@ -25,6 +25,7 @@ common_sources = files(\n \t'eal_common_tailqs.c',\n \t'eal_common_thread.c',\n \t'eal_common_timer.c',\n+\t'hotplug_mp.c',\n \t'malloc_elem.c',\n \t'malloc_heap.c',\n \t'malloc_mp.c',\ndiff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile\nindex 3719ec9d7..6c225b54a 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_thread.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_proc.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_fbarray.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += rte_malloc.c\n+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += hotplug_mp.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_elem.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_heap.c\n SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += malloc_mp.c\ndiff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c\nindex 8655b8691..0c6984990 100644\n--- a/lib/librte_eal/linuxapp/eal/eal.c\n+++ b/lib/librte_eal/linuxapp/eal/eal.c\n@@ -850,6 +850,12 @@ rte_eal_init(int argc, char **argv)\n \t\t}\n \t}\n \n+\t/* register mp action callbacks for hotplug */\n+\tif (rte_dev_hotplug_mp_init() < 0) {\n+\t\trte_eal_init_alert(\"failed to register mp callback for hotplug\\n\");\n+\t\treturn -1;\n+\t}\n+\n \tif (rte_bus_scan()) {\n \t\trte_eal_init_alert(\"Cannot scan the buses for devices\\n\");\n \t\trte_errno = ENODEV;\n",
    "prefixes": [
        "v10",
        "05/19"
    ]
}