From 79cde50e2764803ade9fda523280bac53a32aa02 Mon Sep 17 00:00:00 2001 From: beatzaplenty Date: Tue, 28 Jul 2026 17:55:26 +1000 Subject: [PATCH] fix(ha/cluster-init): use targetcli delete commands for LIO teardown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clearconfig does not reliably clear kernel LIO configfs state — the kernel still holds backing-file references, blocking umount. Replace clearconfig with explicit targetcli delete commands (/iscsi delete, /backstores/fileio delete) which do release kernel state. Also make DRBD secondary demote idempotent (skip if already Secondary). Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01HaH1cSGvhogRP5ExoF6nD8 --- scripts/ha/cluster-init.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/ha/cluster-init.sh b/scripts/ha/cluster-init.sh index 9f1271b..6d850fd 100755 --- a/scripts/ha/cluster-init.sh +++ b/scripts/ha/cluster-init.sh @@ -186,9 +186,14 @@ log "Configuring LIO iSCSI target via targetcli..." # VIP resource will make the target reachable at the VIP address. # # Clear any existing LIO state first (idempotent: re-run after a partial failure). -if ls /sys/kernel/config/target/iscsi/ 2>/dev/null | grep -q iqn; then - log "Clearing existing LIO targets before reconfiguration..." - echo "clearconfig confirm=yes" | targetcli 2>/dev/null || true +# Use specific delete commands — clearconfig does not reliably clear kernel state. +if ls /sys/kernel/config/target/iscsi/ 2>/dev/null | grep -q "${ISCSI_IQN}"; then + log "Clearing existing LIO target ${ISCSI_IQN} before reconfiguration..." + targetcli "/iscsi delete ${ISCSI_IQN}" 2>/dev/null || true +fi +if ls /sys/kernel/config/target/core/ 2>/dev/null | grep -q "fileio"; then + log "Clearing existing LIO backstore ha-lun0 before reconfiguration..." + targetcli "/backstores/fileio delete ha-lun0" 2>/dev/null || true fi targetcli </dev/null || warn "LIO clearconfig had errors — umount may fail" +# Use specific delete commands (clearconfig does not reliably clear kernel configfs state). +targetcli "/iscsi delete ${ISCSI_IQN}" 2>/dev/null || warn "LIO iscsi delete failed — umount may fail" +targetcli "/backstores/fileio delete ha-lun0" 2>/dev/null || warn "LIO backstore delete failed" log "Distributing iSCSI saveconfig to $NODE2..." n2_scp /etc/target/saveconfig.json /etc/target/saveconfig.json @@ -210,7 +217,7 @@ log "Unmounting ${XFS_MOUNT} — Pacemaker manages it..." umount "${XFS_MOUNT}" || { sync; umount -l "${XFS_MOUNT}"; } log "Demoting DRBD to Secondary — Pacemaker manages primary role..." -drbdadm secondary ha-data +[[ "$(drbdadm role ha-data 2>/dev/null)" == "Primary/Secondary" ]] && drbdadm secondary ha-data || true # ── 7. Pacemaker resources ──────────────────────────────────────────────── log "Configuring Pacemaker cluster properties..."