Skip to content

Commit 6786d45

Browse files
authored
fix(linstor): surface ambiguous template fallbacks and legacy orphan cleanup (#13078)
Co-authored-by: jmsperu <jmsperu@users.noreply.github.com>
1 parent 3f6866d commit 6786d45

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,19 @@ private boolean deRefOrDeleteResource(DevelopersApi api, String rscName, String
508508
// if there is only one template-for property left for templates, the template isn't needed anymore
509509
// or if it isn't a template anyway, it will not have this Aux property
510510
// _cs-template-for- properties work like a ref-count.
511-
if (rd.getProps().keySet().stream()
511+
long remainingTemplateRefs = rd.getProps().keySet().stream()
512512
.filter(key -> key.startsWith("Aux/" + LinstorUtil.CS_TEMPLATE_FOR_PREFIX))
513-
.count() == expectedProps) {
513+
.count();
514+
if (remainingTemplateRefs == expectedProps) {
515+
// Surface the legacy case where a resource has zero `_cs-template-for-` aux
516+
// properties even though we never decremented one — that's a template predating
517+
// the ref-count convention, or a stale orphan. Logging before deletion lets
518+
// operators audit how many such orphans existed at upgrade time.
519+
if (expectedProps == 0) {
520+
logger.info("Linstor: deleting resource {} which has no _cs-template-for- aux properties " +
521+
"(legacy template predating the ref-count convention, or a stale orphan). " +
522+
"Resource group context: {}", rd.getName(), rscGrpName);
523+
}
514524
ApiCallRcList answers = api.resourceDefinitionDelete(rd.getName());
515525
checkLinstorAnswersThrow(answers);
516526
deleted = true;

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,26 @@ public static ResourceDefinition findResourceDefinition(DevelopersApi api, Strin
543543
.filter(rscDfn -> rscDfn.getProps().containsKey(LinstorUtil.getTemplateForAuxPropKey(rscGrpName)))
544544
.findFirst();
545545

546-
return rd.orElseGet(() -> rdsStartingWith.get(0));
546+
if (rd.isPresent()) {
547+
return rd.get();
548+
}
549+
// Fallback: no resource has the exact "_cs-template-for-<rscGrpName>" property.
550+
// This happens when (a) the matched resource is a legacy template created before that
551+
// convention was introduced, or (b) the template was cached by a different resource
552+
// group and the operator hopes to share it. Log so the ambiguity is visible — silent
553+
// first-match fallback has previously routed clones to the wrong template when
554+
// multiple resource groups coexisted on the same controller.
555+
ResourceDefinition fallback = rdsStartingWith.get(0);
556+
LOGGER.warn("LINSTOR findResourceDefinition: no resource for '{}' has the expected " +
557+
"Aux property '{}' for resource group '{}'; falling back to first match '{}' " +
558+
"(present aux properties: {}). If this is wrong, set the property explicitly " +
559+
"or remove the unrelated resource definition.",
560+
rscName, getTemplateForAuxPropKey(rscGrpName), rscGrpName,
561+
fallback.getName(),
562+
fallback.getProps().keySet().stream()
563+
.filter(k -> k.startsWith("Aux/" + CS_TEMPLATE_FOR_PREFIX))
564+
.collect(Collectors.toList()));
565+
return fallback;
547566
}
548567

549568
public static boolean isRscDiskless(ResourceWithVolumes rsc) {

0 commit comments

Comments
 (0)