summaryrefslogtreecommitdiffstats
path: root/core/modules/run-virt/data/opt/openslx/scripts/systemd-mount_vm_store
blob: cd85ef9e925743894689614fc89dc60e7d84967b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/ash

. /opt/openslx/config || exit 1

[ -z "$SLX_VM_NFS" ] && exit 0

# create target directory
mkdir -p /mnt/vmstore

OUTFILE=$(mktemp)

# check if it is a CIFS-share or NFS-share
# no bash, so this is a bit ugly...
if [ "${SLX_VM_NFS#//}" = "${SLX_VM_NFS}" ]; then
	# doesn't start with '//' -> assume NFS
	RET=1
	if [ -n "$SLX_VM_NFS_OPTS" ]; then
		/opt/openslx/bin/timeout -t 10 -s 9 mount -v -t nfs -o "${SLX_VM_NFS_OPTS},ro" "$SLX_VM_NFS" /mnt/vmstore
		RET=$?
	fi
	if [ "$RET" != "0" ]; then
		/opt/openslx/bin/timeout -t 6 -s 9 mount -v -t nfs -o ro,async,nolock "$SLX_VM_NFS" /mnt/vmstore
		RET=$?
	fi
	if [ "$RET" != "0" ]; then
		/opt/openslx/bin/timeout -t 6 -s 9 mount -v -t nfs -o vers=3,ro,async,nolock "$SLX_VM_NFS" /mnt/vmstore
		RET=$?
	fi
else
	# starts with '//' -> assume CIFS
	export USER="$SLX_VM_NFS_USER"
	export PASSWD="$SLX_VM_NFS_PASSWD"
	RET=1
	if [ -n "$SLX_VM_NFS_OPTS" ]; then
		/opt/openslx/bin/timeout -t 10 -s 9 mount -v -t cifs -o "${SLX_VM_NFS_OPTS},uid=0,gid=0,forceuid,forcegid,file_mode=0664,dir_mode=0775,ro" "$SLX_VM_NFS" /mnt/vmstore
		RET=$?
	fi
	if [ "$RET" != "0" ]; then
		for vers in "" "3.0" "2.1" "1.0" "2.0"; do
			[ -n "$vers" ] && vers=",vers=${vers}"
			for sec in "" "ntlmssp" "ntlmv2" "ntlm"; do
				[ -n "$sec" ] && sec=",sec=${sec}"
				/opt/openslx/bin/timeout -t 10 -s 9 mount -v -t cifs -o "ro,file_mode=0644,dir_mode=0755,uid=0,gid=0,forceuid,forcegid,nounix${vers}${sec}" "$SLX_VM_NFS" /mnt/vmstore
				RET=$?
				[ "$RET" = "0" ] && break
			done
			[ "$RET" = "0" ] && break
		done
	fi
	unset USER
	unset PASSWD
fi > "$OUTFILE" 2>&1

if [ "$RET" -ne "0" ]; then
	if [ -s "$OUTFILE" ]; then
		slxlog --sync "mount-vmstore-fail" "Mounting '$SLX_VM_NFS' failed. VMs will not boot." "$OUTFILE"
	else
		slxlog --sync "mount-vmstore-fail" "Mounting '$SLX_VM_NFS' failed. VMs will not boot."
	fi
fi
rm -f -- "$OUTFILE"

exit $RET