[CRIU] [PATCH 2/2] inotify: Use fast way of obtaining desired watch descriptor number

Kirill Tkhai ktkhai at virtuozzo.com
Wed Feb 14 18:37:18 MSK 2018


This patch makes restore_one_inotify() to request specific
watch descriptor number instead of iterating in (possible)
long-duration loop if system supports it.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/fsnotify.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/criu/fsnotify.c b/criu/fsnotify.c
index 5fb26d0e9..73dae3938 100644
--- a/criu/fsnotify.c
+++ b/criu/fsnotify.c
@@ -35,6 +35,7 @@
 #include "files-reg.h"
 #include "file-ids.h"
 #include "criu-log.h"
+#include "kerndat.h"
 #include "common/list.h"
 #include "common/lock.h"
 #include "irmap.h"
@@ -569,11 +570,13 @@ static int restore_one_inotify(int inotify_fd, struct fsnotify_mark_info *info)
 			iwe->mask, mask);
 	}
 
-	/*
-	 * FIXME The kernel allocates wd-s sequentially,
-	 * this is suboptimal, but the kernel doesn't
-	 * provide and API for this yet :(
-	 */
+	if (kdat.has_inotify_setnextwd) {
+		if (ioctl(inotify_fd, INOTIFY_IOC_SETNEXTWD, iwe->wd)) {
+			pr_perror("Can't set next inotify wd");
+			return -1;
+		}
+	}
+
 	while (1) {
 		int wd;
 
@@ -589,6 +592,9 @@ static int restore_one_inotify(int inotify_fd, struct fsnotify_mark_info *info)
 			break;
 		}
 
+		if (kdat.has_inotify_setnextwd)
+			return -1;
+
 		inotify_rm_watch(inotify_fd, wd);
 	}
 



More information about the CRIU mailing list