2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 05:48:05 +00:00

test: Add inotify02

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@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Cyrill Gorcunov 2015-10-21 10:28:00 +03:00 committed by Pavel Emelyanov
parent 7ba43a5521
commit 2a25092152
3 changed files with 103 additions and 0 deletions

View File

@ -100,6 +100,7 @@ generate_test_list()
static/eventfs00
static/signalfd00
static/inotify00
static/inotify02
static/inotify_irmap
static/fanotify00
static/unbound_sock

View File

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

View File

@ -0,0 +1 @@
{'flags': 'noauto'}