commit b0ca9a11581e3ec62429e41899f76fe3afc8b294
Author: Andrew Beekhof <andrew@beekhof.net>
Date:   Wed Oct 11 22:28:58 2017 +1100

    Fix: Tools: Allow crm_resource to operate on anonymous clones in unknown states
    
    Since the clone_name value wont be set

Index: pacemaker-1.1.16+20170320.77ea74d/include/crm/pengine/status.h
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/include/crm/pengine/status.h
+++ pacemaker-1.1.16+20170320.77ea74d/include/crm/pengine/status.h
@@ -49,9 +49,10 @@ enum pe_restart {
 };
 
 enum pe_find {
-    pe_find_renamed = 0x001,
-    pe_find_clone = 0x004,
-    pe_find_current = 0x008,
+    pe_find_renamed  = 0x001,
+    pe_find_anon     = 0x002,
+    pe_find_clone    = 0x004,
+    pe_find_current  = 0x008,
     pe_find_inactive = 0x010,
 };
 
@@ -434,6 +435,7 @@ gboolean cluster_status(pe_working_set_t
 void set_working_set_defaults(pe_working_set_t * data_set);
 void cleanup_calculations(pe_working_set_t * data_set);
 resource_t *pe_find_resource(GListPtr rsc_list, const char *id_rh);
+resource_t *pe_find_resource_with_flags(GListPtr rsc_list, const char *id, enum pe_find flags);
 node_t *pe_find_node(GListPtr node_list, const char *uname);
 node_t *pe_find_node_id(GListPtr node_list, const char *id);
 node_t *pe_find_node_any(GListPtr node_list, const char *id, const char *uname);
Index: pacemaker-1.1.16+20170320.77ea74d/lib/pengine/native.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/lib/pengine/native.c
+++ pacemaker-1.1.16+20170320.77ea74d/lib/pengine/native.c
@@ -179,14 +179,19 @@ native_find_rsc(resource_t * rsc, const
             match = TRUE;
         }
 
-    } else {
-        if (strcmp(rsc->id, id) == 0) {
-            match = TRUE;
+    } else if (strcmp(rsc->id, id) == 0) {
+        match = TRUE;
+
+    } else if (is_set(flags, pe_find_renamed)
+               && rsc->clone_name && strcmp(rsc->clone_name, id) == 0) {
+        match = TRUE;
 
-        } else if (is_set(flags, pe_find_renamed)
-                   && rsc->clone_name && strcmp(rsc->clone_name, id) == 0) {
+    } else if (is_set(flags, pe_find_anon) && is_not_set(rsc->flags, pe_rsc_unique)) {
+        char *tmp = clone_strip(rsc->id);
+        if(strcmp(tmp, id) == 0) {
             match = TRUE;
         }
+        free(tmp);
     }
 
     if (match && on_node) {
Index: pacemaker-1.1.16+20170320.77ea74d/lib/pengine/status.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/lib/pengine/status.c
+++ pacemaker-1.1.16+20170320.77ea74d/lib/pengine/status.c
@@ -251,13 +251,19 @@ set_working_set_defaults(pe_working_set_
 resource_t *
 pe_find_resource(GListPtr rsc_list, const char *id)
 {
+    return pe_find_resource_with_flags(rsc_list, id, pe_find_renamed | pe_find_current);
+}
+
+resource_t *
+pe_find_resource_with_flags(GListPtr rsc_list, const char *id, enum pe_find flags)
+{
     GListPtr rIter = NULL;
 
     for (rIter = rsc_list; id && rIter; rIter = rIter->next) {
         resource_t *parent = rIter->data;
 
         resource_t *match =
-            parent->fns->find_rsc(parent, id, NULL, pe_find_renamed | pe_find_current);
+            parent->fns->find_rsc(parent, id, NULL, flags);
         if (match != NULL) {
             return match;
         }
Index: pacemaker-1.1.16+20170320.77ea74d/tools/crm_resource.c
===================================================================
--- pacemaker-1.1.16+20170320.77ea74d.orig/tools/crm_resource.c
+++ pacemaker-1.1.16+20170320.77ea74d/tools/crm_resource.c
@@ -834,7 +834,7 @@ main(int argc, char **argv)
             goto bail;
         }
 
-        rsc = pe_find_resource(data_set.resources, rsc_id);
+        rsc = pe_find_resource_with_flags(data_set.resources, rsc_id, pe_find_renamed | pe_find_current | pe_find_anon);
 
         rc = -EINVAL;
         if (rsc == NULL) {
@@ -856,7 +856,7 @@ main(int argc, char **argv)
 
     } else if (rsc_cmd == 'A' || rsc_cmd == 'a') {
         GListPtr lpc = NULL;
-        resource_t *rsc = pe_find_resource(data_set.resources, rsc_id);
+        resource_t *rsc = pe_find_resource_with_flags(data_set.resources, rsc_id, pe_find_renamed | pe_find_current | pe_find_anon);
         xmlNode *cib_constraints = get_object_root(XML_CIB_TAG_CONSTRAINTS, data_set.input);
 
         if (rsc == NULL) {
@@ -968,7 +968,7 @@ main(int argc, char **argv)
         rc = cli_resource_move(rsc_id, host_uname, cib_conn, &data_set);
 
     } else if (rsc_cmd == 'B' && host_uname) {
-        resource_t *rsc = pe_find_resource(data_set.resources, rsc_id);
+        resource_t *rsc = pe_find_resource_with_flags(data_set.resources, rsc_id, pe_find_renamed | pe_find_current | pe_find_anon);
         node_t *dest = pe_find_node(data_set.nodes, host_uname);
 
         rc = -ENXIO;
@@ -985,7 +985,7 @@ main(int argc, char **argv)
         rc = cli_resource_ban(rsc_id, dest->details->uname, NULL, cib_conn);
 
     } else if (rsc_cmd == 'B' || rsc_cmd == 'M') {
-        resource_t *rsc = pe_find_resource(data_set.resources, rsc_id);
+        resource_t *rsc = pe_find_resource_with_flags(data_set.resources, rsc_id, pe_find_renamed | pe_find_current | pe_find_anon);
 
         rc = -ENXIO;
         if (rsc_id == NULL) {
@@ -1106,7 +1106,7 @@ main(int argc, char **argv)
         rc = cli_resource_delete_attribute(rsc_id, prop_set, prop_id, prop_name, cib_conn, &data_set);
 
     } else if (rsc_cmd == 'C' && rsc_id) {
-        resource_t *rsc = pe_find_resource(data_set.resources, rsc_id);
+        resource_t *rsc = pe_find_resource_with_flags(data_set.resources, rsc_id, pe_find_renamed | pe_find_current | pe_find_anon);
 
         if(do_force == FALSE) {
             rsc = uber_parent(rsc);
