mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-07 02:23:42 +08:00
Compare commits
6 Commits
v7.44
...
ea49cb144b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea49cb144b | ||
|
|
b8e778a79d | ||
|
|
c70e12f0a2 | ||
|
|
6281205912 | ||
|
|
1ffc5c55b2 | ||
|
|
c3302e1720 |
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"
|
||||||
|
|||||||
@@ -185,26 +185,68 @@ configureDNS() {
|
|||||||
|
|
||||||
getHostPorts() {
|
getHostPorts() {
|
||||||
|
|
||||||
local list="$1"
|
local list="${HOST_PORTS:-}"
|
||||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||||
|
list="${list//,,/,}"
|
||||||
|
|
||||||
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
[ -z "$list" ] && list="$MON_PORT" || list+=",$MON_PORT"
|
||||||
|
|
||||||
|
# Remove duplicates
|
||||||
|
list=$(echo "$list," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||||
|
|
||||||
echo "$list"
|
echo "$list"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserPorts() {
|
getUserPorts() {
|
||||||
|
|
||||||
local args=""
|
local list="${USER_PORTS:-}"
|
||||||
local list=$1
|
|
||||||
list=$(echo "${list// /}" | sed 's/,*$//g')
|
list=$(echo "${list// /}" | sed 's/,*$//g')
|
||||||
|
|
||||||
local ssh="22"
|
local ssh="22"
|
||||||
local dsm="5000"
|
local dsm="5000,5001"
|
||||||
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
[ -z "$list" ] && list="$ssh,$dsm" || list+=",$ssh,$dsm"
|
||||||
|
|
||||||
echo "$list"
|
list="${list//,,/,}"
|
||||||
|
list="${list//,/ }"
|
||||||
|
list="${list## }"
|
||||||
|
list="${list%% }"
|
||||||
|
|
||||||
|
local exclude
|
||||||
|
exclude=$(getHostPorts)
|
||||||
|
exclude="${exclude//,/ }"
|
||||||
|
exclude="${exclude## }"
|
||||||
|
exclude="${exclude%% }"
|
||||||
|
|
||||||
|
local ports=""
|
||||||
|
|
||||||
|
for userport in $list; do
|
||||||
|
|
||||||
|
local num="${userport///tcp}"
|
||||||
|
num="${num///udp}"
|
||||||
|
[ -z "$num" ] && continue
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if [ -n "$num" ]; then
|
||||||
|
[ -z "$ports" ] && ports="$userport" || ports+=",$userport"
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
# Remove duplicates
|
||||||
|
ports=$(echo "$ports," | awk 'BEGIN{RS=ORS=","} !seen[$0]++' | sed 's/,*$//g')
|
||||||
|
|
||||||
|
echo "$ports"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,8 +262,8 @@ getSlirp() {
|
|||||||
|
|
||||||
for port in $list; do
|
for port in $list; do
|
||||||
|
|
||||||
proto="tcp"
|
local proto="tcp"
|
||||||
num="${port%/tcp}"
|
local num="${port%/tcp}"
|
||||||
|
|
||||||
if [[ "$port" == *"/udp" ]]; then
|
if [[ "$port" == *"/udp" ]]; then
|
||||||
proto="udp"
|
proto="udp"
|
||||||
@@ -235,6 +277,8 @@ getSlirp() {
|
|||||||
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
args+="hostfwd=$proto::$num-$VM_NET_IP:$num,"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
args=$(echo "$args" | sed 's/,*$//g')
|
||||||
|
|
||||||
echo "${args%?}"
|
echo "${args%?}"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -255,7 +299,7 @@ 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=$(getSlirp)
|
||||||
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
[ -n "$forward" ] && NET_OPTS+=",$forward"
|
||||||
|
|
||||||
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
if [[ "${DNSMASQ_DISABLE:-}" == [Yy1]* ]]; then
|
||||||
@@ -299,7 +343,7 @@ configurePasst() {
|
|||||||
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
[ -n "$PASST_MTU" ] && PASST_OPTS+=" -m $PASST_MTU"
|
||||||
|
|
||||||
local forward=""
|
local forward=""
|
||||||
forward=$(getUserPorts "${USER_PORTS:-}")
|
forward=$(getUserPorts)
|
||||||
forward="${forward///tcp}"
|
forward="${forward///tcp}"
|
||||||
forward="${forward///udp}"
|
forward="${forward///udp}"
|
||||||
|
|
||||||
@@ -324,12 +368,19 @@ 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: $?"
|
|
||||||
|
rm -f "$log"
|
||||||
|
PASST_OPTS="${PASST_OPTS/ -q/}"
|
||||||
|
{ $PASST ${PASST_OPTS:+ $PASST_OPTS}; rc=$?; } || :
|
||||||
|
|
||||||
|
if (( rc != 0 )); then
|
||||||
[ -f "$log" ] && cat "$log"
|
[ -f "$log" ] && cat "$log"
|
||||||
error "$msg"
|
error "Failed to start passt, reason: $rc"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
if [[ "$PASST_DEBUG" == [Yy1]* ]]; then
|
||||||
tail -fn +0 "$log" --pid=$$ &
|
tail -fn +0 "$log" --pid=$$ &
|
||||||
else
|
else
|
||||||
@@ -440,7 +491,7 @@ configureNAT() {
|
|||||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exclude=$(getHostPorts "$HOST_PORTS")
|
exclude=$(getHostPorts)
|
||||||
|
|
||||||
if [ -n "$exclude" ]; then
|
if [ -n "$exclude" ]; then
|
||||||
if [[ "$exclude" != *","* ]]; then
|
if [[ "$exclude" != *","* ]]; then
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user