[CRIU] [PATCH 3/3] zdtm: emulate a situation with invalid files in irmap cache
Andrey Vagin
avagin at openvz.org
Wed Mar 16 11:22:11 PDT 2016
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
test/zdtm/static/inotify_irmap.c | 50 +++++++++++++++++++++----------------
test/zdtm/static/inotify_irmap.desc | 2 +-
test/zdtm/static/inotify_irmap.hook | 18 +++++++++++++
3 files changed, 48 insertions(+), 22 deletions(-)
create mode 100755 test/zdtm/static/inotify_irmap.hook
diff --git a/test/zdtm/static/inotify_irmap.c b/test/zdtm/static/inotify_irmap.c
index e16a418..8722010 100644
--- a/test/zdtm/static/inotify_irmap.c
+++ b/test/zdtm/static/inotify_irmap.c
@@ -19,51 +19,59 @@ const char *test_doc = "Check for irmap";
const char *test_author = "Pavel Emelyanov <xemul at parallels.com>";
#define TDIR "/etc"
-#define TFIL TDIR"/zdtm-test"
+char test_files[2][128] = {TDIR"/zdtm-test", TDIR"/zdtm-test1"};
#define BUFF_SIZE ((sizeof(struct inotify_event) + PATH_MAX))
int main (int argc, char *argv[])
{
char buf[BUFF_SIZE];
- int fd, wd;
+ int fd, wd, i;
test_init(argc, argv);
- unlink(TFIL);
- if (creat(TFIL, 0600) < 0) {
- pr_perror("Can't make test file");
- exit(1);
+ for (i = 0; i < 2; i++) {
+ unlink(test_files[i]);
+ if (creat(test_files[i], 0600) < 0) {
+ pr_perror("Can't make test file");
+ exit(1);
+ }
}
fd = inotify_init1(IN_NONBLOCK);
if (fd < 0) {
- fail("inotify_init failed");
- unlink(TFIL);
- exit(1);
+ pr_perror("inotify_init failed");
+ goto err;
}
- wd = inotify_add_watch(fd, TFIL, IN_OPEN);
- if (wd < 0) {
- fail("inotify_add_watch failed");
- unlink(TFIL);
- exit(1);
+ for (i = 0; i < 2; i++) {
+ wd = inotify_add_watch(fd, test_files[i], IN_OPEN);
+ if (wd < 0) {
+ pr_perror("inotify_add_watch failed");
+ goto err;
+ }
}
test_daemon();
test_waitsig();
- memset(buf, 0, sizeof(buf));
- wd = open(TFIL, O_RDONLY);
- if (read(fd, buf, sizeof(buf)) <= 0) {
- unlink(TFIL);
- fail("No events in queue");
- exit(1);
+ for (i = 0; i < 2; i++) {
+ memset(buf, 0, sizeof(buf));
+ wd = open(test_files[i], O_RDONLY);
+ if (read(fd, buf, sizeof(buf)) <= 0) {
+ fail("No events in queue");
+ goto err;
+ }
}
close(wd);
close(fd);
- unlink(TFIL);
+ for (i = 0; i < 2; i++)
+ unlink(test_files[i]);
pass();
return 0;
+err:
+ for (i = 0; i < 2; i++)
+ unlink(test_files[i]);
+ return 1;
}
diff --git a/test/zdtm/static/inotify_irmap.desc b/test/zdtm/static/inotify_irmap.desc
index 9c5994e..525a4a6 100644
--- a/test/zdtm/static/inotify_irmap.desc
+++ b/test/zdtm/static/inotify_irmap.desc
@@ -1 +1 @@
-{'flags': 'suid', 'opts' : '--force-irmap'}
+{'flags': 'suid', 'opts' : '--force-irmap --irmap-scan-path /zdtm/static'}
diff --git a/test/zdtm/static/inotify_irmap.hook b/test/zdtm/static/inotify_irmap.hook
new file mode 100755
index 0000000..eca6bfa
--- /dev/null
+++ b/test/zdtm/static/inotify_irmap.hook
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+umask 0000
+
+[ "$1" == "--pre-restore" ] && {
+ # emulate rsync
+ rm -rf etc/zdtm-test
+ touch etc/zdtm-test
+}
+
+[ "$1" == "--post-pre-dump" ] && {
+ echo 'invalidate the irmap cache'
+ mv etc/zdtm-test etc/zdtm-test2
+ mv etc/zdtm-test1 etc/zdtm-test
+ mv etc/zdtm-test2 etc/zdtm-test1
+}
+
+exit 0
--
2.5.0
More information about the CRIU
mailing list