[CRIU] [PATCH v2] zdtm: Add a test to check if we can C/R ghost files with no parent dirs.
Andrei Vagin
avagin at virtuozzo.com
Thu Dec 7 18:34:33 MSK 2017
On Thu, Dec 07, 2017 at 01:46:41PM +0300, Vitaly Ostrosablin wrote:
> This is test that triggers a bug with ghost files, that was resolved in
> patch "Don't fail if ghost file has no parent dirs".
>
> Signed-off-by: Vitaly Ostrosablin <vostrosablin at virtuozzo.com>
> ---
> test/zdtm/static/Makefile | 1 +
> test/zdtm/static/unlink_multiple_largefiles.c | 97 ++++++++++++++++++++++++
> test/zdtm/static/unlink_multiple_largefiles.desc | 1 +
> 3 files changed, 99 insertions(+)
> create mode 100644 test/zdtm/static/unlink_multiple_largefiles.c
> create mode 100644 test/zdtm/static/unlink_multiple_largefiles.desc
>
> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
> index 0e1db5c5..8c4e5e7a 100644
> --- a/test/zdtm/static/Makefile
> +++ b/test/zdtm/static/Makefile
> @@ -192,6 +192,7 @@ TST_NOFILE := \
> s390x_mmap_high \
> uffd-events \
> thread_different_uid_gid \
> + unlink_multiple_largefiles \
> # jobctl00 \
>
> include ../Makefile.inc
> diff --git a/test/zdtm/static/unlink_multiple_largefiles.c b/test/zdtm/static/unlink_multiple_largefiles.c
> new file mode 100644
> index 00000000..bfcf5aae
> --- /dev/null
> +++ b/test/zdtm/static/unlink_multiple_largefiles.c
> @@ -0,0 +1,97 @@
> +#include <unistd.h>
> +#include <errno.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <stdio.h>
> +#include <fcntl.h>
> +#include <signal.h>
> +
> +#include "zdtmtst.h"
> +
> +#define FSIZE 0x3B600000ULL
> +#define NFILES 10
> +
> +const char *test_doc = "C/R of ten big (951MiB) unlinked files in root dir";
> +const char *test_author = "Vitaly Ostrosablin <vostrosablin at virtuozzo.com>";
> +
> +int create_unlinked_file(int fileno)
> +{
> + int fd;
> + char buf[1000000];
> + char fnm[15];
> +
> + sprintf(fnm, "/unlinked%d", fileno);
> + fd = open(fnm, O_WRONLY | O_CREAT | O_TRUNC | O_LARGEFILE, 0644);
> + if (fd < 0) {
> + pr_perror("Cannot create file %s\n", fnm);
> + exit(1);
> + }
> + test_msg("Created file: %s, fd %d\n", fnm, fd);
> +
> + if (lseek64(fd, FSIZE, SEEK_SET) < 0) {
> + pr_perror("Cannot seek to offset %llx\n", FSIZE);
> + goto failed;
> + }
> + test_msg("File positioning done, offset=%llx\n", FSIZE);
> +
> + int bufsz = sizeof(buf);
all vars has to be declared at the beginning of a block.
> + memset(buf, 0, bufsz);
> + if (write(fd, buf, bufsz) != bufsz) {
> + pr_perror("Cannot write %i bytes to file\n", bufsz);
> + goto failed;
> + }
> + test_msg("%i bytes written to file\n", bufsz);
> +
> + if (unlink(fnm) < 0) {
> + pr_perror("Cannot unlink file %s\n", fnm);
> + goto failed;
> + }
> + test_msg("File %s is unlinked\n", fnm);
> +
> + return fd;
> +failed:
> + unlink(fnm);
> + close(fd);
> + return -1;
> +}
> +
> +int main(int argc, char **argv)
> +{
> + int fd[10] = {0};
> + int count = 0;
> +
> + test_init(argc, argv);
> +
> + // We need to create 10 unlinked files, each is around 1GB in size
we usually use another format for comments:
/* We need to create 10 unlinked files, each is around 1GB in size */
> + for (count = 0; count < NFILES; count++) {
> +
> + test_msg("Creating unlinked file %d/%d\n", count + 1, NFILES);
> + int tempfd = create_unlinked_file(count);
all vars has to be declared at the beginning of a block
> +
> + if (tempfd < 0) {
> + pr_perror("Cannot create unlinked file %d/%d\n",
> + count + 1, NFILES);
> + return 1;
> + }
> +
> + fd[count] = tempfd;
> + }
> + test_msg("Created %d unlinked files\n", NFILES);
> +
> + test_daemon();
> + test_msg("Test daemonized, PID %d\n", getpid());
> + test_waitsig();
> +
> + test_msg("PID %d resumed, cleaning up...\n", getpid());
> +
> + for (count = 0; count < NFILES; count++) {
> + test_msg("Closing fd #%d (%d)\n", count, fd[count]);
> + if (close(fd[count]) == -1) {
This test checks only that a process has a set of file descriptors,
which can be closed successfully. I think we need to check a bit more.
We can check that a /proc/self/fd/X symlink isn't changed, we can check
content of this files, etc.
> + pr_perror("Close failed, errno %d\n", errno);
> + return 1;
> + }
> + }
> +
> + pass();
> + return 0;
> +}
> diff --git a/test/zdtm/static/unlink_multiple_largefiles.desc b/test/zdtm/static/unlink_multiple_largefiles.desc
> new file mode 100644
> index 00000000..ded89879
> --- /dev/null
> +++ b/test/zdtm/static/unlink_multiple_largefiles.desc
> @@ -0,0 +1 @@
> +{'flags': 'crfail'}
Developers runs zdtm tests on their own hosts and we don't want to create
anything outside of the criu test directory, so lets run this tests only
if a test runs in a new mount namespace.
{ 'flavor': 'ns uns' }
> --
> 2.15.0
>
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list