From mboxrd@z Thu Jan 1 00:00:00 1970 From: Slava Ovsiienko Subject: [PATCH v5 09/13] net/mlx5: update E-Switch VXLAN netlink routines Date: Sat, 3 Nov 2018 06:18:42 +0000 Message-ID: <1541225876-8817-10-git-send-email-viacheslavo@mellanox.com> References: <1541181152-15788-2-git-send-email-viacheslavo@mellanox.com> <1541225876-8817-1-git-send-email-viacheslavo@mellanox.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Cc: "dev@dpdk.org" , Yongseok Koh , Slava Ovsiienko To: Shahaf Shuler Return-path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20043.outbound.protection.outlook.com [40.107.2.43]) by dpdk.org (Postfix) with ESMTP id 7D45A5B30 for ; Sat, 3 Nov 2018 07:18:43 +0100 (CET) In-Reply-To: <1541225876-8817-1-git-send-email-viacheslavo@mellanox.com> Content-Language: en-US List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This part of patchset updates Netlink exchange routine. Message sequence numbers became not random ones, the multipart reply messages are supported, not propagating errors to the following socket calls, Netlink replies buffer size is increased to MNL_SOCKET_BUFFER_SIZE and now is preallocated at context creation time instead of stack usage. This update is needed to support Netlink query operations. Suggested-by: Adrien Mazarguil Signed-off-by: Viacheslav Ovsiienko Acked-by: Yongseok Koh --- drivers/net/mlx5/mlx5_flow_tcf.c | 83 +++++++++++++++++++++++++++++-------= ---- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_= tcf.c index ba17806..26a91c5 100644 --- a/drivers/net/mlx5/mlx5_flow_tcf.c +++ b/drivers/net/mlx5/mlx5_flow_tcf.c @@ -3725,37 +3725,76 @@ struct pedit_parser { /** * Send Netlink message with acknowledgment. * - * @param ctx + * @param tcf * Flow context to use. * @param nlh * Message to send. This function always raises the NLM_F_ACK flag befor= e * sending. + * @param[in] msglen + * Message length. Message buffer may contain multiple commands and + * nlmsg_len field not always corresponds to actual message length. + * If 0 specified the nlmsg_len field in header is used as message lengt= h. + * @param[in] cb + * Callback handler for received message. + * @param[in] arg + * Context pointer for callback handler. * * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ static int -flow_tcf_nl_ack(struct mlx5_flow_tcf_context *ctx, struct nlmsghdr *nlh) +flow_tcf_nl_ack(struct mlx5_flow_tcf_context *tcf, + struct nlmsghdr *nlh, + uint32_t msglen, + mnl_cb_t cb, void *arg) { - alignas(struct nlmsghdr) - uint8_t ans[mnl_nlmsg_size(sizeof(struct nlmsgerr)) + - nlh->nlmsg_len - sizeof(*nlh)]; - uint32_t seq =3D ctx->seq++; - struct mnl_socket *nl =3D ctx->nl; - int ret; - - nlh->nlmsg_flags |=3D NLM_F_ACK; + unsigned int portid =3D mnl_socket_get_portid(tcf->nl); + uint32_t seq =3D tcf->seq++; + int err, ret; + + assert(tcf->nl); + assert(tcf->buf); + if (!seq) + /* seq 0 is reserved for kernel event-driven notifications. */ + seq =3D tcf->seq++; nlh->nlmsg_seq =3D seq; - ret =3D mnl_socket_sendto(nl, nlh, nlh->nlmsg_len); - if (ret !=3D -1) - ret =3D mnl_socket_recvfrom(nl, ans, sizeof(ans)); - if (ret !=3D -1) - ret =3D mnl_cb_run - (ans, ret, seq, mnl_socket_get_portid(nl), NULL, NULL); + if (!msglen) { + msglen =3D nlh->nlmsg_len; + nlh->nlmsg_flags |=3D NLM_F_ACK; + } + ret =3D mnl_socket_sendto(tcf->nl, nlh, msglen); + err =3D (ret <=3D 0) ? errno : 0; + nlh =3D (struct nlmsghdr *)(tcf->buf); + /* + * The following loop postpones non-fatal errors until multipart + * messages are complete. + */ if (ret > 0) + while (true) { + ret =3D mnl_socket_recvfrom(tcf->nl, tcf->buf, + tcf->buf_size); + if (ret < 0) { + err =3D errno; + if (err !=3D ENOSPC) + break; + } + if (!err) { + ret =3D mnl_cb_run(nlh, ret, seq, portid, + cb, arg); + if (ret < 0) { + err =3D errno; + break; + } + } + /* Will receive till end of multipart message */ + if (!(nlh->nlmsg_flags & NLM_F_MULTI) || + nlh->nlmsg_type =3D=3D NLMSG_DONE) + break; + } + if (!err) return 0; - rte_errno =3D errno; - return -rte_errno; + rte_errno =3D err; + return -err; } =20 /** @@ -3786,7 +3825,7 @@ struct pedit_parser { nlh =3D dev_flow->tcf.nlh; nlh->nlmsg_type =3D RTM_NEWTFILTER; nlh->nlmsg_flags =3D NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL; - if (!flow_tcf_nl_ack(ctx, nlh)) + if (!flow_tcf_nl_ack(ctx, nlh, 0, NULL, NULL)) return 0; return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -3825,7 +3864,7 @@ struct pedit_parser { nlh =3D dev_flow->tcf.nlh; nlh->nlmsg_type =3D RTM_DELTFILTER; nlh->nlmsg_flags =3D NLM_F_REQUEST; - flow_tcf_nl_ack(ctx, nlh); + flow_tcf_nl_ack(ctx, nlh, 0, NULL, NULL); } =20 /** @@ -4358,7 +4397,7 @@ struct pedit_parser { tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); tcm->tcm_parent =3D TC_H_INGRESS; /* Ignore errors when qdisc is already absent. */ - if (flow_tcf_nl_ack(ctx, nlh) && + if (flow_tcf_nl_ack(ctx, nlh, 0, NULL, NULL) && rte_errno !=3D EINVAL && rte_errno !=3D ENOENT) return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -4374,7 +4413,7 @@ struct pedit_parser { tcm->tcm_handle =3D TC_H_MAKE(TC_H_INGRESS, 0); tcm->tcm_parent =3D TC_H_INGRESS; mnl_attr_put_strz_check(nlh, sizeof(buf), TCA_KIND, "ingress"); - if (flow_tcf_nl_ack(ctx, nlh)) + if (flow_tcf_nl_ack(ctx, nlh, 0, NULL, NULL)) return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "netlink: failed to create ingress" --=20 1.8.3.1