Merge osm_mcm_port (mgrp's joined ports list) and osm_mcm_info (port's
multicast groups list where port is joined in) structures in a single
one - we need a both equivalently and merging simplifies allocation and
cleanup mechanisms dramatically.

As "side effect" it also fixes non-member re-join bug (reported by Eli
couple of months ago) "automatically":

http://lists.openfabrics.org/pipermail/general/2009-May/059644.html

Signed-off-by: Sasha Khapyorsky <sas...@voltaire.com>
---
 opensm/include/opensm/osm_mcm_port.h |   18 ++++++--
 opensm/include/opensm/osm_port.h     |   81 ----------------------------------
 opensm/opensm/Makefile.am            |    3 +-
 opensm/opensm/osm_drop_mgr.c         |   13 ++---
 opensm/opensm/osm_mcm_port.c         |    8 ++-
 opensm/opensm/osm_multicast.c        |   38 +++++++++++-----
 opensm/opensm/osm_port.c             |   59 ------------------------
 opensm/opensm/osm_sm.c               |    1 -
 8 files changed, 51 insertions(+), 170 deletions(-)

diff --git a/opensm/include/opensm/osm_mcm_port.h 
b/opensm/include/opensm/osm_mcm_port.h
index 74b6615..4d82df7 100644
--- a/opensm/include/opensm/osm_mcm_port.h
+++ b/opensm/include/opensm/osm_mcm_port.h
@@ -57,6 +57,9 @@
 #endif                         /* __cplusplus */
 
 BEGIN_C_DECLS
