mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-22 01:31:34 +00:00
zdtm: Test that opened and unlinked files with non zero link count work
Same as unlink_fstat0x, but leave one link alive. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
563b116096
commit
fe187fe0ed
3 changed files with 96 additions and 0 deletions
|
|
@ -44,6 +44,7 @@ static/socket_udplite
|
|||
static/selfexe00
|
||||
static/unlink_fstat00
|
||||
static/unlink_fstat02
|
||||
static/unlink_fstat03
|
||||
static/eventfs00
|
||||
static/signalfd00
|
||||
static/inotify00
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ TST_FILE = \
|
|||
unlink_fstat00 \
|
||||
unlink_fstat01 \
|
||||
unlink_fstat02 \
|
||||
unlink_fstat03 \
|
||||
unlink_largefile \
|
||||
mtime_mmap \
|
||||
fifo \
|
||||
|
|
|
|||
94
test/zdtm/live/static/unlink_fstat03.c
Normal file
94
test/zdtm/live/static/unlink_fstat03.c
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
const char *test_doc = "Open, link, unlink former, change size, migrate, check size";
|
||||
|
||||
char *filename;
|
||||
TEST_OPTION(filename, string, "file name", 1);
|
||||
static char link_name[1024];
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int fd;
|
||||
size_t fsize=1000;
|
||||
uint8_t buf[fsize];
|
||||
struct stat fst, fst2;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd < 0) {
|
||||
err("can't open %s: %m\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sprintf(link_name, "%s.link", filename);
|
||||
if (link(filename, link_name)) {
|
||||
err("can't link files");
|
||||
goto failed0;
|
||||
}
|
||||
|
||||
if (fstat(fd, &fst) < 0) {
|
||||
err("can't get file info %s before: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (fst.st_size != 0) {
|
||||
err("%s file size eq %d\n", fst.st_size);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (unlink(filename) < 0) {
|
||||
err("can't unlink %s: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
memset(buf, '0', sizeof(buf));
|
||||
if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
|
||||
err("can't write %s: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
if (fstat(fd, &fst2) < 0) {
|
||||
err("can't get %s file info after: %m\n", filename);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if ((fst.st_dev != fst2.st_dev) || (fst.st_ino != fst2.st_ino)) {
|
||||
fail("files differ after restore\n");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
if (fst2.st_size != fsize) {
|
||||
fail("(via fstat): file size changed to %d", fst.st_size);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
fst2.st_size = lseek(fd, 0, SEEK_END);
|
||||
if (fst2.st_size != fsize) {
|
||||
fail("(via lseek): file size changed to %d", fst.st_size);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
pass();
|
||||
return 0;
|
||||
|
||||
failed:
|
||||
unlink(link_name);
|
||||
failed0:
|
||||
unlink(filename);
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue