corosync 3.1.7
Typedefs | Enumerations | Functions
sam.h File Reference
#include <corosync/corotypes.h>
Include dependency graph for sam.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef int(* sam_hc_callback_t) (void)
 Callback definition for event driven checking. More...
 

Enumerations

enum  sam_recovery_policy_t {
  SAM_RECOVERY_POLICY_QUIT = 1 , SAM_RECOVERY_POLICY_RESTART = 2 , SAM_RECOVERY_POLICY_QUORUM = 0x08 , SAM_RECOVERY_POLICY_QUORUM_QUIT = SAM_RECOVERY_POLICY_QUORUM | SAM_RECOVERY_POLICY_QUIT ,
  SAM_RECOVERY_POLICY_QUORUM_RESTART = SAM_RECOVERY_POLICY_QUORUM | SAM_RECOVERY_POLICY_RESTART , SAM_RECOVERY_POLICY_CMAP = 0x10 , SAM_RECOVERY_POLICY_CONFDB = 0x10
}
 sam_recovery_policy_t enum More...
 

Functions

cs_error_t sam_initialize (int time_interval, sam_recovery_policy_t recovery_policy)
 Create a new SAM connection. More...
 
cs_error_t sam_finalize (void)
 Close the SAM handle. More...
 
cs_error_t sam_start (void)
 Start healthchecking. More...
 
cs_error_t sam_stop (void)
 Stop healthchecking. More...
 
cs_error_t sam_warn_signal_set (int warn_signal)
 Set warning signal to be sent. More...
 
cs_error_t sam_register (unsigned int *instance_id)
 Register application. More...
 
cs_error_t sam_hc_send (void)
 Send healthcheck confirmation. More...
 
cs_error_t sam_hc_callback_register (sam_hc_callback_t cb)
 Register healtcheck callback. More...
 
cs_error_t sam_data_getsize (size_t *size)
 Return size of stored data. More...
 
cs_error_t sam_data_restore (void *data, size_t size)
 Return stored data. More...
 
cs_error_t sam_data_store (const void *data, size_t size)
 Store user data. More...
 
cs_error_t sam_mark_failed (void)
 Marks child as failed. More...
 

Typedef Documentation

◆ sam_hc_callback_t

typedef int(* sam_hc_callback_t) (void)

Callback definition for event driven checking.

Definition at line 59 of file sam.h.

Enumeration Type Documentation

◆ sam_recovery_policy_t

sam_recovery_policy_t enum

Enumerator
SAM_RECOVERY_POLICY_QUIT 
SAM_RECOVERY_POLICY_RESTART 
SAM_RECOVERY_POLICY_QUORUM 
SAM_RECOVERY_POLICY_QUORUM_QUIT 
SAM_RECOVERY_POLICY_QUORUM_RESTART 
SAM_RECOVERY_POLICY_CMAP 
SAM_RECOVERY_POLICY_CONFDB 

Definition at line 46 of file sam.h.

Function Documentation

◆ sam_data_getsize()

cs_error_t sam_data_getsize ( size_t *  size)

Return size of stored data.

Parameters
sizePointer to variable, where stored data size is returned. If nothing or NULL is stored, then 0 is returned.
Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEin case you call this function before sam_init or after sam_finalize
CS_ERR_INVALID_PARAMif size parameter is NULL

Definition at line 431 of file sam.c.

References CS_ERR_INVALID_PARAM.

◆ sam_data_restore()

cs_error_t sam_data_restore ( void *  data,
size_t  size 
)

Return stored data.

Parameters
dataPointer to place, where to store data
sizeAllocated size of data
Return values
CS_OKif no problem appeared
CS_ERR_BAD_HANDLEif you call this function before sam_init or after sam_finalize
CS_ERR_INVALID_PARAMif data is NULL or size is less then currently saved user data length

Definition at line 453 of file sam.c.

References CS_ERR_INVALID_PARAM, and CS_OK.

◆ sam_data_store()

cs_error_t sam_data_store ( const void *  data,
size_t  size 
)

Store user data.

Such stored data survives restart of child.

Parameters
dataData to store. You can use NULL to delete data
sizeSize of data to store.
Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEif you call this function before sam_init or after sam_finalize
CS_ERR_NO_MEMORYif data is too large and malloc/realloc was not succesfull
CS_ERR_LIBRARYif some internal error appeared (communication with parent process)

Definition at line 498 of file sam.c.

◆ sam_finalize()

