Commit deb61cdb authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

fsnotify: dump tmpfs notify watchers by names (v2)

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 06662f9f
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/inotify.h> #include <sys/inotify.h>
#include <sys/vfs.h> #include <sys/vfs.h>
#include <linux/magic.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/mman.h> #include <sys/mman.h>
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#include "protobuf.h" #include "protobuf.h"
#include "protobuf/fsnotify.pb-c.h" #include "protobuf/fsnotify.pb-c.h"
#include "protobuf/mnt.pb-c.h"
#undef LOG_PREFIX #undef LOG_PREFIX
#define LOG_PREFIX "fsnotify: " #define LOG_PREFIX "fsnotify: "
...@@ -129,13 +131,40 @@ out: ...@@ -129,13 +131,40 @@ out:
int check_open_handle(unsigned int s_dev, unsigned long i_ino, int check_open_handle(unsigned int s_dev, unsigned long i_ino,
FhEntry *f_handle) FhEntry *f_handle)
{ {
int fd; int fd = -1;
char *path; char *path;
fd = open_handle(s_dev, i_ino, f_handle); fd = open_handle(s_dev, i_ino, f_handle);
if (fd >= 0) { if (fd >= 0) {
close(fd); struct mount_info *mi;
pr_debug("\tHandle %x:%lx is openable\n", s_dev, i_ino); 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; return 0;
} }
...@@ -146,9 +175,13 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino, ...@@ -146,9 +175,13 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
return -1; return -1;
} }
out:
pr_debug("\tDumping %s as path for handle\n", path); pr_debug("\tDumping %s as path for handle\n", path);
f_handle->path = path; f_handle->path = path;
return 0; return 0;
err:
close_safe(&fd);
return -1;
} }
static int dump_inotify_entry(union fdinfo_entries *e, void *arg) static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment