Commit 7079bb10 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

fsnotify: parse_fdinfo_pid_s() returns allocated object for inotify wd (v2)

We are going to collect all objects in a list and write them into
the inotify image. The inotify wd image will be depricated.

v2: cb() must always free an entry
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c716f6b8
...@@ -353,7 +353,8 @@ pipe_err: ...@@ -353,7 +353,8 @@ pipe_err:
static int check_one_inotify(union fdinfo_entries *e, void *arg) static int check_one_inotify(union fdinfo_entries *e, void *arg)
{ {
*(int *)arg = e->ify.wd; *(int *)arg = e->ify.e.wd;
free_inotify_wd_entry(e);
return 0; return 0;
} }
......
...@@ -199,7 +199,8 @@ err: ...@@ -199,7 +199,8 @@ err:
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.e;
int ret = -1;
we->id = *(u32 *)arg; we->id = *(u32 *)arg;
pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n", pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n",
...@@ -209,9 +210,13 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg) ...@@ -209,9 +210,13 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
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)) if (check_open_handle(we->s_dev, we->i_ino, we->f_handle))
return -1; goto out;
return pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD); if (pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD))
goto out;
out:
free_inotify_wd_entry(e);
return ret;
} }
static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p) static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
...@@ -231,8 +236,13 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p) ...@@ -231,8 +236,13 @@ static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
static int pre_dump_inotify_entry(union fdinfo_entries *e, void *arg) static int pre_dump_inotify_entry(union fdinfo_entries *e, void *arg)
{ {
InotifyWdEntry *we = &e->ify; InotifyWdEntry *we = &e->ify.e;
return irmap_queue_cache(we->s_dev, we->i_ino, we->f_handle); int ret;
ret = irmap_queue_cache(we->s_dev, we->i_ino, we->f_handle);
free_inotify_wd_entry(e);
return ret;
} }
static int pre_dump_one_inotify(int pid, int lfd) static int pre_dump_one_inotify(int pid, int lfd)
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "asm/types.h" #include "asm/types.h"
#include "files.h" #include "files.h"
#include "protobuf.h"
#include "protobuf/fsnotify.pb-c.h"
struct fsnotify_params { struct fsnotify_params {
u32 id; u32 id;
u32 faflags; u32 faflags;
......
...@@ -166,15 +166,23 @@ extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_m ...@@ -166,15 +166,23 @@ extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_m
extern int parse_self_maps_lite(struct vm_area_list *vms); extern int parse_self_maps_lite(struct vm_area_list *vms);
extern int parse_pid_status(pid_t pid, struct proc_status_creds *); extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
struct inotify_wd_entry {
InotifyWdEntry e;
FhEntry f_handle;
struct list_head node;
};
union fdinfo_entries { union fdinfo_entries {
EventfdFileEntry efd; EventfdFileEntry efd;
EventpollTfdEntry epl; EventpollTfdEntry epl;
SignalfdEntry sfd; SignalfdEntry sfd;
InotifyWdEntry ify; struct inotify_wd_entry ify;
FanotifyMarkEntry ffy; FanotifyMarkEntry ffy;
TimerfdEntry tfy; TimerfdEntry tfy;
}; };
extern void free_inotify_wd_entry(union fdinfo_entries *e);
struct fdinfo_common { struct fdinfo_common {
off64_t pos; off64_t pos;
int flags; int flags;
......
...@@ -1038,6 +1038,12 @@ static void free_fhandle(FhEntry *fh) ...@@ -1038,6 +1038,12 @@ static void free_fhandle(FhEntry *fh)
xfree(fh->handle); xfree(fh->handle);
} }
void free_inotify_wd_entry(union fdinfo_entries *e)
{
free_fhandle(e->ify.e.f_handle);
xfree(e);
}
static void parse_fhandle_encoded(char *tok, FhEntry *fh) static void parse_fhandle_encoded(char *tok, FhEntry *fh)
{ {
char *d = (char *)fh->handle; char *d = (char *)fh->handle;
...@@ -1290,36 +1296,45 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type, ...@@ -1290,36 +1296,45 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type,
continue; continue;
} }
if (fdinfo_field(str, "inotify wd")) { if (fdinfo_field(str, "inotify wd")) {
FhEntry f_handle = FH_ENTRY__INIT; InotifyWdEntry *ify;
union fdinfo_entries *e;
int hoff; int hoff;
inotify_wd_entry__init(&entry.ify);
entry.ify.f_handle = &f_handle;
if (type != FD_TYPES__INOTIFY) if (type != FD_TYPES__INOTIFY)
goto parse_err; goto parse_err;
e = xmalloc(sizeof(*e));
if (!e)
goto parse_err;
ify = &e->ify.e;
inotify_wd_entry__init(ify);
ify->f_handle = &e->ify.f_handle;
fh_entry__init(ify->f_handle);
ret = sscanf(str, ret = sscanf(str,
"inotify wd:%x ino:%"PRIx64" sdev:%x " "inotify wd:%x ino:%"PRIx64" sdev:%x "
"mask:%x ignored_mask:%x " "mask:%x ignored_mask:%x "
"fhandle-bytes:%x fhandle-type:%x " "fhandle-bytes:%x fhandle-type:%x "
"f_handle: %n", "f_handle: %n",
&entry.ify.wd, &entry.ify.i_ino, &entry.ify.s_dev, &ify->wd, &ify->i_ino, &ify->s_dev,
&entry.ify.mask, &entry.ify.ignored_mask, &ify->mask, &ify->ignored_mask,
&entry.ify.f_handle->bytes, &entry.ify.f_handle->type, &ify->f_handle->bytes, &ify->f_handle->type,
&hoff); &hoff);
if (ret != 7) if (ret != 7) {
free_inotify_wd_entry(e);
goto parse_err; goto parse_err;
}
if (alloc_fhandle(&f_handle)) { if (alloc_fhandle(ify->f_handle)) {
free_inotify_wd_entry(e);
ret = -1; ret = -1;
goto out; goto out;
} }
parse_fhandle_encoded(str + hoff, entry.ify.f_handle); parse_fhandle_encoded(str + hoff, ify->f_handle);
ret = cb(&entry, arg); ret = cb(e, arg);
free_fhandle(&f_handle);
if (ret) if (ret)
goto out; goto out;
......
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