root/lib/pengine/remote.c

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

DEFINITIONS

This source file includes following definitions.
  1. pe__resource_is_remote_conn
  2. pe__is_remote_node
  3. pe__is_guest_node
  4. pe__is_guest_or_remote_node
  5. pe__is_bundle_node
  6. pe__resource_contains_guest_node
  7. xml_contains_remote_node
  8. pe_foreach_guest_node
  9. pe_create_remote_xml
  10. pe__add_param_check
  11. pe__foreach_param_check
  12. pe__free_param_checks

   1 /*
   2  * Copyright 2013-2022 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 Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 #include <crm/msg_xml.h>
  12 #include <crm/common/xml.h>
  13 #include <crm/pengine/internal.h>
  14 #include <glib.h>
  15 
  16 bool
  17 pe__resource_is_remote_conn(const pe_resource_t *rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
  18                             const pe_working_set_t *data_set)
  19 {
  20     return (rsc != NULL) && rsc->is_remote_node
  21            && pe__is_remote_node(pe_find_node(data_set->nodes, rsc->id));
  22 }
  23 
  24 bool
  25 pe__is_remote_node(const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  26 {
  27     return (node != NULL) && (node->details->type == node_remote)
  28            && ((node->details->remote_rsc == NULL)
  29                || (node->details->remote_rsc->container == NULL));
  30 }
  31 
  32 bool
  33 pe__is_guest_node(const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  34 {
  35     return (node != NULL) && (node->details->type == node_remote)
  36            && (node->details->remote_rsc != NULL)
  37            && (node->details->remote_rsc->container != NULL);
  38 }
  39 
  40 bool
  41 pe__is_guest_or_remote_node(const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  42 {
  43     return (node != NULL) && (node->details->type == node_remote);
  44 }
  45 
  46 bool
  47 pe__is_bundle_node(const pe_node_t *node)
     /* [previous][next][first][last][top][bottom][index][help] */
  48 {
  49     return pe__is_guest_node(node)
  50            && pe_rsc_is_bundled(node->details->remote_rsc);
  51 }
  52 
  53 /*!
  54  * \internal
  55  * \brief Check whether a resource creates a guest node
  56  *
  57  * If a given resource contains a filler resource that is a remote connection,
  58  * return that filler resource (or NULL if none is found).
  59  *
  60  * \param[in] data_set  Working set of cluster
  61  * \param[in] rsc       Resource to check
  62  *
  63  * \return Filler resource with remote connection, or NULL if none found
  64  */
  65 pe_resource_t *
  66 pe__resource_contains_guest_node(const pe_working_set_t *data_set,
     /* [previous][next][first][last][top][bottom][index][help] */
  67                                  const pe_resource_t *rsc)
  68 {
  69     if ((rsc != NULL) && (data_set != NULL)
  70         && pcmk_is_set(data_set->flags, pe_flag_have_remote_nodes)) {
  71 
  72         for (GList *gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
  73             pe_resource_t *filler = gIter->data;
  74 
  75             if (filler->is_remote_node) {
  76                 return filler;
  77             }
  78         }
  79     }
  80     return NULL;
  81 }
  82 
  83 bool
  84 xml_contains_remote_node(xmlNode *xml)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86     const char *value = NULL;
  87 
  88     if (xml == NULL) {
  89         return false;
  90     }
  91 
  92     value = crm_element_value(xml, XML_ATTR_TYPE);
  93     if (!pcmk__str_eq(value, "remote", pcmk__str_casei)) {
  94         return false;
  95     }
  96 
  97     value = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
  98     if (!pcmk__str_eq(value, PCMK_RESOURCE_CLASS_OCF, pcmk__str_casei)) {
  99         return false;
 100     }
 101 
 102     value = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
 103     if (!pcmk__str_eq(value, "pacemaker", pcmk__str_casei)) {
 104         return false;
 105     }
 106 
 107     return true;
 108 }
 109 
 110 /*!
 111  * \internal
 112  * \brief Execute a supplied function for each guest node running on a host
 113  *
 114  * \param[in]     data_set   Working set for cluster
 115  * \param[in]     host       Host node to check
 116  * \param[in]     helper     Function to call for each guest node
 117  * \param[in,out] user_data  Pointer to pass to helper function
 118  */
 119 void
 120 pe_foreach_guest_node(const pe_working_set_t *data_set, const pe_node_t *host,
     /* [previous][next][first][last][top][bottom][index][help] */
 121                       void (*helper)(const pe_node_t*, void*), void *user_data)
 122 {
 123     GList *iter;
 124 
 125     CRM_CHECK(data_set && host && host->details && helper, return);
 126     if (!pcmk_is_set(data_set->flags, pe_flag_have_remote_nodes)) {
 127         return;
 128     }
 129     for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
 130         pe_resource_t *rsc = (pe_resource_t *) iter->data;
 131 
 132         if (rsc->is_remote_node && (rsc->container != NULL)) {
 133             pe_node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
 134 
 135             if (guest_node) {
 136                 (*helper)(guest_node, user_data);
 137             }
 138         }
 139     }
 140 }
 141 
 142 /*!
 143  * \internal
 144  * \brief Create CIB XML for an implicit remote connection
 145  *
 146  * \param[in,out] parent           If not NULL, use as parent XML element
 147  * \param[in]     uname            Name of Pacemaker Remote node
 148  * \param[in]     container        If not NULL, use this as connection container
 149  * \param[in]     migrateable      If not NULL, use as allow-migrate value
 150  * \param[in]     is_managed       If not NULL, use as is-managed value
 151  * \param[in]     start_timeout    If not NULL, use as remote connect timeout
 152  * \param[in]     server           If not NULL, use as remote server value
 153  * \param[in]     port             If not NULL, use as remote port value
 154  *
 155  * \return Newly created XML
 156  */
 157 xmlNode *
 158 pe_create_remote_xml(xmlNode *parent, const char *uname,
     /* [previous][next][first][last][top][bottom][index][help] */
 159                      const char *container_id, const char *migrateable,
 160                      const char *is_managed, const char *start_timeout,
 161                      const char *server, const char *port)
 162 {
 163     xmlNode *remote;
 164     xmlNode *xml_sub;
 165 
 166     remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
 167 
 168     // Add identity
 169     crm_xml_add(remote, XML_ATTR_ID, uname);
 170     crm_xml_add(remote, XML_AGENT_ATTR_CLASS, PCMK_RESOURCE_CLASS_OCF);
 171     crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
 172     crm_xml_add(remote, XML_ATTR_TYPE, "remote");
 173 
 174     // Add meta-attributes
 175     xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
 176     crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
 177     crm_create_nvpair_xml(xml_sub, NULL,
 178                           XML_RSC_ATTR_INTERNAL_RSC, XML_BOOLEAN_TRUE);
 179     if (container_id) {
 180         crm_create_nvpair_xml(xml_sub, NULL,
 181                               XML_RSC_ATTR_CONTAINER, container_id);
 182     }
 183     if (migrateable) {
 184         crm_create_nvpair_xml(xml_sub, NULL,
 185                               XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
 186     }
 187     if (is_managed) {
 188         crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
 189     }
 190 
 191     // Add instance attributes
 192     if (port || server) {
 193         xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
 194         crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
 195         if (server) {
 196             crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_REMOTE_RA_ADDR,
 197                                   server);
 198         }
 199         if (port) {
 200             crm_create_nvpair_xml(xml_sub, NULL, "port", port);
 201         }
 202     }
 203 
 204     // Add operations
 205     xml_sub = create_xml_node(remote, "operations");
 206     crm_create_op_xml(xml_sub, uname, "monitor", "30s", "30s");
 207     if (start_timeout) {
 208         crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
 209     }
 210     return remote;
 211 }
 212 
 213 // History entry to be checked for fail count clearing
 214 struct check_op {
 215     const xmlNode *rsc_op; // History entry XML
 216     pe_resource_t *rsc;    // Known resource corresponding to history entry
 217     pe_node_t *node; // Known node corresponding to history entry
 218     enum pe_check_parameters check_type; // What needs checking
 219 };
 220 
 221 void
 222 pe__add_param_check(const xmlNode *rsc_op, pe_resource_t *rsc,
     /* [previous][next][first][last][top][bottom][index][help] */
 223                     pe_node_t *node, enum pe_check_parameters flag,
 224                     pe_working_set_t *data_set)
 225 {
 226     struct check_op *check_op = NULL;
 227 
 228     CRM_CHECK(data_set && rsc_op && rsc && node, return);
 229 
 230     check_op = calloc(1, sizeof(struct check_op));
 231     CRM_ASSERT(check_op != NULL);
 232 
 233     crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
 234     check_op->rsc_op = rsc_op;
 235     check_op->rsc = rsc;
 236     check_op->node = node;
 237     check_op->check_type = flag;
 238     data_set->param_check = g_list_prepend(data_set->param_check, check_op);
 239 }
 240 
 241 /*!
 242  * \internal
 243  * \brief Call a function for each action to be checked for addr substitution
 244  *
 245  * \param[in,out] data_set  Working set for cluster
 246  * \param[in]     cb        Function to be called
 247  */
 248 void
 249 pe__foreach_param_check(pe_working_set_t *data_set,
     /* [previous][next][first][last][top][bottom][index][help] */
 250                        void (*cb)(pe_resource_t*, pe_node_t*, const xmlNode*,
 251                                   enum pe_check_parameters))
 252 {
 253     CRM_CHECK(data_set && cb, return);
 254 
 255     for (GList *item = data_set->param_check; item != NULL; item = item->next) {
 256         struct check_op *check_op = item->data;
 257 
 258         cb(check_op->rsc, check_op->node, check_op->rsc_op,
 259            check_op->check_type);
 260     }
 261 }
 262 
 263 void
 264 pe__free_param_checks(pe_working_set_t *data_set)
     /* [previous][next][first][last][top][bottom][index][help] */
 265 {
 266     if (data_set && data_set->param_check) {
 267         g_list_free_full(data_set->param_check, free);
 268         data_set->param_check = NULL;
 269     }
 270 }

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