From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 520082BF1 for ; Wed, 28 Feb 2018 02:58:15 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2018 17:58:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,403,1515484800"; d="scan'208";a="207521526" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 27 Feb 2018 17:58:14 -0800 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 27 Feb 2018 17:58:13 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 27 Feb 2018 17:58:13 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.116]) by shsmsx102.ccr.corp.intel.com ([169.254.2.124]) with mapi id 14.03.0319.002; Wed, 28 Feb 2018 09:58:11 +0800 From: "Tan, Jianfeng" To: "Burakov, Anatoly" , "dev@dpdk.org" Thread-Topic: [PATCH v3 4/5] eal: prevent secondary process init while sending messages Thread-Index: AQHTr9hD0MEwv5ObUEOVQWVY42fa+aO5CX9g Date: Wed, 28 Feb 2018 01:58:11 +0000 Message-ID: References: <31f6d9ef676fb1eb0a664c06d62d66f32876dcb6.1519672713.git.anatoly.burakov@intel.com> <4be9dbc2f5751e9584f69997d4ef0077992eae52.1519740527.git.anatoly.burakov@intel.com> In-Reply-To: <4be9dbc2f5751e9584f69997d4ef0077992eae52.1519740527.git.anatoly.burakov@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 4/5] eal: prevent secondary process init while sending messages X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Feb 2018 01:58:16 -0000 Hi Anatoly, > -----Original Message----- > From: Burakov, Anatoly > Sent: Tuesday, February 27, 2018 10:36 PM > To: dev@dpdk.org > Cc: Tan, Jianfeng > Subject: [PATCH v3 4/5] eal: prevent secondary process init while sending > messages >=20 > Currently, it is possible to spin up a secondary process while > either sendmsg or request is in progress. Fix this by adding > directory locks during init, sendmsg and requests. Could you give a more detailed example for this issue? And why locking the directory can help? Thanks, Jianfeng >=20 > Signed-off-by: Anatoly Burakov > --- >=20 > Notes: > v3: no changes >=20 > v2: no changes >=20 > lib/librte_eal/common/eal_common_proc.c | 47 > ++++++++++++++++++++++++++++++++- > 1 file changed, 46 insertions(+), 1 deletion(-) >=20 > diff --git a/lib/librte_eal/common/eal_common_proc.c > b/lib/librte_eal/common/eal_common_proc.c > index 7c87971..7856a7b 100644 > --- a/lib/librte_eal/common/eal_common_proc.c > +++ b/lib/librte_eal/common/eal_common_proc.c > @@ -507,6 +507,7 @@ rte_mp_channel_init(void) > { > char thread_name[RTE_MAX_THREAD_NAME_LEN]; > char *path; > + int dir_fd; > pthread_t tid; >=20 > snprintf(mp_filter, PATH_MAX, ".%s_unix_*", > @@ -516,14 +517,32 @@ rte_mp_channel_init(void) > snprintf(mp_dir_path, PATH_MAX, "%s", dirname(path)); > free(path); >=20 > + /* lock the directory */ > + dir_fd =3D open(mp_dir_path, O_RDONLY); > + if (dir_fd < 0) { > + RTE_LOG(ERR, EAL, "failed to open %s: %s\n", > + mp_dir_path, strerror(errno)); > + return -1; > + } > + > + if (flock(dir_fd, LOCK_EX)) { > + RTE_LOG(ERR, EAL, "failed to lock %s: %s\n", > + mp_dir_path, strerror(errno)); > + close(dir_fd); > + return -1; > + } > + > if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY && > unlink_sockets(mp_filter)) { > RTE_LOG(ERR, EAL, "failed to unlink mp sockets\n"); > + close(dir_fd); > return -1; > } >=20 > - if (open_socket_fd() < 0) > + if (open_socket_fd() < 0) { > + close(dir_fd); > return -1; > + } >=20 > if (pthread_create(&tid, NULL, mp_handle, NULL) < 0) { > RTE_LOG(ERR, EAL, "failed to create mp thead: %s\n", > @@ -536,6 +555,11 @@ rte_mp_channel_init(void) > /* try best to set thread name */ > snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, > "rte_mp_handle"); > rte_thread_setname(tid, thread_name); > + > + /* unlock the directory */ > + flock(dir_fd, LOCK_UN); > + close(dir_fd); > + > return 0; > } >=20 > @@ -650,6 +674,14 @@ mp_send(struct rte_mp_msg *msg, const char > *peer, int type) > return -1; > } > dir_fd =3D dirfd(mp_dir); > + /* lock the directory to prevent processes spinning up while we send > */ > + if (flock(dir_fd, LOCK_EX)) { > + RTE_LOG(ERR, EAL, "Unable to lock directory %s\n", > + mp_dir_path); > + rte_errno =3D errno; > + closedir(mp_dir); > + return -1; > + } > while ((ent =3D readdir(mp_dir))) { > char path[PATH_MAX]; > const char *peer_name; > @@ -673,6 +705,8 @@ mp_send(struct rte_mp_msg *msg, const char *peer, > int type) > else if (active > 0 && send_msg(path, msg, type) < 0) > ret =3D -1; > } > + /* unlock the dir */ > + flock(dir_fd, LOCK_UN); >=20 > closedir(mp_dir); > return ret; > @@ -832,6 +866,15 @@ rte_mp_request(struct rte_mp_msg *req, struct > rte_mp_reply *reply, > } > dir_fd =3D dirfd(mp_dir); >=20 > + /* lock the directory to prevent processes spinning up while we send > */ > + if (flock(dir_fd, LOCK_EX)) { > + RTE_LOG(ERR, EAL, "Unable to lock directory %s\n", > + mp_dir_path); > + closedir(mp_dir); > + rte_errno =3D errno; > + return -1; > + } > + > while ((ent =3D readdir(mp_dir))) { > const char *peer_name; > char path[PATH_MAX]; > @@ -857,6 +900,8 @@ rte_mp_request(struct rte_mp_msg *req, struct > rte_mp_reply *reply, > if (mp_request_one(path, req, reply, &end)) > ret =3D -1; > } > + /* unlock the directory */ > + flock(dir_fd, LOCK_UN); >=20 > closedir(mp_dir); > return ret; > -- > 2.7.4