[CRIU] [PATCH 1/2] kdat: Add check for inotify() INOTIFY_IOC_SETNEXTWD cmd
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Feb 14 18:37:10 MSK 2018
This is a new ioctl, which allows to request next descriptor
allocated by inotify_add_watch().
https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git/commit/?h=for_next&id=e1603b6effe177210701d3d7132d1b68e7bd2c93
The patch checks this cmd is supported by kernel.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/include/fsnotify.h | 4 ++++
criu/include/kerndat.h | 1 +
criu/kerndat.c | 28 ++++++++++++++++++++++++++++
3 files changed, 33 insertions(+)
diff --git a/criu/include/fsnotify.h b/criu/include/fsnotify.h
index 7bf5af455..935dd60f4 100644
--- a/criu/include/fsnotify.h
+++ b/criu/include/fsnotify.h
@@ -8,6 +8,10 @@
#define KERNEL_FS_EVENT_ON_CHILD 0x08000000
+#ifndef INOTIFY_IOC_SETNEXTWD
+#define INOTIFY_IOC_SETNEXTWD _IOW('I', 0, __s32)
+#endif
+
extern int is_inotify_link(char *link);
extern int is_fanotify_link(char *link);
extern const struct fdtype_ops inotify_dump_ops;
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index 9e7af14a3..db03eb86f 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -73,6 +73,7 @@ struct kerndat_s {
unsigned long files_stat_max_files;
bool has_pid_for_children_ns;
bool x86_has_ptrace_fpu_xsave_bug;
+ bool has_inotify_setnextwd;
};
extern struct kerndat_s kdat;
diff --git a/criu/kerndat.c b/criu/kerndat.c
index cea2e3348..d0d06e3a0 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -12,6 +12,8 @@
#include <sys/socket.h>
#include <arpa/inet.h> /* for sockaddr_in and inet_ntoa() */
#include <sys/prctl.h>
+#include <sys/inotify.h>
+
#include "common/config.h"
#include "int.h"
@@ -32,6 +34,7 @@
#include <compel/plugins/std/syscall-codes.h>
#include <compel/compel.h>
#include "netfilter.h"
+#include "fsnotify.h"
#include "linux/userfaultfd.h"
#include "prctl.h"
#include "uffd.h"
@@ -792,6 +795,29 @@ int kerndat_has_pid_for_children_ns(void)
return 0;
}
+int kerndat_has_inotify_setnextwd(void)
+{
+ int ret = 0;
+ int fd;
+
+ fd = inotify_init();
+ if (fd < 0) {
+ pr_perror("Can't create inotify");
+ return -1;
+ }
+
+ if (ioctl(fd, INOTIFY_IOC_SETNEXTWD, 0x10)) {
+ if (errno != ENOTTY) {
+ pr_perror("Can't call ioctl");
+ ret = -1;
+ }
+ } else
+ kdat.has_inotify_setnextwd = true;
+
+ close(fd);
+ return ret;
+}
+
int __attribute__((weak)) kdat_x86_has_ptrace_fpu_xsave_bug(void)
{
return 0;
@@ -1077,6 +1103,8 @@ int kerndat_init(void)
ret = kerndat_has_pid_for_children_ns();
if (!ret)
ret = kerndat_x86_has_ptrace_fpu_xsave_bug();
+ if (!ret)
+ ret = kerndat_has_inotify_setnextwd();
kerndat_lsm();
kerndat_mmap_min_addr();
More information about the CRIU
mailing list