Subject: patch for vdevmap in vserver.{start,stop}
From: Corey Wright <undefined@pobox.com>
Date: Mon, 20 Sep 2010 03:05:36 -0500
Mon, 20 Sep 2010 03:05:36 -0500
the attached patches fix the following problems observed in debian's
util-vserver 0.30.216-pre2864-2 (from squeeze, but backported to lenny for
use with linux 2.6.32.21-vs2.3.0.36.29.6), but verified against svn trunk:

1. vserver.start silently fails setting up vdevmap because S_CONTEXT is not
defined (and function handleDeviceMap returns 0 after 'test -n "$xid"'
fails early on).

2. vserver.start would loudly fail (ie "vc_set_mapping(): No such process")
if S_CONTEXT was defined because the context doesn't exist yet.

3. vserver.stop fails unsetting vdevmap and complains (ie "vc_unset_mapping
(): No such process") because the context no longer exists by the time
function handleDeviceMap is called.

i might have moved the call to handleDeviceMap later than necessary in
vserver.start and earlier than necessary in vserver.stop, but it works for
me, though i don't know where you would put the call if you need init
scripts within the guest to call mknod (because i don't call
handleDeviceMap until after init scripts have executed).

the code to set S_CONTEXT was based on how N_CONTEXT is set in function
_generateIntefaceOptions in vserver.functions, though i could have done
something more straightforward like how ctx is set in
_generateChcontextOptions (ie 'read ctx <"$vdir"/context'), but i like the
elegance of a call to getFileValue.

thanks for util-vserver!

corey
-- 
undefined@pobox.com


--- vserver.start.orig	2010-06-05 11:55:50.000000000 -0500
+++ vserver.start	2010-09-20 02:18:29.000000000 -0500
@@ -123,8 +123,6 @@ prepareInit      "$VSERVER_DIR"
 addtoCPUSET      "$VSERVER_DIR"
 attachToCgroup   "$VSERVER_DIR"
 
-handleDeviceMap --set "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
-
 pushd "$VSERVER_DIR"/vdir/ >/dev/null
 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" pre-start
 popd >/dev/null
@@ -186,6 +184,9 @@ is_executed=1
 "${INITCMD_START_SYNC[@]}"
 popd >/dev/null
 
+getFileValue S_CONTEXT "$VSERVER_DIR/context"
+handleDeviceMap --set "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
+
 pushd "$VSERVER_DIR"/vdir/ >/dev/null
 execScriptlets   "$VSERVER_DIR" "$VSERVER_NAME" post-start
 popd >/dev/null


--- vserver.stop.orig	2010-06-05 11:55:50.000000000 -0500
+++ vserver.stop	2010-09-20 02:23:54.000000000 -0500
@@ -68,6 +68,8 @@ cd "$VSERVER_DIR"/vdir/
 execScriptlets     "$VSERVER_DIR" "$VSERVER_NAME" pre-stop
 cd "$VSERVER_DIR"/vdir/
 
+handleDeviceMap --unset "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
+
 test -z "$OPTION_DEFAULTTTY" || setDefaultTTY "$VSERVER_DIR"
 
 $_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !SC_HELPER
@@ -117,8 +119,6 @@ sendKillSequence   "$S_CONTEXT" "${INITK
 
 execScriptlets    "$VSERVER_DIR" "$VSERVER_NAME" post-stop
 
-handleDeviceMap --unset "$S_CONTEXT" "$VSERVER_DIR/apps/vdevmap"
-
 umountVserver     "$VSERVER_DIR" || :
 disableInterfaces "$VSERVER_DIR"