From d31d9fa58482a44144bda5c04f2431273ca121eb Mon Sep 17 00:00:00 2001 From: beatzaplenty Date: Tue, 28 Jul 2026 17:50:24 +1000 Subject: [PATCH] fix(ha/cluster-init): fix LIO teardown, mount idempotency, VIP portal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove VIP-specific portal binding — the VIP doesn't exist until Pacemaker assigns it; the default all-IPs portal (::0:3260) is correct for Pacemaker to manage - Clear existing LIO targets before re-running targetcli (idempotent on partial failures) - Tear down LIO kernel objects after saveconfig so umount succeeds (LIO holds the backing file open otherwise) - Guard mount with mountpoint check so re-runs don't fail when already mounted - Use --replace for cibadmin constraints (idempotent vs --create) Co-Authored-By: Claude Sonnet 4.6 Claude-Session: https://claude.ai/code/session_01HaH1cSGvhogRP5ExoF6nD8 --- scripts/ha/cluster-init.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/ha/cluster-init.sh b/scripts/ha/cluster-init.sh index 59335a7..9f1271b 100755 --- a/scripts/ha/cluster-init.sh +++ b/scripts/ha/cluster-init.sh @@ -165,7 +165,7 @@ fi log "Mounting ${DRBD_DEVICE} at ${XFS_MOUNT}..." mkdir -p "${XFS_MOUNT}" -mount "${DRBD_DEVICE}" "${XFS_MOUNT}" +mountpoint -q "${XFS_MOUNT}" || mount "${DRBD_DEVICE}" "${XFS_MOUNT}" # ── 4. NFS dataset directories ──────────────────────────────────────────── log "Creating NFS dataset directories..." @@ -181,21 +181,33 @@ fi # ── 6. LIO iSCSI target ─────────────────────────────────────────────────── log "Configuring LIO iSCSI target via targetcli..." +# Note: do NOT bind portal to ${VIP} here — the VIP isn't assigned yet (Pacemaker +# creates it). The default portal (all IPs, port 3260) is correct; Pacemaker's +# 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 +fi targetcli </dev/null || warn "LIO clearconfig had errors — umount may fail" + log "Distributing iSCSI saveconfig to $NODE2..." n2_scp /etc/target/saveconfig.json /etc/target/saveconfig.json log "Unmounting ${XFS_MOUNT} — Pacemaker manages it..." -umount "${XFS_MOUNT}" +umount "${XFS_MOUNT}" || { sync; umount -l "${XFS_MOUNT}"; } log "Demoting DRBD to Secondary — Pacemaker manages primary role..." drbdadm secondary ha-data @@ -277,7 +289,7 @@ cibadmin --replace --scope resources --xml-text " " log "Adding ordering and colocation constraints..." -cibadmin --create --scope constraints --xml-text " +cibadmin --replace --scope constraints --xml-text "