cs_error_t sam_finalize ( void  )

Close the SAM handle.

This function should be called as late as possible. (in reality, if you plan just quit, and checking is stopped, there is no need to call it). Function will stop healtchecking and put library to state, where no new start is possible.

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLElibrary was not initialized by sam_initialize

Definition at line 696 of file sam.c.

◆ sam_hc_callback_register()

cs_error_t sam_hc_callback_register ( sam_hc_callback_t  cb)

Register healtcheck callback.

After you will call this function, and set cb to something else then NULL, SAM is automatically switched from application driven healtchecking to event driven healtchecking. In other words, is not longer needed to call sam_hc_send, but your callback function must return 0 in case of healtchecking is correct, or value different then 0, in case something happend. After next hc iteration, warning signal and after that kill signal is sent back to your application.

Parameters
cbPointer to healtcheck function, or NULL to switch back to application driven hc
Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEin case, you call this function before sam_init or after sam_start
CS_ERR_LIBRARYinternal library call failed. This can be one of pipe or pthread creation.

Definition at line 1406 of file sam.c.

References CS_OK.

◆ sam_hc_send()

cs_error_t sam_hc_send ( void  )

Send healthcheck confirmation.

This should be called after sam_start

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEhealthchecking is not in running state (no sam_start was called, or called after sam_stop/sam_finalize)

Definition at line 680 of file sam.c.

◆ sam_initialize()

cs_error_t sam_initialize ( int  time_interval,
sam_recovery_policy_t  recovery_policy 
)

Create a new SAM connection.

This function must be called before any other. It is recommended to call it as one of first in application.

Parameters
time_intervalTime interval in milliseconds of healthcheck. After this time, application will be killed and recovery policy will be taken. This can be zero, which means, that there is no time limit (only fall of application is checked and only then recovery action is taken)
recovery_policyOne of SAM_RECOVERY_POLICY_RESTART, which means, that after timeout application will be killed and new instance will be started. SAM_RECOVERY_POLICY_QUIT will just stop application
Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEin case user is trying to initialize initialized instance
CS_ERR_INVALID_PARAMin case recovery_policy had bad value

Definition at line 275 of file sam.c.

◆ sam_mark_failed()

cs_error_t sam_mark_failed ( void  )

Marks child as failed.

This can be called only with SAM_RECOVERY_POLICY_CMAP flag set and makes sense only for SAM_RECOVERY_POLICY_RESTART. This will kill child without sending warning signal. Cmap state key will be set to failed.

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLElibrary was not initialized or was already finalized
CS_ERR_INVALID_PARAMrecovery policy doesn't have SAM_RECOVERY_POLICY_CMAP flag set
CS_ERR_LIBRARYif some internal error appeared (communication with parent process)

Definition at line 720 of file sam.c.

◆ sam_register()

cs_error_t sam_register ( unsigned int *  instance_id)

Register application.

This is one of most crucial function. In case, your application will be restarted, you will always return to point after calling this function. This function can be called only once, and SAM must be initialized by sam_initialize. You can choose any place in your application, where to call this function.

Parameters
instance_idNULL or pointer to int memory, where current instance of application will be returned. It's always safe to suppose, that first instance (this means, no recovery action was taken yet) will be always 1 and instance_id will be raising up to MAX_INT (after this, it will fall to 0).
Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEin case, you call this function twice, or before sam_init
CS_ERR_LIBRARYinternal library call failed. This can be one of pipe or fork creation. You can get more information from errno

Definition at line 1203 of file sam.c.

◆ sam_start()

cs_error_t sam_start ( void  )

Start healthchecking.

From this time, you should call every time_interval sam_hc_send, otherwise, recovery action will be taken.

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEcomponent was not registered by sam_register

Definition at line 587 of file sam.c.

◆ sam_stop()

cs_error_t sam_stop ( void  )

Stop healthchecking.

Oposite of sam_start. You can call sam_start and sam_stop how many times you want.

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLEhealthchecking is not in running state (no sam_start was called)

Definition at line 635 of file sam.c.

◆ sam_warn_signal_set()

cs_error_t sam_warn_signal_set ( int  warn_signal)

Set warning signal to be sent.

Default signal is SIGTERM. You can use SIGKILL to emulate NOT sending warning signal and just send SIGKILL.

Return values
CS_OKin case no problem appeared
CS_ERR_BAD_HANDLElibrary was not initialized by sam_initialize or is finalized

Definition at line 741 of file sam.c.