From 0e1ebca855bccb18e7a0a253bf42edcd572b2438 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Jun 25 2024 20:45:19 +0000 Subject: sanlock: rem_lockspace EBUSY when orphans exist If a lockspace has orphan resources, return -EBUSY for rem_lockspace rather than starting lockspace removal, but blocking the completion. This allows the caller to properly clean up the orphans and then remove the lockspace. --- diff --git a/src/lockspace.c b/src/lockspace.c index da51af0..7e5185d 100644 --- a/src/lockspace.c +++ b/src/lockspace.c @@ -1328,6 +1328,17 @@ int rem_lockspace_start(struct sanlk_lockspace *ls, unsigned int *space_id) goto out; } + if (sp->flags & SP_USED_BY_ORPHANS) { + /* lock ordering: spaces_mutex, then resource_mutex (resource_orphan_count) */ + int orphans = resource_orphan_count(sp->space_name); + if (orphans) { + log_space(sp, "rem_lockspace ignored for orphan count %d", orphans); + pthread_mutex_unlock(&spaces_mutex); + rv = -EBUSY; + goto out; + } + } + /* * Removal happens in a round about way: * - we set external_remove