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-2021 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/pengine/internal.h>
  17 #include <crm/pengine/pe_types.h>
  18 
  19 GList *
  20 pe__rscs_with_tag(pe_working_set_t *data_set, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  21 {
  22     gpointer value;
  23     GList *retval = NULL;
  24 
  25     if (data_set->tags == NULL) {
  26         return retval;
  27     }
  28 
  29     value = g_hash_table_lookup(data_set->tags, tag_name);
  30 
  31     if (value == NULL) {
  32         return retval;
  33     }
  34 
  35     for (GList *refs = ((pe_tag_t *) value)->refs; refs; refs = refs->next) {
  36         const char *id = (const char *) refs->data;
  37         pe_resource_t *rsc = pe_find_resource_with_flags(data_set->resources, id,
  38                                                          pe_find_renamed|pe_find_any);
  39 
  40         if (!rsc) {
  41             continue;
  42         }
  43 
  44         retval = g_list_append(retval, strdup(rsc_printable_id(rsc)));
  45     }
  46 
  47     return retval;
  48 }
  49 
  50 GList *
  51 pe__unames_with_tag(pe_working_set_t *data_set, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  52 {
  53     gpointer value;
  54     GList *retval = NULL;
  55 
  56     if (data_set->tags == NULL) {
  57         return retval;
  58     }
  59 
  60     value = g_hash_table_lookup(data_set->tags, tag_name);
  61 
  62     if (value == NULL) {
  63         return retval;
  64     }
  65 
  66     /* Iterate over the list of node IDs. */
  67     for (GList *refs = ((pe_tag_t *) value)->refs; refs; refs = refs->next) {
  68         /* Find the node that has this ID. */
  69         const char *id = (const char *) refs->data;
  70         pe_node_t *node = pe_find_node_id(data_set->nodes, id);
  71 
  72         if (!node) {
  73             continue;
  74         }
  75 
  76         /* Get the uname for the node and add it to the return list. */
  77         retval = g_list_append(retval, strdup(node->details->uname));
  78     }
  79 
  80     return retval;
  81 }
  82 
  83 bool
  84 pe__rsc_has_tag(pe_working_set_t *data_set, const char *rsc_name, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86     GList *rscs = pe__rscs_with_tag(data_set, tag_name);
  87     bool retval = false;
  88 
  89     if (rscs == NULL) {
  90         return retval;
  91     }
  92 
  93     retval = g_list_find_custom(rscs, rsc_name, (GCompareFunc) strcmp) != NULL;
  94     g_list_free_full(rscs, free);
  95     return retval;
  96 }
  97 
  98 bool
  99 pe__uname_has_tag(pe_working_set_t *data_set, const char *node_name, const char *tag_name)
     /* [previous][next][first][last][top][bottom][index][help] */
 100 {
 101     GList *unames = pe__unames_with_tag(data_set, tag_name);
 102     bool retval = false;
 103 
 104     if (unames == NULL) {
 105         return retval;
 106     }
 107 
 108     retval = g_list_find_custom(unames, node_name, (GCompareFunc) strcmp) != NULL;
 109     g_list_free_full(unames, free);
 110     return retval;
 111 }

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