Commit 223a9982 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm/tempfs: check that overmounted parts are restored (v2)

v2: check that plain file opened on tempfs
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 22694546
...@@ -122,6 +122,7 @@ static/pty03 ...@@ -122,6 +122,7 @@ static/pty03
static/mountpoints static/mountpoints
ns/static/session00 ns/static/session00
ns/static/session01 ns/static/session01
ns/static/tempfs
static/utsname static/utsname
static/ipc_namespace static/ipc_namespace
static/shm static/shm
...@@ -156,6 +157,7 @@ chroot-file ...@@ -156,6 +157,7 @@ chroot-file
rtc rtc
tempfs tempfs
maps007 maps007
tempfs
" "
source $(readlink -f `dirname $0`/env.sh) || exit 1 source $(readlink -f `dirname $0`/env.sh) || exit 1
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <linux/limits.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -14,11 +15,12 @@ char *dirname; ...@@ -14,11 +15,12 @@ char *dirname;
TEST_OPTION(dirname, string, "directory name", 1); TEST_OPTION(dirname, string, "directory name", 1);
#define TEST_WORD "testtest" #define TEST_WORD "testtest"
#define TEST_WORD2 "TESTTEST"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd, ret = 1; int fd, fdo, ret = 1;
char buf[1024]; char buf[1024], fname[PATH_MAX], overmount[PATH_MAX];
test_init(argc, argv); test_init(argc, argv);
...@@ -28,43 +30,82 @@ int main(int argc, char **argv) ...@@ -28,43 +30,82 @@ int main(int argc, char **argv)
return 1; return 1;
} }
snprintf(buf, sizeof(buf), "%s/test", dirname); snprintf(fname, sizeof(buf), "%s/test.file", dirname);
fd = open(buf, O_RDWR | O_CREAT); 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) { if (fd < 0) {
err("open failed"); 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"); 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_daemon();
test_waitsig(); test_waitsig();
if (lseek(fd, 0, SEEK_SET) < 0) { if (umount(overmount) < 0) {
fail("Seek failed"); fail("Can't mount tmpfs");
goto outuc; goto err;
} }
lseek(fdo, 0, SEEK_SET);
buf[sizeof(TEST_WORD) + 1] = '\0'; 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"); fail("Read failed");
goto outuc; goto err;
} }
close(fdo);
if (strcmp(buf, TEST_WORD)) { if (strcmp(buf, TEST_WORD)) {
fail("File corrupted"); 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(); pass();
ret = 0; ret = 0;
outuc: err:
close(fd); umount2(dirname, MNT_DETACH);
outum:
umount(dirname);
rmdir(dirname); rmdir(dirname);
return ret; return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment