Compare commits

...

12 Commits

Author SHA1 Message Date
Kroese
bc0defd813 feat: Add custom .yml for Github Codespaces (#1066) 2025-10-15 11:39:36 +02:00
Kroese
48e7a9fff0 fix: Round down minimum disk size (#1065) 2025-10-15 11:37:05 +02:00
Kroese
c2fa58ef27 feat: Fall back to slirp when passt fails (#1064) 2025-10-15 10:31:42 +02:00
Kroese
ea49cb144b feat: Validate user port configuration (#1063) 2025-10-14 16:44:11 +02:00
Kroese
b8e778a79d fix: Configure ports for Slirp networking (#1062) 2025-10-14 14:16:20 +02:00
Kroese
c70e12f0a2 fix: Lower spare disk space (#1061)
Reduced spare disk space threshold from 2GB to 512MB.
2025-10-14 03:33:25 +02:00
Kroese
6281205912 feat: Add "max" setting for DISK_SIZE (#1060) 2025-10-14 01:22:44 +02:00
Kroese
1ffc5c55b2 fix: Show Passt output on error (#1059) 2025-10-13 14:11:54 +02:00
Kroese
c3302e1720 fix: Rename physical to logical (#1058) 2025-10-13 09:28:25 +02:00
Kroese
25227944b5 fix: Do not reset loading animation (#1056) 2025-10-12 01:51:17 +02:00
Kroese
06650e916a build: Run check for all files (#1057)
Removed specific paths from pull request triggers.
2025-10-12 01:48:25 +02:00
Kroese
2e34dffed5 feat: Expose only selected ports with Passt (#1055) 2025-10-12 01:44:24 +02:00
7 changed files with 162 additions and 81 deletions

View File

@@ -2,5 +2,5 @@
"name": "dsm",
"service": "dsm",
"forwardPorts": [5000],
"dockerComposeFile": "compose.yml"
"dockerComposeFile": ".github/codespaces.yml"
}

19
.github/codespaces.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
services:
dsm:
container_name: dsm
image: vdsm/virtual-dsm
environment:
RAM_SIZE: "max"
DISK_SIZE: "max"
CPU_CORES: "max"
devices:
- /dev/kvm
- /dev/net/tun
cap_add:
- NET_ADMIN
ports:
- 5000:5000
volumes:
- ./dsm:/storage
restart: on-failure
stop_grace_period: 2m

View File

@@ -1,11 +1,6 @@
on:
workflow_dispatch:
pull_request:
paths:
- '**/*.sh'
- 'Dockerfile'
- '.github/workflows/test.yml'
- '.github/workflows/check.yml'
name: "Test"
permissions: {}

View File

@@ -98,10 +98,10 @@ createDisk() {
local FS=$5
local DATA_SIZE DIR SPACE GB FA
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
rm -f "$DISK_FILE"
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
if [[ "$ALLOCATE" != [Nn]* ]]; then
# Check free diskspace
@@ -424,7 +424,7 @@ addDisk () {
local DISK_FMT=$7
local DISK_IO=$8
local DISK_CACHE=$9
local DISK_EXT DIR SPACE DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
local DISK_EXT DIR SPACE GB DATA_SIZE FS PREV_FMT PREV_EXT CUR_SIZE
DISK_EXT=$(fmt2ext "$DISK_FMT")
local DISK_FILE="$DISK_BASE.$DISK_EXT"
@@ -432,6 +432,16 @@ addDisk () {
DIR=$(dirname "$DISK_FILE")
[ ! -d "$DIR" ] && return 0
if [[ "${DISK_SPACE,,}" == "max" ]]; then
local SPARE=536870912
SPACE=$(df --output=avail -B 1 "$DIR" | tail -n 1)
(( SPACE < SPARE )) && SPACE="$SPARE" || SPACE=$((SPACE-SPARE))
GB=$(( SPACE/1073741825 ))
DISK_SPACE="${GB}G"
fi
SPACE="${DISK_SPACE// /}"
[ -z "$SPACE" ] && SPACE="16G"
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"

View File

@@ -183,63 +183,92 @@ configureDNS() {
return 0
}
getHostPorts() {
local list=""
list+="$MON_PORT,"
list+="${HOST_PORTS// /},"
# Remove duplicates
list=$(echo "${list//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
echo "$list"
return 0
}
getUserPorts() {
local args=""
local list=$1
local ssh="22"
local dsm="5000"
local dsm="5000,5001"
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
local list="$ssh,$dsm,"
list+="${USER_PORTS// /},"
list="${list//,/ }"
list="${list## }"
list="${list%% }"
local exclude
exclude=$(getHostPorts)
for port in $list; do
proto="tcp"
num="$port"
local ports=""
local userport=""
local hostport=""
if [[ "$port" == */udp ]]; then
for userport in ${list//,/ }; do
local num="${userport///tcp}"
num="${num///udp}"
for hostport in ${exclude//,/ }; do
local val="${hostport///tcp}"
if [[ "$num" == "${val///udp}" ]]; then
num=""
warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
fi
done
[ -n "$num" ] && ports+="$userport,"
done
# Remove duplicates
ports=$(echo "${ports//,,/,}," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
echo "$ports"
return 0
}
getSlirp() {
local args=""
local list=""
list=$(getUserPorts)
for port in ${list//,/ }; do
local proto="tcp"
local num="${port%/tcp}"
[ -z "$num" ] && continue
if [[ "$port" == *"/udp" ]]; then
proto="udp"
num="${port%/udp}"
elif [[ "$port" != *"/tcp" ]]; then
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
proto="udp"
num="${port%/udp}"
elif [[ "$port" == */tcp ]]; then
proto="tcp"
num="${port%/tcp}"
fi
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
done
args=$(echo "$args" | sed 's/,*$//g')
echo "${args%?}"
return 0
}
getHostPorts() {
local list="$1"
list=$(echo "${list// /}" | sed 's/,*$//g')
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
if [[ "${NETWORK,,}" == "passt" ]]; then
local DNS_PORT="53"
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
[ -z "$list" ] && list="$DNS_PORT" || list+=",$DNS_PORT"
fi
[ -z "$list" ] && list="$COM_PORT" || list+=",$COM_PORT"
[ -z "$list" ] && list="$CHR_PORT" || list+=",$CHR_PORT"
[ -z "$list" ] && list="$WSD_PORT" || list+=",$WSD_PORT"
fi
echo "$list"
return 0
}
configureSlirp() {
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
@@ -255,17 +284,18 @@ configureSlirp() {
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
local forward
forward=$(getUserPorts "${USER_PORTS:-}")
local forward=""
forward=$(getSlirp)
[ -n "$forward" ] && NET_OPTS+=",$forward"
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
cp /etc/resolv.conf /etc/resolv.dnsmasq
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
echo "$gateway" > /run/shm/qemu.gw
else
[ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
fi
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
VM_NET_IP="$ip"
return 0
}
@@ -298,16 +328,17 @@ configurePasst() {
PASST_OPTS+=" -n $VM_NET_MASK"
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
exclude=$(getHostPorts "$HOST_PORTS")
local forward=""
forward=$(getUserPorts)
forward="${forward///tcp}"
forward="${forward///udp}"
if [ -z "$exclude" ]; then
exclude="%${VM_NET_DEV}/all"
else
exclude="%${VM_NET_DEV}/~${exclude//,/,~}"
if [ -n "$forward" ]; then
forward="%${VM_NET_DEV}/$forward"
PASST_OPTS+=" -t $forward"
PASST_OPTS+=" -u $forward"
fi
PASST_OPTS+=" -t $exclude"
PASST_OPTS+=" -u $exclude"
PASST_OPTS+=" -H $VM_NET_HOST"
PASST_OPTS+=" -M $GATEWAY_MAC"
PASST_OPTS+=" -P /var/run/passt.pid"
@@ -315,7 +346,7 @@ configurePasst() {
PASST_OPTS+=" -q"
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
cp /etc/resolv.conf /etc/resolv.dnsmasq
[ ! -f /etc/resolv.dnsmasq ] && cp /etc/resolv.conf /etc/resolv.dnsmasq
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
fi
@@ -323,10 +354,17 @@ configurePasst() {
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
local msg="Failed to start passt, reason: $?"
[ -f "$log" ] && cat "$log"
error "$msg"
return 1
rm -f "$log"
PASST_OPTS="${PASST_OPTS/ -q/}"
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
if (( rc != 0 )); then
[ -f "$log" ] && cat "$log"
warn "failed to start passt ($rc), falling back to slirp networking!"
configureSlirp && return 0 || return 1
fi
fi
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
@@ -439,7 +477,7 @@ configureNAT() {
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
fi
exclude=$(getHostPorts "$HOST_PORTS")
exclude=$(getHostPorts)
if [ -n "$exclude" ]; then
if [[ "$exclude" != *","* ]]; then
@@ -599,12 +637,17 @@ getInfo() {
fi
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1)
IP6=""
{ IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || :
if (( rc != 0 )); then
error "Could not determine container IP address!" && exit 26
fi
IP6=""
# shellcheck disable=SC2143
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up)
{ IP6=$(ip -6 addr show dev "$VM_NET_DEV" scope global up); rc=$?; } 2>/dev/null || :
(( rc != 0 )) && IP6=""
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
fi
@@ -651,11 +694,6 @@ getInfo() {
[ -z "$MTU" ] && MTU="$mtu"
[ -z "$MTU" ] && MTU="0"
if [ "$MTU" -gt "1500" ]; then
[[ "$DEBUG" == [Yy1]* ]] && echo "MTU size is too large: $MTU, ignoring..."
MTU="0"
fi
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
@@ -780,16 +818,21 @@ else
if ! configureSlirp; then
error "Failed to configure user-mode networking!"
exit 24
fi
if [ -z "$USER_PORTS" ]; then
info "Notice: slirp networking is active, so when you want to expose ports, you will need to map them using this variable: \"USER_PORTS=5000,5001\"."
fi ;;
*)
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
esac
case "${NETWORK,,}" in
"passt" | "slirp" )
if [ -z "$USER_PORTS" ]; then
info "Notice: because user-mode networking is active, if you need to expose ports, add them to the \"USER_PORTS\" variable."
fi ;;
esac
fi
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"

View File

@@ -62,7 +62,7 @@ CPU_CORES="${CPU_CORES// /}"
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
if [ "$CPU_CORES" -gt "$CORES" ]; then
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of physical cores, so will be limited to ${CORES}."
warn "The amount for CPU_CORES (${CPU_CORES}) exceeds the amount of logical cores available, so will be limited to ${CORES}."
CPU_CORES="$CORES"
fi

View File

@@ -93,6 +93,12 @@ function processInfo() {
}
}
function extractContent(s) {
var span = document.createElement('span');
span.innerHTML = s;
return span.textContent || span.innerText;
};
function setInfo(msg, loading, error) {
try {
@@ -119,9 +125,17 @@ function setInfo(msg, loading, error) {
spin.style.visibility = 'hidden';
}
var p = "<p class=\"loading\">";
loading = !!loading;
if (loading) {
msg = "<p class=\"loading\">" + msg + "</p>";
msg = p + msg + "</p>";
}
if (msg.includes(p)) {
if (el.innerHTML.includes(p)) {
el.getElementsByClassName('loading')[0].textContent = extractContent(msg);
return true;
}
}
el.innerHTML = msg;