diff options
Diffstat (limited to 'lib/pengine/bundle.c')
-rw-r--r-- | lib/pengine/bundle.c | 415 |
1 files changed, 315 insertions, 100 deletions
diff --git a/lib/pengine/bundle.c b/lib/pengine/bundle.c index ff1b365..fd859d5 100644 --- a/lib/pengine/bundle.c +++ b/lib/pengine/bundle.c @@ -20,8 +20,69 @@ #include <crm/common/xml_internal.h> #include <pe_status_private.h> -#define PE__VARIANT_BUNDLE 1 -#include "./variant.h" +enum pe__bundle_mount_flags { + pe__bundle_mount_none = 0x00, + + // mount instance-specific subdirectory rather than source directly + pe__bundle_mount_subdir = 0x01 +}; + +typedef struct { + char *source; + char *target; + char *options; + uint32_t flags; // bitmask of pe__bundle_mount_flags +} pe__bundle_mount_t; + +typedef struct { + char *source; + char *target; +} pe__bundle_port_t; + +enum pe__container_agent { + PE__CONTAINER_AGENT_UNKNOWN, + PE__CONTAINER_AGENT_DOCKER, + PE__CONTAINER_AGENT_RKT, + PE__CONTAINER_AGENT_PODMAN, +}; + +#define PE__CONTAINER_AGENT_UNKNOWN_S "unknown" +#define PE__CONTAINER_AGENT_DOCKER_S "docker" +#define PE__CONTAINER_AGENT_RKT_S "rkt" +#define PE__CONTAINER_AGENT_PODMAN_S "podman" + +typedef struct pe__bundle_variant_data_s { + int promoted_max; + int nreplicas; + int nreplicas_per_host; + char *prefix; + char *image; + const char *ip_last; + char *host_network; + char *host_netmask; + char *control_port; + char *container_network; + char *ip_range_start; + gboolean add_host; + gchar *container_host_options; + char *container_command; + char *launcher_options; + const char *attribute_target; + + pcmk_resource_t *child; + + GList *replicas; // pe__bundle_replica_t * + GList *ports; // pe__bundle_port_t * + GList *mounts; // pe__bundle_mount_t * + + enum pe__container_agent agent_type; +} pe__bundle_variant_data_t; + +#define get_bundle_variant_data(data, rsc) \ + CRM_ASSERT(rsc != NULL); \ + CRM_ASSERT(rsc->variant == pcmk_rsc_variant_bundle); \ + CRM_ASSERT(rsc->variant_opaque != NULL); \ + data = (pe__bundle_variant_data_t *) rsc->variant_opaque; /*! * \internal @@ -32,7 +93,7 @@ * \return Maximum replicas for bundle corresponding to \p rsc */ int -pe__bundle_max(const pe_resource_t *rsc) +pe__bundle_max(const pcmk_resource_t *rsc) { const pe__bundle_variant_data_t *bundle_data = NULL; @@ -42,19 +103,149 @@ pe__bundle_max(const pe_resource_t *rsc) /*! * \internal - * \brief Get maximum number of bundle replicas allowed to run on one node + * \brief Get the resource inside a bundle * - * \param[in] rsc Bundle or bundled resource to check + * \param[in] bundle Bundle to check * - * \return Maximum replicas per node for bundle corresponding to \p rsc + * \return Resource inside \p bundle if any, otherwise NULL */ -int -pe__bundle_max_per_node(const pe_resource_t *rsc) +pcmk_resource_t * +pe__bundled_resource(const pcmk_resource_t *rsc) { const pe__bundle_variant_data_t *bundle_data = NULL; get_bundle_variant_data(bundle_data, pe__const_top_resource(rsc, true)); - return bundle_data->nreplicas_per_host; + return bundle_data->child; +} + +/*! + * \internal + * \brief Get containerized resource corresponding to a given bundle container + * + * \param[in] instance Collective instance that might be a bundle container + * + * \return Bundled resource instance inside \p instance if it is a bundle + * container instance, otherwise NULL + */ +const pcmk_resource_t * +pe__get_rsc_in_container(const pcmk_resource_t *instance) +{ + const pe__bundle_variant_data_t *data = NULL; + const pcmk_resource_t *top = pe__const_top_resource(instance, true); + + if ((top == NULL) || (top->variant != pcmk_rsc_variant_bundle)) { + return NULL; + } + get_bundle_variant_data(data, top); + + for (const GList *iter = data->replicas; iter != NULL; iter = iter->next) { + const pe__bundle_replica_t *replica = iter->data; + + if (instance == replica->container) { + return replica->child; + } + } + return NULL; +} + +/*! + * \internal + * \brief Check whether a given node is created by a bundle + * + * \param[in] bundle Bundle resource to check + * \param[in] node Node to check + * + * \return true if \p node is an instance of \p bundle, otherwise false + */ +bool +pe__node_is_bundle_instance(const pcmk_resource_t *bundle, + const pcmk_node_t *node) +{ + pe__bundle_variant_data_t *bundle_data = NULL; + + get_bundle_variant_data(bundle_data, bundle); + for (GList *iter = bundle_data->replicas; iter != NULL; iter = iter->next) { + pe__bundle_replica_t *replica = iter->data; + + if (pe__same_node(node, replica->node)) { + return true; + } + } + return false; +} + +/*! + * \internal + * \brief Get the container of a bundle's first replica + * + * \param[in] bundle Bundle resource to get container for + * + * \return Container resource from first replica of \p bundle if any, + * otherwise NULL + */ +pcmk_resource_t * +pe__first_container(const pcmk_resource_t *bundle) +{ + const pe__bundle_variant_data_t *bundle_data = NULL; + const pe__bundle_replica_t *replica = NULL; + + get_bundle_variant_data(bundle_data, bundle); + if (bundle_data->replicas == NULL) { + return NULL; + } + replica = bundle_data->replicas->data; + return replica->container; +} + +/*! + * \internal + * \brief Iterate over bundle replicas + * + * \param[in,out] bundle Bundle to iterate over + * \param[in] fn Function to call for each replica (its return value + * indicates whether to continue iterating) + * \param[in,out] user_data Pointer to pass to \p fn + */ +void +pe__foreach_bundle_replica(pcmk_resource_t *bundle, + bool (*fn)(pe__bundle_replica_t *, void *), + void *user_data) +{ + const pe__bundle_variant_data_t *bundle_data = NULL; + + get_bundle_variant_data(bundle_data, bundle); + for (GList *iter = bundle_data->replicas; iter != NULL; iter = iter->next) { + if (!fn((pe__bundle_replica_t *) iter->data, user_data)) { + break; + } + } +} + +/*! + * \internal + * \brief Iterate over const bundle replicas + * + * \param[in] bundle Bundle to iterate over + * \param[in] fn Function to call for each replica (its return value + * indicates whether to continue iterating) + * \param[in,out] user_data Pointer to pass to \p fn + */ +void +pe__foreach_const_bundle_replica(const pcmk_resource_t *bundle, + bool (*fn)(const pe__bundle_replica_t *, + void *), + void *user_data) +{ + const pe__bundle_variant_data_t *bundle_data = NULL; + + get_bundle_variant_data(bundle_data, bundle); + for (const GList *iter = bundle_data->replicas; iter != NULL; + iter = iter->next) { + + if (!fn((const pe__bundle_replica_t *) iter->data, user_data)) { + break; + } + } } static char * @@ -159,7 +350,8 @@ valid_network(pe__bundle_variant_data_t *data) if(data->nreplicas_per_host > 1) { pe_err("Specifying the 'control-port' for %s requires 'replicas-per-host=1'", data->prefix); data->nreplicas_per_host = 1; - // @TODO to be sure: pe__clear_resource_flags(rsc, pe_rsc_unique); + // @TODO to be sure: + // pe__clear_resource_flags(rsc, pcmk_rsc_unique); } return TRUE; } @@ -167,7 +359,7 @@ valid_network(pe__bundle_variant_data_t *data) } static int -create_ip_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, +create_ip_resource(pcmk_resource_t *parent, pe__bundle_variant_data_t *data, pe__bundle_replica_t *replica) { if(data->ip_range_start) { @@ -198,7 +390,8 @@ create_ip_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, } xml_obj = create_xml_node(xml_ip, "operations"); - crm_create_op_xml(xml_obj, ID(xml_ip), "monitor", "60s", NULL); + crm_create_op_xml(xml_obj, ID(xml_ip), PCMK_ACTION_MONITOR, "60s", + NULL); // TODO: Other ops? Timeouts and intervals from underlying resource? @@ -226,7 +419,7 @@ container_agent_str(enum pe__container_agent t) } static int -create_container_resource(pe_resource_t *parent, +create_container_resource(pcmk_resource_t *parent, const pe__bundle_variant_data_t *data, pe__bundle_replica_t *replica) { @@ -295,11 +488,11 @@ create_container_resource(pe_resource_t *parent, } if (data->control_port != NULL) { - pcmk__g_strcat(buffer, " ", env_opt, "PCMK_remote_port=", - data->control_port, NULL); + pcmk__g_strcat(buffer, " ", env_opt, "PCMK_" PCMK__ENV_REMOTE_PORT "=", + data->control_port, NULL); } else { - g_string_append_printf(buffer, " %sPCMK_remote_port=%d", env_opt, - DEFAULT_REMOTE_PORT); + g_string_append_printf(buffer, " %sPCMK_" PCMK__ENV_REMOTE_PORT "=%d", + env_opt, DEFAULT_REMOTE_PORT); } for (GList *iter = data->mounts; iter != NULL; iter = iter->next) { @@ -449,14 +642,15 @@ create_container_resource(pe_resource_t *parent, } xml_obj = create_xml_node(xml_container, "operations"); - crm_create_op_xml(xml_obj, ID(xml_container), "monitor", "60s", NULL); + crm_create_op_xml(xml_obj, ID(xml_container), PCMK_ACTION_MONITOR, "60s", + NULL); // TODO: Other ops? Timeouts and intervals from underlying resource? if (pe__unpack_resource(xml_container, &replica->container, parent, parent->cluster) != pcmk_rc_ok) { return pcmk_rc_unpack_error; } - pe__set_resource_flags(replica->container, pe_rsc_replica_container); + pe__set_resource_flags(replica->container, pcmk_rsc_replica_container); parent->children = g_list_append(parent->children, replica->container); return pcmk_rc_ok; @@ -469,13 +663,13 @@ create_container_resource(pe_resource_t *parent, * \param[in] uname Name of node to ban */ static void -disallow_node(pe_resource_t *rsc, const char *uname) +disallow_node(pcmk_resource_t *rsc, const char *uname) { gpointer match = g_hash_table_lookup(rsc->allowed_nodes, uname); if (match) { - ((pe_node_t *) match)->weight = -INFINITY; - ((pe_node_t *) match)->rsc_discover_mode = pe_discover_never; + ((pcmk_node_t *) match)->weight = -INFINITY; + ((pcmk_node_t *) match)->rsc_discover_mode = pcmk_probe_never; } if (rsc->children) { g_list_foreach(rsc->children, (GFunc) disallow_node, (gpointer) uname); @@ -483,12 +677,12 @@ disallow_node(pe_resource_t *rsc, const char *uname) } static int -create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, +create_remote_resource(pcmk_resource_t *parent, pe__bundle_variant_data_t *data, pe__bundle_replica_t *replica) { if (replica->child && valid_network(data)) { GHashTableIter gIter; - pe_node_t *node = NULL; + pcmk_node_t *node = NULL; xmlNode *xml_remote = NULL; char *id = crm_strdup_printf("%s-%d", data->prefix, replica->offset); char *port_s = NULL; @@ -527,8 +721,8 @@ create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, free(port_s); /* Abandon our created ID, and pull the copy from the XML, because we - * need something that will get freed during data set cleanup to use as - * the node ID and uname. + * need something that will get freed during scheduler data cleanup to + * use as the node ID and uname. */ free(id); id = NULL; @@ -545,12 +739,12 @@ create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, } else { node->weight = -INFINITY; } - node->rsc_discover_mode = pe_discover_never; + node->rsc_discover_mode = pcmk_probe_never; /* unpack_remote_nodes() ensures that each remote node and guest node - * has a pe_node_t entry. Ideally, it would do the same for bundle nodes. - * Unfortunately, a bundle has to be mostly unpacked before it's obvious - * what nodes will be needed, so we do it just above. + * has a pcmk_node_t entry. Ideally, it would do the same for bundle + * nodes. Unfortunately, a bundle has to be mostly unpacked before it's + * obvious what nodes will be needed, so we do it just above. * * Worse, that means that the node may have been utilized while * unpacking other resources, without our weight correction. The most @@ -569,7 +763,7 @@ create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, replica->node = pe__copy_node(node); replica->node->weight = 500; - replica->node->rsc_discover_mode = pe_discover_exclusive; + replica->node->rsc_discover_mode = pcmk_probe_exclusive; /* Ensure the node shows up as allowed and with the correct discovery set */ if (replica->child->allowed_nodes != NULL) { @@ -581,7 +775,7 @@ create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, pe__copy_node(replica->node)); { - pe_node_t *copy = pe__copy_node(replica->node); + pcmk_node_t *copy = pe__copy_node(replica->node); copy->weight = -INFINITY; g_hash_table_insert(replica->child->parent->allowed_nodes, (gpointer) replica->node->details->id, copy); @@ -625,7 +819,7 @@ create_remote_resource(pe_resource_t *parent, pe__bundle_variant_data_t *data, } static int -create_replica_resources(pe_resource_t *parent, pe__bundle_variant_data_t *data, +create_replica_resources(pcmk_resource_t *parent, pe__bundle_variant_data_t *data, pe__bundle_replica_t *replica) { int rc = pcmk_rc_ok; @@ -658,7 +852,8 @@ create_replica_resources(pe_resource_t *parent, pe__bundle_variant_data_t *data, * containers with pacemaker-remoted inside in order to start * services inside those containers. */ - pe__set_resource_flags(replica->remote, pe_rsc_allow_remote_remotes); + pe__set_resource_flags(replica->remote, + pcmk_rsc_remote_nesting_allowed); } return rc; } @@ -695,9 +890,9 @@ port_free(pe__bundle_port_t *port) } static pe__bundle_replica_t * -replica_for_remote(pe_resource_t *remote) +replica_for_remote(pcmk_resource_t *remote) { - pe_resource_t *top = remote; + pcmk_resource_t *top = remote; pe__bundle_variant_data_t *bundle_data = NULL; if (top == NULL) { @@ -722,7 +917,7 @@ replica_for_remote(pe_resource_t *remote) } bool -pe__bundle_needs_remote_name(pe_resource_t *rsc) +pe__bundle_needs_remote_name(pcmk_resource_t *rsc) { const char *value; GHashTable *params = NULL; @@ -740,12 +935,12 @@ pe__bundle_needs_remote_name(pe_resource_t *rsc) } const char * -pe__add_bundle_remote_name(pe_resource_t *rsc, pe_working_set_t *data_set, +pe__add_bundle_remote_name(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler, xmlNode *xml, const char *field) { // REMOTE_CONTAINER_HACK: Allow remote nodes that start containers with pacemaker remote inside - pe_node_t *node = NULL; + pcmk_node_t *node = NULL; pe__bundle_replica_t *replica = NULL; if (!pe__bundle_needs_remote_name(rsc)) { @@ -786,7 +981,7 @@ pe__add_bundle_remote_name(pe_resource_t *rsc, pe_working_set_t *data_set, } while (0) gboolean -pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) +pe__unpack_bundle(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler) { const char *value = NULL; xmlNode *xml_obj = NULL; @@ -819,7 +1014,7 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) } // Use 0 for default, minimum, and invalid promoted-max - value = crm_element_value(xml_obj, XML_RSC_ATTR_PROMOTED_MAX); + value = crm_element_value(xml_obj, PCMK_META_PROMOTED_MAX); if (value == NULL) { // @COMPAT deprecated since 2.0.0 value = crm_element_value(xml_obj, "masters"); @@ -842,7 +1037,7 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) value = crm_element_value(xml_obj, "replicas-per-host"); pcmk__scan_min_int(value, &bundle_data->nreplicas_per_host, 1); if (bundle_data->nreplicas_per_host == 1) { - pe__clear_resource_flags(rsc, pe_rsc_unique); + pe__clear_resource_flags(rsc, pcmk_rsc_unique); } bundle_data->container_command = crm_element_value_copy(xml_obj, "run-command"); @@ -934,13 +1129,11 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) XML_RSC_ATTR_ORDERED, XML_BOOLEAN_TRUE); value = pcmk__itoa(bundle_data->nreplicas); - crm_create_nvpair_xml(xml_set, NULL, - XML_RSC_ATTR_INCARNATION_MAX, value); + crm_create_nvpair_xml(xml_set, NULL, PCMK_META_CLONE_MAX, value); free(value); value = pcmk__itoa(bundle_data->nreplicas_per_host); - crm_create_nvpair_xml(xml_set, NULL, - XML_RSC_ATTR_INCARNATION_NODEMAX, value); + crm_create_nvpair_xml(xml_set, NULL, PCMK_META_CLONE_NODE_MAX, value); free(value); crm_create_nvpair_xml(xml_set, NULL, XML_RSC_ATTR_UNIQUE, @@ -951,8 +1144,7 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) XML_RSC_ATTR_PROMOTABLE, XML_BOOLEAN_TRUE); value = pcmk__itoa(bundle_data->promoted_max); - crm_create_nvpair_xml(xml_set, NULL, - XML_RSC_ATTR_PROMOTED_MAX, value); + crm_create_nvpair_xml(xml_set, NULL, PCMK_META_PROMOTED_MAX, value); free(value); } @@ -972,7 +1164,7 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) GString *buffer = NULL; if (pe__unpack_resource(xml_resource, &(bundle_data->child), rsc, - data_set) != pcmk_rc_ok) { + scheduler) != pcmk_rc_ok) { return FALSE; } @@ -1033,8 +1225,8 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) replica->offset = lpc++; // Ensure the child's notify gets set based on the underlying primitive's value - if (pcmk_is_set(replica->child->flags, pe_rsc_notify)) { - pe__set_resource_flags(bundle_data->child, pe_rsc_notify); + if (pcmk_is_set(replica->child->flags, pcmk_rsc_notify)) { + pe__set_resource_flags(bundle_data->child, pcmk_rsc_notify); } allocate_ip(bundle_data, replica, buffer); @@ -1109,7 +1301,7 @@ pe__unpack_bundle(pe_resource_t *rsc, pe_working_set_t *data_set) } static int -replica_resource_active(pe_resource_t *rsc, gboolean all) +replica_resource_active(pcmk_resource_t *rsc, gboolean all) { if (rsc) { gboolean child_active = rsc->fns->active(rsc, all); @@ -1124,7 +1316,7 @@ replica_resource_active(pe_resource_t *rsc, gboolean all) } gboolean -pe__bundle_active(pe_resource_t *rsc, gboolean all) +pe__bundle_active(pcmk_resource_t *rsc, gboolean all) { pe__bundle_variant_data_t *bundle_data = NULL; GList *iter = NULL; @@ -1171,8 +1363,8 @@ pe__bundle_active(pe_resource_t *rsc, gboolean all) * * \return Bundle replica if found, NULL otherwise */ -pe_resource_t * -pe__find_bundle_replica(const pe_resource_t *bundle, const pe_node_t *node) +pcmk_resource_t * +pe__find_bundle_replica(const pcmk_resource_t *bundle, const pcmk_node_t *node) { pe__bundle_variant_data_t *bundle_data = NULL; CRM_ASSERT(bundle && node); @@ -1195,7 +1387,7 @@ pe__find_bundle_replica(const pe_resource_t *bundle, const pe_node_t *node) * \deprecated This function will be removed in a future release */ static void -print_rsc_in_list(pe_resource_t *rsc, const char *pre_text, long options, +print_rsc_in_list(pcmk_resource_t *rsc, const char *pre_text, long options, void *print_data) { if (rsc != NULL) { @@ -1214,7 +1406,7 @@ print_rsc_in_list(pe_resource_t *rsc, const char *pre_text, long options, * \deprecated This function will be removed in a future release */ static void -bundle_print_xml(pe_resource_t *rsc, const char *pre_text, long options, +bundle_print_xml(pcmk_resource_t *rsc, const char *pre_text, long options, void *print_data) { pe__bundle_variant_data_t *bundle_data = NULL; @@ -1232,9 +1424,10 @@ bundle_print_xml(pe_resource_t *rsc, const char *pre_text, long options, status_print(XML_ATTR_ID "=\"%s\" ", rsc->id); status_print("type=\"%s\" ", container_agent_str(bundle_data->agent_type)); status_print("image=\"%s\" ", bundle_data->image); - status_print("unique=\"%s\" ", pe__rsc_bool_str(rsc, pe_rsc_unique)); - status_print("managed=\"%s\" ", pe__rsc_bool_str(rsc, pe_rsc_managed)); - status_print("failed=\"%s\" ", pe__rsc_bool_str(rsc, pe_rsc_failed)); + status_print("unique=\"%s\" ", pe__rsc_bool_str(rsc, pcmk_rsc_unique)); + status_print("managed=\"%s\" ", + pe__rsc_bool_str(rsc, pcmk_rsc_managed)); + status_print("failed=\"%s\" ", pe__rsc_bool_str(rsc, pcmk_rsc_failed)); status_print(">\n"); for (GList *gIter = bundle_data->replicas; gIter != NULL; @@ -1254,12 +1447,13 @@ bundle_print_xml(pe_resource_t *rsc, const char *pre_text, long options, free(child_text); } -PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pe_resource_t *", "GList *", "GList *") +PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pcmk_resource_t *", "GList *", + "GList *") int pe__bundle_xml(pcmk__output_t *out, va_list args) { uint32_t show_opts = va_arg(args, uint32_t); - pe_resource_t *rsc = va_arg(args, pe_resource_t *); + pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *); GList *only_node = va_arg(args, GList *); GList *only_rsc = va_arg(args, GList *); @@ -1313,10 +1507,11 @@ pe__bundle_xml(pcmk__output_t *out, va_list args) "id", rsc->id, "type", container_agent_str(bundle_data->agent_type), "image", bundle_data->image, - "unique", pe__rsc_bool_str(rsc, pe_rsc_unique), - "maintenance", pe__rsc_bool_str(rsc, pe_rsc_maintenance), - "managed", pe__rsc_bool_str(rsc, pe_rsc_managed), - "failed", pe__rsc_bool_str(rsc, pe_rsc_failed), + "unique", pe__rsc_bool_str(rsc, pcmk_rsc_unique), + "maintenance", + pe__rsc_bool_str(rsc, pcmk_rsc_maintenance), + "managed", pe__rsc_bool_str(rsc, pcmk_rsc_managed), + "failed", pe__rsc_bool_str(rsc, pcmk_rsc_failed), "description", desc); CRM_ASSERT(rc == pcmk_rc_ok); } @@ -1358,9 +1553,9 @@ pe__bundle_xml(pcmk__output_t *out, va_list args) static void pe__bundle_replica_output_html(pcmk__output_t *out, pe__bundle_replica_t *replica, - pe_node_t *node, uint32_t show_opts) + pcmk_node_t *node, uint32_t show_opts) { - pe_resource_t *rsc = replica->child; + pcmk_resource_t *rsc = replica->child; int offset = 0; char buffer[LINE_MAX]; @@ -1394,23 +1589,24 @@ pe__bundle_replica_output_html(pcmk__output_t *out, pe__bundle_replica_t *replic * otherwise unmanaged, or an empty string otherwise */ static const char * -get_unmanaged_str(const pe_resource_t *rsc) +get_unmanaged_str(const pcmk_resource_t *rsc) { - if (pcmk_is_set(rsc->flags, pe_rsc_maintenance)) { + if (pcmk_is_set(rsc->flags, pcmk_rsc_maintenance)) { return " (maintenance)"; } - if (!pcmk_is_set(rsc->flags, pe_rsc_managed)) { + if (!pcmk_is_set(rsc->flags, pcmk_rsc_managed)) { return " (unmanaged)"; } return ""; } -PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pe_resource_t *", "GList *", "GList *") +PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pcmk_resource_t *", "GList *", + "GList *") int pe__bundle_html(pcmk__output_t *out, va_list args) { uint32_t show_opts = va_arg(args, uint32_t); - pe_resource_t *rsc = va_arg(args, pe_resource_t *); + pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *); GList *only_node = va_arg(args, GList *); GList *only_rsc = va_arg(args, GList *); @@ -1460,7 +1656,7 @@ pe__bundle_html(pcmk__output_t *out, va_list args) PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Container bundle%s: %s [%s]%s%s%s%s%s", (bundle_data->nreplicas > 1)? " set" : "", rsc->id, bundle_data->image, - pcmk_is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", + pcmk_is_set(rsc->flags, pcmk_rsc_unique)? " (unique)" : "", desc ? " (" : "", desc ? desc : "", desc ? ")" : "", get_unmanaged_str(rsc)); @@ -1497,7 +1693,7 @@ pe__bundle_html(pcmk__output_t *out, va_list args) PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Container bundle%s: %s [%s]%s%s%s%s%s", (bundle_data->nreplicas > 1)? " set" : "", rsc->id, bundle_data->image, - pcmk_is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", + pcmk_is_set(rsc->flags, pcmk_rsc_unique)? " (unique)" : "", desc ? " (" : "", desc ? desc : "", desc ? ")" : "", get_unmanaged_str(rsc)); @@ -1512,9 +1708,9 @@ pe__bundle_html(pcmk__output_t *out, va_list args) static void pe__bundle_replica_output_text(pcmk__output_t *out, pe__bundle_replica_t *replica, - pe_node_t *node, uint32_t show_opts) + pcmk_node_t *node, uint32_t show_opts) { - const pe_resource_t *rsc = replica->child; + const pcmk_resource_t *rsc = replica->child; int offset = 0; char buffer[LINE_MAX]; @@ -1538,12 +1734,13 @@ pe__bundle_replica_output_text(pcmk__output_t *out, pe__bundle_replica_t *replic pe__common_output_text(out, rsc, buffer, node, show_opts); } -PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pe_resource_t *", "GList *", "GList *") +PCMK__OUTPUT_ARGS("bundle", "uint32_t", "pcmk_resource_t *", "GList *", + "GList *") int pe__bundle_text(pcmk__output_t *out, va_list args) { uint32_t show_opts = va_arg(args, uint32_t); - pe_resource_t *rsc = va_arg(args, pe_resource_t *); + pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *); GList *only_node = va_arg(args, GList *); GList *only_rsc = va_arg(args, GList *); @@ -1593,7 +1790,7 @@ pe__bundle_text(pcmk__output_t *out, va_list args) PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Container bundle%s: %s [%s]%s%s%s%s%s", (bundle_data->nreplicas > 1)? " set" : "", rsc->id, bundle_data->image, - pcmk_is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", + pcmk_is_set(rsc->flags, pcmk_rsc_unique)? " (unique)" : "", desc ? " (" : "", desc ? desc : "", desc ? ")" : "", get_unmanaged_str(rsc)); @@ -1630,7 +1827,7 @@ pe__bundle_text(pcmk__output_t *out, va_list args) PCMK__OUTPUT_LIST_HEADER(out, FALSE, rc, "Container bundle%s: %s [%s]%s%s%s%s%s", (bundle_data->nreplicas > 1)? " set" : "", rsc->id, bundle_data->image, - pcmk_is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", + pcmk_is_set(rsc->flags, pcmk_rsc_unique)? " (unique)" : "", desc ? " (" : "", desc ? desc : "", desc ? ")" : "", get_unmanaged_str(rsc)); @@ -1651,8 +1848,8 @@ static void print_bundle_replica(pe__bundle_replica_t *replica, const char *pre_text, long options, void *print_data) { - pe_node_t *node = NULL; - pe_resource_t *rsc = replica->child; + pcmk_node_t *node = NULL; + pcmk_resource_t *rsc = replica->child; int offset = 0; char buffer[LINE_MAX]; @@ -1682,7 +1879,7 @@ print_bundle_replica(pe__bundle_replica_t *replica, const char *pre_text, * \deprecated This function will be removed in a future release */ void -pe__print_bundle(pe_resource_t *rsc, const char *pre_text, long options, +pe__print_bundle(pcmk_resource_t *rsc, const char *pre_text, long options, void *print_data) { pe__bundle_variant_data_t *bundle_data = NULL; @@ -1703,8 +1900,8 @@ pe__print_bundle(pe_resource_t *rsc, const char *pre_text, long options, status_print("%sContainer bundle%s: %s [%s]%s%s\n", pre_text, ((bundle_data->nreplicas > 1)? " set" : ""), rsc->id, bundle_data->image, - pcmk_is_set(rsc->flags, pe_rsc_unique) ? " (unique)" : "", - pcmk_is_set(rsc->flags, pe_rsc_managed) ? "" : " (unmanaged)"); + pcmk_is_set(rsc->flags, pcmk_rsc_unique)? " (unique)" : "", + pcmk_is_set(rsc->flags, pcmk_rsc_managed)? "" : " (unmanaged)"); if (options & pe_print_html) { status_print("<br />\n<ul>\n"); } @@ -1784,7 +1981,7 @@ free_bundle_replica(pe__bundle_replica_t *replica) } void -pe__free_bundle(pe_resource_t *rsc) +pe__free_bundle(pcmk_resource_t *rsc) { pe__bundle_variant_data_t *bundle_data = NULL; CRM_CHECK(rsc != NULL, return); @@ -1818,9 +2015,9 @@ pe__free_bundle(pe_resource_t *rsc) } enum rsc_role_e -pe__bundle_resource_state(const pe_resource_t *rsc, gboolean current) +pe__bundle_resource_state(const pcmk_resource_t *rsc, gboolean current) { - enum rsc_role_e container_role = RSC_ROLE_UNKNOWN; + enum rsc_role_e container_role = pcmk_role_unknown; return container_role; } @@ -1832,9 +2029,9 @@ pe__bundle_resource_state(const pe_resource_t *rsc, gboolean current) * \return Number of configured replicas, or 0 on error */ int -pe_bundle_replicas(const pe_resource_t *rsc) +pe_bundle_replicas(const pcmk_resource_t *rsc) { - if ((rsc == NULL) || (rsc->variant != pe_container)) { + if ((rsc == NULL) || (rsc->variant != pcmk_rsc_variant_bundle)) { return 0; } else { pe__bundle_variant_data_t *bundle_data = NULL; @@ -1845,7 +2042,7 @@ pe_bundle_replicas(const pe_resource_t *rsc) } void -pe__count_bundle(pe_resource_t *rsc) +pe__count_bundle(pcmk_resource_t *rsc) { pe__bundle_variant_data_t *bundle_data = NULL; @@ -1869,7 +2066,7 @@ pe__count_bundle(pe_resource_t *rsc) } gboolean -pe__bundle_is_filtered(const pe_resource_t *rsc, GList *only_rsc, +pe__bundle_is_filtered(const pcmk_resource_t *rsc, GList *only_rsc, gboolean check_parent) { gboolean passes = FALSE; @@ -1913,7 +2110,7 @@ pe__bundle_is_filtered(const pe_resource_t *rsc, GList *only_rsc, * g_list_free(). */ GList * -pe__bundle_containers(const pe_resource_t *bundle) +pe__bundle_containers(const pcmk_resource_t *bundle) { GList *containers = NULL; const pe__bundle_variant_data_t *data = NULL; @@ -1927,14 +2124,14 @@ pe__bundle_containers(const pe_resource_t *bundle) return containers; } -// Bundle implementation of resource_object_functions_t:active_node() -pe_node_t * -pe__bundle_active_node(const pe_resource_t *rsc, unsigned int *count_all, +// Bundle implementation of pcmk_rsc_methods_t:active_node() +pcmk_node_t * +pe__bundle_active_node(const pcmk_resource_t *rsc, unsigned int *count_all, unsigned int *count_clean) { - pe_node_t *active = NULL; - pe_node_t *node = NULL; - pe_resource_t *container = NULL; + pcmk_node_t *active = NULL; + pcmk_node_t *node = NULL; + pcmk_resource_t *container = NULL; GList *containers = NULL; GList *iter = NULL; GHashTable *nodes = NULL; @@ -2002,3 +2199,21 @@ done: g_hash_table_destroy(nodes); return active; } + +/*! + * \internal + * \brief Get maximum bundle resource instances per node + * + * \param[in] rsc Bundle resource to check + * + * \return Maximum number of \p rsc instances that can be active on one node + */ +unsigned int +pe__bundle_max_per_node(const pcmk_resource_t *rsc) +{ + pe__bundle_variant_data_t *bundle_data = NULL; + + get_bundle_variant_data(bundle_data, rsc); + CRM_ASSERT(bundle_data->nreplicas_per_host >= 0); + return (unsigned int) bundle_data->nreplicas_per_host; +} |