This source file includes following definitions.
- do_cib_updated
 
- revision_check_callback
 
- do_cib_replaced
 
- do_cib_control
 
- crmd_cib_smart_opt
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 #include <crm_internal.h>
  20 
  21 #include <unistd.h>  
  22 
  23 #include <crm/common/alerts_internal.h>
  24 #include <crm/common/xml.h>
  25 #include <crm/crm.h>
  26 #include <crm/msg_xml.h>
  27 
  28 #include <crmd.h>
  29 #include <crmd_callbacks.h>  
  30 #include <crmd_fsa.h>
  31 #include <crmd_messages.h>
  32 
  33 
  34 struct crm_subsystem_s *cib_subsystem = NULL;
  35 
  36 int cib_retries = 0;
  37 
  38 static void
  39 do_cib_updated(const char *event, xmlNode * msg)
     
  40 {
  41     if (crm_patchset_contains_alert(msg, TRUE)) {
  42         mainloop_set_trigger(config_read);
  43     }
  44 }
  45 
  46 static void
  47 revision_check_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
     
  48 {
  49     int cmp = -1;
  50     xmlNode *generation = NULL;
  51     const char *revision = NULL;
  52 
  53     if (rc != pcmk_ok) {
  54         fsa_data_t *msg_data = NULL;
  55 
  56         register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
  57         return;
  58     }
  59 
  60     generation = output;
  61     CRM_CHECK(safe_str_eq(crm_element_name(generation), XML_TAG_CIB),
  62               crm_log_xml_err(output, __FUNCTION__); return);
  63 
  64     crm_trace("Checking our feature revision %s is allowed", CRM_FEATURE_SET);
  65 
  66     revision = crm_element_value(generation, XML_ATTR_CRM_VERSION);
  67     cmp = compare_version(revision, CRM_FEATURE_SET);
  68 
  69     if (cmp > 0) {
  70         crm_err("Shutting down because the current configuration is not supported by this version "
  71                 CRM_XS " build=%s supported=%s current=%s",
  72                 PACEMAKER_VERSION, CRM_FEATURE_SET, revision);
  73         
  74         register_fsa_error_adv(C_FSA_INTERNAL, I_SHUTDOWN, NULL, NULL, __FUNCTION__);
  75         return;
  76     }
  77 }
  78 
  79 static void
  80 do_cib_replaced(const char *event, xmlNode * msg)
     
  81 {
  82     crm_debug("Updating the CIB after a replace: DC=%s", AM_I_DC ? "true" : "false");
  83     if (AM_I_DC == FALSE) {
  84         return;
  85 
  86     } else if (fsa_state == S_FINALIZE_JOIN && is_set(fsa_input_register, R_CIB_ASKED)) {
  87         
  88         return;
  89     }
  90 
  91     
  92     populate_cib_nodes(node_update_quick|node_update_all, __FUNCTION__);
  93     register_fsa_input(C_FSA_INTERNAL, I_ELECTION, NULL);
  94 }
  95 
  96 
  97 void
  98 do_cib_control(long long action,
     
  99                enum crmd_fsa_cause cause,
 100                enum crmd_fsa_state cur_state,
 101                enum crmd_fsa_input current_input, fsa_data_t * msg_data)
 102 {
 103     CRM_ASSERT(fsa_cib_conn != NULL);
 104 
 105     if (action & A_CIB_STOP) {
 106 
 107         if (fsa_cib_conn->state != cib_disconnected && last_resource_update != 0) {
 108             crm_info("Waiting for resource update %d to complete", last_resource_update);
 109             crmd_fsa_stall(FALSE);
 110             return;
 111         }
 112 
 113         crm_info("Disconnecting CIB");
 114         clear_bit(fsa_input_register, R_CIB_CONNECTED);
 115 
 116         fsa_cib_conn->cmds->del_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY, do_cib_updated);
 117 
 118         if (fsa_cib_conn->state != cib_disconnected) {
 119             fsa_cib_conn->cmds->set_slave(fsa_cib_conn, cib_scope_local);
 120             fsa_cib_conn->cmds->signoff(fsa_cib_conn);
 121         }
 122         crm_notice("Disconnected from the CIB");
 123     }
 124 
 125     if (action & A_CIB_START) {
 126         int rc = pcmk_ok;
 127 
 128         if (cur_state == S_STOPPING) {
 129             crm_err("Ignoring request to start the CIB after shutdown");
 130             return;
 131         }
 132 
 133         rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
 134 
 135         if (rc != pcmk_ok) {
 136             
 137             sleep(1);
 138             rc = fsa_cib_conn->cmds->signon(fsa_cib_conn, CRM_SYSTEM_CRMD, cib_command_nonblocking);
 139         }
 140 
 141         if (rc != pcmk_ok) {
 142             crm_info("Could not connect to the CIB service: %s", pcmk_strerror(rc));
 143 
 144         } else if (pcmk_ok !=
 145                    fsa_cib_conn->cmds->set_connection_dnotify(fsa_cib_conn,
 146                                                               crmd_cib_connection_destroy)) {
 147             crm_err("Could not set dnotify callback");
 148 
 149         } else if (pcmk_ok !=
 150                    fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_REPLACE_NOTIFY,
 151                                                            do_cib_replaced)) {
 152             crm_err("Could not set CIB notification callback (replace)");
 153 
 154         } else if (pcmk_ok !=
 155                    fsa_cib_conn->cmds->add_notify_callback(fsa_cib_conn, T_CIB_DIFF_NOTIFY,
 156                                                            do_cib_updated)) {
 157             crm_err("Could not set CIB notification callback (update)");
 158 
 159         } else {
 160             set_bit(fsa_input_register, R_CIB_CONNECTED);
 161         }
 162 
 163         if (is_set(fsa_input_register, R_CIB_CONNECTED) == FALSE) {
 164 
 165             cib_retries++;
 166             crm_warn("Couldn't complete CIB registration %d"
 167                      " times... pause and retry", cib_retries);
 168 
 169             if (cib_retries < 30) {
 170                 crm_timer_start(wait_timer);
 171                 crmd_fsa_stall(FALSE);
 172 
 173             } else {
 174                 crm_err("Could not complete CIB"
 175                         " registration  %d times..." " hard error", cib_retries);
 176                 register_fsa_error(C_FSA_INTERNAL, I_ERROR, NULL);
 177             }
 178         } else {
 179             int call_id = 0;
 180 
 181             crm_info("CIB connection established");
 182 
 183             call_id = fsa_cib_conn->cmds->query(fsa_cib_conn, NULL, NULL, cib_scope_local);
 184 
 185             fsa_register_cib_callback(call_id, FALSE, NULL, revision_check_callback);
 186             cib_retries = 0;
 187         }
 188     }
 189 }
 190 
 191 
 192 
 193 
 194 
 195 
 196 
 197 int crmd_cib_smart_opt()
     
 198 {
 199     int call_opt = cib_quorum_override;
 200 
 201     if (fsa_state == S_ELECTION || fsa_state == S_PENDING) {
 202         crm_info("Sending update to local CIB in state: %s", fsa_state2string(fsa_state));
 203         call_opt |= cib_scope_local;
 204     }
 205     return call_opt;
 206 }