root/lib/pengine/tags.c

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

DEFINITIONS

This source file includes following definitions.
  1. pe__rscs_with_tag
  2. pe__unames_with_tag
  3. pe__rsc_has_tag
  4. pe__uname_has_tag

   1 /*
   2  * Copyright 2020-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 Lesser General Public License
   7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <glib.h>
  13 #include <stdbool.h>
  14 
  15 #include <crm/common/util.h>
  16 #include <crm/common/scheduler.h>
  17 #include <crm/pengine/internal.h>
  18 
  19 GList *
  20 pe__rscs_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22     gpointer value;
  23     GList *retval = NULL;
  24 
  25     if (scheduler->priv->tags == NULL) {
  26         return retval;
  27     }
  28 
  29     value = g_hash_table_lookup(scheduler->priv->tags, tag_name);
  30 
  31     if (value == NULL) {
  32         return retval;
  33     }
  34 
  35     for (GList *refs = ((pcmk__idref_t *) value)->refs;
  36          refs != NULL; refs = refs->next) {
  37 
  38         const char *id = (const char *) refs->data;
  39         const uint32_t flags = pcmk_rsc_match_history|pcmk_rsc_match_basename;
  40         pcmk_resource_t *rsc =
  41             pe_find_resource_with_flags(scheduler->priv->resources, id, flags);
  42 
  43         if (!rsc) {
  44             continue;
  45         }
  46 
  47         retval = g_list_append(retval, strdup(rsc_printable_id(rsc)));
  48     }
  49 
  50     return retval;
  51 }
  52 
  53 GList *
  54 pe__unames_with_tag(pcmk_scheduler_t *scheduler, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  55 {
  56     gpointer value;
  57     GList *retval = NULL;
  58 
  59     if (scheduler->priv->tags == NULL) {
  60         return retval;
  61     }
  62 
  63     value = g_hash_table_lookup(scheduler->priv->tags, tag_name);
  64 
  65     if (value == NULL) {
  66         return retval;
  67     }
  68 
  69     /* Iterate over the list of node IDs. */
  70     for (GList *refs = ((pcmk__idref_t *) value)->refs;
  71          refs != NULL; refs = refs->next) {
  72 
  73         /* Find the node that has this ID. */
  74         const char *id = (const char *) refs->data;
  75         pcmk_node_t *node = pe_find_node_id(scheduler->nodes, id);
  76 
  77         if (!node) {
  78             continue;
  79         }
  80 
  81         /* Get the uname for the node and add it to the return list. */
  82         retval = g_list_append(retval, strdup(node->priv->name));
  83     }
  84 
  85     return retval;
  86 }
  87 
  88 bool
  89 pe__rsc_has_tag(pcmk_scheduler_t *scheduler, const char *rsc_name,
     /* [previous][next][first][last][top][bottom][index][help] */
  90                 const char *tag_name)
  91 {
  92     GList *rscs = pe__rscs_with_tag(scheduler, tag_name);
  93     bool retval = false;
  94 
  95     if (rscs == NULL) {
  96         return retval;
  97     }
  98 
  99     retval = g_list_find_custom(rscs, rsc_name, (GCompareFunc) strcmp) != NULL;
 100     g_list_free_full(rscs, free);
 101     return retval;
 102 }
 103 
 104 bool
 105 pe__uname_has_tag(pcmk_scheduler_t *scheduler, const char *node_name,
     /* [previous][next][first][last][top][bottom][index][help] */
 106                   const char *tag_name)
 107 {
 108     GList *unames = pe__unames_with_tag(scheduler, tag_name);
 109     bool retval = false;
 110 
 111     if (unames == NULL) {
 112         return retval;
 113     }
 114 
 115     retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL;
 116     g_list_free_full(unames, free);
 117     return retval;
 118 }

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