dhodovsk / source-git / pacemaker

Forked from source-git/pacemaker 3 years ago
Clone

Blame daemons/controld/controld_based.c

rpm-build 3ee90c
/*
rpm-build 3ee90c
 * Copyright 2004-2019 the Pacemaker project contributors
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * The version control history for this file may have further details.
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * This source code is licensed under the GNU General Public License version 2
rpm-build 3ee90c
 * or later (GPLv2+) WITHOUT ANY WARRANTY.
rpm-build 3ee90c
 */
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm_internal.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <unistd.h>  /* sleep */
rpm-build 3ee90c
rpm-build 3ee90c
#include <crm/common/alerts_internal.h>
rpm-build 3ee90c
#include <crm/common/xml.h>
rpm-build 3ee90c
#include <crm/crm.h>
rpm-build 3ee90c
#include <crm/msg_xml.h>
rpm-build 3ee90c
rpm-build 3ee90c
#include <pacemaker-controld.h>
rpm-build 3ee90c
rpm-build 3ee90c
int cib_retries = 0;
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
do_cib_updated(const char *event, xmlNode * msg)
rpm-build 3ee90c
{
rpm-build 3ee90c
    if (crm_patchset_contains_alert(msg, TRUE)) {
rpm-build 3ee90c
        mainloop_set_trigger(config_read);
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
static void
rpm-build 3ee90c
do_cib_replaced(const char *event, xmlNode * msg)
rpm-build 3ee90c
{
rpm-build 3ee90c
    crm_debug("Updating the CIB after a replace: DC=%s", AM_I_DC ? "true" : "false");
rpm-build 3ee90c
    if (AM_I_DC == FALSE) {
rpm-build 3ee90c
        return;
rpm-build 3ee90c
rpm-build 3ee90c
    } else if (fsa_state == S_FINALIZE_JOIN && is_set(fsa_input_register, R_CIB_ASKED)) {
rpm-build 3ee90c
        /* no need to restart the join - we asked for this replace op */
rpm-build 3ee90c
        return;
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    /* start the join process again so we get everyone's LRM status */
rpm-build 3ee90c
    populate_cib_nodes(node_update_quick|node_update_all, __FUNCTION__);
rpm-build 3ee90c
    register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL);
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
/* A_CIB_STOP, A_CIB_START, O_CIB_RESTART */
rpm-build 3ee90c
void
rpm-build 3ee90c
do_cib_control(long long action,
rpm-build 3ee90c
               enum crmd_fsa_cause cause,
rpm-build 3ee90c
               enum crmd_fsa_state cur_state,
rpm-build 3ee90c
               enum crmd_fsa_input current_input, fsa_data_t * msg_data)
rpm-build 3ee90c
{
rpm-build 3ee90c
    CRM_ASSERT(fsa_cib_conn != NULL);
rpm-build 3ee90c
rpm-build 3ee90c
    if (action & A_CIB_STOP) {
rpm-build 3ee90c
rpm-build 3ee90c
        if (fsa_cib_conn->state != cib_disconnected && last_resource_update != 0) {
rpm-build 3ee90c
            crm_info("Waiting for resource update %d to complete", last_resource_update);
rpm-build 3ee90c
            crmd_fsa_stall(FALSE);
rpm-build 3ee90c
            return;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        crm_info("Disconnecting from the CIB manager");
rpm-build 3ee90c
        clear_bit(fsa_input_register, R_CIB_CONNECTED);
rpm-build 3ee90c
rpm-build 3ee90c
        fsa_cib_conn->cmds->del_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY, do_cib_updated);
rpm-build 3ee90c
rpm-build 3ee90c
        if (fsa_cib_conn->state != cib_disconnected) {
rpm-build 3ee90c
            fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local);
rpm-build 3ee90c
            fsa_cib_conn->cmds->signoff(fsa_cib_conn);
rpm-build 3ee90c
        }
rpm-build 3ee90c
        crm_notice("Disconnected from the CIB manager");
rpm-build 3ee90c
    }
rpm-build 3ee90c
rpm-build 3ee90c
    if (action & A_CIB_START) {
rpm-build 3ee90c
        int rc = pcmk_ok;
rpm-build 3ee90c
rpm-build 3ee90c
        if (cur_state == S_STOPPING) {
rpm-build 3ee90c
            crm_err("Ignoring request to connect to the CIB manager after shutdown");
rpm-build 3ee90c
            return;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
rpm-build 3ee90c
rpm-build 3ee90c
        if (rc != pcmk_ok) {
rpm-build 3ee90c
            /* a short wait that usually avoids stalling the FSA */
rpm-build 3ee90c
            sleep(1);
rpm-build 3ee90c
            rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        if (rc != pcmk_ok) {
rpm-build 3ee90c
            crm_info("Could not connect to the CIB manager: %s", pcmk_strerror(rc));
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (pcmk_ok !=
rpm-build 3ee90c
                   fsa_cib_conn->cmds->set_connection_dnotify(fsa_cib_conn,
rpm-build 3ee90c
                                                              crmd_cib_connection_destroy)) {
rpm-build 3ee90c
            crm_err("Could not set dnotify callback");
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (pcmk_ok !=
rpm-build 3ee90c
                   fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_REPLACE_NOTIFY,
rpm-build 3ee90c
                                                           do_cib_replaced)) {
rpm-build 3ee90c
            crm_err("Could not set CIB notification callback (replace)");
rpm-build 3ee90c
rpm-build 3ee90c
        } else if (pcmk_ok !=
rpm-build 3ee90c
                   fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY,
rpm-build 3ee90c
                                                           do_cib_updated)) {
rpm-build 3ee90c
            crm_err("Could not set CIB notification callback (update)");
rpm-build 3ee90c
rpm-build 3ee90c
        } else {
rpm-build 3ee90c
            set_bit(fsa_input_register, R_CIB_CONNECTED);
rpm-build 3ee90c
            cib_retries = 0;
rpm-build 3ee90c
        }
rpm-build 3ee90c
rpm-build 3ee90c
        if (is_not_set(fsa_input_register, R_CIB_CONNECTED)) {
rpm-build 3ee90c
rpm-build 3ee90c
            cib_retries++;
rpm-build 3ee90c
            crm_warn("Couldn't complete CIB registration %d"
rpm-build 3ee90c
                     " times... pause and retry", cib_retries);
rpm-build 3ee90c
rpm-build 3ee90c
            if (cib_retries < 30) {
rpm-build 3ee90c
                controld_start_timer(wait_timer);
rpm-build 3ee90c
                crmd_fsa_stall(FALSE);
rpm-build 3ee90c
rpm-build 3ee90c
            } else {
rpm-build 3ee90c
                crm_err("Could not complete CIB"
rpm-build 3ee90c
                        " registration  %d times..." " hard error", cib_retries);
rpm-build 3ee90c
                register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
rpm-build 3ee90c
            }
rpm-build 3ee90c
        }
rpm-build 3ee90c
    }
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
/*!
rpm-build 3ee90c
 * \internal
rpm-build 3ee90c
 * \brief Get CIB call options to use local scope if master unavailable
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \return CIB call options
rpm-build 3ee90c
 */
rpm-build 3ee90c
int crmd_cib_smart_opt()
rpm-build 3ee90c
{
rpm-build 3ee90c
    int call_opt = cib_quorum_override;
rpm-build 3ee90c
rpm-build 3ee90c
    if (fsa_state == S_ELECTION || fsa_state == S_PENDING) {
rpm-build 3ee90c
        crm_info("Sending update to local CIB in state: %s", fsa_state2string(fsa_state));
rpm-build 3ee90c
        call_opt |= cib_scope_local;
rpm-build 3ee90c
    }
rpm-build 3ee90c
    return call_opt;
rpm-build 3ee90c
}
rpm-build 3ee90c
rpm-build 3ee90c
/*!
rpm-build 3ee90c
 * \internal
rpm-build 3ee90c
 * \brief Check whether an action type should be recorded in the CIB
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \param[in] action  Action type
rpm-build 3ee90c
 *
rpm-build 3ee90c
 * \return TRUE if action should be recorded, FALSE otherwise
rpm-build 3ee90c
 */
rpm-build 3ee90c
bool
rpm-build 3ee90c
controld_action_is_recordable(const char *action)
rpm-build 3ee90c
{
rpm-build 3ee90c
    if (safe_str_eq(action, CRMD_ACTION_CANCEL)
rpm-build 3ee90c
        || safe_str_eq(action, CRMD_ACTION_DELETE)
rpm-build 3ee90c
        || safe_str_eq(action, CRMD_ACTION_NOTIFY)
rpm-build 3ee90c
        || safe_str_eq(action, CRMD_ACTION_METADATA)) {
rpm-build 3ee90c
        return FALSE;
rpm-build 3ee90c
    }
rpm-build 3ee90c
    return TRUE;
rpm-build 3ee90c
}