mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
9 Commits
v7.43
...
c70e12f0a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c70e12f0a2 | ||
|
|
6281205912 | ||
|
|
1ffc5c55b2 | ||
|
|
c3302e1720 | ||
|
|
25227944b5 | ||
|
|
06650e916a | ||
|
|
2e34dffed5 | ||
|
|
3db91f077f | ||
|
|
fae14f4dd9 |
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -1,11 +1,6 @@
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
|
||||||
- '**/*.sh'
|
|
||||||
- 'Dockerfile'
|
|
||||||
- '.github/workflows/test.yml'
|
|
||||||
- '.github/workflows/check.yml'
|
|
||||||
|
|
||||||
name: "Test"
|
name: "Test"
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
|||||||
16
src/disk.sh
16
src/disk.sh
@@ -98,10 +98,10 @@ createDisk() {
|
|||||||
local FS=$5
|
local FS=$5
|
||||||
local DATA_SIZE DIR SPACE GB FA
|
local DATA_SIZE DIR SPACE GB FA
|
||||||
|
|
||||||
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
|
||||||
|
|
||||||
rm -f "$DISK_FILE"
|
rm -f "$DISK_FILE"
|
||||||
|
|
||||||
|
DATA_SIZE=$(numfmt --from=iec "$DISK_SPACE")
|
||||||
|
|
||||||
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
if [[ "$ALLOCATE" != [Nn]* ]]; then
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
@@ -424,7 +424,7 @@ addDisk () {
|
|||||||
local DISK_FMT=$7
|
local DISK_FMT=$7
|
||||||
local DISK_IO=$8
|
local DISK_IO=$8
|
||||||
local DISK_CACHE=$9
|
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")
|
DISK_EXT=$(fmt2ext "$DISK_FMT")
|
||||||
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
local DISK_FILE="$DISK_BASE.$DISK_EXT"
|
||||||
@@ -432,6 +432,16 @@ addDisk () {
|
|||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
[ ! -d "$DIR" ] && return 0
|
[ ! -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/1073741824 ))
|
||||||
|
DISK_SPACE="${GB}G"
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
SPACE="${DISK_SPACE// /}"
|
SPACE="${DISK_SPACE// /}"
|
||||||
[ -z "$SPACE" ] && SPACE="16G"
|
[ -z "$SPACE" ] && SPACE="16G"
|
||||||
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"
|
[ -z "${SPACE//[0-9. ]}" ] && SPACE="${SPACE}G"
|
||||||
|
|||||||
153
src/network.sh
153
src/network.sh
@@ -20,6 +20,7 @@ set -Eeuo pipefail
|
|||||||
: "${VM_NET_MASK:="255.255.255.0"}"
|
: "${VM_NET_MASK:="255.255.255.0"}"
|
||||||
|
|
||||||
: "${PASST:="passt"}"
|
: "${PASST:="passt"}"
|
||||||
|
: "${PASST_MTU:=""}"
|
||||||
: "${PASST_OPTS:=""}"
|
: "${PASST_OPTS:=""}"
|
||||||
: "${PASST_DEBUG:=""}"
|
: "${PASST_DEBUG:=""}"
|
||||||
|
|
||||||
@@ -182,38 +183,6 @@ configureDNS() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserPorts() {
|
|
||||||
|
|
||||||
local args=""
|
|
||||||
local list=$1
|
|
||||||
local ssh="22"
|
|
||||||
local dsm="5000"
|
|
||||||
|
|
||||||
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
|
||||||
|
|
||||||
list="${list//,/ }"
|
|
||||||
list="${list## }"
|
|
||||||
list="${list%% }"
|
|
||||||
|
|
||||||
for port in $list; do
|
|
||||||
proto="tcp"
|
|
||||||
num="$port"
|
|
||||||
|
|
||||||
if [[ "$port" == */udp ]]; then
|
|
||||||
proto="udp"
|
|
||||||
num="${port%/udp}"
|
|
||||||
elif [[ "$port" == */tcp ]]; then
|
|
||||||
proto="tcp"
|
|
||||||
num="${port%/tcp}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "${args%?}"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
getHostPorts() {
|
getHostPorts() {
|
||||||
|
|
||||||
local list="$1"
|
local list="$1"
|
||||||
@@ -221,24 +190,55 @@ getHostPorts() {
|
|||||||
|
|
||||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
||||||
|
|
||||||
if [[ "${NETWORK,,}" == "passt" ]]; then
|
echo "$list"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
local DNS_PORT="53"
|
getUserPorts() {
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
local args=""
|
||||||
[ -z "$list" ] && list="$DNS_PORT" || list+=",$DNS_PORT"
|
local list=$1
|
||||||
fi
|
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||||
|
|
||||||
[ -z "$list" ] && list="$COM_PORT" || list+=",$COM_PORT"
|
local ssh="22"
|
||||||
[ -z "$list" ] && list="$CHR_PORT" || list+=",$CHR_PORT"
|
local dsm="5000"
|
||||||
[ -z "$list" ] && list="$WSD_PORT" || list+=",$WSD_PORT"
|
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$list"
|
echo "$list"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSlirp() {
|
||||||
|
|
||||||
|
local args=""
|
||||||
|
local list=""
|
||||||
|
|
||||||
|
list=$(getUserPorts)
|
||||||
|
list="${list//,/ }"
|
||||||
|
list="${list## }"
|
||||||
|
list="${list%% }"
|
||||||
|
|
||||||
|
for port in $list; do
|
||||||
|
|
||||||
|
proto="tcp"
|
||||||
|
num="${port%/tcp}"
|
||||||
|
|
||||||
|
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}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "${args%?}"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
configureSlirp() {
|
configureSlirp() {
|
||||||
|
|
||||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
[[ "$DEBUG" == [Yy1]* ]] && echo "Configuring slirp networking..."
|
||||||
@@ -254,17 +254,18 @@ configureSlirp() {
|
|||||||
|
|
||||||
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
NET_OPTS="-netdev user,id=hostnet0,ipv4=on,host=$gateway,net=${gateway%.*}.0/24,dhcpstart=$ip,${ipv6}hostname=$VM_NET_HOST"
|
||||||
|
|
||||||
local forward
|
local forward=""
|
||||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" != [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||||
|
echo "$gateway" > /run/shm/qemu.gw
|
||||||
|
else
|
||||||
cp /etc/resolv.conf /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
|
echo -e "nameserver 127.0.0.1\nsearch .\noptions ndots:0" >/etc/resolv.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
configureDNS "lo" "$ip" "$VM_NET_MAC" "$VM_NET_HOST" "$VM_NET_MASK" "$gateway" || return 1
|
|
||||||
|
|
||||||
VM_NET_IP="$ip"
|
VM_NET_IP="$ip"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -295,17 +296,19 @@ configurePasst() {
|
|||||||
PASST_OPTS+=" -a $ip"
|
PASST_OPTS+=" -a $ip"
|
||||||
PASST_OPTS+=" -g $gateway"
|
PASST_OPTS+=" -g $gateway"
|
||||||
PASST_OPTS+=" -n $VM_NET_MASK"
|
PASST_OPTS+=" -n $VM_NET_MASK"
|
||||||
|
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
||||||
|
|
||||||
exclude=$(getHostPorts "$HOST_PORTS")
|
local forward=""
|
||||||
|
forward=$(getUserPorts "${USER_PORTS:-}")
|
||||||
|
forward="${forward///tcp}"
|
||||||
|
forward="${forward///udp}"
|
||||||
|
|
||||||
if [ -z "$exclude" ]; then
|
if [ -n "$forward" ]; then
|
||||||
exclude="all"
|
forward="%${VM_NET_DEV}/$forward"
|
||||||
else
|
PASST_OPTS+=" -t $forward"
|
||||||
exclude="~${exclude//,/,~}"
|
PASST_OPTS+=" -u $forward"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PASST_OPTS+=" -t $exclude"
|
|
||||||
PASST_OPTS+=" -u $exclude"
|
|
||||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
PASST_OPTS+=" -P /var/run/passt.pid"
|
||||||
@@ -321,10 +324,17 @@ configurePasst() {
|
|||||||
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
[[ "$DEBUG" == [Yy1]* ]] && printf "Passt arguments:\n\n%s\n\n" "${PASST_OPTS// -/$'\n-'}"
|
||||||
|
|
||||||
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
if ! $PASST ${PASST_OPTS:+ $PASST_OPTS} >/dev/null 2>&1; then
|
||||||
local msg="Failed to start passt, reason: $?"
|
|
||||||
[ -f "$log" ] && cat "$log"
|
rm -f "$log"
|
||||||
error "$msg"
|
PASST_OPTS="${PASST_OPTS/ -q/}"
|
||||||
return 1
|
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
|
[ -f "$log" ] && cat "$log"
|
||||||
|
error "Failed to start passt, reason: $rc"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||||
@@ -597,12 +607,17 @@ getInfo() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
GATEWAY=$(ip route list dev "$VM_NET_DEV" | awk ' /^default/ {print $3}' | head -n 1)
|
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)
|
{ IP=$(ip address show dev "$VM_NET_DEV" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/ | head -n 1); rc=$?; } 2>/dev/null || :
|
||||||
IP6=""
|
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
|
error "Could not determine container IP address!" && exit 26
|
||||||
|
fi
|
||||||
|
|
||||||
|
IP6=""
|
||||||
# shellcheck disable=SC2143
|
# shellcheck disable=SC2143
|
||||||
if [ -f /proc/net/if_inet6 ] && [ -n "$(ifconfig -a | grep inet6)" ]; then
|
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)
|
[ -n "$IP6" ] && IP6=$(echo "$IP6" | sed -e's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d' | head -n 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -649,11 +664,6 @@ getInfo() {
|
|||||||
[ -z "$MTU" ] && MTU="$mtu"
|
[ -z "$MTU" ] && MTU="$mtu"
|
||||||
[ -z "$MTU" ] && MTU="0"
|
[ -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 [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
||||||
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
warn "MTU size is $MTU, but cannot be set for $ADAPTER adapters!" && MTU="0"
|
||||||
@@ -778,16 +788,21 @@ else
|
|||||||
if ! configureSlirp; then
|
if ! configureSlirp; then
|
||||||
error "Failed to configure user-mode networking!"
|
error "Failed to configure user-mode networking!"
|
||||||
exit 24
|
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 ;;
|
fi ;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
error "Unrecognized NETWORK value: \"$NETWORK\"" && exit 24 ;;
|
||||||
esac
|
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
|
fi
|
||||||
|
|
||||||
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$VM_NET_MAC"
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ CPU_CORES="${CPU_CORES// /}"
|
|||||||
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
[ -n "${CPU_CORES//[0-9 ]}" ] && error "Invalid amount of CPU_CORES: $CPU_CORES" && exit 15
|
||||||
|
|
||||||
if [ "$CPU_CORES" -gt "$CORES" ]; then
|
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"
|
CPU_CORES="$CORES"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,14 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
path="/run/shm/msg.html"
|
path="/run/shm/msg.html"
|
||||||
|
|
||||||
|
if [ -f "$path" ] && [ -s "$path" ]; then
|
||||||
|
echo -n "s: " && cat "$path"
|
||||||
|
fi
|
||||||
|
|
||||||
inotifywait -m "$path" |
|
inotifywait -m "$path" |
|
||||||
while read -r fp event fn; do
|
while read -r fp event fn; do
|
||||||
case "${event,,}" in
|
case "${event,,}" in
|
||||||
"modify" ) echo -n "s: " && cat "$path" ;;
|
"modify"* ) echo -n "s: " && cat "$path" ;;
|
||||||
|
"delete_self" ) echo "c: vnc" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -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) {
|
function setInfo(msg, loading, error) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -119,9 +125,17 @@ function setInfo(msg, loading, error) {
|
|||||||
spin.style.visibility = 'hidden';
|
spin.style.visibility = 'hidden';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var p = "<p class=\"loading\">";
|
||||||
loading = !!loading;
|
loading = !!loading;
|
||||||
if (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;
|
el.innerHTML = msg;
|
||||||
|
|||||||
Reference in New Issue
Block a user