[Devel] [PATCH libvzctl] scripts: vz -- Handle optional VZ images without error exit

Cyrill Gorcunov gorcunov at virtuozzo.com
Mon May 23 03:37:17 PDT 2016


The images we dump with scripts are optional, so we should
not fail if some of them are missing. Moverover in migration
cases not all of them are appearing in constrast with when
c/r cycle is done via vzctl natively.

Thus rework the restore scritps. In particular "action" script
now require any error case must be handled explicitily with
varbose error messaging.

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

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 scripts/vz-rst-action.in | 11 ++++++++---
 scripts/vz-rst.in        | 12 ++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/scripts/vz-rst-action.in b/scripts/vz-rst-action.in
index 43c3142..c910677 100755
--- a/scripts/vz-rst-action.in
+++ b/scripts/vz-rst-action.in
@@ -73,7 +73,7 @@ case "$CRTOOLS_SCRIPT_ACTION" in
 		[ -n "$VE_IPTABLES_MASK" ] && cgset -r ve.iptables_mask="$VE_IPTABLES_MASK" $VEID
 		[ -n "$VE_FEATURES" ] && cgset -r ve.features="$VE_FEATURES" $VEID
 		[ -n "$VE_AIO_MAX_NR" ] && cgset -r ve.aio_max_nr="$VE_AIO_MAX_NR" $VEID
- 		cgset -r ve.state="START $pid" $VEID || exit
+		cgset -r ve.state="START $pid" $VEID || { echo "Failed to start $VEID"; exit 1; }
 	fi
 	;;
 "post-setup-namespaces")
@@ -87,7 +87,7 @@ case "$CRTOOLS_SCRIPT_ACTION" in
 	[ -n "$STATUSFD" ] && printf '\0\0\0\0' >&${STATUSFD}
 	[ -n "$WAITFD" ] && ret=$(cat <&$WAITFD | hexdump -e '"%d"' -n 4)
 
-	[ "$ret" -eq "0" ]
+	[ "$ret" -eq "0" ] || { echo "Failed on network unlocking for $VEID"; exit 1; }
 	;;
 "post-restore")
 	if [ -z "$CRTOOLS_IMAGE_DIR" ]; then
@@ -98,6 +98,11 @@ case "$CRTOOLS_SCRIPT_ACTION" in
 		[ -n "$VEID" ] && { cgexec -g ve:$VEID echo `cat $CRTOOLS_IMAGE_DIR/vz_core_pattern.img` \
 			> /proc/sys/kernel/core_pattern || { echo "Failed to restore core_pattern"; exit 1; } }
 	fi
-	[ -n "$VEID" ] && cgset -r ve.pseudosuper="0" $VEID
+	[ -n "$VEID" ] && { cgset -r ve.pseudosuper="0" $VEID || { echo "Failed to drop pseudosuper on $VEID"; exit 1; } }
 	;;
 esac
+
+#
+# Exit with success by default, any error must cause
+# messaging with explicit "exit 1"
+exit 0
diff --git a/scripts/vz-rst.in b/scripts/vz-rst.in
index 3917564..654cdd3 100755
--- a/scripts/vz-rst.in
+++ b/scripts/vz-rst.in
@@ -60,12 +60,12 @@ extra_args_path="$VE_DUMP_DIR/restore-extra-args"
 
 # Setup VE specific settings (cgroup interface)
 if [ -n "$VEID" ]; then
-        export VE_CLOCK_BOOTBASED=`cat $VE_DUMP_DIR/vz_clock_bootbased.img`
-        export VE_CLOCK_MONOTONIC=`cat $VE_DUMP_DIR/vz_clock_monotonic.img`
-        export VE_IPTABLES_MASK=`cat $VE_DUMP_DIR/vz_iptables_mask.img`
-        export VE_OS_RELEASE=`cat $VE_DUMP_DIR/vz_os_release.img`
-        export VE_FEATURES=`cat $VE_DUMP_DIR/vz_features.img`
-        export VE_AIO_MAX_NR=`cat $VE_DUMP_DIR/vz_aio_max_nr.img`
+	[ -f $VE_DUMP_DIR/vz_clock_bootbased.img ] && export VE_CLOCK_BOOTBASED=`cat $VE_DUMP_DIR/vz_clock_bootbased.img`
+	[ -f $VE_DUMP_DIR/vz_clock_monotonic.img ] && export VE_CLOCK_MONOTONIC=`cat $VE_DUMP_DIR/vz_clock_monotonic.img`
+	[ -f $VE_DUMP_DIR/vz_iptables_mask.img ] && export VE_IPTABLES_MASK=`cat $VE_DUMP_DIR/vz_iptables_mask.img`
+	[ -f $VE_DUMP_DIR/vz_os_release.img ] && export VE_OS_RELEASE=`cat $VE_DUMP_DIR/vz_os_release.img`
+	[ -f $VE_DUMP_DIR/vz_features.img ] && export VE_FEATURES=`cat $VE_DUMP_DIR/vz_features.img`
+	[ -f $VE_DUMP_DIR/vz_aio_max_nr.img ] && export VE_AIO_MAX_NR=`cat $VE_DUMP_DIR/vz_aio_max_nr.img`
 fi
 
 # Setup default log name if not explicitly specified
-- 
2.5.5



More information about the Devel mailing list