[CRIU] [PATCH 2/4] fsnotify: Check on dump that file handle can be opened

Pavel Emelyanov xemul at parallels.com
Tue Jan 28 10:53:29 PST 2014


Some filesystems do not provide open-by-handle functionality. For those,
we should abort fsnotifies dumping, not restoring.

The open_mount() changes are about opening mountpoints inside another
mount namespace.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 fsnotify.c | 23 +++++++++++++++++++++++
 mount.c    | 14 ++++++++++++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/fsnotify.c b/fsnotify.c
index 6b8dce4..e7af866 100644
--- a/fsnotify.c
+++ b/fsnotify.c
@@ -123,6 +123,22 @@ out:
 	return fd;
 }
 
+static int check_open_handle(unsigned int s_dev, unsigned long i_ino,
+		FhEntry *f_handle)
+{
+	int fd;
+
+	fd = open_handle(s_dev, i_ino, f_handle);
+	if (fd >= 0) {
+		close(fd);
+		pr_debug("\tHandle %x:%lx is openable\n", s_dev, i_ino);
+		return 0;
+	}
+
+	pr_err("\tHandle %x:%lx cannot be opened\n", s_dev, i_ino);
+	return -1;
+}
+
 static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
 {
 	InotifyWdEntry *we = &e->ify;
@@ -133,6 +149,10 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
 	pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
 			we->f_handle->bytes, we->f_handle->type,
 			we->f_handle->handle[0], we->f_handle->handle[1]);
+
+	if (check_open_handle(we->s_dev, we->i_ino, we->f_handle))
+		return -1;
+
 	return pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD);
 }
 
@@ -173,6 +193,9 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
 		pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
 			fme->ie->f_handle->bytes, fme->ie->f_handle->type,
 			fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]);
+
+		if (check_open_handle(fme->s_dev, fme->ie->i_ino, fme->ie->f_handle))
+			return -1;
 	}
 
 	if (fme->type == MARK_TYPE__MOUNT) {
diff --git a/mount.c b/mount.c
index c136c7f..3d72521 100644
--- a/mount.c
+++ b/mount.c
@@ -74,8 +74,18 @@ int open_mount(unsigned int s_dev)
 	struct mount_info *i;
 
 	for (i = mntinfo; i != NULL; i = i->next)
-		if (s_dev == i->s_dev)
-			return open(i->mountpoint, O_RDONLY);
+		if (s_dev == i->s_dev) {
+			if (mntns_root == -1) {
+				pr_debug("mpopen %s\n", i->mountpoint);
+				return open(i->mountpoint, O_RDONLY);
+			} else if (i->mountpoint[1] == '\0') {
+				pr_debug("mpopen root\n");
+				return dup(mntns_root);
+			} else {
+				pr_debug("mpopen %d:%s\n", mntns_root, i->mountpoint + 1);
+				return openat(mntns_root, i->mountpoint + 1, O_RDONLY);
+			}
+		}
 
 	return -ENOENT;
 }
-- 
1.8.4.2


More information about the CRIU mailing list