[CRIU] [PATCH RFC] zdtm: Cleanup binfmt_misc entries in case of fail

Pavel Emelyanov xemul at virtuozzo.com
Mon Dec 5 00:49:35 PST 2016


On 12/01/2016 03:47 PM, Kirill Tkhai wrote:
> On 30.11.2016 11:43, Pavel Emelyanov wrote:
>> On 11/28/2016 07:47 PM, Kirill Tkhai wrote:
>>> Add binfmt_misc hook to cleanup registered entries even
>>> in case of test failed.
>>>
>>> Q:Guys, is there a better way to get test's filename option value,
>>> than I used in zdtm.py?
>>>
>>> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
>>> ---
>>>  test/zdtm.py                      |    2 +-
>>>  test/zdtm/static/binfmt_misc.c    |    4 ++--
>>>  test/zdtm/static/binfmt_misc.hook |   27 +++++++++++++++++++++++++++
>>>  3 files changed, 30 insertions(+), 3 deletions(-)
>>>  create mode 100755 test/zdtm/static/binfmt_misc.hook
>>>
>>> diff --git a/test/zdtm.py b/test/zdtm.py
>>> index 7ca4bbf..4532d83 100755
>>> --- a/test/zdtm.py
>>> +++ b/test/zdtm.py
>>> @@ -962,7 +962,7 @@ join_ns_file = '/run/netns/zdtm_netns'
>>>  	hname = test.getname() + '.hook'
>>>  	if os.access(hname, os.X_OK):
>>>  		print "Running %s(%s)" % (hname, ', '.join(args))
>>> -		hook = subprocess.Popen([hname] + args)
>>> +		hook = subprocess.Popen([hname] + args + ["--name", os.path.basename(test.getname())])
>>
>> Can hook find this out himself by analyzing the $0 variable?
> 
> I'm not sure I understand TEST_OPTION(filename) meaning right. Is it always equal to test's name?

You don't need TEST_OPTION here, it's for test_name.c compilation and launching.
We're talking about test_name.hook stuff.

>>>  		if hook.wait() != 0:
>>>  			raise test_fail_exc("hook " + " ".join(args))
>>>  
>>> diff --git a/test/zdtm/static/binfmt_misc.c b/test/zdtm/static/binfmt_misc.c
>>> index 62b9b51..ef362c2 100644
>>> --- a/test/zdtm/static/binfmt_misc.c
>>> +++ b/test/zdtm/static/binfmt_misc.c
>>> @@ -104,8 +104,8 @@ int main(int argc, char **argv)
>>>  
>>>  	test_init(argc, argv);
>>>  
>>> -	snprintf(NAME[0], PATH_MAX, "%s_magic", filename);
>>> -	snprintf(NAME[1], PATH_MAX, "%s_extention", filename);
>>> +	snprintf(NAME[0], PATH_MAX, "criu_zdtm_%s_magic", filename);
>>> +	snprintf(NAME[1], PATH_MAX, "criu_zdtm_%s_extention", filename);
>>>  
>>>  	if (mkdir(dirname, 0777)) {
>>>  		fail("mkdir");
>>> diff --git a/test/zdtm/static/binfmt_misc.hook b/test/zdtm/static/binfmt_misc.hook
>>> new file mode 100755
>>> index 0000000..a0f86ff
>>> --- /dev/null
>>> +++ b/test/zdtm/static/binfmt_misc.hook
>>> @@ -0,0 +1,27 @@
>>> +#!/bin/bash
>>> +
>>> +[ "$1" == "--clean" ] || exit 0
>>> +
>>> +if [ "$#" -ne 3 -o "$2" != "--name" ]; then
>>> +	echo "Wrong arguments were passed"
>>> +	exit -1
>>> +fi
>>> +
>>> +name=$3
>>> +
>>> +tname=$(mktemp -d binfmt_misc.XXXXXX)
>>> +mount -t binfmt_misc none $tname
>>> +
>>> +echo "Cleaning $tname: $@"
>>> +set +e
>>> +if [ -e $tname/criu_zdtm_${name}.test_magic ]; then
>>> +	echo -1 > $tname/criu_zdtm_${name}.test_magic
>>> +fi
>>> +
>>> +if [ -e $tname/criu_zdtm_${name}.test_extention ]; then
>>> +	echo -1 > $tname/criu_zdtm_${name}.test_extention
>>> +fi
>>> +set -e
>>> +
>>> +umount "$tname"
>>> +rmdir "$tname"
>>>
>>> _______________________________________________
>>> CRIU mailing list
>>> CRIU at openvz.org
>>> https://lists.openvz.org/mailman/listinfo/criu
> .
> 



More information about the CRIU mailing list