get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 43725,
    "url": "http://patches.dpdk.org/api/patches/43725/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/20180816030455.41354-3-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": "<20180816030455.41354-3-qi.z.zhang@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20180816030455.41354-3-qi.z.zhang@intel.com",
    "date": "2018-08-16T03:04:50",
    "name": "[v15,2/7] eal: enable hotplug on multi-process",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "d6c49a850efb13bce011b8daffaa4b380e533b18",
    "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/20180816030455.41354-3-qi.z.zhang@intel.com/mbox/",
    "series": [
        {
            "id": 993,
            "url": "http://patches.dpdk.org/api/series/993/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=993",
            "date": "2018-08-16T03:04:48",
            "name": "enable hotplug on multi-process",
            "version": 15,
            "mbox": "http://patches.dpdk.org/series/993/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/43725/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/43725/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 C5B724C8C;\n\tThu, 16 Aug 2018 05:04:21 +0200 (CEST)",
            "from mga11.intel.com (mga11.intel.com [192.55.52.93])\n\tby dpdk.org (Postfix) with ESMTP id 6DBF64C57\n\tfor <dev@dpdk.org>; Thu, 16 Aug 2018 05:04:19 +0200 (CEST)",
            "from orsmga002.jf.intel.com ([10.7.209.21])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t15 Aug 2018 20:04:19 -0700",
            "from dpdk51.sh.intel.com ([10.67.110.190])\n\tby orsmga002.jf.intel.com with ESMTP; 15 Aug 2018 20:04:16 -0700"
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,245,1531810800\"; d=\"scan'208\";a=\"83720821\"",
        "From": "Qi Zhang <qi.z.zhang@intel.com>",
        "To": "thomas@monjalon.net, gaetan.rivet@6wind.com, anatoly.burakov@intel.com, \n\tarybchenko@solarflare.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": "Thu, 16 Aug 2018 11:04:50 +0800",
        "Message-Id": "<20180816030455.41354-3-qi.z.zhang@intel.com>",
        "X-Mailer": "git-send-email 2.13.6",
        "In-Reply-To": "<20180816030455.41354-1-qi.z.zhang@intel.com>",
        "References": "<20180607123849.14439-1-qi.z.zhang@intel.com>\n\t<20180816030455.41354-1-qi.z.zhang@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v15 2/7] 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>\nAcked-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n lib/librte_eal/bsdapp/eal/Makefile      |   1 +\n lib/librte_eal/common/eal_common_dev.c  | 198 +++++++++++++++++++++++++++++++-\n lib/librte_eal/common/eal_private.h     |  37 ++++++\n lib/librte_eal/common/hotplug_mp.c      | 185 +++++++++++++++++++++++++++++\n lib/librte_eal/common/hotplug_mp.h      |  48 ++++++++\n lib/librte_eal/common/include/rte_dev.h |   6 +\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 9 files changed, 478 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 d27da3d15..4351c6a20 100644\n--- a/lib/librte_eal/bsdapp/eal/Makefile\n+++ b/lib/librte_eal/bsdapp/eal/Makefile\n@@ -62,6 +62,7 @@ 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) += eal_common_uuid.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 678dbcac7..d0a457ddb 100644\n--- a/lib/librte_eal/common/eal_common_dev.c\n+++ b/lib/librte_eal/common/eal_common_dev.c\n@@ -19,8 +19,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@@ -127,8 +129,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@@ -193,8 +196,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@@ -227,7 +229,193 @@ 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, EAL_DEV_MP_BUS_NAME_MAX_LEN);\n+\tstrlcpy(req.devname, devname, EAL_DEV_MP_DEV_NAME_MAX_LEN);\n+\tstrlcpy(req.devargs, devargs, EAL_DEV_MP_DEV_ARGS_MAX_LEN);\n+\n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY) {\n+\t\t/**\n+\t\t * If in secondary process, just send IPC request to\n+\t\t * primary process.\n+\t\t */\n+\t\tret = eal_dev_hotplug_request_to_primary(&req);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\t\"Failed to send hotplug request to primary\\n\");\n+\t\t\treturn -ENOMSG;\n+\t\t}\n+\t\tif (req.result)\n+\t\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\t\"Failed to hotplug add device\\n\");\n+\t\treturn req.result;\n+\t}\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+\n+\tif (ret) {\n+\t\t/* step h) */\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to attach device on primary process\\n\");\n+\n+\t\t/**\n+\t\t * it is possible that secondary process failed to attached a\n+\t\t * device that primary process have during initialization,\n+\t\t * so for -EEXIST case, we still need to sync with secondary\n+\t\t * process.\n+\t\t */\n+\t\tif (ret != -EEXIST)\n+\t\t\treturn ret;\n+\t}\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\tret = -ENOMSG;\n+\t\tgoto rollback;\n+\t}\n+\n+\tif (req.result) {\n+\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\"Failed to attach device on secondary process\\n\");\n+\t\tret = req.result;\n+\n+\t\t/* for -EEXIST, we don't need to rollback */\n+\t\tif (ret == -EEXIST)\n+\t\t\treturn ret;\n+\t\tgoto rollback;\n+\t}\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 ret;\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, EAL_DEV_MP_BUS_NAME_MAX_LEN);\n+\tstrlcpy(req.devname, devname, EAL_DEV_MP_DEV_NAME_MAX_LEN);\n+\n+\tif (rte_eal_process_type() != RTE_PROC_PRIMARY) {\n+\t\t/**\n+\t\t * If in secondary process, just send IPC request to\n+\t\t * primary process.\n+\t\t */\n+\t\tret = eal_dev_hotplug_request_to_primary(&req);\n+\t\tif (ret) {\n+\t\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\t\"Failed to send hotplug request to primary\\n\");\n+\t\t\treturn -ENOMSG;\n+\t\t}\n+\t\tif (req.result)\n+\t\t\tRTE_LOG(ERR, EAL,\n+\t\t\t\t\"Failed to hotplug remove device\\n\");\n+\t\treturn req.result;\n+\t}\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 -ENOMSG;\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\tret = req.result;\n+\t\t/**\n+\t\t * if -ENOENT, we don't need to rollback, since devices is\n+\t\t * already detached on secondary process.\n+\t\t */\n+\t\tif (ret != -ENOENT)\n+\t\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\t/* if -ENOENT, we don't need to rollback */\n+\t\tif (ret == -ENOENT)\n+\t\t\treturn ret;\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 ret;\n }\n \ndiff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h\nindex 4f809a83c..946bb01db 100644\n--- a/lib/librte_eal/common/eal_private.h\n+++ b/lib/librte_eal/common/eal_private.h\n@@ -304,4 +304,41 @@ int\n rte_devargs_layers_parse(struct rte_devargs *devargs,\n \t\t\t const char *devstr);\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..03f7e4240\n--- /dev/null\n+++ b/lib/librte_eal/common/hotplug_mp.c\n@@ -0,0 +1,185 @@\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\treturn ret;\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\tif (req->t == EAL_DEV_REQ_TYPE_ATTACH &&\n+\t\t\t\treq->result != -EEXIST)\n+\t\t\t\tbreak;\n+\t\t\tif (req->t == EAL_DEV_REQ_TYPE_DETACH &&\n+\t\t\t\treq->result != -ENOENT)\n+\t\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\t\t\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..22efa073e\n--- /dev/null\n+++ b/lib/librte_eal/common/hotplug_mp.h\n@@ -0,0 +1,48 @@\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+#define EAL_DEV_MP_DEV_NAME_MAX_LEN RTE_DEV_NAME_MAX_LEN\n+#define EAL_DEV_MP_BUS_NAME_MAX_LEN 32\n+#define EAL_DEV_MP_DEV_ARGS_MAX_LEN 128\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[EAL_DEV_MP_BUS_NAME_MAX_LEN];\n+\tchar devname[EAL_DEV_MP_DEV_NAME_MAX_LEN];\n+\tchar devargs[EAL_DEV_MP_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_dev.h b/lib/librte_eal/common/include/rte_dev.h\nindex b80a80598..c023bfbca 100644\n--- a/lib/librte_eal/common/include/rte_dev.h\n+++ b/lib/librte_eal/common/include/rte_dev.h\n@@ -193,6 +193,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 +215,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 56005bea8..16d4433d2 100644\n--- a/lib/librte_eal/common/meson.build\n+++ b/lib/librte_eal/common/meson.build\n@@ -27,6 +27,7 @@ common_sources = files(\n \t'eal_common_thread.c',\n \t'eal_common_timer.c',\n \t'eal_common_uuid.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 fd92c75c2..58455c1a6 100644\n--- a/lib/librte_eal/linuxapp/eal/Makefile\n+++ b/lib/librte_eal/linuxapp/eal/Makefile\n@@ -70,6 +70,7 @@ 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) += eal_common_uuid.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 e59ac6577..f2c90c528 100644\n--- a/lib/librte_eal/linuxapp/eal/eal.c\n+++ b/lib/librte_eal/linuxapp/eal/eal.c\n@@ -865,6 +865,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": [
        "v15",
        "2/7"
    ]
}