mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-11-03 00:14:58 +08:00
fix: Inherit owner from parent folder (#1092)
This commit is contained in:
parent
b7f5214a7b
commit
a0328e1e9c
24
src/disk.sh
24
src/disk.sh
@ -17,6 +17,14 @@ SYSTEM="$STORAGE/$BASE.system.img"
|
|||||||
[ ! -s "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
[ ! -s "$BOOT" ] && error "Virtual DSM boot-image does not exist ($BOOT)" && exit 81
|
||||||
[ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
[ ! -s "$SYSTEM" ] && error "Virtual DSM system-image does not exist ($SYSTEM)" && exit 82
|
||||||
|
|
||||||
|
if ! setOwner "$BOOT"; then
|
||||||
|
error "Failed to set the owner for \"$BOOT\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! setOwner "$SYSTEM"; then
|
||||||
|
error "Failed to set the owner for \"$SYSTEM\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
fmt2ext() {
|
fmt2ext() {
|
||||||
local DISK_FMT="$1"
|
local DISK_FMT="$1"
|
||||||
|
|
||||||
@ -338,23 +346,23 @@ checkFS () {
|
|||||||
DIR=$(dirname "$DISK_FILE")
|
DIR=$(dirname "$DISK_FILE")
|
||||||
[ ! -d "$DIR" ] && return 0
|
[ ! -d "$DIR" ] && return 0
|
||||||
|
|
||||||
if [[ "${FS,,}" == "overlay"* ]]; then
|
if [[ "${FS,,}" == "overlay"* && "$PODMAN" != [Yy1]* ]]; then
|
||||||
info "Warning: the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!"
|
warn "the filesystem of $DIR is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fuse"* ]]; then
|
if [[ "${FS,,}" == "fuse"* ]]; then
|
||||||
info "Warning: the filesystem of $DIR is FUSE, this extra layer will negatively affect performance!"
|
warn "the filesystem of $DIR is FUSE, this extra layer will negatively affect performance!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! supportsDirect "$FS"; then
|
if ! supportsDirect "$FS"; then
|
||||||
info "Warning: the filesystem of $DIR is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
warn "the filesystem of $DIR is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if isCow "$FS"; then
|
if isCow "$FS"; then
|
||||||
if [ -f "$DISK_FILE" ]; then
|
if [ -f "$DISK_FILE" ]; then
|
||||||
FA=$(lsattr "$DISK_FILE")
|
FA=$(lsattr "$DISK_FILE")
|
||||||
if [[ "$FA" != *"C"* ]]; then
|
if [[ "$FA" != *"C"* ]]; then
|
||||||
info "Warning: COW (copy on write) is not disabled for $DISK_DESC image file $DISK_FILE, this is recommended on ${FS^^} filesystems!"
|
warn "COW (copy on write) is not disabled for $DISK_DESC image file $DISK_FILE, this is recommended on ${FS^^} filesystems!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -543,6 +551,12 @@ addDisk () {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "$DISK_FILE" ]; then
|
||||||
|
if ! setOwner "$DISK_FILE"; then
|
||||||
|
error "Failed to set the owner for \"$DISK_FILE\" !"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
DISK_OPTS+=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" "" "")
|
DISK_OPTS+=$(createDevice "$DISK_FILE" "$DISK_TYPE" "$DISK_INDEX" "$DISK_ADDRESS" "$DISK_FMT" "$DISK_IO" "$DISK_CACHE" "" "")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -82,16 +82,16 @@ rm -f "$STORAGE/$BASE.system.img"
|
|||||||
# Check filesystem
|
# Check filesystem
|
||||||
FS=$(stat -f -c %T "$STORAGE")
|
FS=$(stat -f -c %T "$STORAGE")
|
||||||
|
|
||||||
if [[ "${FS,,}" == "overlay"* ]]; then
|
if [[ "${FS,,}" == "overlay"* && "$PODMAN" != [Yy1]* ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is OverlayFS, this usually means it was binded to an invalid path!"
|
warn "the filesystem of $STORAGE is OverlayFS, this usually means it was binded to an invalid path!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fuse"* ]]; then
|
if [[ "${FS,,}" == "fuse"* ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is FUSE, this extra layer will negatively affect performance!"
|
warn "the filesystem of $STORAGE is FUSE, this extra layer will negatively affect performance!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
if [[ "${FS,,}" == "ecryptfs" || "${FS,,}" == "tmpfs" ]]; then
|
||||||
info "Warning: the filesystem of $STORAGE is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
warn "the filesystem of $STORAGE is $FS, which does not support O_DIRECT mode, adjusting settings..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "${FS,,}" == "fat"* || "${FS,,}" == "vfat"* || "${FS,,}" == "msdos"* ]]; then
|
if [[ "${FS,,}" == "fat"* || "${FS,,}" == "vfat"* || "${FS,,}" == "msdos"* ]]; then
|
||||||
@ -100,6 +100,10 @@ fi
|
|||||||
|
|
||||||
if [[ "${FS,,}" != "exfat"* && "${FS,,}" != "ntfs"* && "${FS,,}" != "unknown"* ]]; then
|
if [[ "${FS,,}" != "exfat"* && "${FS,,}" != "ntfs"* && "${FS,,}" != "unknown"* ]]; then
|
||||||
TMP="$STORAGE/tmp"
|
TMP="$STORAGE/tmp"
|
||||||
|
rm -rf "$TMP"
|
||||||
|
if ! makeDir "$TMP"; then
|
||||||
|
error "Failed to create directory \"$TMP\" !" && exit 93
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
TMP="/tmp/dsm"
|
TMP="/tmp/dsm"
|
||||||
TMP_SPACE=2147483648
|
TMP_SPACE=2147483648
|
||||||
@ -108,10 +112,9 @@ else
|
|||||||
if (( TMP_SPACE > SPACE )); then
|
if (( TMP_SPACE > SPACE )); then
|
||||||
error "Not enough free space inside the container, have $SPACE_MB available but need at least 2 GB." && exit 93
|
error "Not enough free space inside the container, have $SPACE_MB available but need at least 2 GB." && exit 93
|
||||||
fi
|
fi
|
||||||
|
rm -rf "$TMP" && mkdir -p "$TMP"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$TMP" && mkdir -p "$TMP"
|
|
||||||
|
|
||||||
# Check free diskspace
|
# Check free diskspace
|
||||||
ROOT_SPACE=536870912
|
ROOT_SPACE=536870912
|
||||||
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
SPACE=$(df --output=avail -B 1 / | tail -n 1)
|
||||||
@ -224,6 +227,8 @@ if ! touch "$SYSTEM"; then
|
|||||||
error "Could not create file $SYSTEM for the system disk." && exit 98
|
error "Could not create file $SYSTEM for the system disk." && exit 98
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
! setOwner "$SYSTEM" && error "Failed to set the owner for \"$SYSTEM\" !"
|
||||||
|
|
||||||
if [[ "${FS,,}" == "btrfs" ]]; then
|
if [[ "${FS,,}" == "btrfs" ]]; then
|
||||||
{ chattr +C "$SYSTEM"; } || :
|
{ chattr +C "$SYSTEM"; } || :
|
||||||
FA=$(lsattr "$SYSTEM")
|
FA=$(lsattr "$SYSTEM")
|
||||||
@ -256,8 +261,12 @@ PART="$TMP/partition.fdisk"
|
|||||||
sfdisk -q "$SYSTEM" < "$PART"
|
sfdisk -q "$SYSTEM" < "$PART"
|
||||||
|
|
||||||
MOUNT="$TMP/system"
|
MOUNT="$TMP/system"
|
||||||
rm -rf "$MOUNT" && mkdir -p "$MOUNT"
|
rm -rf "$MOUNT"
|
||||||
|
|
||||||
|
if ! makeDir "$MOUNT"; then
|
||||||
|
error "Failed to create directory \"$MOUNT\" !" && exit 93
|
||||||
|
fi
|
||||||
|
|
||||||
MSG="Extracting system partition..."
|
MSG="Extracting system partition..."
|
||||||
info "Install: $MSG" && html "$MSG"
|
info "Install: $MSG" && html "$MSG"
|
||||||
|
|
||||||
@ -291,6 +300,7 @@ fakeroot -- bash -c "set -Eeu;\
|
|||||||
|
|
||||||
rm -rf "$MOUNT"
|
rm -rf "$MOUNT"
|
||||||
echo "$BASE" > "$STORAGE/dsm.ver"
|
echo "$BASE" > "$STORAGE/dsm.ver"
|
||||||
|
! setOwner "$STORAGE/dsm.ver" && error "Failed to set the owner for \"$STORAGE/dsm.ver\" !"
|
||||||
|
|
||||||
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
|
if [[ "$URL" == "file://$STORAGE/$BASE.pat" ]]; then
|
||||||
rm -f "$PAT"
|
rm -f "$PAT"
|
||||||
@ -298,7 +308,13 @@ else
|
|||||||
mv -f "$PAT" "$STORAGE/$BASE.pat"
|
mv -f "$PAT" "$STORAGE/$BASE.pat"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f "$STORAGE/$BASE.pat" ]; then
|
||||||
|
! setOwner "$STORAGE/$BASE.pat" && error "Failed to set the owner for \"$STORAGE/$BASE.pat\" !"
|
||||||
|
fi
|
||||||
|
|
||||||
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
mv -f "$BOOT" "$STORAGE/$BASE.boot.img"
|
||||||
|
! setOwner "$STORAGE/$BASE.boot.img" && error "Failed to set the owner for \"$STORAGE/$BASE.boot.img\" !"
|
||||||
|
|
||||||
rm -rf "$TMP"
|
rm -rf "$TMP"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -218,11 +218,14 @@ getUserPorts() {
|
|||||||
|
|
||||||
for hostport in ${exclude//,/ }; do
|
for hostport in ${exclude//,/ }; do
|
||||||
|
|
||||||
local val="${hostport///tcp}"
|
local port="${hostport///tcp}"
|
||||||
|
port="${port///udp}"
|
||||||
|
|
||||||
if [[ "$num" == "${val///udp}" ]]; then
|
if [[ "$num" == "$port" ]]; then
|
||||||
num=""
|
num=""
|
||||||
warn "Could not assign port ${val///udp} to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
if [[ "$port" != "$WEB_PORT" ]]; then
|
||||||
|
warn "Could not assign port $port to \"USER_PORTS\" because it is already in \"HOST_PORTS\"!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
@ -343,6 +346,12 @@ configurePasst() {
|
|||||||
|
|
||||||
PASST_OPTS+=" -H $VM_NET_HOST"
|
PASST_OPTS+=" -H $VM_NET_HOST"
|
||||||
PASST_OPTS+=" -M $GATEWAY_MAC"
|
PASST_OPTS+=" -M $GATEWAY_MAC"
|
||||||
|
|
||||||
|
local uid gid
|
||||||
|
uid=$(id -u)
|
||||||
|
gid=$(id -g)
|
||||||
|
PASST_OPTS+=" --runas $uid:$gid"
|
||||||
|
|
||||||
PASST_OPTS+=" -P /var/run/passt.pid"
|
PASST_OPTS+=" -P /var/run/passt.pid"
|
||||||
PASST_OPTS+=" -l $log"
|
PASST_OPTS+=" -l $log"
|
||||||
PASST_OPTS+=" -q"
|
PASST_OPTS+=" -q"
|
||||||
@ -697,7 +706,7 @@ getInfo() {
|
|||||||
[ -z "$MTU" ] && MTU="0"
|
[ -z "$MTU" ] && MTU="0"
|
||||||
|
|
||||||
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
if [[ "${ADAPTER,,}" != "virtio-net-pci" ]]; then
|
||||||
if [[ "$MTU" != "0" && "$MTU" != "1500" ]]; then
|
if [[ "$MTU" != "0" ]] && [ "$MTU" -lt "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"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -710,6 +719,7 @@ getInfo() {
|
|||||||
# Generate MAC address based on Docker container ID in hostname
|
# Generate MAC address based on Docker container ID in hostname
|
||||||
VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/')
|
VM_NET_MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:11:32:\3:\4:\5/')
|
||||||
echo "${VM_NET_MAC^^}" > "$file"
|
echo "${VM_NET_MAC^^}" > "$file"
|
||||||
|
! setOwner "$file" && error "Failed to set the owner for \"$file\" !"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -828,7 +838,7 @@ else
|
|||||||
"passt" | "slirp" )
|
"passt" | "slirp" )
|
||||||
|
|
||||||
if [ -z "$USER_PORTS" ]; then
|
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."
|
info "Notice: because user-mode networking is active, when you need to forward custom ports to DSM, add them to the \"USER_PORTS\" variable."
|
||||||
fi ;;
|
fi ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|||||||
@ -78,8 +78,7 @@ fi
|
|||||||
|
|
||||||
# Check folder
|
# Check folder
|
||||||
|
|
||||||
if [[ "${COMMIT:-}" == [Yy1]* ]]; then
|
if [[ "${STORAGE,,}" != "/storage" ]]; then
|
||||||
STORAGE="/local"
|
|
||||||
mkdir -p "$STORAGE"
|
mkdir -p "$STORAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -88,7 +87,9 @@ if [ ! -d "$STORAGE" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -w "$STORAGE" ]; then
|
if [ ! -w "$STORAGE" ]; then
|
||||||
error "Storage folder ($STORAGE) is not writeable!" && exit 13
|
msg="Storage folder ($STORAGE) is not writeable!"
|
||||||
|
msg+=" If SELinux is active, you need to add the \":Z\" flag to the bind mount."
|
||||||
|
error "$msg" && exit 13
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check filesystem
|
# Check filesystem
|
||||||
|
|||||||
37
src/utils.sh
37
src/utils.sh
@ -67,6 +67,37 @@ fKill() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setOwner() {
|
||||||
|
local file="$1"
|
||||||
|
local dir uid gid
|
||||||
|
|
||||||
|
[ ! -f "$file" ] && return 1
|
||||||
|
|
||||||
|
dir=$(dirname -- "$file")
|
||||||
|
uid=$(stat -c '%u' "$dir")
|
||||||
|
gid=$(stat -c '%g' "$dir")
|
||||||
|
|
||||||
|
! chown "$uid:$gid" "$file" && return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
makeDir() {
|
||||||
|
local path="$1"
|
||||||
|
local dir uid gid
|
||||||
|
|
||||||
|
[ -d "$path" ] && return 0
|
||||||
|
! mkdir -p "$path" && return 1
|
||||||
|
|
||||||
|
dir=$(dirname -- "$path")
|
||||||
|
uid=$(stat -c '%u' "$dir")
|
||||||
|
gid=$(stat -c '%g' "$dir")
|
||||||
|
|
||||||
|
! chown "$uid:$gid" "$path" && return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
escape () {
|
escape () {
|
||||||
local s
|
local s
|
||||||
s=${1//&/\&}
|
s=${1//&/\&}
|
||||||
@ -123,11 +154,11 @@ cpu() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
cpu="${cpu// CPU/}"
|
cpu="${cpu// CPU/}"
|
||||||
cpu="${cpu// [0-9] Core}"
|
|
||||||
cpu="${cpu// [0-9][0-9] Core}"
|
|
||||||
cpu="${cpu// [0-9][0-9][0-9] Core}"
|
cpu="${cpu// [0-9][0-9][0-9] Core}"
|
||||||
cpu="${cpu//[0-9]th Gen }"
|
cpu="${cpu// [0-9][0-9] Core}"
|
||||||
|
cpu="${cpu// [0-9] Core}"
|
||||||
cpu="${cpu//[0-9][0-9]th Gen }"
|
cpu="${cpu//[0-9][0-9]th Gen }"
|
||||||
|
cpu="${cpu//[0-9]th Gen }"
|
||||||
cpu="${cpu// Processor/}"
|
cpu="${cpu// Processor/}"
|
||||||
cpu="${cpu// Quad core/}"
|
cpu="${cpu// Quad core/}"
|
||||||
cpu="${cpu// Dual core/}"
|
cpu="${cpu// Dual core/}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user