[CRIU] [PATCH 5/5] test: Add unlink_dir test

Andrei Vagin avagin at gmail.com
Wed Feb 27 09:51:32 MSK 2019


Hi Cyrill,

Looks at this patch. The test passes without C/R and fails with C/R.

@@ -3,6 +3,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
+#include <sched.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -126,9 +127,22 @@ int main(int argc, char ** argv)
                        return 1;
                }
        }
-
+       if (mkdir(path_dir1, 0700) < 0) {
+               pr_perror("Can't create directory %s", path_dir1);
+               return 1;
+       }
+       dirfd1 = open(path_dir1, O_RDONLY | O_DIRECTORY);
+       if (dirfd1 < 0) {
+               pr_perror("Can't open %s", path_dir1);
+               return 1;
+       }
        test_daemon();
        test_waitsig();
+               if (rmdir(path_dir1)) {
+                       pr_perror("Can't rmdir %s", path_dir1);
+                       return 1;
+               }
+
 
        for (i = 0; i < ARRAY_SIZE(path_dirs); i++) {
                if (access(path_dirs[i], F_OK)) {

[root at fc24 criu]# python test/zdtm.py run -t zdtm/static/unlink_dir 
=== Run 1/1 ================ zdtm/static/unlink_dir
======================= Run zdtm/static/unlink_dir in h ========================
Start test
./unlink_dir --pidfile=unlink_dir.pid --outfile=unlink_dir.out --dirname=unlink_dir.test
Run criu dump
Run criu restore
Send the 15 signal to  36
Wait for zdtm/static/unlink_dir(36) to die for 0.100000
############### Test zdtm/static/unlink_dir FAIL at result check ###############
Test output: ================================
09:49:53.510:    36: ERR: unlink_dir.c:142: Can't rmdir unlink_dir.test/gd1 (errno = 2 (No such file or directory))

 <<< ================================
##################################### FAIL #####################################


[root at fc24 criu]# python test/zdtm.py run -t zdtm/static/unlink_dir  --iter 0
=== Run 1/1 ================ zdtm/static/unlink_dir
======================= Run zdtm/static/unlink_dir in h ========================
Start test
./unlink_dir --pidfile=unlink_dir.pid --outfile=unlink_dir.out --dirname=unlink_dir.test
Send the 15 signal to  36
Wait for zdtm/static/unlink_dir(36) to die for 0.100000
Removing dump/zdtm/static/unlink_dir/36
======================= Test zdtm/static/unlink_dir PASS =======================


On Tue, Feb 26, 2019 at 12:13:35PM +0300, Cyrill Gorcunov wrote:
> To check ghost directories cleanup.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
> ---
>  test/zdtm/static/Makefile     |   1 +
>  test/zdtm/static/unlink_dir.c | 143 ++++++++++++++++++++++++++++++++++
>  2 files changed, 144 insertions(+)
>  create mode 100644 test/zdtm/static/unlink_dir.c
> 
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index a31c202d5409..303ed7d40ffe 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -345,6 +345,7 @@ TST_DIR		=				\
>  		private_bind_propagation	\
>  		ghost_on_rofs			\
>  		overmounted_file		\
> +		unlink_dir			\
>  
>  TST_DIR_FILE	=				\
>  		chroot				\
> diff --git a/test/zdtm/static/unlink_dir.c b/test/zdtm/static/unlink_dir.c
> new file mode 100644
> index 000000000000..47a5673b8b5f
> --- /dev/null
> +++ b/test/zdtm/static/unlink_dir.c
> @@ -0,0 +1,143 @@
> +#include <stdlib.h>
> +#include <fcntl.h>
> +#include <errno.h>
> +#include <unistd.h>
> +#include <string.h>
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +
> +#include <linux/limits.h>
> +
> +#include "zdtmtst.h"
> +
> +const char *test_doc	= "Check cleanup order of ghost directory and files inside";
> +const char *test_author	= "Cyrill Gorcunov <gorcunov at gmail.com>";
> +
> +char *dirname;
> +TEST_OPTION(dirname, string, "directory name", 1);
> +
> +int main(int argc, char ** argv)
> +{
> +	int dirfd1, dirfd2, dirfd2_dup, dirfd4;
> +	char path_dir1[PATH_MAX];
> +	char path_dir2[PATH_MAX];
> +	char path_dir3[PATH_MAX];
> +	char path_dir4[PATH_MAX];
> +
> +	/* Order does matter */
> +	char *path_dirs[] = {
> +		path_dir4,
> +		path_dir3,
> +		path_dir2,
> +		path_dir1,
> +	};
> +
> +	char path[PATH_MAX];
> +	int fds[4], i;
> +
> +	int lo = ARRAY_SIZE(fds) / 2;
> +	int hi = ARRAY_SIZE(fds);
> +
> +	test_init(argc, argv);
> +
> +	if (mkdir(dirname, 0700) < 0) {
> +		pr_perror("Can't create directory %s", dirname);
> +		return 1;
> +	}
> +
> +	ssprintf(path_dir1, "%s/%s", dirname, "gd1");
> +	if (mkdir(path_dir1, 0700) < 0) {
> +		pr_perror("Can't create directory %s", path_dir1);
> +		return 1;
> +	}
> +
> +	ssprintf(path_dir2, "%s/%s/%s", dirname, "gd1", "gd2");
> +	if (mkdir(path_dir2, 0700) < 0) {
> +		pr_perror("Can't create directory %s", path_dir2);
> +		return 1;
> +	}
> +
> +	ssprintf(path_dir3, "%s/%s/%s/%s", dirname, "gd1", "gd2", "gd3");
> +	if (mkdir(path_dir3, 0700) < 0) {
> +		pr_perror("Can't create directory %s", path_dir3);
> +		return 1;
> +	}
> +
> +	ssprintf(path_dir4, "%s/%s/%s/%s/%s", dirname, "gd1", "gd2", "gd3", "gd4");
> +	if (mkdir(path_dir4, 0700) < 0) {
> +		pr_perror("Can't create directory %s", path_dir4);
> +		return 1;
> +	}
> +
> +	for (i = 0; i < lo; i++) {
> +		ssprintf(path, "%s/%d", path_dir1, i);
> +		fds[i] = open(path, O_RDONLY | O_CREAT | O_TRUNC);
> +		if (fds[i] < 0) {
> +			pr_perror("Can't open %s", path);
> +			return 1;
> +		}
> +		if (unlink(path)) {
> +			pr_perror("Can't unlink %s", path);
> +			return 1;
> +		}
> +	}
> +
> +	dirfd2 = open(path_dir2, O_RDONLY | O_DIRECTORY);
> +	if (dirfd2 < 0) {
> +		pr_perror("Can't open %s", path_dir2);
> +		return 1;
> +	}
> +
> +	dirfd2_dup = dup(dirfd2);
> +	if (dirfd2_dup < 0) {
> +		pr_perror("Can't dup on %s\n", path_dir2);
> +		return 1;
> +	}
> +
> +	dirfd4 = open(path_dir4, O_RDONLY | O_DIRECTORY);
> +	if (dirfd4 < 0) {
> +		pr_perror("Can't open %s", path_dir4);
> +		return 1;
> +	}
> +
> +	for (i = lo; i < hi; i++) {
> +		ssprintf(path, "%s/%d", path_dir2, i);
> +		fds[i] = open(path, O_RDONLY | O_CREAT | O_TRUNC);
> +		if (fds[i] < 0) {
> +			pr_perror("Can't open %s", path);
> +			return 1;
> +		}
> +		if (unlink(path)) {
> +			pr_perror("Can't unlink %s", path);
> +			return 1;
> +		}
> +	}
> +
> +	dirfd1 = open(path_dir1, O_RDONLY | O_DIRECTORY);
> +	if (dirfd1 < 0) {
> +		pr_perror("Can't open %s", path_dir1);
> +		return 1;
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(path_dirs); i++) {
> +		if (rmdir(path_dirs[i])) {
> +			pr_perror("Can't rmdir %s", path_dirs[i]);
> +			return 1;
> +		}
> +	}
> +
> +	test_daemon();
> +	test_waitsig();
> +
> +	for (i = 0; i < ARRAY_SIZE(path_dirs); i++) {
> +		if (access(path_dirs[i], F_OK)) {
> +			if (errno == ENOENT)
> +				continue;
> +			fail("Unexpected error on %s", path_dirs[i]);
> +			exit(1);
> +		}
> +	}
> +	pass();
> +	return 0;
> +}
> -- 
> 2.20.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list