[Devel] [PATCH libvzctl 3/3] scripts: Tune up ploop links on post-setup-namespaces stage

Cyrill Gorcunov gorcunov at gmail.com
Thu Oct 12 10:21:31 MSK 2017


From: Cyrill Gorcunov <gorcunov at openvz.org>

The restore of ploop device is a bit tricky: its major/minor
is not a constant but allocated dynamicaly by the kernel
driver. Thus we may have a situation when /dev/ploopXX
points for some obsolete name which we have to resolve
into valid device.

For this sake we save old name in dev/$uuid form and
when mount namespaces are restored but their roots
are not moved we should walk over every root point
and figure out if there ploop device to be adjusted.

This patch requires CRIU to export "CRIU_MNT_NS_ROOTS".

https://jira.sw.ru/browse/PSBM-71861

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 scripts/vz-rst-action.in | 67 ++++++++++++++++++++++++++----------------------
 1 file changed, 37 insertions(+), 30 deletions(-)

diff --git a/scripts/vz-rst-action.in b/scripts/vz-rst-action.in
index fec68a7..a532bad 100755
--- a/scripts/vz-rst-action.in
+++ b/scripts/vz-rst-action.in
@@ -28,40 +28,48 @@
 
 exec 1>&2
 
+action_script=@SCRIPTDIR@/vz-rst-action
+
 restore_devices()
 {
 	local s d t major minor old dir device
 	local pid=$CRTOOLS_INIT_PID
 
-	root=/proc/$pid/root
-
-	# VE_PLOOP_DEVS=UUID at ploopN:major:minor:[root]
-	for s in $VE_PLOOP_DEVS; do
-		uuid=${s%%@*}
-		t=${s#*@}
-		device=${t%%:*}
-		t=${t#*:}
-		major=${t%%:*}
-		t=${t#*:}
-		minor=${t%%:*}
-
-		[ ! -L "$root/dev/$uuid" ] && continue
-
-		old=$(readlink $root/dev/$uuid)
-		[ -z "$old" ] && continue
-
-		for d in "${old}" "${device}"; do
-			dir=$root/$d
-			dir=${dir%/*}
-			if [ -e "$dir" ]; then
-				rm -f $root/$d
-			else
-				mkdir -p $dir
-			fi
-			mknod -m 600 $root/$d b $major $minor
-		done
+	if [ -z "$VZ_RST_USE_NSENTER" ]; then
+		export VZ_RST_USE_NSENTER="y"
+		nsenter -m -t $pid bash $action_script
+		exit 0
+	fi
 
-		rm -f $root/dev/$uuid
+	for root in $CRIU_MNT_NS_ROOTS; do
+		# VE_PLOOP_DEVS=UUID at ploopN:major:minor:[root]
+		for s in $VE_PLOOP_DEVS; do
+			uuid=${s%%@*}
+			t=${s#*@}
+			device=${t%%:*}
+			t=${t#*:}
+			major=${t%%:*}
+			t=${t#*:}
+			minor=${t%%:*}
+
+			[ ! -L "$root/dev/$uuid" ] && continue
+
+			old=$(readlink $root/dev/$uuid)
+			[ -z "$old" ] && continue
+
+			for d in "${old}" "${device}"; do
+				dir=$root/$d
+				dir=${dir%/*}
+				if [ -e "$dir" ]; then
+					rm -f $root/$d
+				else
+					mkdir -p $dir
+				fi
+				mknod -m 600 $root/$d b $major $minor
+			done
+
+			rm -f $root/dev/$uuid
+		done
 	done
 }
 
@@ -87,6 +95,7 @@ case "$CRTOOLS_SCRIPT_ACTION" in
 	;;
 "post-setup-namespaces")
 	if [ -n "$VEID" ]; then
+		restore_devices
 		[ -n "$VE_OS_RELEASE" ] && cgset -r ve.os_release="$VE_OS_RELEASE" $VEID
 		[ -n "$VE_PID_MAX" ] && cgset -r ve.pid_max="$VE_PID_MAX" $VEID
 	fi
@@ -97,8 +106,6 @@ case "$CRTOOLS_SCRIPT_ACTION" in
 		exit 1
 	fi
 
-	restore_devices
-
 	if [ -n "$VEID" ]; then
 		[ -f "$CRTOOLS_IMAGE_DIR/vz_core_pattern.img" ] && \
 			{ cgexec -g ve:$VEID echo `cat $CRTOOLS_IMAGE_DIR/vz_core_pattern.img` \
-- 
2.7.5



More information about the Devel mailing list