| 599 | } |
| 600 | |
| 601 | cs_error_t sam_start (void) |
| 602 | { |
| 603 | char command; |
| 604 | cs_error_t ret; |
| 605 | sam_recovery_policy_t recpol; |
| 606 | |
| 607 | ret = CS_OK; |
| 608 | |
| 609 | pthread_mutex_lock (&sam_internal_data.lock); |
| 610 | |
| 611 | if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_REGISTERED) { |
| 612 | ret = CS_ERR_BAD_HANDLE; |
| 613 | goto exit_mutex_unlock; |
| 614 | } |
| 615 | |
| 616 | recpol = sam_internal_data.recovery_policy; |
| 617 | |
| 618 | command = SAM_COMMAND_START; |
| 619 | |
| 620 | if (sam_safe_write (sam_internal_data.child_fd_out, &command, sizeof (command)) != sizeof (command)) { |
| 621 | ret = CS_ERR_LIBRARY; |
| 622 | goto exit_mutex_unlock; |
| 623 | } |
| 624 | |
| 625 | if (recpol & SAM_RECOVERY_POLICY_QUORUM || recpol & SAM_RECOVERY_POLICY_CMAP) { |
| 626 | /* |
| 627 | * Wait for parent reply |
| 628 | */ |
| 629 | if ((ret = sam_read_reply (sam_internal_data.child_fd_in)) != CS_OK) { |
| 630 | goto exit_mutex_unlock; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | if (sam_internal_data.hc_callback) { |
| 635 | if (sam_safe_write (sam_internal_data.cb_wpipe_fd, &command, sizeof (command)) != sizeof (command)) { |
| 636 | ret = CS_ERR_LIBRARY; |
| 637 | goto exit_mutex_unlock; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | sam_internal_data.internal_status = SAM_INTERNAL_STATUS_STARTED; |
| 642 | |
| 643 | exit_mutex_unlock: |
| 644 | pthread_mutex_unlock (&sam_internal_data.lock); |
| 645 | |
| 646 | return (ret); |
| 647 | } |
| 648 | |
| 649 | static cs_error_t sam_stop_nolock (void) |
| 650 | { |