Commit a0053823 authored by Pavel Emelyanov's avatar Pavel Emelyanov

test: Add test for tempfs mount with open file

This test fails when run in ns:

(00.300947)      1: Error (util.c:568): exited, status=1
(00.300964)      1: Error (cr-restore.c:1067): 5 exited, status=1
(00.300989)      1: Error (mount.c:637): Can't restore tmpfs content
(00.301005) Error (cr-restore.c:1602): Restoring FAILED.

Reason for failure -- tar is spawned in new mount namespace where
it can not be found (bug #2870).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b99fa574
......@@ -150,6 +150,7 @@ tun
chroot
chroot-file
rtc
tempfs
"
source $(readlink -f `dirname $0`/env.sh) || exit 1
......
......@@ -144,6 +144,7 @@ TST_DIR = \
overmount_file \
overmount_fifo \
overmount_sock \
tempfs \
TST_DIR_FILE = \
chroot \
......
#include <stdbool.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include "zdtmtst.h"
const char *test_doc = "Check tmpfs mount";
const char *test_author = "Pavel Emelianov <xemul@parallels.com>";
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
#define TEST_WORD "testtest"
int main(int argc, char **argv)
{
int fd, ret = 1;
char buf[1024];
test_init(argc, argv);
mkdir(dirname, 0700);
if (mount("none", dirname, "tmpfs", 0, "") < 0) {
fail("Can't mount tmpfs");
return 1;
}
snprintf(buf, sizeof(buf), "%s/test", dirname);
fd = open(buf, O_RDWR | O_CREAT);
if (fd < 0) {
err("open failed");
goto outum;
}
if (write(fd, TEST_WORD, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
err("write() failed");
goto outuc;
}
test_daemon();
test_waitsig();
if (lseek(fd, 0, SEEK_SET) < 0) {
fail("Seek failed");
goto outuc;
}
buf[sizeof(TEST_WORD) + 1] = '\0';
if (read(fd, buf, sizeof(TEST_WORD)) != sizeof(TEST_WORD)) {
fail("Read failed");
goto outuc;
}
if (strcmp(buf, TEST_WORD)) {
fail("File corrupted");
goto outuc;
}
pass();
ret = 0;
outuc:
close(fd);
outum:
umount(dirname);
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