2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-11-19 08:52:15 +00:00

feat(uftp): receive the root image over UFTP on EL stateless nodes

genimage adds the UFTP fetch helper and uftpd to the stateless initial
ramdisk of an EL image that has the UFTP 5 receiver of xcat-dep for its
architecture. It checks that the built ramdisk holds the receiver files.
It writes a marker with the digest of the published ramdisk, which
nodeset compares before it asks for UFTP. Without a usable receiver,
genimage removes the helper and the marker.

When nodeset passes xcat.uftp=, xcatroot receives the first copy of the
image over UFTP. The helper asks the listener for the archive that the
checksum file names, as fetched before the request. xcatroot checks the
received file against the checksum file like an HTTP download. A
mismatch or a failed transfer is followed by the HTTP download loop.
UFTP is used only together with rootimgchecksum=yes.
This commit is contained in:
Vinícius Ferrão
2026-10-17 13:37:58 -03:00
parent 0f2f1cfd05
commit 3dcf4bdef7
9 changed files with 606 additions and 5 deletions
@@ -141,6 +141,52 @@ sub publish_boot_files {
return 1;
}
# Puts the UFTP fetch helper in the xCAT dracut module of an initial ramdisk when $wanted is true and the image has the
# UFTP 5 receiver of xcat-dep for its architecture, and removes an older copy otherwise. Returns the receiver or undef.
sub add_uftp_receiver {
my ($rootimg_dir, $arch, $moduledir, $wanted) = @_;
require xCAT::UFTP;
my $copy = "$moduledir/$xCAT::UFTP::HELPER";
if (-e $copy || -l $copy) {
unlink($copy) or die("Error: cannot remove $copy: $!\n");
}
return unless $wanted;
my ($receiver, $warning) = xCAT::UFTP::usable_receiver($rootimg_dir, $arch);
print "Warning: $warning\n" if $warning;
return unless $receiver;
my $helper = dirname(__FILE__) . "/$xCAT::UFTP::HELPER";
File::Copy::copy($helper, $copy) && chmod(0644, $copy) or die("Error: cannot copy $helper to $copy: $!\n");
print "Adding the UFTP receiver $receiver to the initial ramdisk.\n";
return $receiver;
}
# Returns the lsinitrd lines of the initial ramdisk $initrd, a path inside the image, or undef when the image cannot list it.
sub initrd_listing {
my ($rootimg_dir, $initrd) = @_;
my @listing = `chroot $rootimg_dir lsinitrd $initrd 2>&1`;
return $? ? undef : \@listing;
}
# Dies unless the initial ramdisk $initrd, a path inside the image, holds the UFTP receiver files.
sub check_uftp_initrd {
my ($rootimg_dir, $initrd, $mode) = @_;
require xCAT::UFTP;
my $listing = initrd_listing($rootimg_dir, $initrd);
my @missing = $listing ? xCAT::UFTP::initrd_missing_files($listing) : ('a readable file list');
die("Error: the initial ramdisk for $mode lacks the UFTP receiver files: @missing\n") if @missing;
return 1;
}
# Records next to a published initial ramdisk whether it can receive the root image over UFTP.
sub mark_uftp_receiver {
my ($initrd, $receiver) = @_;
require xCAT::UFTP;
my $error = $receiver ? xCAT::UFTP::write_initrd_marker($initrd) : xCAT::UFTP::remove_initrd_marker($initrd);
print "Warning: $error\n" if $error;
print "The initial ramdisk $initrd can receive the root image over UFTP.\n" if $receiver && !$error;
return !$error;
}
sub varsubinline{
my $line=shift;
my $refvardict=shift;
@@ -0,0 +1,460 @@
# Receive a stateless root image over UFTP multicast. xcatroot sources this
# file when nodeset passes xcat.uftp=, and calls xcat_uftp_rootimg. The file
# is not checked here: xcatroot checks it like an HTTP download.
: "${XCAT_UFTP_ATTEMPTS:=2}"
: "${XCAT_UFTP_GRACE:=30}"
: "${XCAT_UFTP_POLL:=5}"
: "${XCAT_UFTP_REQUEST_TIMEOUT:=15}"
: "${XCAT_UFTP_STOP_WAIT:=10}"
xcat_fetch_log() {
if command -v logger >/dev/null 2>&1; then
# SYSLOGHOST is either empty or "-n <server>" and must split.
logger $SYSLOGHOST -t "${log_label:-xcat.deployment}" -p "local4.$1" "$2"
fi
echo "$2" >&2
}
xcat_uint_ok() {
case "$1" in
0) return 0 ;;
''|0*|*[!0-9]*) return 1 ;;
esac
[ "${#1}" -le 9 ] && [ "$1" -le "$2" ]
}
xcat_port_ok() {
xcat_uint_ok "$1" 65535 && [ "$1" -gt 0 ]
}
xcat_ipv4_ok() {
case "$1" in
''|*[!0-9.]*|.*|*.|*..*) return 1 ;;
esac
_xf_ifs=$IFS
IFS=.
set -- $1
IFS=$_xf_ifs
[ "$#" -eq 4 ] || return 1
for _xf_octet do
xcat_uint_ok "$_xf_octet" 255 || return 1
done
}
xcat_sha256_ok() {
case "$1" in
*[!0-9a-f]*) return 1 ;;
esac
[ "${#1}" -eq 64 ]
}
xcat_fingerprint_ok() {
case "$1" in
??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??:??) ;;
*) return 1 ;;
esac
case "$1" in
*[!0-9A-F:]*) return 1 ;;
esac
}
# Print the first SHA-256 checksum that the sha256sum file $1 lists for the name $2.
xcat_listed_sha256() {
[ -r "$1" ] || return 1
while read -r _xf_sum _xf_name || [ -n "$_xf_sum" ]; do
if [ "${_xf_name#\*}" = "$2" ] && xcat_sha256_ok "$_xf_sum"; then
printf '%s\n' "$_xf_sum"
return 0
fi
done < "$1"
return 1
}
# Split an http(s) URL into XCAT_URL_SCHEME, XCAT_URL_HOST (IPv6 keeps its
# brackets), XCAT_URL_PORT (the scheme default when absent) and XCAT_URL_PATH.
xcat_url_parse() {
case "$1" in
http://*) XCAT_URL_SCHEME=http; _xf_rest=${1#http://} ;;
https://*) XCAT_URL_SCHEME=https; _xf_rest=${1#https://} ;;
*) return 1 ;;
esac
case "$_xf_rest" in
*/*) _xf_authority=${_xf_rest%%/*}; XCAT_URL_PATH=/${_xf_rest#*/} ;;
*) _xf_authority=$_xf_rest; XCAT_URL_PATH=/ ;;
esac
case "$_xf_authority" in
*@*) return 1 ;;
\[*\]:*) XCAT_URL_HOST="${_xf_authority%%]:*}]"; XCAT_URL_PORT=${_xf_authority##*]:} ;;
\[*\]) XCAT_URL_HOST=$_xf_authority; XCAT_URL_PORT= ;;
*\[*|*\]*|*:*:*) return 1 ;;
*:*) XCAT_URL_HOST=${_xf_authority%:*}; XCAT_URL_PORT=${_xf_authority##*:} ;;
*) XCAT_URL_HOST=$_xf_authority; XCAT_URL_PORT= ;;
esac
case "$XCAT_URL_HOST" in
''|\[\]) return 1 ;;
\[*\])
_xf_inner=${XCAT_URL_HOST#\[}
_xf_inner=${_xf_inner%\]}
case "$_xf_inner" in
*[!0-9A-Fa-f:.]*|*:*:*:*:*:*:*:*:*) return 1 ;;
*:*) ;;
*) return 1 ;;
esac
;;
*[!A-Za-z0-9.-]*|-*|.*) return 1 ;;
esac
if [ -z "$XCAT_URL_PORT" ]; then
if [ "$XCAT_URL_SCHEME" = https ]; then
XCAT_URL_PORT=443
else
XCAT_URL_PORT=80
fi
fi
xcat_port_ok "$XCAT_URL_PORT" || return 1
case "$XCAT_URL_PATH" in
*[?#%]*) return 1 ;;
esac
}
# Print the image path the listener expects: repeated slashes collapsed and
# every segment limited to the characters packimage accepts.
xcat_image_path() {
_xf_path=$1
while :; do
case "$_xf_path" in
*//*) _xf_path=${_xf_path%%//*}/${_xf_path#*//} ;;
*) break ;;
esac
done
case "$_xf_path" in
/|*/|[!/]*) return 1 ;;
esac
_xf_ifs=$IFS
IFS=/
set -f
set -- ${_xf_path#/}
set +f
IFS=$_xf_ifs
for _xf_segment do
case "$_xf_segment" in
''|.*|*[!A-Za-z0-9._+-]*) return 1 ;;
esac
done
printf '%s\n' "$_xf_path"
}
# Print the transfer request URL for an image URL: same scheme and host,
# the listener port, and the image path.
xcat_uftp_url() {
xcat_url_parse "$1" || return 1
_xf_image=$(xcat_image_path "$XCAT_URL_PATH") || return 1
printf '%s://%s:%s/xcat-uftp/v1/transfer/%s%s\n' \
"$XCAT_URL_SCHEME" "$XCAT_URL_HOST" "$2" "$3" "$_xf_image"
}
xcat_http_get() {
if command -v curl >/dev/null 2>&1; then
curl --fail --silent --show-error --max-time "$3" -o "$2" "$1"
elif command -v wget >/dev/null 2>&1; then
# wget -T limits idle time only, so a watchdog limits the whole request.
wget -q -T "$3" -t 1 -O "$2" "$1" &
_xf_get=$!
(
_xf_left=$3
while [ "$_xf_left" -gt 0 ]; do
sleep 1
kill -0 "$_xf_get" 2>/dev/null || exit 0
_xf_left=$((_xf_left - 1))
done
kill -KILL "$_xf_get" 2>/dev/null
) &
_xf_dog=$!
wait "$_xf_get"
_xf_rc=$?
kill "$_xf_dog" 2>/dev/null
wait "$_xf_dog" 2>/dev/null
return "$_xf_rc"
else
return 127
fi
}
xcat_uftp_read_ack() {
XCAT_ACK_STATUS='' XCAT_ACK_JOB='' XCAT_ACK_FILE='' XCAT_ACK_PORT='' XCAT_ACK_MCAST=''
XCAT_ACK_SERVER_ID='' XCAT_ACK_SERVER_IP='' XCAT_ACK_CLIENT_IP=''
XCAT_ACK_START_IN='' XCAT_ACK_TIMEOUT=''
while IFS= read -r _xf_line || [ -n "$_xf_line" ]; do
_xf_key=${_xf_line%%=*}
_xf_value=${_xf_line#*=}
[ "$_xf_key" != "$_xf_line" ] || return 1
case "$_xf_key" in
status) XCAT_ACK_STATUS=$_xf_value ;;
job) XCAT_ACK_JOB=$_xf_value ;;
file) XCAT_ACK_FILE=$_xf_value ;;
port) XCAT_ACK_PORT=$_xf_value ;;
mcast) XCAT_ACK_MCAST=$_xf_value ;;
server_id) XCAT_ACK_SERVER_ID=$_xf_value ;;
server_ip) XCAT_ACK_SERVER_IP=$_xf_value ;;
client_ip) XCAT_ACK_CLIENT_IP=$_xf_value ;;
start_in) XCAT_ACK_START_IN=$_xf_value ;;
timeout) XCAT_ACK_TIMEOUT=$_xf_value ;;
esac
done < "$1"
[ "$XCAT_ACK_STATUS" = queued ] || return 1
case "$XCAT_ACK_JOB" in
????????????????) ;;
*) return 1 ;;
esac
case "$XCAT_ACK_JOB" in
*[!0-9a-f]*) return 1 ;;
esac
[ "$XCAT_ACK_FILE" = "$2" ] || return 1
xcat_port_ok "$XCAT_ACK_PORT" || return 1
xcat_ipv4_ok "$XCAT_ACK_MCAST" || return 1
xcat_ipv4_ok "$XCAT_ACK_SERVER_IP" || return 1
xcat_ipv4_ok "$XCAT_ACK_CLIENT_IP" || return 1
case "$XCAT_ACK_SERVER_ID" in
0x????????) ;;
*) return 1 ;;
esac
case "${XCAT_ACK_SERVER_ID#0x}" in
*[!0-9A-F]*) return 1 ;;
esac
: "${XCAT_ACK_START_IN:=0}"
xcat_uint_ok "$XCAT_ACK_START_IN" 3600 || return 1
xcat_uint_ok "$XCAT_ACK_TIMEOUT" 86400 && [ "$XCAT_ACK_TIMEOUT" -gt 0 ]
}
# Print a monotonic time in whole seconds.
xcat_now() {
if [ -r /proc/uptime ]; then
read -r _xf_uptime _xf_idle < /proc/uptime
echo "${_xf_uptime%%.*}"
else
date +%s
fi
}
# Print the last three lines of the file $1. The initramfs has no tail.
xcat_last_lines() {
_xf_l1= _xf_l2= _xf_l3=
while IFS= read -r _xf_line || [ -n "$_xf_line" ]; do
_xf_l1=$_xf_l2 _xf_l2=$_xf_l3 _xf_l3=$_xf_line
done < "$1"
printf '%s %s %s' "$_xf_l1" "$_xf_l2" "$_xf_l3"
}
xcat_child_running() {
kill -0 "$1" 2>/dev/null || return 1
if [ -r "/proc/$1/stat" ]; then
read -r _xf_pid _xf_comm _xf_state _xf_rest < "/proc/$1/stat" || return 1
[ "$_xf_state" != Z ] || return 1
fi
return 0
}
xcat_uftp_start_receiver() {
printf '%s|%s|0|%s\n' "$XCAT_ACK_SERVER_ID" "$XCAT_ACK_SERVER_IP" "$XCAT_FETCH_FP" \
> "$1/servers" || return 1
"$XCAT_UFTPD" -d -q -E -x 2 -p "$XCAT_ACK_PORT" -M "$XCAT_ACK_MCAST" \
-I "$XCAT_ACK_CLIENT_IP" -S "$1/servers" -D "$1/dest" -T "$1/tmp" \
-F "$1/status" </dev/null >"$1/uftpd.log" 2>&1 &
XCAT_UFTP_PID=$!
}
xcat_uftp_stop_receiver() {
_xf_receiver=$XCAT_UFTP_PID
[ -n "$_xf_receiver" ] || return 0
XCAT_UFTP_PID=
kill -TERM "$_xf_receiver" 2>/dev/null
(
_xf_waited=0
while [ "$_xf_waited" -lt "$XCAT_UFTP_STOP_WAIT" ]; do
kill -0 "$_xf_receiver" 2>/dev/null || exit 0
sleep 1
_xf_waited=$((_xf_waited + 1))
done
kill -KILL "$_xf_receiver" 2>/dev/null
) &
_xf_watchdog=$!
wait "$_xf_receiver" 2>/dev/null
wait "$_xf_watchdog" 2>/dev/null
return 0
}
xcat_uftp_cleanup() {
xcat_uftp_stop_receiver
if [ -n "$XCAT_FETCH_STAGING" ]; then
rm -rf "$XCAT_FETCH_STAGING"
XCAT_FETCH_STAGING=
fi
}
# Succeed when this attempt's receiver reported the expected file as copied
# in a session it opened with the expected server, and the file was moved
# out of the temporary directory.
xcat_uftp_completed() {
[ -f "$1/dest/$XCAT_FETCH_FILE" ] && [ -r "$1/status" ] || return 1
_xf_sid=${XCAT_ACK_SERVER_ID#0x}
_xf_groups=
while IFS=';' read -r _xf_kind _xf_stamp _xf_server _xf_group _xf_name _xf_size _xf_result; do
[ "$_xf_server" = "$_xf_sid" ] || continue
case "$_xf_kind" in
CONNECT) _xf_groups="$_xf_groups $_xf_group " ;;
RESULT)
[ "$_xf_name" = "$XCAT_FETCH_FILE" ] && [ "$_xf_result" = copied ] || continue
case "$_xf_groups" in
*" $_xf_group "*) return 0 ;;
esac
;;
esac
done < "$1/status"
return 1
}
xcat_uftp_job_state() {
XCAT_JOB_STATE='' XCAT_JOB_START_IN='' XCAT_JOB_REASON=''
xcat_http_get "$XCAT_FETCH_JOB_URL" "$1/job" "$2" || return 1
while IFS= read -r _xf_line || [ -n "$_xf_line" ]; do
case "$_xf_line" in
state=*) XCAT_JOB_STATE=${_xf_line#state=} ;;
start_in=*) XCAT_JOB_START_IN=${_xf_line#start_in=} ;;
reason=*) XCAT_JOB_REASON=${_xf_line#reason=} ;;
esac
done < "$1/job"
case "$XCAT_JOB_STATE" in
pending|running|done|failed) ;;
*) return 1 ;;
esac
xcat_uint_ok "${XCAT_JOB_START_IN:-0}" 86400 || XCAT_JOB_START_IN=0
}
xcat_uftp_attempt() {
_xf_staging=$XCAT_FETCH_DIR.xcat-uftp.$$.$1
mkdir "$_xf_staging" || return 1
XCAT_FETCH_STAGING=$_xf_staging
mkdir "$XCAT_FETCH_STAGING/dest" "$XCAT_FETCH_STAGING/tmp" || return 1
if ! xcat_http_get "$XCAT_FETCH_LISTENER" "$XCAT_FETCH_STAGING/ack" "$XCAT_UFTP_REQUEST_TIMEOUT"; then
xcat_fetch_log warning "UFTP listener did not accept the request $XCAT_FETCH_LISTENER"
return 1
fi
if ! xcat_uftp_read_ack "$XCAT_FETCH_STAGING/ack" "$XCAT_FETCH_FILE"; then
xcat_fetch_log warning "UFTP listener sent an invalid reply"
return 1
fi
XCAT_FETCH_JOB_URL="$XCAT_URL_SCHEME://$XCAT_URL_HOST:$XCAT_FETCH_PORT/xcat-uftp/v1/job/$XCAT_ACK_JOB"
xcat_uftp_start_receiver "$XCAT_FETCH_STAGING" || return 1
xcat_fetch_log info "UFTP transfer $XCAT_ACK_JOB queued; sending starts in ${XCAT_ACK_START_IN}s"
_xf_start=$(xcat_now)
_xf_deadline=$((_xf_start + XCAT_ACK_START_IN + XCAT_ACK_TIMEOUT + XCAT_UFTP_GRACE))
_xf_cap=$((_xf_deadline + XCAT_ACK_TIMEOUT))
_xf_next_poll=$((_xf_start + XCAT_UFTP_POLL))
_xf_done_at=
while _xf_now=$(xcat_now) && [ "$_xf_now" -lt "$_xf_deadline" ]; do
if xcat_uftp_completed "$XCAT_FETCH_STAGING"; then
xcat_uftp_stop_receiver
# Check the type only after the receiver stops: a batch member can deliver a symbolic link.
_xf_file=$XCAT_FETCH_STAGING/dest/$XCAT_FETCH_FILE
if [ -f "$_xf_file" ] && [ ! -L "$_xf_file" ]; then
return 0
fi
xcat_fetch_log warning "$XCAT_FETCH_FILE from UFTP is not a regular file"
return 1
fi
if ! xcat_child_running "$XCAT_UFTP_PID"; then
xcat_fetch_log warning "UFTP receiver stopped: $(xcat_last_lines "$XCAT_FETCH_STAGING/uftpd.log" 2>/dev/null)"
return 1
fi
if [ "$_xf_now" -ge "$_xf_next_poll" ]; then
_xf_next_poll=$((_xf_now + XCAT_UFTP_POLL))
_xf_budget=$((_xf_deadline - _xf_now))
[ "$_xf_budget" -le "$XCAT_UFTP_REQUEST_TIMEOUT" ] || _xf_budget=$XCAT_UFTP_REQUEST_TIMEOUT
if xcat_uftp_job_state "$XCAT_FETCH_STAGING" "$_xf_budget"; then
case "$XCAT_JOB_STATE" in
failed)
xcat_fetch_log warning "UFTP transfer $XCAT_ACK_JOB failed on the server: $XCAT_JOB_REASON"
return 1
;;
done)
: "${_xf_done_at:=$_xf_now}"
if [ $((_xf_now - _xf_done_at)) -ge "$XCAT_UFTP_GRACE" ]; then
xcat_fetch_log warning "UFTP transfer $XCAT_ACK_JOB ended without this node"
return 1
fi
;;
pending)
_xf_wanted=$((_xf_now + XCAT_JOB_START_IN + XCAT_ACK_TIMEOUT + XCAT_UFTP_GRACE))
[ "$_xf_wanted" -le "$_xf_deadline" ] || _xf_deadline=$_xf_wanted
[ "$_xf_deadline" -le "$_xf_cap" ] || _xf_deadline=$_xf_cap
;;
esac
fi
fi
sleep 1
done
xcat_fetch_log warning "UFTP transfer $XCAT_ACK_JOB did not finish in $((_xf_deadline - _xf_start))s"
return 1
}
xcat_fetch_interrupted() {
xcat_uftp_cleanup
xcat_fetch_log err "Root image download interrupted"
exit 130
}
xcat_uftp_usable() {
if ! xcat_port_ok "$1" || ! xcat_fingerprint_ok "$2"; then
xcat_fetch_log warning "Ignoring malformed xcat.uftp or xcat.uftpfp kernel arguments"
return 1
fi
if ! xcat_url_parse "$XCAT_FETCH_URL" || [ "$XCAT_URL_SCHEME" != http ]; then
xcat_fetch_log warning "UFTP is used only with http image URLs"
return 1
fi
XCAT_UFTPD=$(command -v uftpd) || {
xcat_fetch_log warning "uftpd is not in the initramfs; run genimage with uftp installed in the image"
return 1
}
XCAT_FETCH_LISTENER=$(xcat_uftp_url "$XCAT_FETCH_URL" "$1" "$XCAT_FETCH_SHA256") || {
xcat_fetch_log warning "Cannot build a UFTP request for $XCAT_FETCH_URL"
return 1
}
XCAT_FETCH_PORT=$1
XCAT_FETCH_FP=$2
}
# xcat_uftp_rootimg <imgurl> <file> <checksum file> <listener port> <server fingerprint>
# The checksum file is the sha256sum file published with the image, which
# names the archive to the listener.
xcat_uftp_rootimg() {
XCAT_FETCH_URL=$1
XCAT_FETCH_FILE=${1##*/}
# uftpd takes only absolute directories.
case "$2" in
/*) XCAT_FETCH_DEST=$2 ;;
*) XCAT_FETCH_DEST=${PWD%/}/$2 ;;
esac
XCAT_FETCH_DIR=${XCAT_FETCH_DEST%/*}/
XCAT_FETCH_STAGING=
XCAT_UFTP_PID=
XCAT_FETCH_SHA256=$(xcat_listed_sha256 "$3" "$XCAT_FETCH_FILE") || {
xcat_fetch_log warning "$XCAT_FETCH_URL.sha256 lists no SHA-256 checksum for $XCAT_FETCH_FILE"
return 1
}
xcat_uftp_usable "$4" "$5" || return 1
trap xcat_fetch_interrupted INT TERM HUP
_xf_attempt=1
while [ "$_xf_attempt" -le "$XCAT_UFTP_ATTEMPTS" ]; do
if xcat_uftp_attempt "$_xf_attempt" && mv -f "$XCAT_FETCH_STAGING/dest/$XCAT_FETCH_FILE" "$XCAT_FETCH_DEST"; then
xcat_uftp_cleanup
trap - INT TERM HUP
xcat_fetch_log info "Received $XCAT_FETCH_FILE over UFTP"
return 0
fi
xcat_uftp_cleanup
_xf_attempt=$((_xf_attempt + 1))
done
trap - INT TERM HUP
return 1
}
@@ -8,6 +8,16 @@ dracut_install ethtool
inst "$moddir/xcat-updateflag" "/tmp/updateflag"
inst "$moddir/xcatroot" "/sbin/xcatroot"
inst_hook cmdline 10 "$moddir/xcat-cmdline.sh"
# genimage adds the UFTP helper only when the image has a UFTP 5 receiver.
if [ -r "$moddir/xcat-rootimg-fetch.sh" ]; then
inst "$moddir/xcat-rootimg-fetch.sh" "/lib/xcat-rootimg-fetch.sh"
for uftpd in /usr/sbin/uftpd /usr/bin/uftpd; do
if [ -x "$uftpd" ]; then
dracut_install "$uftpd"
break
fi
done
fi
for file in /etc/udev/rules.d/*;do
grep -qi xcat $file && inst $file $file
done
@@ -52,7 +52,23 @@ rootimg_matches_checksum() {
return 1
}
# Downloads the image at $1 to the file $2, over UFTP the first time when nodeset asks for it.
rootimg_download() {
if [ -n "$rootimg_uftp" ]; then
rootimg_uftp_port=$rootimg_uftp
rootimg_uftp=
# nodeset asks for UFTP only with the checksum, which the caller checks on the received file.
if [ "$rootimgchecksum" = yes ] && [ -r /lib/xcat-rootimg-fetch.sh ] && . /lib/xcat-rootimg-fetch.sh &&
xcat_uftp_rootimg "$1" "$2" /tmp/rootimg.sha256.before "$rootimg_uftp_port" "$(getarg xcat.uftpfp=)"; then
return 0
fi
logger $SYSLOGHOST -t $log_label -p local4.warning "Cannot receive $1 over UFTP, downloading it over HTTP..."
fi
wget -nv "$1"
}
rootimgchecksum="$(getarg rootimgchecksum=)"
rootimg_uftp="$(getarg xcat.uftp=)"
imgurl="$(getarg imgurl=)";
if [ ! -z "$imgurl" ]; then
@@ -69,7 +85,7 @@ if [ ! -z "$imgurl" ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..."
echo Getting $imgurl...
[ "$rootimgchecksum" != yes ] || rootimg_fetch_checksum "$imgurl" /tmp/rootimg.sha256.before || rm -f /tmp/rootimg.sha256.before
if ! wget -nv $imgurl; then
if ! rootimg_download "$imgurl" "$FILENAME"; then
logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..."
rm -f $FILENAME
echo Failed to get the image, waiting for next retrying...
@@ -8,6 +8,16 @@ dracut_install ethtool
inst "$moddir/xcat-updateflag" "/tmp/updateflag"
inst "$moddir/xcatroot" "/sbin/xcatroot"
inst_hook cmdline 10 "$moddir/xcat-cmdline.sh"
# genimage adds the UFTP helper only when the image has a UFTP 5 receiver.
if [ -r "$moddir/xcat-rootimg-fetch.sh" ]; then
inst "$moddir/xcat-rootimg-fetch.sh" "/lib/xcat-rootimg-fetch.sh"
for uftpd in /usr/sbin/uftpd /usr/bin/uftpd; do
if [ -x "$uftpd" ]; then
dracut_install "$uftpd"
break
fi
done
fi
for file in /etc/udev/rules.d/*;do
grep -qi xcat $file && inst $file $file
done
@@ -53,7 +53,23 @@ rootimg_matches_checksum() {
return 1
}
# Downloads the image at $1 to the file $2, over UFTP the first time when nodeset asks for it.
rootimg_download() {
if [ -n "$rootimg_uftp" ]; then
rootimg_uftp_port=$rootimg_uftp
rootimg_uftp=
# nodeset asks for UFTP only with the checksum, which the caller checks on the received file.
if [ "$rootimgchecksum" = yes ] && [ -r /lib/xcat-rootimg-fetch.sh ] && . /lib/xcat-rootimg-fetch.sh &&
xcat_uftp_rootimg "$1" "$2" /tmp/rootimg.sha256.before "$rootimg_uftp_port" "$(getarg xcat.uftpfp=)"; then
return 0
fi
logger $SYSLOGHOST -t $log_label -p local4.warning "Cannot receive $1 over UFTP, downloading it over HTTP..."
fi
curl --fail "$1" -o "$2"
}
rootimgchecksum="$(getarg rootimgchecksum=)"
rootimg_uftp="$(getarg xcat.uftp=)"
imgurl="$(getarg imgurl=)";
if [ ! -z "$imgurl" ]; then
@@ -70,7 +86,7 @@ if [ ! -z "$imgurl" ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..."
echo Getting $imgurl...
[ "$rootimgchecksum" != yes ] || rootimg_fetch_checksum "$imgurl" /tmp/rootimg.sha256.before || rm -f /tmp/rootimg.sha256.before
if ! curl --fail $imgurl -o $FILENAME; then
if ! rootimg_download "$imgurl" "$FILENAME"; then
logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..."
rm -f $FILENAME
echo Failed to get the image, waiting for next retrying...
@@ -28,6 +28,17 @@ install() {
# cmdline hook
inst_hook cmdline 10 "$moddir/xcat-cmdline.sh"
# genimage adds the UFTP helper only when the image has a UFTP 5 receiver.
if [ -r "$moddir/xcat-rootimg-fetch.sh" ]; then
inst_simple "$moddir/xcat-rootimg-fetch.sh" "/lib/xcat-rootimg-fetch.sh"
for uftpd in /usr/sbin/uftpd /usr/bin/uftpd; do
if [ -x "$uftpd" ]; then
dracut_install "$uftpd"
break
fi
done
fi
# udev rules with "xcat"
for file in /etc/udev/rules.d/*; do
if grep -qi xcat "$file"; then
@@ -53,7 +53,23 @@ rootimg_matches_checksum() {
return 1
}
# Downloads the image at $1 to the file $2, over UFTP the first time when nodeset asks for it.
rootimg_download() {
if [ -n "$rootimg_uftp" ]; then
rootimg_uftp_port=$rootimg_uftp
rootimg_uftp=
# nodeset asks for UFTP only with the checksum, which the caller checks on the received file.
if [ "$rootimgchecksum" = yes ] && [ -r /lib/xcat-rootimg-fetch.sh ] && . /lib/xcat-rootimg-fetch.sh &&
xcat_uftp_rootimg "$1" "$2" /tmp/rootimg.sha256.before "$rootimg_uftp_port" "$(getarg xcat.uftpfp=)"; then
return 0
fi
logger $SYSLOGHOST -t $log_label -p local4.warning "Cannot receive $1 over UFTP, downloading it over HTTP..."
fi
curl --fail "$1" -o "$2"
}
rootimgchecksum="$(getarg rootimgchecksum=)"
rootimg_uftp="$(getarg xcat.uftp=)"
imgurl="$(getarg imgurl=)";
if [ ! -z "$imgurl" ]; then
@@ -70,7 +86,7 @@ if [ ! -z "$imgurl" ]; then
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Downloading $imgurl..."
echo Getting $imgurl...
[ "$rootimgchecksum" != yes ] || rootimg_fetch_checksum "$imgurl" /tmp/rootimg.sha256.before || rm -f /tmp/rootimg.sha256.before
if ! curl --fail $imgurl -o $FILENAME; then
if ! rootimg_download "$imgurl" "$FILENAME"; then
logger $SYSLOGHOST -t $log_label -p local4.error "Downloading $imgurl FAILED, retrying..."
rm -f $FILENAME
echo Failed to get the image, waiting for next retrying...
+18 -2
View File
@@ -1085,6 +1085,10 @@ sub mkinitrd_dracut {
my $dracutmpath = $dracutmoduledir . "98xcat/";
mkpath($dracutmpath);
# Only a stateless initial ramdisk that checks the root image receives it over UFTP.
my $uftp_receiver = eval { imgutils::add_uftp_receiver($rootimg_dir, $arch, $dracutmpath, $mode eq 'stateless' && $dracutver >= "033") };
xdie($@) if $@;
if ($dracutver >= "105") {
# Copy xcat module to the image depending on the mode
my %files = (
@@ -1299,6 +1303,7 @@ sub mkinitrd_dracut {
!system("chroot $rootimg_dir dracut $additional_options -f /tmp/initrd.$$.gz $kernelver")
or xdie("Error: failed to generate the initial ramdisk for $mode.\n");
umount_chroot($rootimg_dir);
eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver;
if ($native_bootdir) {
eval {
imgutils::publish_boot_files($native_bootdir, $destdir,
@@ -1306,11 +1311,15 @@ sub mkinitrd_dracut {
} or xdie($@);
print "the initial ramdisk for $mode is generated successfully.\n";
mark_rootimg_check($mode);
mark_uftp_receiver($mode, $uftp_receiver);
return;
}
print "the initial ramdisk for $mode is generated successfully.\n";
print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz");
move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz") and mark_rootimg_check($mode);
print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz\n");
if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) {
mark_rootimg_check($mode);
mark_uftp_receiver($mode, $uftp_receiver);
}
}
# nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum.
@@ -1322,6 +1331,13 @@ sub mark_rootimg_check {
print "Warning: $error\n" if $error;
}
# nodeset tells a node to receive the root image over UFTP only when this marker matches its initial ramdisk.
sub mark_uftp_receiver {
my ($mode, $receiver) = @_;
return unless $mode eq 'stateless';
imgutils::mark_uftp_receiver("$destdir/initrd-$mode.gz", $receiver);
}
sub mkinitrd {
my ($mode) = @_; # statelite or stateless