[CRIU] [PATCH v2] fsnotify: Filter out internal inotify bits when restoring marks

Cyrill Gorcunov gorcunov at gmail.com
Mon Oct 12 10:19:27 PDT 2015


On Mon, Oct 12, 2015 at 02:06:33PM +0300, Pavel Emelyanov wrote:
> 
> If this bit becomes valid we'll notice it via warning and take actions.
> If we simply filter those out, as you propose, we'll miss it.

Attached
-------------- next part --------------
>From 4e7caff29d1e14146d0f58b0dd871ee440c26b50 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Mon, 12 Oct 2015 20:18:07 +0300
Subject: [PATCH] fsnotify: Filter out internal inotify bits when restoring
 marks

The kernel prior 4.3 is exporting FS_EVENT_ON_CHILD
bit via procfs fdinfo interface. This bit is kernel's
internal and should not be passed in inotify_add_watch
call. Thus simply filter it out when obtain from old
images for backward compatibility reason.

More details here https://lkml.org/lkml/2015/9/21/680

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 fsnotify.c         | 14 ++++++++++++++
 include/fsnotify.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/fsnotify.c b/fsnotify.c
index 024553f1c8e0..cbf9c4dc293b 100644
--- a/fsnotify.c
+++ b/fsnotify.c
@@ -223,6 +223,10 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
 			we->f_handle->bytes, we->f_handle->type,
 			we->f_handle->handle[0], we->f_handle->handle[1]);
 
+	if (we->mask & KERNEL_FS_EVENT_ON_CHILD)
+		pr_warn_once("\t\tDetected FS_EVENT_ON_CHILD bit "
+			     "in mask (will be ignored on restore)\n");
+
 	if (check_open_handle(we->s_dev, we->i_ino, we->f_handle)) {
 		free_inotify_wd_entry(e);
 		return -1;
@@ -813,6 +817,16 @@ static int collect_one_inotify_mark(void *o, ProtobufCMessage *msg)
 	INIT_LIST_HEAD(&mark->list);
 	mark->remap = NULL;
 
+	/*
+	 * The kernel prior 4.3 might export internal event
+	 * mask bits which are not part of user-space API. It
+	 * is fixed in kernel but we have to keep backward
+	 * compatibility with old images. So mask out
+	 * inappropriate bits (in particular fdinfo might
+	 * have FS_EVENT_ON_CHILD bit set).
+	 */
+	mark->iwe->mask &= ~KERNEL_FS_EVENT_ON_CHILD;
+
 	return collect_inotify_mark(mark);
 }
 
diff --git a/include/fsnotify.h b/include/fsnotify.h
index 3fd5307e092e..48e3982cf7aa 100644
--- a/include/fsnotify.h
+++ b/include/fsnotify.h
@@ -7,6 +7,8 @@
 #include "protobuf.h"
 #include "protobuf/fsnotify.pb-c.h"
 
+#define KERNEL_FS_EVENT_ON_CHILD 0x08000000
+
 struct fsnotify_params {
 	u32	faflags;
 	u32	evflags;
-- 
2.4.3



More information about the CRIU mailing list