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

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