ssa.c: In downstream handler, optimize rsock search when DB update msg received from access

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Move comment in ssa_downstream_handler

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Minor code refactoring in ssa_downstream_handler

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Cosmetic change to remove trailing whitespace

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_downstream_close_ssa_conn, make sure connection parameter is valid

and not already closed (NULL)

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Close rsocket if ACM reconnects without disconnect

In case of port bouncing, ACM could reconnect to AL within
keepalive time interval. As result, AL could hold two connections
to the same ACM.

This patch removes the keepalive disabled check from
the code in ssa_check_listen_events which checked
for duplicated rsocket ID/number.

Original commit for that code segment:
commit d202bb6a685ef568f94ac37b02adbd3d3a8eb96f
Author: Sasha Kotchubievsky <sashakot@mellanox.com>
Date:   Thu Jul 31 14:40:33 2014 +0300

    ssa.c: Close old connection after fast client reconnection

    Only close connection if keepalive disabled (0).
    Otherwise, close stalls downstream thread (~33 seconds
    using default parameters).

    Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
    Signed-off-by: Hal Rosenstock <hal@mellanox.com>

Note that when duplicated connection is detected, underlying rclose
can stall downstream thread. Solution is to move the actual rclose
into a separate thread (and handle any errors appropriately in
rsocket calls in downstream thread if they could occur).

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_stop_access, handle NULL SMDB reference object

If ibssa application couldn't open ib devices and exits,
smdb pointer is NULL. This can cause crash.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_close_devices, call ibv_close_device only if verbs pointer is not NULL

If ibssa application couldn't open ib devices and exits,
verbs pointer is NULL.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_ctrl_stop, avoid blocking in case of uninitialized socket pair

If ibssa application is exiting as result after
ib device opening failure, the sock is uninitialized.
IO operation on unitized socket could crash or block the
application.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
acm: Use defines rather than hard coded constants for SA and ACM base/class version

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Use pointers instead of pthread_t for access_thread and access_prdb_handler

Static, global pointers are initialized by 0. It allows for them
to be checked in destroy and to join only if the thread was actually
created.

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Fix some newly added minor memory leaks

in ssa_stop_access and error paths in ssa_start_access

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
acm.c: Cosmetic formatting change

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Removed a debug log message

SSA_DB_QUERY msg received

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
core: Eliminated no longer used or needed CORE_INTEGRATION define

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
distrib: Eliminated no longer used or needed INETGRATION and ACCESS_INTEGRATION defines

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Skip PRDB calculation in case of SMDB update waiting.

 Problem:
 Access can receive SSA_CONN_DONE message even SMDB
 update is coming.  Access could crash because it may touch
 SMDB during updating.
 Downstream doesn't accept incoming ACM connection in case
 of waiting for SMDB update. It checks Access's state using flags:
 access_update_pending and access_update_waiting. Access may
 change the state after the flags checking, but
 before SSA_CONN_DONE message processing.
 Solution:
 1. Access will check the flags before PRDB calculation. The
    flags can be changed only in Access thread. So, Access knows
    that there is no SMDB updating at the time.
 2. If Access is waiting for SMDB update, it skips PRDB
    calculation, but adds a new consumer to the internal list.
    Only Access touches the data structure.
    PRDB for the new consumer will be computed when ongoing
    SMDB will be received.
 3. Downstream accepts new PRDB connection even if SMDB
    update is coming.
ssa.c: Remove log unnecessary log message