1 /*
2 * Copyright 2004-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 #ifndef PCMK__CRM_COMMON_CLONE_INTERNAL__H
11 #define PCMK__CRM_COMMON_CLONE_INTERNAL__H
12
13 #include <stdio.h> // NULL
14 #include <stdbool.h> // bool
15 #include <crm/common/scheduler_types.h> // pcmk_resource_t
16 #include <crm/common/resources.h> // pcmk_rsc_unique,
17 #include <crm/common/resources_internal.h> // pcmk__rsc_variant_clone etc.
18 #include <crm/common/util.h> // pcmk_is_set
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 // Clone resource flags (used in variant data)
25 enum pcmk__clone_flags {
26 // Whether instances should be started sequentially
27 pcmk__clone_ordered = (1 << 0),
28
29 // Whether promotion scores have been added
30 pcmk__clone_promotion_added = (1 << 1),
31
32 // Whether promotion constraints have been added
33 pcmk__clone_promotion_constrained = (1 << 2),
34 };
35
36 /*!
37 * \internal
38 * \brief Check whether a resource is a clone resource
39 *
40 * \param[in] rsc Resource to check
41 *
42 * \return true if \p rsc is a clone, otherwise false
43 *
44 * \note This does not return true if \p rsc has a clone ancestor.
45 */
46 static inline bool
47 pcmk__is_clone(const pcmk_resource_t *rsc)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
48 {
49 return (rsc != NULL) && (rsc->priv->variant == pcmk__rsc_variant_clone);
50 }
51
52 /*!
53 * \internal
54 * \brief Check whether a resource is a globally unique clone
55 *
56 * \param[in] rsc Resource to check
57 *
58 * \return true if \p rsc is a unique clone, otherwise false
59 */
60 static inline bool
61 pcmk__is_unique_clone(const pcmk_resource_t *rsc)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
62 {
63 return pcmk__is_clone(rsc) && pcmk_is_set(rsc->flags, pcmk__rsc_unique);
64 }
65
66 /*!
67 * \internal
68 * \brief Check whether a resource is an anonymous clone
69 *
70 * \param[in] rsc Resource to check
71 *
72 * \return true if \p rsc is an anonymous clone, otherwise false
73 */
74 static inline bool
75 pcmk__is_anonymous_clone(const pcmk_resource_t *rsc)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
76 {
77 return pcmk__is_clone(rsc) && !pcmk_is_set(rsc->flags, pcmk__rsc_unique);
78 }
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif // PCMK__CRM_COMMON_CLONE_INTERNAL__H