ssa.c: In ssa_downstream_svc_server, close connection if update pending or waiting

While DB update is pending or waiting, incoming connections cannot
be accepted.

Unfortunately, in rsockets, connection must be accepted before torn down in
case of update is pending or waiting so that is what this change does.

This relies on downstream client reconnecting some time later.
This part is not currently implemented (can only kill and restart
downstream client to "simulate" this behavior).

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: Fix smdb_dump directory in case of PRDB calculation failure

The smdb_dump directory name is changed from 'smdb_dump_dir/epoch'
to 'smdb_dump_dir.epoch', since it might cause an error when
calling 'mkdir()' and smdb_dump_dir doesn't exist.

Signed-off-by: Ilya Nelkenbaum <ilyan@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa.c: In ssa_calculate_prdb, make a couple of error messages more informative

In case of mkdir() failure, dump_dir directory
is printed in log error message as well.

Signed-off-by: Ilya Nelkenbaum <ilyan@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa_log.c: Make get_thread_id function global rather than static

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa_log.c: Use tid if thread's name is not set in get_thread_id

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
tests: Add access to GNU extension functions to testers

All other SSA components (core plugin, ibacm, ibssa)
are GNU compatible already.

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

Signed-off-by: Lenny Verkhovsky <lennyb@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
ssa_db.h: Add DB_EPOCH_INVALID definition

Epoch 0 (DB_EPOCH_INVALID) is used as invalid epoch.

Signed-off-by: Ilya Nelkenbaum <ilyan@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
plugin/ssa_extract.c: Eliminate full LFT extract dependency on 'first' flag

Currently full LFT tables extraction is conditionalized
on 'first' flag, that is raised after first SUBNET UP event.
This flag is also used in other SSA mechanisms, such as
distribution tree generation and thus it might interrupt
LFT tables extraction.

In order to avoid that, a simple check for already existing
LFT tables is performed, and if not - full LFT tables extraction
is forced.

Signed-off-by: Ilya Nelkenbaum <ilyan@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
plugin: Add first as parameter to ssa_db_validate_lft in ssa_extract

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
plugin: Add first as parameter to ssa_db_compare in ssa_comparison

Due to this (and previous) change can now make first variable
in core.c static rather than global as it no longer needs to be
extern'd elsewhere.

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
Set epoch to DB_EPOCH_INVALID rather than 0

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
tests/loadsave: Include common.h in loadsave.c

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
tests/loadsave: Use CFLAGS instead of CPPFLAGS

C-source uses CFLAGS in compilation and not CPPFLAGS

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
acm.c: Create ibacm.log before opening SSA devices

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
configure: Add configuration for addr2line path

If addr2line utility is found, a new configuration parameter
is defined in config.h:

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
configure: Add HAVE_ADDR2LINE configuration define

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
configure: Add configuration for gstack

If gstack utility is found, a new configuration parameters
is defined in config.h:

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
Add ssa_signal_handler.c under shared subdirectory

SSA signal handler allows for proper error reporting that
make us able to reproduce and fix bugs.
ssa_set_ssa_signal_handler() function initiates the signal
handler.
The handler dumps the stack backtrace to SSA log. ssa_open_log
function creates the log. Before the function call, the log
is NULL and no backtrace is dumped.

The signal handler grabs a stack using two different ways.
1. System backtrace call.
   See http://linux.die.net/man/3/backtrace
   The function returns binary names, shifts and symbols. The symbols
   are taken from dynamic symbol name.
   Use -rdynamic option to gcc, which makes it pass a flag to the linker
   which ensures that all symbols are placed in the table.
   We use addr2line utility for translation shift to location is source.
   If the utility install the signal handler will launch it and translate
   a shift in binary file to the source file and line number.
   The signal handler dosen't print 3 top frames in stack which corresponded to
   internal functions used for backtrace dumping.
   Using backtrace we get only stack for current thread.
2. gstack ustility.
   See http://linux.die.net/man/1/gstack
   The utility prints a stack trace for all running threads.
   The signal handler launch the utility only if it exist on the computer.

ssa_signal_handler.c includes two testers. First one checks
run_cmd function. Use _SSA_RUN_CMD_TESTER define for building
the tester. The second one checks the signal handler in
multithreaded environment. Use _SSA_RUN_CMD_TESTER for compilation.

Examples:
backtrace output with addr2line:
==== [BACKTRACE] ====
3  0x40f387 in ssa_ctrl_run () from ssa.c:4079
4  0x4048da in distrib_ctrl_handler () from distrib.c:447
==== [BACKTRACE] ====

backtrace output without addr2line:
==== [BACKTRACE] ====
/lib64/libpthread.so.0() [0x33caa0f500]
/sashakot/usr/sbin/ibssa(ssa_ctrl_run+0x84) [0x40f097]
/sashakot/usr/sbin/ibssa() [0x4045ea]
==== [BACKTRACE] ====

gstack output:
==== [gstack BACKTRACE] ====
Thread 8 (Thread 0x7f7533f58700 (LWP 21754)):
0  0x00000033ca2db60d in read () from /lib64/libc.so.6
1  0x00000033ca271f68 in _IO_new_file_underflow () from /lib64/libc.so.6
2  0x00000033ca274e8d in _IO_default_xsgetn_internal () from /lib64/libc.so.6
3  0x00000033ca2676e2 in fread () from /lib64/libc.so.6
4  0x0000000000419394 in run_cmd ()
5  0x000000000041962a in ssa_print_backtrace_with_gstack ()
6  0x00000000004197c7 in ssa_print_backtrace ()
7  0x0000000000419321 in ssa_signal_handler ()
8  <signal handler called>
9  0x000000000040f387 in ssa_ctrl_run ()
10 0x00000000004048da in distrib_ctrl_handler ()
11 0x00000033caa07851 in start_thread () from /lib64/libpthread.so.0
12 0x00000033ca2e890d in clone () from /lib64/libc.so.6
Thread 7 (Thread 0x7f753334e700 (LWP 21755)):
0  0x00000033ca2df253 in poll () from /lib64/libc.so.6
1  0x00007f753418f314 in rpoll () from /sashakot/usr/lib/librdmacm.so.1
2  0x00000000004089ff in ssa_upstream_handler ()
3  0x00000033caa07851 in start_thread () fro/usr/bin/gstack 21753
==== [gstack  BACKTRACE] ====

Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Signed-off-by: Hal Rosenstock <hal@mellanox.com>
Use ssa_signal_handler in SSA components

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