root/daemons/controld/controld_attrd.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. controld_close_attrd_ipc
  2. node_type
  3. when
  4. handle_attr_error
  5. update_attrd
  6. update_attrd_list
  7. update_attrd_remote_node_removed
  8. update_attrd_clear_failures

   1 /*
   2  * Copyright 2006-2024 the Pacemaker project contributors
   3  *
   4  * The version control history for this file may have further details.
   5  *
   6  * This source code is licensed under the GNU General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <crm/crm.h>
  13 #include <crm/common/attrs_internal.h>
  14 #include <crm/common/ipc.h>
  15 #include <crm/common/ipc_attrd_internal.h>
  16 #include <crm/common/xml.h>
  17 
  18 #include <pacemaker-controld.h>
  19 
  20 static pcmk_ipc_api_t *attrd_api = NULL;
  21 
  22 void
  23 controld_close_attrd_ipc(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25     if (attrd_api != NULL) {
  26         crm_trace("Closing connection to pacemaker-attrd");
  27         pcmk_disconnect_ipc(attrd_api);
  28         pcmk_free_ipc_api(attrd_api);
  29         attrd_api = NULL;
  30     }
  31 }
  32 
  33 static inline const char *
  34 node_type(bool is_remote)
     /* [previous][next][first][last][top][bottom][index][help] */
  35 {
  36     return is_remote? "Pacemaker Remote" : "cluster";
  37 }
  38 
  39 static inline const char *
  40 when(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42     return pcmk_is_set(controld_globals.fsa_input_register,
  43                        R_SHUTDOWN)? " at shutdown" : "";
  44 }
  45 
  46 static void
  47 handle_attr_error(void)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     if (AM_I_DC) {
  50         /* We are unable to provide accurate information to the
  51          * scheduler, so allow another node to take over DC.
  52          * @TODO Should we do this unconditionally on any failure?
  53          */
  54         crmd_exit(CRM_EX_FATAL);
  55 
  56     } else if (pcmk_is_set(controld_globals.fsa_input_register, R_SHUTDOWN)) {
  57         // Fast-track shutdown since unable to request via attribute
  58         register_fsa_input(C_FSA_INTERNAL, I_FAIL, NULL);
  59     }
  60 }
  61 
  62 void
  63 update_attrd(const char *host, const char *name, const char *value,
     /* [previous][next][first][last][top][bottom][index][help] */
  64              const char *user_name, gboolean is_remote_node)
  65 {
  66     int rc = pcmk_rc_ok;
  67 
  68     if (attrd_api == NULL) {
  69         rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
  70     }
  71     if (rc == pcmk_rc_ok) {
  72         uint32_t attrd_opts = pcmk__node_attr_value;
  73 
  74         if (is_remote_node) {
  75             pcmk__set_node_attr_flags(attrd_opts, pcmk__node_attr_remote);
  76         }
  77         rc = pcmk__attrd_api_update(attrd_api, host, name, value,
  78                                     NULL, NULL, user_name, attrd_opts);
  79     }
  80     if (rc != pcmk_rc_ok) {
  81         do_crm_log(AM_I_DC? LOG_CRIT : LOG_ERR,
  82                    "Could not update attribute %s=%s for %s node %s%s: %s "
  83                    CRM_XS " rc=%d", name, value, node_type(is_remote_node),
  84                    host, when(), pcmk_rc_str(rc), rc);
  85         handle_attr_error();
  86     }
  87 }
  88 
  89 void
  90 update_attrd_list(GList *attrs, uint32_t opts)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92     int rc = pcmk_rc_ok;
  93 
  94     if (attrd_api == NULL) {
  95         rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
  96     }
  97     if (rc == pcmk_rc_ok) {
  98         rc = pcmk__attrd_api_update_list(attrd_api, attrs, NULL, NULL, NULL,
  99                                          opts | pcmk__node_attr_value);
 100     }
 101     if (rc != pcmk_rc_ok) {
 102         do_crm_log(AM_I_DC? LOG_CRIT : LOG_ERR,
 103                    "Could not update multiple node attributes: %s "
 104                    CRM_XS " rc=%d", pcmk_rc_str(rc), rc);
 105         handle_attr_error();
 106     }
 107 }
 108 
 109 void
 110 update_attrd_remote_node_removed(const char *host, const char *user_name)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112     int rc = pcmk_rc_ok;
 113 
 114     if (attrd_api == NULL) {
 115         rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
 116     }
 117     if (rc == pcmk_rc_ok) {
 118         crm_trace("Asking attribute manager to purge Pacemaker Remote node %s",
 119                   host);
 120         rc = pcmk__attrd_api_purge(attrd_api, host, true);
 121     }
 122     if (rc != pcmk_rc_ok) {
 123         crm_err("Could not purge Pacemaker Remote node %s "
 124                 "in attribute manager%s: %s " CRM_XS " rc=%d",
 125                 host, when(), pcmk_rc_str(rc), rc);
 126     }
 127 }
 128 
 129 void
 130 update_attrd_clear_failures(const char *host, const char *rsc, const char *op,
     /* [previous][next][first][last][top][bottom][index][help] */
 131                             const char *interval_spec, gboolean is_remote_node)
 132 {
 133     int rc = pcmk_rc_ok;
 134 
 135     if (attrd_api == NULL) {
 136         rc = pcmk_new_ipc_api(&attrd_api, pcmk_ipc_attrd);
 137     }
 138     if (rc == pcmk_rc_ok) {
 139         uint32_t attrd_opts = pcmk__node_attr_none;
 140 
 141         if (is_remote_node) {
 142             pcmk__set_node_attr_flags(attrd_opts, pcmk__node_attr_remote);
 143         }
 144         rc = pcmk__attrd_api_clear_failures(attrd_api, host, rsc, op,
 145                                             interval_spec, NULL, attrd_opts);
 146     }
 147     if (rc != pcmk_rc_ok) {
 148         const char *interval_desc = "all";
 149 
 150         if (op != NULL) {
 151             interval_desc = pcmk__s(interval_spec, "nonrecurring");
 152         }
 153         crm_err("Could not clear failure of %s %s for %s on %s node %s%s: %s "
 154                 CRM_XS " rc=%d", interval_desc, pcmk__s(op, "operations"),
 155                 pcmk__s(rsc, "all resources"), node_type(is_remote_node), host,
 156                 when(), pcmk_rc_str(rc), rc);
 157     }
 158 }

/* [previous][next][first][last][top][bottom][index][help] */