-
Notifications
You must be signed in to change notification settings - Fork 1.3k
KVM: Enable HA heartbeat on ShareMountPoint #12773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sureshanaparti
merged 17 commits into
apache:4.22
from
weizhouapache:4.22-kvm-ha-on-shared-mount-point
Apr 10, 2026
+253
−22
Merged
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
93b95aa
KVM: Enable HA heartbeat on ShareMountPoint
weizhouapache f6c6a17
Update plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm…
weizhouapache a803c2f
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache eacece1
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache 4e4da44
move STORAGE_POOL_TYPES_WITH_HA_SUPPORT to HighAvailabilityManager an…
weizhouapache 5443527
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache bca0221
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache c9b0f97
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache 1268f5d
minor changes
weizhouapache 8670f25
Update plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm…
weizhouapache b543690
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache 67d9c8f
fix wrong logic
weizhouapache 6bcb459
KVM: remove KVMHABase.s_heartBeatPath
weizhouapache d30ca6e
small refactoring
weizhouapache ab4557d
Update scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh
weizhouapache a361b28
ensure mountPoint ends with a single trailing slash when delete vms o…
weizhouapache 9cebe72
Merge branch '4.22' into 4.22-kvm-ha-on-shared-mount-point
weizhouapache File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| #!/bin/bash | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| help() { | ||
| printf "Usage: $0 | ||
| -i identifier (required for CLI compatibility; value ignored by local-only heartbeat) | ||
| -p path (required for CLI compatibility; value ignored by local-only heartbeat) | ||
| -m mount point (local path where heartbeat will be written) | ||
| -h host (host IP/name to include in heartbeat filename) | ||
| -r write/read hb log (read-check mode) | ||
| -c cleanup (trigger emergency reboot) | ||
| -t interval between read hb log\n" | ||
| exit 1 | ||
| } | ||
|
|
||
| #set -x | ||
| NfsSvrIP= | ||
| NfsSvrPath= | ||
| MountPoint= | ||
| HostIP= | ||
| interval= | ||
| rflag=0 | ||
| cflag=0 | ||
|
|
||
| while getopts 'i:p:m:h:t:rc' OPTION | ||
| do | ||
| case $OPTION in | ||
| i) | ||
| NfsSvrIP="$OPTARG" | ||
| ;; # retained for CLI compatibility but unused for local-only script | ||
| p) | ||
| NfsSvrPath="$OPTARG" | ||
| ;; # retained for CLI compatibility but unused for local-only script | ||
| m) | ||
| MountPoint="$OPTARG" | ||
| ;; | ||
| h) | ||
| HostIP="$OPTARG" | ||
| ;; | ||
| r) | ||
| rflag=1 | ||
| ;; | ||
| t) | ||
| interval="$OPTARG" | ||
| ;; | ||
| c) | ||
| cflag=1 | ||
| ;; | ||
| *) | ||
| help | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # For local-only heartbeat we require a mountpoint | ||
| if [ -z "$MountPoint" ] | ||
| then | ||
| echo "Mount point (-m) is required" | ||
| help | ||
| fi | ||
|
|
||
| # Ensure mount point exists and is writable | ||
| if [ ! -d "$MountPoint" ]; then | ||
| mkdir -p "$MountPoint" 2>/dev/null | ||
| if [ $? -ne 0 ]; then | ||
| echo "Failed to create mount point directory: $MountPoint" >&2 | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exit 1 | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Determine a sensible HostIP if not provided | ||
| if [ -z "$HostIP" ]; then | ||
| # try to get a non-loopback IPv4 address, fallback to hostname | ||
| ipaddr=$(hostname -I 2>/dev/null | awk '{print $1}') | ||
| if [ -n "$ipaddr" ]; then | ||
| HostIP="$ipaddr" | ||
| else | ||
| HostIP=$(hostname) | ||
| fi | ||
| fi | ||
|
|
||
| #delete VMs on this mountpoint (best-effort) | ||
| deleteVMs() { | ||
| local mountPoint=$1 | ||
| vmPids=$(ps aux | grep qemu | grep "$mountPoint" | awk '{print $2}' 2> /dev/null) | ||
| if [ $? -gt 0 ] | ||
| then | ||
| return | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if [ -z "$vmPids" ] | ||
| then | ||
| return | ||
| fi | ||
|
|
||
| for pid in $vmPids | ||
| do | ||
| kill -9 $pid &> /dev/null | ||
| done | ||
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #checking is there the mount point present under $MountPoint? | ||
| mounts=$(cat /proc/mounts | grep "$MountPoint") | ||
| if [ $? -gt 0 ] | ||
| then | ||
| # mount point not present — we don't remount in local-only script | ||
| # nothing to do here; keep for compatibility with original flow | ||
| : | ||
| else | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # mount exists; if not in read-check mode, consider deleting VMs similar to original behavior | ||
| if [ "$rflag" == "0" ] | ||
| then | ||
| deleteVMs $MountPoint | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hbFolder="$MountPoint/KVMHA/" | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| hbFile="$hbFolder/hb-$HostIP" | ||
|
|
||
| write_hbLog() { | ||
| #write the heart beat log | ||
| stat "$hbFile" &> /dev/null | ||
| if [ $? -gt 0 ] | ||
| then | ||
| # create a new one | ||
| mkdir -p "$hbFolder" &> /dev/null | ||
| # touch will be done by atomic write below; ensure folder is writable | ||
| if [ ! -w "$hbFolder" ]; then | ||
| printf "Folder not writable: $hbFolder" >&2 | ||
| return 2 | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| timestamp=$(date +%s) | ||
| # Write atomically to avoid partial writes (write to tmp then mv) | ||
| tmpfile="${hbFile}.$$" | ||
| printf "%s\n" "$timestamp" > "$tmpfile" 2>/dev/null | ||
| if [ $? -ne 0 ]; then | ||
| printf "Failed to write heartbeat to $tmpfile" >&2 | ||
| return 2 | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mv -f "$tmpfile" "$hbFile" 2>/dev/null | ||
| return $? | ||
| } | ||
|
|
||
| check_hbLog() { | ||
| if [ ! -f "$hbFile" ]; then | ||
| # signal large difference if file missing | ||
| return 999999 | ||
| fi | ||
| now=$(date +%s) | ||
| hb=$(cat "$hbFile" 2>/dev/null) | ||
| if [ -z "$hb" ]; then | ||
| return 999998 | ||
| fi | ||
| diff=`expr $now - $hb 2>/dev/null` | ||
| if [ $? -ne 0 ] | ||
| then | ||
| return 999997 | ||
| fi | ||
| if [ -z "$interval" ]; then | ||
| # if no interval provided, consider 0 as success | ||
| if [ $diff -gt 0 ]; then | ||
| return $diff | ||
| else | ||
| return 0 | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
weizhouapache marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| if [ $diff -gt $interval ] | ||
| then | ||
| return $diff | ||
| fi | ||
| return 0 | ||
| } | ||
|
|
||
| if [ "$rflag" == "1" ] | ||
| then | ||
| check_hbLog | ||
| diff=$? | ||
| if [ $diff == 0 ] | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| then | ||
| echo "=====> ALIVE <=====" | ||
| else | ||
| echo "=====> Considering host as DEAD because last write on [$hbFile] was [$diff] seconds ago, but the max interval is [$interval] <======" | ||
| fi | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exit 0 | ||
| elif [ "$cflag" == "1" ] | ||
| then | ||
| /usr/bin/logger -t heartbeat "kvmsmpheartbeat.sh will reboot system because it was unable to write the heartbeat to the storage." | ||
| sync & | ||
| sleep 5 | ||
| echo b > /proc/sysrq-trigger | ||
| exit $? | ||
| else | ||
| write_hbLog | ||
| exit $? | ||
| fi | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.