| 274 | } |
| 275 | |
| 276 | cs_error_t sam_initialize ( |
| 277 | int time_interval, |
| 278 | sam_recovery_policy_t recovery_policy) |
| 279 | { |
| 280 | quorum_callbacks_t quorum_callbacks; |
| 281 | uint32_t quorum_type; |
| 282 | cs_error_t ret; |
| 283 | |
| 284 | ret = CS_OK; |
| 285 | |
| 286 | if (SAM_RP_MASK (recovery_policy) != SAM_RECOVERY_POLICY_QUIT && |
| 287 | SAM_RP_MASK (recovery_policy) != SAM_RECOVERY_POLICY_RESTART) { |
| 288 | return (CS_ERR_INVALID_PARAM); |
| 289 | } |
| 290 | |
| 291 | pthread_mutex_lock (&sam_internal_data.lock); |
| 292 | |
| 293 | if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_NOT_INITIALIZED) { |
| 294 | ret = CS_ERR_BAD_HANDLE; |
| 295 | goto exit_mutex_unlock; |
| 296 | } |
| 297 | |
| 298 | if (recovery_policy & SAM_RECOVERY_POLICY_QUORUM) { |
| 299 | /* |
| 300 | * Initialize quorum |
| 301 | */ |
| 302 | quorum_callbacks.quorum_notify_fn = quorum_notification_fn; |
| 303 | if ((ret = quorum_initialize (&sam_internal_data.quorum_handle, &quorum_callbacks, &quorum_type)) != CS_OK) { |
| 304 | goto exit_mutex_unlock; |
| 305 | } |
| 306 | |
| 307 | if ((ret = quorum_trackstart (sam_internal_data.quorum_handle, CS_TRACK_CHANGES)) != CS_OK) { |
| 308 | goto exit_error_quorum; |
| 309 | } |
| 310 | |
| 311 | if ((ret = quorum_fd_get (sam_internal_data.quorum_handle, &sam_internal_data.quorum_fd)) != CS_OK) { |
| 312 | goto exit_error_quorum; |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * Dispatch initial quorate state |
| 317 | */ |
| 318 | if ((ret = quorum_dispatch (sam_internal_data.quorum_handle, CS_DISPATCH_ONE)) != CS_OK) { |
| 319 | goto exit_error_quorum; |
| 320 | } |
| 321 | } |
| 322 | sam_internal_data.recovery_policy = recovery_policy; |
| 323 | |
| 324 | sam_internal_data.time_interval = time_interval; |
| 325 | |
| 326 | sam_internal_data.internal_status = SAM_INTERNAL_STATUS_INITIALIZED; |
| 327 | |
| 328 | sam_internal_data.warn_signal = SIGTERM; |
| 329 | |
| 330 | sam_internal_data.am_i_child = 0; |
| 331 | |
| 332 | sam_internal_data.user_data = NULL; |
| 333 | sam_internal_data.user_data_size = 0; |