From patchwork Sun Mar 23 20:18:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 3880691 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D981A9F38E for ; Sun, 23 Mar 2014 20:18:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EBC6E20220 for ; Sun, 23 Mar 2014 20:18:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DABB62020F for ; Sun, 23 Mar 2014 20:18:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbaCWUSo (ORCPT ); Sun, 23 Mar 2014 16:18:44 -0400 Received: from mga11.intel.com ([192.55.52.93]:10324 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751160AbaCWUSd (ORCPT ); Sun, 23 Mar 2014 16:18:33 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 23 Mar 2014 13:18:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,715,1389772800"; d="scan'208";a="505038288" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by fmsmga002.fm.intel.com with ESMTP; 23 Mar 2014 13:18:32 -0700 From: sean.hefty@intel.com To: sean.hefty@intel.com, ira.weiny@intel.com, kaike.wan@intel.com, john.fleck@intel.com, linux-rdma@vger.kernel.org Subject: [PATCH 5/9] ibacm: Record index for source and destination addresses Date: Sun, 23 Mar 2014 13:18:17 -0700 Message-Id: <1395605901-9080-6-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 In-Reply-To: <1395605901-9080-1-git-send-email-sean.hefty@intel.com> References: <1395605901-9080-1-git-send-email-sean.hefty@intel.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Sean Hefty When processing a resolve route message, record what index the source and destination addresses were located at directly into the message. This replaces returning pointers to the source and destination address that must then be passed around. When provider plug-in support is added in subsequent patches, this will avoid pointer exchanges between the core and provider code. Fix a minor issue where the src_out field may be uninitialized (value read from client message). Src_out now becomes a boolean value, rather than an index. The actual location for the output is specified as an index. This change cleanups the call to acm_svr_select_src, which selects a source address. It is only called when a source is needed, which is explicitly determined by seeing if src_out is set, rather than relying on a zero src type field. Signed-off-by: Sean Hefty --- src/acm.c | 54 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/acm.c b/src/acm.c index 4fc650b..16e929b 100644 --- a/src/acm.c +++ b/src/acm.c @@ -49,6 +49,8 @@ #include "acm_mad.h" #define src_out data[0] +#define src_index data[1] +#define dst_index data[2] #define IB_LID_MCAST_START 0xc000 @@ -1069,7 +1071,7 @@ acm_client_resolve_resp(struct acm_client *client, struct acm_msg *req_msg, if (req_msg->hdr.src_out) { msg.hdr.length += ACM_MSG_EP_LENGTH; memcpy(&msg.resolve_data[1], - &req_msg->resolve_data[req_msg->hdr.src_out], + &req_msg->resolve_data[req_msg->hdr.src_index], ACM_MSG_EP_LENGTH); } } @@ -1980,9 +1982,6 @@ static int acm_svr_select_src(struct acm_ep_addr_data *src, struct acm_ep_addr_d int ret; SOCKET s; - if (src->type) - return 0; - acm_log(2, "selecting source address\n"); memset(&addr, 0, sizeof addr); switch (dst->type) { @@ -2038,24 +2037,24 @@ out: * references to the source and destination addresses. * The message buffer contains extra address data buffers. If a * source address is not given, reference an empty address buffer, - * and we'll resolve a source address later. + * and we'll resolve a source address later. Record the location of + * the source and destination addresses in the message header data + * to avoid further searches. */ -static uint8_t -acm_svr_verify_resolve(struct acm_msg *msg, - struct acm_ep_addr_data **saddr, struct acm_ep_addr_data **daddr) +static uint8_t acm_svr_verify_resolve(struct acm_msg *msg) { - struct acm_ep_addr_data *src = NULL, *dst = NULL; - int i, cnt; + int i, cnt, have_dst = 0; if (msg->hdr.length < ACM_MSG_HDR_LENGTH) { acm_log(0, "ERROR - invalid msg hdr length %d\n", msg->hdr.length); return ACM_STATUS_EINVAL; } + msg->hdr.src_out = 1; cnt = (msg->hdr.length - ACM_MSG_HDR_LENGTH) / ACM_MSG_EP_LENGTH; for (i = 0; i < cnt; i++) { if (msg->resolve_data[i].flags & ACM_EP_FLAG_SOURCE) { - if (src) { + if (!msg->hdr.src_out) { acm_log(0, "ERROR - multiple sources specified\n"); return ACM_STATUS_ESRCADDR; } @@ -2064,10 +2063,11 @@ acm_svr_verify_resolve(struct acm_msg *msg, acm_log(0, "ERROR - unsupported source address type\n"); return ACM_STATUS_ESRCTYPE; } - src = &msg->resolve_data[i]; + msg->hdr.src_out = 0; + msg->hdr.src_index = i; } if (msg->resolve_data[i].flags & ACM_EP_FLAG_DEST) { - if (dst) { + if (have_dst) { acm_log(0, "ERROR - multiple destinations specified\n"); return ACM_STATUS_EDESTADDR; } @@ -2076,22 +2076,20 @@ acm_svr_verify_resolve(struct acm_msg *msg, acm_log(0, "ERROR - unsupported destination address type\n"); return ACM_STATUS_EDESTTYPE; } - dst = &msg->resolve_data[i]; + have_dst = 1; + msg->hdr.dst_index = i; } } - if (!dst) { + if (!have_dst) { acm_log(0, "ERROR - destination address required\n"); return ACM_STATUS_EDESTTYPE; } - if (!src) { - msg->hdr.src_out = i; - src = &msg->resolve_data[i]; - memset(src, 0, sizeof *src); + if (msg->hdr.src_out) { + msg->hdr.src_index = i; + memset(&msg->resolve_data[i], 0, sizeof(struct acm_ep_addr_data)); } - *saddr = src; - *daddr = dst; return ACM_STATUS_SUCCESS; } @@ -2138,16 +2136,20 @@ acm_svr_resolve_dest(struct acm_client *client, struct acm_msg *msg) int ret; acm_log(2, "client %d\n", client->index); - status = acm_svr_verify_resolve(msg, &saddr, &daddr); + status = acm_svr_verify_resolve(msg); if (status) { acm_log(0, "notice - misformatted or unsupported request\n"); return acm_client_resolve_resp(client, msg, NULL, status); } - status = acm_svr_select_src(saddr, daddr); - if (status) { - acm_log(0, "notice - unable to select suitable source address\n"); - return acm_client_resolve_resp(client, msg, NULL, status); + saddr = &msg->resolve_data[msg->hdr.src_index]; + daddr = &msg->resolve_data[msg->hdr.dst_index]; + if (msg->hdr.src_out) { + status = acm_svr_select_src(saddr, daddr); + if (status) { + acm_log(0, "notice - unable to select suitable source address\n"); + return acm_client_resolve_resp(client, msg, NULL, status); + } } acm_format_name(2, log_data, sizeof log_data,