mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-02-24 05:20:02 +08:00
Add vhost support in NAT mode
Add vhost support in NAT mode
This commit is contained in:
commit
24efe5585c
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@ -72,7 +72,7 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
-
|
||||
name: Create a release
|
||||
uses: kroese/github-release@v6
|
||||
uses: action-pack/github-release@v6
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
with:
|
||||
@ -81,7 +81,7 @@ jobs:
|
||||
body: "Release v${{ vars.MAJOR }}.${{ vars.MINOR }}"
|
||||
-
|
||||
name: Increment minor version
|
||||
uses: kroese/increment@v1
|
||||
uses: action-pack/increment@v1
|
||||
with:
|
||||
name: 'MINOR'
|
||||
token: ${{ secrets.REPO_ACCESS_TOKEN }}
|
||||
@ -97,7 +97,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Push to Gitlab mirror
|
||||
uses: kroese/gitlab-sync@v2
|
||||
uses: action-pack/gitlab-sync@v2
|
||||
with:
|
||||
url: ${{ secrets.GITLAB_URL }}
|
||||
token: ${{ secrets.GITLAB_TOKEN }}
|
||||
|
@ -9,6 +9,7 @@ services:
|
||||
RAM_SIZE: "512M"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/vhost-net
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
ports:
|
||||
|
@ -40,6 +40,7 @@ services:
|
||||
DISK_SIZE: "16G"
|
||||
devices:
|
||||
- /dev/kvm
|
||||
- /dev/vhost-net
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
ports:
|
||||
|
@ -5,7 +5,7 @@ set -u
|
||||
|
||||
: ${DHCP:='N'}
|
||||
|
||||
if [ "$DHCP" = "Y" ]; then
|
||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||
PORT=5555
|
||||
IP="127.0.0.1"
|
||||
else
|
||||
|
@ -36,7 +36,7 @@ if [ -f "${DATA}" ]; then
|
||||
|
||||
echo "INFO: Resizing data disk from $OLD_SIZE to $DATA_SIZE bytes.."
|
||||
|
||||
if [ "$ALLOCATE" = "N" ]; then
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Resize file by changing its length
|
||||
truncate -s "${DATA_SIZE}" "${DATA}";
|
||||
@ -58,7 +58,7 @@ if [ -f "${DATA}" ]; then
|
||||
echo "ERROR: Could not allocate a file for the virtual disk." && exit 85
|
||||
fi
|
||||
|
||||
if [ "$ALLOCATE" = "Z" ]; then
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
|
||||
GB=$(( (REQ + 1073741823)/1073741824 ))
|
||||
|
||||
@ -81,7 +81,7 @@ fi
|
||||
|
||||
if [ ! -f "${DATA}" ]; then
|
||||
|
||||
if [ "$ALLOCATE" = "N" ]; then
|
||||
if [[ "${ALLOCATE}" == [Nn]* ]]; then
|
||||
|
||||
# Create an empty file
|
||||
truncate -s "${DATA_SIZE}" "${DATA}"
|
||||
@ -102,7 +102,7 @@ if [ ! -f "${DATA}" ]; then
|
||||
echo "ERROR: Could not allocate a file for the virtual disk." && exit 87
|
||||
fi
|
||||
|
||||
if [ "$ALLOCATE" = "Z" ]; then
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
|
||||
echo "INFO: Preallocating ${DISK_SIZE} of diskspace, please wait..."
|
||||
dd if=/dev/urandom of="${DATA}" count="${DATA_SIZE}" bs=1M iflag=count_bytes status=none
|
||||
|
@ -33,7 +33,7 @@ TMP="$STORAGE/tmp"
|
||||
RD="$TMP/rd.gz"
|
||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||
|
||||
[ "$DEBUG" = "Y" ] && set -x
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
|
||||
LOC="$DL/release/7.0.1/42218/DSM_VirtualDSM_42218.pat"
|
||||
|
||||
@ -113,7 +113,7 @@ BOOT=$(find "$TMP" -name "*.bin.zip")
|
||||
BOOT=$(echo "$BOOT" | head -c -5)
|
||||
unzip -q -o "$BOOT".zip -d "$TMP"
|
||||
|
||||
[ "$ALLOCATE" != "Z" ] && echo "Install: Allocating diskspace..."
|
||||
[[ "${ALLOCATE}" == [Zz]* ]] && echo "Install: Allocating diskspace..."
|
||||
|
||||
SYSTEM="$TMP/sys.img"
|
||||
SYSTEM_SIZE=4954537983
|
||||
@ -130,7 +130,7 @@ if ! fallocate -l "${SYSTEM_SIZE}" "${SYSTEM}"; then
|
||||
echo "ERROR: Could not allocate a file for the system disk." && exit 88
|
||||
fi
|
||||
|
||||
if [ "$ALLOCATE" = "Z" ]; then
|
||||
if [[ "${ALLOCATE}" == [Zz]* ]]; then
|
||||
echo "Install: Preallocating 4 GB of diskspace..."
|
||||
dd if=/dev/urandom of="${SYSTEM}" count="${SYSTEM_SIZE}" bs=1M iflag=count_bytes status=none
|
||||
fi
|
||||
@ -211,6 +211,6 @@ mv -f "$SYSTEM" "$STORAGE"/"$BASE".system.img
|
||||
rm -rf "$TMP"
|
||||
|
||||
{ set +x; } 2>/dev/null
|
||||
[ "$DEBUG" = "Y" ] && echo
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && echo
|
||||
|
||||
return 0
|
||||
|
@ -25,7 +25,7 @@ configureDHCP() {
|
||||
NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}')
|
||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||
|
||||
[ "$DEBUG" = "Y" ] && set -x
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge 2> /dev/null ; rc=$?; } || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
@ -80,12 +80,6 @@ configureDHCP() {
|
||||
echo "container: --device-cgroup-rule='c ${MAJOR}:* rwm' --device=/dev/vhost-net" && exit 21
|
||||
fi
|
||||
|
||||
# Create /dev/vhost-net
|
||||
if [ ! -c /dev/vhost-net ]; then
|
||||
mknod /dev/vhost-net c 10 238
|
||||
chmod 660 /dev/vhost-net
|
||||
fi
|
||||
|
||||
{ exec 40>>/dev/vhost-net; rc=$?; } || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
@ -99,7 +93,7 @@ configureDHCP() {
|
||||
configureNAT () {
|
||||
|
||||
VM_NET_IP='20.20.20.21'
|
||||
[ "$DEBUG" = "Y" ] && set -x
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
|
||||
#Create bridge with static IP for the VM guest
|
||||
|
||||
@ -129,7 +123,7 @@ configureNAT () {
|
||||
fi
|
||||
|
||||
{ set +x; } 2>/dev/null
|
||||
[ "$DEBUG" = "Y" ] && echo
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && echo
|
||||
|
||||
#Check port forwarding flag
|
||||
if [[ $(< /proc/sys/net/ipv4/ip_forward) -eq 0 ]]; then
|
||||
@ -149,9 +143,15 @@ configureNAT () {
|
||||
|
||||
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"
|
||||
|
||||
{ exec 40>>/dev/vhost-net; rc=$?; } || :
|
||||
|
||||
if (( rc == 0 )); then
|
||||
NET_OPTS="$NET_OPTS,vhost=on,vhostfd=40"
|
||||
fi
|
||||
|
||||
# Build DNS options from container /etc/resolv.conf
|
||||
|
||||
if [ "$DEBUG" = "Y" ]; then
|
||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
||||
echo "/etc/resolv.conf:" && echo && cat /etc/resolv.conf && echo
|
||||
fi
|
||||
|
||||
@ -178,7 +178,7 @@ configureNAT () {
|
||||
|
||||
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
|
||||
|
||||
[ "$DEBUG" = "Y" ] && set -x
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
|
||||
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
|
||||
|
||||
@ -198,13 +198,19 @@ fi
|
||||
|
||||
[ ! -c /dev/net/tun ] && echo "ERROR: TUN network interface not available..." && exit 85
|
||||
|
||||
# Create the necessary file structure for /dev/vhost-net
|
||||
if [ ! -c /dev/vhost-net ]; then
|
||||
mknod /dev/vhost-net c 10 238
|
||||
chmod 660 /dev/vhost-net
|
||||
fi
|
||||
|
||||
update-alternatives --set iptables /usr/sbin/iptables-legacy > /dev/null
|
||||
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy > /dev/null
|
||||
|
||||
VM_NET_MAC="${VM_NET_MAC//-/:}"
|
||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
||||
|
||||
if [ "$DEBUG" = "Y" ]; then
|
||||
if [[ "${DEBUG}" == [Yy1]* ]]; then
|
||||
|
||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
||||
echo "INFO: Container IP is ${IP} with gateway ${GATEWAY}" && echo
|
||||
@ -213,12 +219,7 @@ if [ "$DEBUG" = "Y" ]; then
|
||||
|
||||
fi
|
||||
|
||||
if [ "$DHCP" != "Y" ]; then
|
||||
|
||||
# Configuration for static IP
|
||||
configureNAT
|
||||
|
||||
else
|
||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||
|
||||
if [[ "$GATEWAY" == "172."* ]]; then
|
||||
echo -n "ERROR: You cannot enable DHCP while the container is "
|
||||
@ -229,22 +230,29 @@ else
|
||||
configureDHCP
|
||||
|
||||
# Display the received IP on port 5000
|
||||
HTML="DSM is using another IP address.<br><br>(Check the logfile to see which one was assigned.)"
|
||||
HTML="DSM is using another IP address.<br><br>Check the Docker logfile to see which one was<br> assigned, or download the\
|
||||
<a href='https://global.synologydownload.com/download/Utility/Assistant/7.0.4-50051/Windows/synology-assistant-7.0.4-50051.exe'>\
|
||||
Synology Assistant</a> utility."
|
||||
|
||||
pkill -f server.sh || true
|
||||
/run/server.sh 80 "${HTML}" > /dev/null &
|
||||
/run/server.sh 5000 "${HTML}" > /dev/null &
|
||||
|
||||
else
|
||||
|
||||
# Configuration for static IP
|
||||
configureNAT
|
||||
|
||||
fi
|
||||
|
||||
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
||||
|
||||
if [ "$DHCP" = "Y" ]; then
|
||||
if [[ "${DHCP}" == [Yy1]* ]]; then
|
||||
# Add extra LAN interface for Docker Healthcheck script
|
||||
NET_OPTS="${NET_OPTS} -netdev user,id=hostnet1,restrict=y,hostfwd=tcp::5555-:5000"
|
||||
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet1,id=net1"
|
||||
fi
|
||||
|
||||
[ "$DEBUG" = "Y" ] && echo && echo "Finished network setup.." && echo
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && echo && echo "Finished network setup.." && echo
|
||||
|
||||
return 0
|
||||
|
@ -32,7 +32,7 @@ _graceful_shutdown() {
|
||||
# Don't send the powerdown signal because vDSM ignores ACPI signals
|
||||
# echo 'system_powerdown' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" > /dev/null
|
||||
|
||||
# Send shutdown command to host via serial port
|
||||
# Send shutdown command to guest agent via serial port
|
||||
RESPONSE=$(curl -s -m 2 -S http://127.0.0.1:2210/write?command=6 2>&1)
|
||||
|
||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
||||
|
13
run/run.sh
13
run/run.sh
@ -11,14 +11,15 @@ set -Eeuo pipefail
|
||||
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
||||
|
||||
echo "Starting Virtual DSM for Docker v${VERSION}..."
|
||||
trap 'echo >&2 "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
||||
|
||||
[ ! -f "/run/run.sh" ] && echo "ERROR: Script must run inside Docker container!" && exit 11
|
||||
[ "$(id -u)" -ne "0" ] && echo "ERROR: Script must be executed with root privileges." && exit 12
|
||||
|
||||
STORAGE="/storage"
|
||||
KERNEL=$(uname -r | cut -b 1)
|
||||
|
||||
trap 'echo >&2 "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
||||
|
||||
[ ! -d "$STORAGE" ] && echo "Storage folder (${STORAGE}) not found!" && exit 69
|
||||
[ ! -f "/run/run.sh" ] && echo "Script must run inside Docker container!" && exit 60
|
||||
[ ! -d "$STORAGE" ] && echo "ERROR: Storage folder (${STORAGE}) not found!" && exit 13
|
||||
|
||||
if [ -f "$STORAGE"/dsm.ver ]; then
|
||||
BASE=$(cat "${STORAGE}/dsm.ver")
|
||||
@ -58,7 +59,7 @@ fi
|
||||
|
||||
if [ -n "${KVM_ERR}" ]; then
|
||||
echo "ERROR: KVM acceleration not detected ${KVM_ERR}, please enable it."
|
||||
[ "$DEBUG" != "Y" ] && exit 88
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && exit 88
|
||||
else
|
||||
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
|
||||
fi
|
||||
@ -78,7 +79,7 @@ trap - ERR
|
||||
|
||||
set -m
|
||||
(
|
||||
[ "$DEBUG" = "Y" ] && set -x
|
||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||
qemu-system-x86_64 ${ARGS:+ $ARGS} & echo $! > "${_QEMU_PID}"
|
||||
{ set +x; } 2>/dev/null
|
||||
)
|
||||
|
@ -31,7 +31,7 @@ HOST_ARGS+=("-cpu_arch=${HOST_CPU}")
|
||||
[ -n "$HOST_VERSION" ] && HOST_ARGS+=("-version=${HOST_VERSION}")
|
||||
[ -n "$HOST_TIMESTAMP" ] && HOST_ARGS+=("-ts=${HOST_TIMESTAMP}")
|
||||
|
||||
if [ "$HOST_DEBUG" = "Y" ]; then
|
||||
if [[ "${HOST_DEBUG}" == [Yy1]* ]]; then
|
||||
set -x
|
||||
./run/host.bin "${HOST_ARGS[@]}" &
|
||||
{ set +x; } 2>/dev/null
|
||||
|
@ -5,8 +5,8 @@ trap 'kill 0' EXIT
|
||||
trap exit SIGINT SIGTERM
|
||||
|
||||
# Serve the page
|
||||
HTML="<HTML><HEAD><STYLE>body { color: white; background-color: #00BFFF; }</STYLE>\
|
||||
</HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
|
||||
HTML="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE><STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,\
|
||||
Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD><BODY><BR><BR><H1><CENTER>$2</CENTER></H1></BODY></HTML>"
|
||||
|
||||
LENGTH="${#HTML}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user