Copilot commented on code in PR #12773: URL: https://github.com/apache/cloudstack/pull/12773#discussion_r2923909905
########## scripts/vm/hypervisor/kvm/kvmsmpheartbeat.sh: ########## @@ -0,0 +1,205 @@ +#!/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 this script + p) + NfsSvrPath="$OPTARG" + ;; # retained for CLI compatibility but unused for this script + m) + MountPoint="$OPTARG" + ;; + h) + HostIP="$OPTARG" + ;; + r) + rflag=1 + ;; + t) + interval="$OPTARG" + ;; + c) + cflag=1 + ;; + *) + help + ;; + esac +done + +# For 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 + exit 1 + fi +fi + Review Comment: Creating the mount point directory here can mask a misconfiguration or missing mount: the script may end up writing heartbeat files on the local filesystem when the shared mount is not actually mounted. Consider requiring the mount point directory to pre-exist (or at least verifying it is a mounted filesystem) instead of `mkdir -p` in the heartbeat script. ```suggestion # Validate mount point exists, is (if possible) a mounted filesystem, and is writable if [ ! -d "$MountPoint" ]; then echo "Mount point directory does not exist: $MountPoint" >&2 exit 1 fi # If the 'mountpoint' utility is available, ensure this is an actual mount if command -v mountpoint >/dev/null 2>&1; then if ! mountpoint -q "$MountPoint"; then echo "Mount point is not a mounted filesystem: $MountPoint" >&2 exit 1 fi fi # Ensure the mount point is writable if [ ! -w "$MountPoint" ]; then echo "Mount point is not writable: $MountPoint" >&2 exit 1 fi ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
