[CRIU] [PATCH] test: Add inotify02
Cyrill Gorcunov
gorcunov at openvz.org
Wed Oct 21 00:28:56 PDT 2015
Its only purpose if to verify that we can show up
a huge number of inotify in fdoutput (before
the kernel v3.18-rc1-7-ga3816ab we can show
only handles which fit page size in summary).
In particular we revealed that hald daemon makes
up to 35 notification marks which kernel can't
show up in a one pass and dump fails.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
test/zdtm.sh | 1 +
test/zdtm/live/static/inotify02.c | 101 +++++++++++++++++++++++++++++++++++
test/zdtm/live/static/inotify02.desc | 1 +
3 files changed, 103 insertions(+)
create mode 100644 test/zdtm/live/static/inotify02.c
create mode 100644 test/zdtm/live/static/inotify02.desc
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 25e27ade786e..691e041d279a 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -100,6 +100,7 @@ generate_test_list()
static/eventfs00
static/signalfd00
static/inotify00
+ static/inotify02
static/inotify_irmap
static/fanotify00
static/unbound_sock
diff --git a/test/zdtm/live/static/inotify02.c b/test/zdtm/live/static/inotify02.c
new file mode 100644
index 000000000000..9e2c5f76c1bf
--- /dev/null
+++ b/test/zdtm/live/static/inotify02.c
@@ -0,0 +1,101 @@
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include <limits.h>
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/inotify.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <signal.h>
+#include <sched.h>
+#include <sys/mount.h>
+#include <sys/prctl.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc = "Check for inotify file-handles storm";
+const char *test_author = "Cyrill Gorcunov <gorcunov at openvz.org>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "directory name", 1);
+
+static int num_of_handles(int fd)
+{
+ char path[64];
+ char buf[512];
+ int ret = 0;
+ FILE *f;
+
+ snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
+ f = fopen(path, "r");
+ if (!f) {
+ err("Can't open %s", path);
+ return -1;
+ }
+
+ while (fgets(buf, sizeof(buf), f)) {
+ if (memcmp(buf, "inotify ", 8))
+ continue;
+ ret++;
+ }
+
+ fclose(f);
+ return ret;
+}
+
+int main (int argc, char *argv[])
+{
+ const unsigned int mask = IN_DELETE | IN_CLOSE_WRITE | IN_DELETE_SELF | IN_CREATE;
+ const int nr_dirs = 64;
+ char temp[nr_dirs][16];
+ char path[PATH_MAX];
+ int fd, i;
+
+ test_init(argc, argv);
+
+ if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+ err("Can't create directory %s", dirname);
+ exit(1);
+ }
+
+ fd = inotify_init1(IN_NONBLOCK);
+ if (fd < 0) {
+ err("inotify_init failed");
+ exit(1);
+ }
+
+ for (i = 0; i < nr_dirs; i++) {
+ snprintf(temp[i], sizeof(temp[0]), "d.%03d", i);
+ snprintf(path, sizeof(path), "%s/%s", dirname, temp[i]);
+ if (mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
+ err("Can't create %s", path);
+ exit(1);
+ }
+
+ if (inotify_add_watch(fd, path, mask) < 0) {
+ err("inotify_add_watch failed on %s", path);
+ exit(1);
+ }
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ i = num_of_handles(fd);
+ close(fd);
+
+ if (i < nr_dirs)
+ fail("Expected %d handles but got %d", nr_dirs, i);
+ else
+ pass();
+
+ return 0;
+}
diff --git a/test/zdtm/live/static/inotify02.desc b/test/zdtm/live/static/inotify02.desc
new file mode 100644
index 000000000000..95c58b4018b3
--- /dev/null
+++ b/test/zdtm/live/static/inotify02.desc
@@ -0,0 +1 @@
+{'flags': 'noauto'}
--
2.4.3
More information about the CRIU
mailing list