Commit 3a86ee36 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fsnotify: Check on dump that file handle can be opened

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.
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 47c60a92
...@@ -123,6 +123,22 @@ out: ...@@ -123,6 +123,22 @@ out:
return fd; 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) static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
{ {
InotifyWdEntry *we = &e->ify; InotifyWdEntry *we = &e->ify;
...@@ -133,6 +149,10 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg) ...@@ -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", 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->bytes, we->f_handle->type,
we->f_handle->handle[0], we->f_handle->handle[1]); 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); 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) ...@@ -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", 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->bytes, fme->ie->f_handle->type,
fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]); 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) { if (fme->type == MARK_TYPE__MOUNT) {
......
...@@ -74,8 +74,18 @@ int open_mount(unsigned int s_dev) ...@@ -74,8 +74,18 @@ int open_mount(unsigned int s_dev)
struct mount_info *i; struct mount_info *i;
for (i = mntinfo; i != NULL; i = i->next) for (i = mntinfo; i != NULL; i = i->next)
if (s_dev == i->s_dev) if (s_dev == i->s_dev) {
return open(i->mountpoint, O_RDONLY); 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; return -ENOENT;
} }
......
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