pacemaker  2.1.6-802a72226b
Scalable High-Availability cluster resource manager
attrs.c
Go to the documentation of this file.
1 /*
2  * Copyright 2011-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 #ifndef _GNU_SOURCE
11 # define _GNU_SOURCE
12 #endif
13 
14 #include <crm_internal.h>
15 
16 #include <stdio.h>
17 
18 #include <crm/msg_xml.h>
20 
21 #define LRM_TARGET_ENV "OCF_RESKEY_" CRM_META "_" XML_LRM_ATTR_TARGET
22 
38 const char *
40 {
41  if (name == NULL || pcmk__strcase_any_of(name, "auto", "localhost", NULL)) {
42  char *target_var = crm_meta_name(XML_RSC_ATTR_TARGET);
43  char *phys_var = crm_meta_name(PCMK__ENV_PHYSICAL_HOST);
44  const char *target = getenv(target_var);
45  const char *host_physical = getenv(phys_var);
46 
47  // It is important to use the name by which the scheduler knows us
48  if (host_physical && pcmk__str_eq(target, "host", pcmk__str_casei)) {
49  name = host_physical;
50 
51  } else {
52  const char *host_pcmk = getenv(LRM_TARGET_ENV);
53 
54  if (host_pcmk) {
55  name = host_pcmk;
56  }
57  }
58  free(target_var);
59  free(phys_var);
60 
61  // TODO? Call get_local_node_name() if name == NULL
62  // (currently would require linkage against libcrmcluster)
63  return name;
64  } else {
65  return NULL;
66  }
67 }
68 
79 char *
80 pcmk_promotion_score_name(const char *rsc_id)
81 {
82  if (pcmk__str_empty(rsc_id)) {
83  rsc_id = getenv("OCF_RESOURCE_INSTANCE");
84  if (pcmk__str_empty(rsc_id)) {
85  return NULL;
86  }
87  }
88  return crm_strdup_printf("master-%s", rsc_id);
89 }
const char * name
Definition: cib.c:24
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:933
#define XML_RSC_ATTR_TARGET
Definition: msg_xml.h:237
char * crm_meta_name(const char *field)
Definition: utils.c:468
char * pcmk_promotion_score_name(const char *rsc_id)
Return the name of the node attribute used as a promotion score.
Definition: attrs.c:80
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
const char * target
Definition: pcmk_fence.c:29
const char * pcmk__node_attr_target(const char *name)
Definition: attrs.c:39
#define PCMK__ENV_PHYSICAL_HOST
#define LRM_TARGET_ENV
Definition: attrs.c:21