[CRIU] [PATCH 4/4] zdtm/tempfs: check that overmounted parts are restored (v2)
Andrey Vagin
avagin at openvz.org
Fri Feb 28 06:39:52 PST 2014
v2: check that plain file opened on tempfs
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
test/zdtm.sh | 2 ++
test/zdtm/live/static/tempfs.c | 75 ++++++++++++++++++++++++++++++++----------
2 files changed, 60 insertions(+), 17 deletions(-)
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 6f0f964..ac6b974 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -122,6 +122,7 @@ static/pty03
static/mountpoints
ns/static/session00
ns/static/session01
+ns/static/tempfs
static/utsname
static/ipc_namespace
static/shm
@@ -156,6 +157,7 @@ chroot-file
rtc
tempfs
maps007
+tempfs
"
source $(readlink -f `dirname $0`/env.sh) || exit 1
diff --git a/test/zdtm/live/static/tempfs.c b/test/zdtm/live/static/tempfs.c
index fd5e711..3a6f449 100644
--- a/test/zdtm/live/static/tempfs.c
+++ b/test/zdtm/live/static/tempfs.c
@@ -4,6 +4,7 @@
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
+#include <linux/limits.h>
#include "zdtmtst.h"
@@ -14,11 +15,12 @@ char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
#define TEST_WORD "testtest"
+#define TEST_WORD2 "TESTTEST"
int main(int argc, char **argv)
{
- int fd, ret = 1;
- char buf[1024];
+ int fd, fdo, ret = 1;
+ char buf[1024], fname[PATH_MAX], overmount[PATH_MAX];
test_init(argc, argv);
@@ -28,43 +30,82 @@ int main(int argc, char **argv)
return 1;
}
- snprintf(buf, sizeof(buf), "%s/test", dirname);
- fd = open(buf, O_RDWR | O_CREAT);
+ snprintf(fname, sizeof(buf), "%s/test.file", dirname);
+ fdo = open(fname, O_RDWR | O_CREAT);
+ if (fdo < 0) {
+ err("open failed");
+ goto err;
+ }
+
+ if (write(fdo, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
+ err("write() failed");
+ goto err;
+ }
+
+ snprintf(overmount, sizeof(buf), "%s/test", dirname);
+ mkdir(overmount, 0700);
+
+ snprintf(fname, sizeof(buf), "%s/test.file", overmount);
+ fd = open(fname, O_RDWR | O_CREAT);
if (fd < 0) {
err("open failed");
- goto outum;
+ goto err;
}
- if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
+ if (write(fd, TEST_WORD2, sizeof(TEST_WORD2)) != sizeof(TEST_WORD2)) {
err("write() failed");
- goto outuc;
+ goto err;
+ }
+ close(fd);
+
+ if (mount("none", overmount, "tmpfs", 0, "") < 0) {
+ fail("Can't mount tmpfs");
+ goto err;
}
test_daemon();
test_waitsig();
- if (lseek(fd, 0, SEEK_SET) < 0) {
- fail("Seek failed");
- goto outuc;
+ if (umount(overmount) < 0) {
+ fail("Can't mount tmpfs");
+ goto err;
}
+ lseek(fdo, 0, SEEK_SET);
buf[sizeof(TEST_WORD) + 1] = '\0';
- if (read(fd, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
+ if (read(fdo, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
fail("Read failed");
- goto outuc;
+ goto err;
}
+ close(fdo);
if (strcmp(buf, TEST_WORD)) {
fail("File corrupted");
- goto outuc;
+ goto err;
+ }
+
+ fd = open(fname, O_RDONLY);
+ if (fd < 0) {
+ err("open failed");
+ goto err;
+ }
+
+ buf[sizeof(TEST_WORD2) + 1] = '\0';
+ if (read(fd, buf, sizeof(TEST_WORD2)) != sizeof(TEST_WORD2)) {
+ fail("Read failed");
+ goto err;
+ }
+ close(fd);
+
+ if (strcmp(buf, TEST_WORD2)) {
+ fail("File corrupted");
+ goto err;
}
pass();
ret = 0;
-outuc:
- close(fd);
-outum:
- umount(dirname);
+err:
+ umount2(dirname, MNT_DETACH);
rmdir(dirname);
return ret;
}
--
1.8.5.3
More information about the CRIU
mailing list