+
+struct osm_mgrp;
+
 /****s* OpenSM: MCM Port Object/osm_mcm_port_t
 * NAME
 *   osm_mcm_port_t
@@ -72,7 +75,9 @@ BEGIN_C_DECLS
 */
 typedef struct osm_mcm_port {
        cl_map_item_t map_item;
+       cl_list_item_t list_item;
        osm_port_t *port;
+       struct osm_mgrp *mgrp;
        ib_gid_t port_gid;
        uint8_t scope_state;
        boolean_t proxy_join;
@@ -85,6 +90,9 @@ typedef struct osm_mcm_port {
 *      port
 *              Reference to the parent port.
 *
+*      mgrp
+*              The pointer to multicast group where this port is member of
+*
 *      port_gid
 *              GID of the member port.
 *
@@ -111,18 +119,20 @@ typedef struct osm_mcm_port {
 *
 * SYNOPSIS
 */
-osm_mcm_port_t *osm_mcm_port_new(IN osm_port_t * port, IN ib_member_rec_t 
*mcmr,
-                                IN boolean_t proxy_join);
+osm_mcm_port_t *osm_mcm_port_new(IN osm_port_t * port, IN struct osm_mgrp 
*mgrp,
+                                IN ib_member_rec_t *mcmr, IN boolean_t proxy);
 /*
 * PARAMETERS
 *      port
 *              [in] Pointer to the port object.
-*              GID of the port to add to the multicast group.
+*
+*      mgrp
+*              [in] Pointer to multicast group where this port is joined.
 *
 *      mcmr
 *              [in] Pointer to MCMember record of the join request
 *
-*      proxy_join
+*      proxy
 *              [in] proxy_join state analyzed from the request
 *
 * RETURN VALUES
diff --git a/opensm/include/opensm/osm_port.h b/opensm/include/opensm/osm_port.h
index 0e0d3d2..000e2fe 100644
--- a/opensm/include/opensm/osm_port.h
+++ b/opensm/include/opensm/osm_port.h
@@ -1411,87 +1411,6 @@ osm_get_port_by_base_lid(IN const osm_subn_t * const 
p_subn,
 *       Port
 *********/
 
-/****f* OpenSM: Port/osm_port_add_mgrp
-* NAME
-*      osm_port_add_mgrp
-*
-* DESCRIPTION
-*      Logically connects a port to a multicast group.
-*
-* SYNOPSIS
-*/
-ib_api_status_t
-osm_port_add_mgrp(IN osm_port_t * const p_port, IN struct osm_mgrp *mgrp);
-/*
-* PARAMETERS
-*      p_port
-*              [in] Pointer to an osm_port_t object.
-*
-*      mgrp
-*              [in] Pointer to the multicast group.
-*
-* RETURN VALUES
-*      IB_SUCCESS
-*      IB_INSUFFICIENT_MEMORY
-*
-* NOTES
-*
-* SEE ALSO
-*      Port object
-*********/
-
-/****f* OpenSM: Port/osm_port_remove_mgrp
-* NAME
-*      osm_port_remove_mgrp
-*
-* DESCRIPTION
-*      Logically disconnects a port from a multicast group.
-*
-* SYNOPSIS
-*/
-void
-osm_port_remove_mgrp(IN osm_port_t * const p_port, IN struct osm_mgrp *mgrp);
-/*
-* PARAMETERS
-*      p_port
-*              [in] Pointer to an osm_port_t object.
-*
-*      mgrp
-*              [in] Pointer to the multicast group.
-*
-* RETURN VALUES
-*      None.
-*
-* NOTES
-*
-* SEE ALSO
-*      Port object
-*********/
-
-/****f* OpenSM: Port/osm_port_remove_all_mgrp
-* NAME
-*      osm_port_remove_all_mgrp
-*
-* DESCRIPTION
-*      Logically disconnects a port from all its multicast groups.
-*
-* SYNOPSIS
-*/
-void osm_port_remove_all_mgrp(IN osm_port_t * const p_port);
-/*
-* PARAMETERS
-*      p_port
-*              [in] Pointer to an osm_port_t object.
-*
-* RETURN VALUES
-*      None.
-*
-* NOTES
-*
-* SEE ALSO
-*      Port object
-*********/
-
 /****f* OpenSM: Physical Port/osm_physp_calc_link_mtu
 * NAME
 *      osm_physp_calc_link_mtu
diff --git a/opensm/opensm/Makefile.am b/opensm/opensm/Makefile.am
index 2d67a95..db7d790 100644
--- a/opensm/opensm/Makefile.am
+++ b/opensm/opensm/Makefile.am
@@ -31,7 +31,7 @@ opensm_SOURCES = main.c osm_console_io.c osm_console.c 
osm_db_files.c \
                 osm_db_pack.c osm_drop_mgr.c \
                 osm_inform.c osm_lid_mgr.c osm_lin_fwd_rcv.c \
                 osm_link_mgr.c osm_mcast_fwd_rcv.c \
-                osm_mcast_mgr.c osm_mcast_tbl.c osm_mcm_info.c \
+                osm_mcast_mgr.c osm_mcast_tbl.c \
                 osm_mcm_port.c osm_mesh.c osm_mtree.c osm_multicast.c 
osm_node.c \
                 osm_node_desc_rcv.c osm_node_info_rcv.c \
                 osm_opensm.c osm_pkey.c osm_pkey_mgr.c osm_pkey_rcv.c \
@@ -83,7 +83,6 @@ opensminclude_HEADERS = \
        $(srcdir)/../include/opensm/osm_mad_pool.h \
        $(srcdir)/../include/opensm/osm_madw.h \
        $(srcdir)/../include/opensm/osm_mcast_tbl.h \
-       $(srcdir)/../include/opensm/osm_mcm_info.h \
        $(srcdir)/../include/opensm/osm_mcm_port.h \
        $(srcdir)/../include/opensm/osm_mesh.h \
        $(srcdir)/../include/opensm/osm_mtree.h \
diff --git a/opensm/opensm/osm_drop_mgr.c b/opensm/opensm/osm_drop_mgr.c
index 4891bb8..4f98cc9 100644
--- a/opensm/opensm/osm_drop_mgr.c
+++ b/opensm/opensm/osm_drop_mgr.c
@@ -57,7 +57,6 @@
 #include <opensm/osm_switch.h>
 #include <opensm/osm_node.h>
 #include <opensm/osm_helper.h>
-#include <opensm/osm_mcm_info.h>
 #include <opensm/osm_multicast.h>
 #include <opensm/osm_remote_sm.h>
 #include <opensm/osm_inform.h>
@@ -157,7 +156,7 @@ static void drop_mgr_remove_port(osm_sm_t * sm, IN 
osm_port_t * p_port)
        ib_net64_t port_guid;
        osm_port_t *p_port_check;
        cl_qmap_t *p_sm_guid_tbl;
-       osm_mcm_info_t *p_mcm;
+       osm_mcm_port_t *mcm_port;
        cl_ptr_vector_t *p_port_lid_tbl;
        uint16_t min_lid_ho;
        uint16_t max_lid_ho;
@@ -209,13 +208,11 @@ static void drop_mgr_remove_port(osm_sm_t * sm, IN 
osm_port_t * p_port)
 
        drop_mgr_clean_physp(sm, p_port->p_physp);
 
-       p_mcm = (osm_mcm_info_t *) cl_qlist_remove_head(&p_port->mcm_list);
-       while (p_mcm != (osm_mcm_info_t *) cl_qlist_end(&p_port->mcm_list)) {
-               osm_mgrp_delete_port(sm->p_subn, sm->p_log, p_mcm->mgrp,
+       while (!cl_is_qlist_empty(&p_port->mcm_list)) {
+               mcm_port = cl_item_obj(cl_qlist_head(&p_port->mcm_list),
+                                      mcm_port, list_item);
+               osm_mgrp_delete_port(sm->p_subn, sm->p_log, mcm_port->mgrp,
                                     p_port->guid);
-               osm_mcm_info_delete(p_mcm);
-               p_mcm =
-                   (osm_mcm_info_t *) cl_qlist_remove_head(&p_port->mcm_list);
        }
 
        /* initialize the p_node - may need to get node_desc later */
diff --git a/opensm/opensm/osm_mcm_port.c b/opensm/opensm/osm_mcm_port.c
index 9381bff..56065e6 100644
--- a/opensm/opensm/osm_mcm_port.c
+++ b/opensm/opensm/osm_mcm_port.c
@@ -47,11 +47,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <opensm/osm_mcm_port.h>
+#include <opensm/osm_multicast.h>
 
 /**********************************************************************
  **********************************************************************/
-osm_mcm_port_t *osm_mcm_port_new(IN osm_port_t *port, IN ib_member_rec_t *mcmr,
-                                IN boolean_t proxy_join)
+osm_mcm_port_t *osm_mcm_port_new(IN osm_port_t *port, IN osm_mgrp_t *mgrp,
+                                IN ib_member_rec_t *mcmr, IN boolean_t proxy)
 {
        osm_mcm_port_t *p_mcm;
 
@@ -59,9 +60,10 @@ osm_mcm_port_t *osm_mcm_port_new(IN osm_port_t *port, IN 
ib_member_rec_t *mcmr,
        if (p_mcm) {
                memset(p_mcm, 0, sizeof(*p_mcm));
                p_mcm->port = port;
+               p_mcm->mgrp = mgrp;
                p_mcm->port_gid = mcmr->port_gid;
                p_mcm->scope_state = mcmr->scope_state;
-               p_mcm->proxy_join = proxy_join;
+               p_mcm->proxy_join = proxy;
        }
 
        return (p_mcm);
diff --git a/opensm/opensm/osm_multicast.c b/opensm/opensm/osm_multicast.c
index b03af48..e775f02 100644
--- a/opensm/opensm/osm_multicast.c
+++ b/opensm/opensm/osm_multicast.c
@@ -50,7 +50,6 @@
 #include <opensm/osm_mtree.h>
 #include <opensm/osm_inform.h>
 #include <opensm/osm_opensm.h>
-#include <opensm/osm_mcm_info.h>
 
 /**********************************************************************
  **********************************************************************/
@@ -95,11 +94,28 @@ osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid)
 
 void osm_mgrp_cleanup(osm_subn_t * subn, osm_mgrp_t * mgrp)
 {
-       if (mgrp->full_members || mgrp->well_known)
+       osm_mcm_port_t *mcm_port;
+
+       if (mgrp->full_members)
                return;
-       subn->mgroups[cl_ntoh16(mgrp->mlid) - IB_LID_MCAST_START_HO] = NULL;
+
+       osm_mtree_destroy(mgrp->p_root);
+       mgrp->p_root = NULL;
+
+       while (cl_qmap_count(&mgrp->mcm_port_tbl)) {
+               mcm_port = (osm_mcm_port_t *)cl_qmap_head(&mgrp->mcm_port_tbl);
+               cl_qmap_remove_item(&mgrp->mcm_port_tbl, &mcm_port->map_item);
+               cl_qlist_remove_item(&mcm_port->port->mcm_list,
+                                    &mcm_port->list_item);
+               osm_mcm_port_delete(mcm_port);
+       }
+
+       if (mgrp->well_known)
+               return;
+
        cl_fmap_remove_item(&subn->mgrp_mgid_tbl, &mgrp->map_item);
-       osm_mgrp_delete(mgrp);
+       subn->mgroups[cl_ntoh16(mgrp->mlid) - IB_LID_MCAST_START_HO] = NULL;
+       free(mgrp);
 }
 
 /**********************************************************************
@@ -151,7 +167,7 @@ osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, 
osm_log_t * log,
                        cl_ntoh16(mgrp->mlid));
        }
 
-       mcm_port = osm_mcm_port_new(port, mcmr, proxy);
+       mcm_port = osm_mcm_port_new(port, mgrp, mcmr, proxy);
        if (!mcm_port)
                return NULL;
 
@@ -176,10 +192,7 @@ osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, 
osm_log_t * log,
                    ib_member_set_scope_state(prev_scope,
                                              prev_join_state | join_state);
        } else {
-               if (osm_port_add_mgrp(port, mgrp)) {
-                       osm_mcm_port_delete(mcm_port);
-                       return NULL;
-               }
+               cl_qlist_insert_tail(&port->mcm_list, &mcm_port->list_item);
                osm_sm_reroute_mlid(&subn->p_osm->sm, mgrp->mlid);
        }
 
@@ -230,10 +243,11 @@ void osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * 
log, osm_mgrp_t * mgrp,
                mcmr->scope_state = mcm_port->scope_state;
        } else {
                mcmr->scope_state = mcm_port->scope_state;
-               cl_qmap_remove_item(&mgrp->mcm_port_tbl, &mcm_port->map_item);
                OSM_LOG(log, OSM_LOG_DEBUG, "removing port 0x%" PRIx64 "\n",
                        cl_ntoh64(mcm_port->port->guid));
-               osm_port_remove_mgrp(mcm_port->port, mgrp);
+               cl_qmap_remove_item(&mgrp->mcm_port_tbl, &mcm_port->map_item);
+               cl_qlist_remove_item(&mcm_port->port->mcm_list,
+                                    &mcm_port->list_item);
                osm_mcm_port_delete(mcm_port);
                osm_sm_reroute_mlid(&subn->p_osm->sm, mgrp->mlid);
        }
@@ -255,8 +269,8 @@ void osm_mgrp_delete_port(osm_subn_t * subn, osm_log_t * 
log, osm_mgrp_t * mgrp,
                mcmrec.scope_state = 0xf;
                osm_mgrp_remove_port(subn, log, mgrp, (osm_mcm_port_t *) item,
                                     &mcmrec);
+               osm_mgrp_cleanup(subn, mgrp);
        }
-       osm_mgrp_cleanup(subn, mgrp);
 }
 
 /**********************************************************************
diff --git a/opensm/opensm/osm_port.c b/opensm/opensm/osm_port.c
index 3470381..dc8a768 100644
--- a/opensm/opensm/osm_port.c
+++ b/opensm/opensm/osm_port.c
@@ -51,7 +51,6 @@
 #include <opensm/osm_port.h>
 #include <opensm/osm_node.h>
 #include <opensm/osm_madw.h>
-#include <opensm/osm_mcm_info.h>
 #include <opensm/osm_switch.h>
 
 /**********************************************************************
@@ -132,8 +131,6 @@ void osm_physp_init(IN osm_physp_t * p_physp, IN const 
ib_net64_t port_guid,
  **********************************************************************/
 void osm_port_delete(IN OUT osm_port_t ** pp_port)
 {
-       /* cleanup all mcm recs attached */
-       osm_port_remove_all_mgrp(*pp_port);
        free(*pp_port);
        *pp_port = NULL;
 }
@@ -223,62 +220,6 @@ Found:
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_port_add_mgrp(IN osm_port_t * p_port, IN osm_mgrp_t *mgrp)
-{
-       ib_api_status_t status = IB_SUCCESS;
-       osm_mcm_info_t *p_mcm;
-
-       p_mcm = osm_mcm_info_new(mgrp);
-       if (p_mcm)
-               cl_qlist_insert_tail(&p_port->mcm_list,
-                                    (cl_list_item_t *) p_mcm);
-       else
-               status = IB_INSUFFICIENT_MEMORY;
-
-       return status;
-}
-
-/**********************************************************************
- **********************************************************************/
-static cl_status_t port_mgrp_find_func(IN const cl_list_item_t * p_list_item,
-                                      IN void *context)
-{
-       if (context == ((osm_mcm_info_t *) p_list_item)->mgrp)
-               return CL_SUCCESS;
-       else
-               return CL_NOT_FOUND;
-}
-
-/**********************************************************************
- **********************************************************************/
-void osm_port_remove_mgrp(IN osm_port_t * p_port, IN osm_mgrp_t *mgrp)
-{
-       cl_list_item_t *p_mcm;
-
-       p_mcm = cl_qlist_find_from_head(&p_port->mcm_list, port_mgrp_find_func,
-                                       mgrp);
-
-       if (p_mcm != cl_qlist_end(&p_port->mcm_list)) {
-               cl_qlist_remove_item(&p_port->mcm_list, p_mcm);
-               osm_mcm_info_delete((osm_mcm_info_t *) p_mcm);
-       }
-}
-
-/**********************************************************************
- **********************************************************************/
-void osm_port_remove_all_mgrp(IN osm_port_t * p_port)
-{
-       cl_list_item_t *p_mcm;
-
-       p_mcm = cl_qlist_remove_head(&p_port->mcm_list);
-       while (p_mcm != cl_qlist_end(&p_port->mcm_list)) {
-               osm_mcm_info_delete((osm_mcm_info_t *) p_mcm);
-               p_mcm = cl_qlist_remove_head(&p_port->mcm_list);
-       }
-}
-
-/**********************************************************************
- **********************************************************************/
 uint8_t osm_physp_calc_link_mtu(IN osm_log_t * p_log,
                                IN const osm_physp_t * p_physp)
 {
diff --git a/opensm/opensm/osm_sm.c b/opensm/opensm/osm_sm.c
index 88f5ebe..6eaee0d 100644
--- a/opensm/opensm/osm_sm.c
+++ b/opensm/opensm/osm_sm.c
@@ -57,7 +57,6 @@
 #include <opensm/osm_log.h>
 #include <opensm/osm_node.h>
 #include <opensm/osm_msgdef.h>
-#include <opensm/osm_mcm_info.h>
 #include <opensm/osm_perfmgr.h>
 #include <opensm/osm_opensm.h>
 
-- 
1.6.5.rc1

_______________________________________________
general mailing list
general@lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to