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
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
......
......@@ -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;
}
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