From patchwork Fri Nov 13 06:19:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Khapyorsky X-Patchwork-Id: 59725 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAD6HJvW002313 for ; Fri, 13 Nov 2009 06:17:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754091AbZKMGRb (ORCPT ); Fri, 13 Nov 2009 01:17:31 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753481AbZKMGRb (ORCPT ); Fri, 13 Nov 2009 01:17:31 -0500 Received: from ey-out-2122.google.com ([74.125.78.25]:2063 "EHLO ey-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753968AbZKMGR3 (ORCPT ); Fri, 13 Nov 2009 01:17:29 -0500 Received: by ey-out-2122.google.com with SMTP id 9so829700eyd.19 for ; Thu, 12 Nov 2009 22:17:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:date:from:to :subject:message-id:mime-version:content-type:content-disposition :user-agent; bh=j7ypEO/C5nTGIhijsArDPaIGXkswVWYzDTmZv4UDqJM=; b=jySmBd6rNMz1HbK04Z3YGxobI8JkTO38UwQgwO7PvQ4kOQmKJG3z5IAiCi50v7Oxby O2ZlcoD30j/GgmGcj0nGOFK7gtp7jPX6OT9k27x4Tnx49XOtH2qhbLST3BB/FVpooEd1 gVbCgUD8r6uSjLsxmg6mNa1lCDIEGnGSfJVe4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=afeg1EG2mv6nvEQo8vsE9QVuZf1inBLrDdrE+lWNZFrJSeV+AE6d5ednDD0093niWj 2GzKyQuXV/pJTnGFAeh5ZglRuicUcThS9PfzrN8QhX5vpt+B0YQsJFIeZGoKb+g6gVF2 keCZd2GZZ+PZh+Nh/oEr7jWniZYQT2Qt3MAt8= Received: by 10.213.24.1 with SMTP id t1mr96004ebb.57.1258093051989; Thu, 12 Nov 2009 22:17:31 -0800 (PST) Received: from me.localdomain (85.64.35.106.dynamic.barak-online.net [85.64.35.106]) by mx.google.com with ESMTPS id 24sm317122eyx.29.2009.11.12.22.17.31 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 12 Nov 2009 22:17:31 -0800 (PST) Received: by me.localdomain (Postfix, from userid 1000) id 586A61209B; Fri, 13 Nov 2009 08:19:48 +0200 (IST) Date: Fri, 13 Nov 2009 08:19:48 +0200 From: Sasha Khapyorsky To: linux-rdma Subject: [PATCH] opensm/osm_sa_mcmember_record.c: move mgid allocation code Message-ID: <20091113061948.GJ7192@me> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/opensm/opensm/osm_sa_mcmember_record.c b/opensm/opensm/osm_sa_mcmember_record.c index 357e6ab..f6a9ead 100644 --- a/opensm/opensm/osm_sa_mcmember_record.c +++ b/opensm/opensm/osm_sa_mcmember_record.c @@ -712,19 +712,45 @@ static boolean_t mgrp_request_is_realizable(IN osm_sa_t * sa, return TRUE; } +static unsigned build_new_mgid(osm_sa_t * sa, ib_net64_t comp_mask, + ib_member_rec_t * mcmr) +{ + ib_gid_t *mgid = &mcmr->mgid; + uint8_t scope; + + /* use the given scope state only if requested! */ + if (comp_mask & IB_MCR_COMPMASK_SCOPE) + ib_member_get_scope_state(mcmr->scope_state, &scope, NULL); + else + /* to guarantee no collision with other subnets use local scope! */ + scope = IB_MC_SCOPE_LINK_LOCAL; + + mgid->raw[0] = 0xff; + mgid->raw[1] = 0x10 | scope; + mgid->raw[2] = 0xa0; + mgid->raw[3] = 0x1b; + + /* HACK: use the SA port gid to make it globally unique */ + memcpy(&mgid->raw[4], &sa->p_subn->opt.subnet_prefix, sizeof(uint64_t)); + + /* HACK: how do we get a unique number - use the mlid twice */ + memcpy(&mgid->raw[10], &mcmr->mlid, sizeof(uint16_t)); + memcpy(&mgid->raw[12], &mcmr->mlid, sizeof(uint16_t)); + + return 1; +} + /********************************************************************** Call this function to create a new mgrp. **********************************************************************/ static ib_api_status_t mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa, IN ib_net64_t comp_mask, IN const ib_member_rec_t * - const p_recvd_mcmember_rec, + p_recvd_mcmember_rec, IN const osm_physp_t * p_physp, OUT osm_mgrp_t ** pp_mgrp) { ib_net16_t mlid; - uint8_t scope; - ib_gid_t *p_mgid; ib_api_status_t status = IB_SUCCESS; ib_member_rec_t mcm_rec = *p_recvd_mcmember_rec; /* copy for modifications */ @@ -743,37 +769,24 @@ static ib_api_status_t mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa, goto Exit; } - OSM_LOG(sa->p_log, OSM_LOG_DEBUG, - "Obtained new mlid 0x%X\n", cl_ntoh16(mlid)); + OSM_LOG(sa->p_log, OSM_LOG_DEBUG, "Obtained new mlid 0x%X\n", + cl_ntoh16(mlid)); + mcm_rec.mlid = mlid; /* we need to create the new MGID if it was not defined */ if (!ib_gid_is_notzero(&p_recvd_mcmember_rec->mgid)) { /* create a new MGID */ char gid_str[INET6_ADDRSTRLEN]; - /* use the given scope state only if requested! */ - if (comp_mask & IB_MCR_COMPMASK_SCOPE) - ib_member_get_scope_state(p_recvd_mcmember_rec-> - scope_state, &scope, NULL); - else - /* to guarantee no collision with other subnets use local scope! */ - scope = IB_MC_SCOPE_LINK_LOCAL; - - p_mgid = &(mcm_rec.mgid); - p_mgid->raw[0] = 0xFF; - p_mgid->raw[1] = 0x10 | scope; - p_mgid->raw[2] = 0xA0; - p_mgid->raw[3] = 0x1B; - - /* HACK: use the SA port gid to make it globally unique */ - memcpy((&p_mgid->raw[4]), - &sa->p_subn->opt.subnet_prefix, sizeof(uint64_t)); - - /* HACK: how do we get a unique number - use the mlid twice */ - memcpy(&p_mgid->raw[10], &mlid, sizeof(uint16_t)); - memcpy(&p_mgid->raw[12], &mlid, sizeof(uint16_t)); + if (!build_new_mgid(sa, comp_mask, &mcm_rec)) { + OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1B23: " + "cannot allocate unique MGID value\n"); + free_mlid(sa, mlid); + status = IB_SA_MAD_STATUS_NO_RESOURCES; + goto Exit; + } OSM_LOG(sa->p_log, OSM_LOG_DEBUG, "Allocated new MGID:%s\n", - inet_ntop(AF_INET6, p_mgid->raw, gid_str, + inet_ntop(AF_INET6, mcm_rec.mgid.raw, gid_str, sizeof gid_str)); } else if (!validate_requested_mgid(sa, &mcm_rec)) { /* a specific MGID was requested so validate the resulting MGID */ @@ -795,7 +808,6 @@ static ib_api_status_t mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa, } /* create a new MC Group */ - mcm_rec.mlid = mlid; *pp_mgrp = osm_mgrp_new(sa->p_subn, mlid, &mcm_rec); if (*pp_mgrp == NULL) { OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1B08: "