[CRIU] [PATCH 2/3] fsnotify: dump tmpfs notify watchers by names (v2)
Andrey Vagin
avagin at openvz.org
Mon Feb 24 07:15:04 PST 2014
Currently file handles are used for dumping {i,fs}notify watchers.
But inode numbers are not restored for tmpfs content, so watchers can't
be opened by handles.
Pavel found, that tmpfs cache is not pruned, so a handle can be opened,
and readlink(/proc/PID/fd/X) will return a corect path to the file.
v2: use read_fd_link()
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
fsnotify.c | 37 +++++++++++++++++++++++++++++++++++--
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/fsnotify.c b/fsnotify.c
index 3f5ef62..b1e1ed3 100644
--- a/fsnotify.c
+++ b/fsnotify.c
@@ -13,6 +13,7 @@
#include <sys/types.h>
#include <sys/inotify.h>
#include <sys/vfs.h>
+#include <linux/magic.h>
#include <sys/wait.h>
#include <sys/poll.h>
#include <sys/mman.h>
@@ -40,6 +41,7 @@
#include "protobuf.h"
#include "protobuf/fsnotify.pb-c.h"
+#include "protobuf/mnt.pb-c.h"
#undef LOG_PREFIX
#define LOG_PREFIX "fsnotify: "
@@ -127,13 +129,40 @@ out:
int check_open_handle(unsigned int s_dev, unsigned long i_ino,
FhEntry *f_handle)
{
- int fd;
+ int fd = -1;
char *path;
fd = open_handle(s_dev, i_ino, f_handle);
if (fd >= 0) {
- close(fd);
+ struct mount_info *mi;
+
pr_debug("\tHandle %x:%lx is openable\n", s_dev, i_ino);
+
+ mi = lookup_mnt_sdev(s_dev);
+ if (mi == NULL) {
+ pr_err("Unable to lookup a mount by dev %x\n", s_dev);
+ goto err;
+ }
+
+ /*
+ * Inode numbers are not restored for tmpfs content, but we can
+ * get file names, becasue tmpfs cache is not pruned.
+ */
+ if (mi->fstype->code == FSTYPE__TMPFS) {
+ char p[PATH_MAX];
+
+ if (read_fd_link(fd, p, sizeof(p)) < 0)
+ goto err;
+ close_safe(&fd);
+
+ path = xstrdup(p);
+ if (path == NULL)
+ return -1;
+
+ goto out;
+ }
+
+ close(fd);
return 0;
}
@@ -144,9 +173,13 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
return -1;
}
+out:
pr_debug("\tDumping %s as path for handle\n", path);
f_handle->path = path;
return 0;
+err:
+ close_safe(&fd);
+ return -1;
}
static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
--
1.8.3.1
More information about the CRIU
mailing list