Commit 78a54bd8 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

fsnotify: parse_fdinfo_pid_s() returns allocated object for fanotify marks

We are going to collect all objects in a list and write them into
the fanotify image. The fanotify mark image will be depricated.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 7079bb10
...@@ -259,7 +259,8 @@ const struct fdtype_ops inotify_dump_ops = { ...@@ -259,7 +259,8 @@ const struct fdtype_ops inotify_dump_ops = {
static int dump_fanotify_entry(union fdinfo_entries *e, void *arg) static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
{ {
struct fsnotify_params *fsn_params = arg; struct fsnotify_params *fsn_params = arg;
FanotifyMarkEntry *fme = &e->ffy; FanotifyMarkEntry *fme = &e->ffy.e;
int ret = -1;
fme->id = fsn_params->id; fme->id = fsn_params->id;
...@@ -275,7 +276,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg) ...@@ -275,7 +276,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
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)) if (check_open_handle(fme->s_dev, fme->ie->i_ino, fme->ie->f_handle))
return -1; goto out;
} }
if (fme->type == MARK_TYPE__MOUNT) { if (fme->type == MARK_TYPE__MOUNT) {
...@@ -286,7 +287,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg) ...@@ -286,7 +287,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
m = lookup_mnt_id(fme->me->mnt_id); m = lookup_mnt_id(fme->me->mnt_id);
if (!m) { if (!m) {
pr_err("Can't find mnt_id %x\n", fme->me->mnt_id); pr_err("Can't find mnt_id %x\n", fme->me->mnt_id);
return -1; goto out;
} }
fme->s_dev = m->s_dev; fme->s_dev = m->s_dev;
...@@ -295,13 +296,18 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg) ...@@ -295,13 +296,18 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
} }
return pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY_MARK), fme, PB_FANOTIFY_MARK); ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY_MARK), fme, PB_FANOTIFY_MARK);
out:
free_fanotify_mark_entry(e);
return ret;
} }
static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p) static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p)
{ {
FanotifyFileEntry fe = FANOTIFY_FILE_ENTRY__INIT; FanotifyFileEntry fe = FANOTIFY_FILE_ENTRY__INIT;
struct fsnotify_params fsn_params = { .id = id, }; struct fsnotify_params fsn_params = { .id = id, };
int ret;
fe.id = id; fe.id = id;
fe.flags = p->flags; fe.flags = p->flags;
...@@ -316,18 +322,22 @@ static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p) ...@@ -316,18 +322,22 @@ static int dump_one_fanotify(int lfd, u32 id, const struct fd_parms *p)
fe.faflags = fsn_params.faflags; fe.faflags = fsn_params.faflags;
fe.evflags = fsn_params.evflags; fe.evflags = fsn_params.evflags;
return pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY_FILE), &fe, PB_FANOTIFY_FILE); ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY_FILE), &fe, PB_FANOTIFY_FILE);
return ret;
} }
static int pre_dump_fanotify_entry(union fdinfo_entries *e, void *arg) static int pre_dump_fanotify_entry(union fdinfo_entries *e, void *arg)
{ {
FanotifyMarkEntry *fme = &e->ffy; FanotifyMarkEntry *fme = &e->ffy.e;
int ret = 0;
if (fme->type == MARK_TYPE__INODE) if (fme->type == MARK_TYPE__INODE)
return irmap_queue_cache(fme->s_dev, fme->ie->i_ino, ret = irmap_queue_cache(fme->s_dev, fme->ie->i_ino,
fme->ie->f_handle); fme->ie->f_handle);
else
return 0; free_fanotify_mark_entry(e);
return ret;
} }
static int pre_dump_one_fanotify(int pid, int lfd) static int pre_dump_one_fanotify(int pid, int lfd)
......
...@@ -172,16 +172,27 @@ struct inotify_wd_entry { ...@@ -172,16 +172,27 @@ struct inotify_wd_entry {
struct list_head node; struct list_head node;
}; };
struct fanotify_mark_entry {
FanotifyMarkEntry e;
FhEntry f_handle;
struct list_head node;
union {
FanotifyInodeMarkEntry ie;
FanotifyMountMarkEntry me;
};
};
union fdinfo_entries { union fdinfo_entries {
EventfdFileEntry efd; EventfdFileEntry efd;
EventpollTfdEntry epl; EventpollTfdEntry epl;
SignalfdEntry sfd; SignalfdEntry sfd;
struct inotify_wd_entry ify; struct inotify_wd_entry ify;
FanotifyMarkEntry ffy; struct fanotify_mark_entry ffy;
TimerfdEntry tfy; TimerfdEntry tfy;
}; };
extern void free_inotify_wd_entry(union fdinfo_entries *e); extern void free_inotify_wd_entry(union fdinfo_entries *e);
extern void free_fanotify_mark_entry(union fdinfo_entries *e);
struct fdinfo_common { struct fdinfo_common {
off64_t pos; off64_t pos;
......
...@@ -1044,6 +1044,13 @@ void free_inotify_wd_entry(union fdinfo_entries *e) ...@@ -1044,6 +1044,13 @@ void free_inotify_wd_entry(union fdinfo_entries *e)
xfree(e); xfree(e);
} }
void free_fanotify_mark_entry(union fdinfo_entries *e)
{
if (e->ffy.e.ie)
free_fhandle(e->ffy.ie.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;
...@@ -1233,37 +1240,44 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type, ...@@ -1233,37 +1240,44 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type,
continue; continue;
} }
if (fdinfo_field(str, "fanotify ino")) { if (fdinfo_field(str, "fanotify ino")) {
FanotifyInodeMarkEntry ie = FANOTIFY_INODE_MARK_ENTRY__INIT; union fdinfo_entries *e;
FhEntry f_handle = FH_ENTRY__INIT;
int hoff = 0; int hoff = 0;
if (type != FD_TYPES__FANOTIFY) if (type != FD_TYPES__FANOTIFY)
goto parse_err; goto parse_err;
fanotify_mark_entry__init(&entry.ffy); e = xmalloc(sizeof(*e));
ie.f_handle = &f_handle; if (!e)
entry.ffy.ie = &ie; goto parse_err;
fanotify_mark_entry__init(&e->ffy.e);
fanotify_inode_mark_entry__init(&e->ffy.ie);
fh_entry__init(&e->ffy.f_handle);
e->ffy.e.ie = &e->ffy.ie;
e->ffy.ie.f_handle = &e->ffy.f_handle;
ret = sscanf(str, ret = sscanf(str,
"fanotify ino:%"PRIx64" sdev:%x mflags:%x mask:%x ignored_mask:%x " "fanotify ino:%"PRIx64" sdev:%x mflags:%x mask:%x ignored_mask:%x "
"fhandle-bytes:%x fhandle-type:%x f_handle: %n", "fhandle-bytes:%x fhandle-type:%x f_handle: %n",
&ie.i_ino, &entry.ffy.s_dev, &e->ffy.ie.i_ino, &e->ffy.e.s_dev,
&entry.ffy.mflags, &entry.ffy.mask, &entry.ffy.ignored_mask, &e->ffy.e.mflags, &e->ffy.e.mask, &e->ffy.e.ignored_mask,
&f_handle.bytes, &f_handle.type, &e->ffy.f_handle.bytes, &e->ffy.f_handle.type,
&hoff); &hoff);
if (ret != 7 || hoff == 0) if (ret != 7 || hoff == 0) {
free_fanotify_mark_entry(e);
goto parse_err; goto parse_err;
}
if (alloc_fhandle(&f_handle)) { if (alloc_fhandle(&e->ffy.f_handle)) {
free_fanotify_mark_entry(e);
ret = -1; ret = -1;
goto out; goto out;
} }
parse_fhandle_encoded(str + hoff, &f_handle); parse_fhandle_encoded(str + hoff, &e->ffy.f_handle);
entry.ffy.type = MARK_TYPE__INODE; e->ffy.e.type = MARK_TYPE__INODE;
ret = cb(&entry, arg); ret = cb(e, arg);
free_fhandle(&f_handle);
if (ret) if (ret)
goto out; goto out;
...@@ -1272,23 +1286,28 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type, ...@@ -1272,23 +1286,28 @@ static int parse_fdinfo_pid_s(char *pid, int fd, int type,
continue; continue;
} }
if (fdinfo_field(str, "fanotify mnt_id")) { if (fdinfo_field(str, "fanotify mnt_id")) {
FanotifyMountMarkEntry me = FANOTIFY_MOUNT_MARK_ENTRY__INIT; union fdinfo_entries *e;
if (type != FD_TYPES__FANOTIFY) if (type != FD_TYPES__FANOTIFY)
goto parse_err; goto parse_err;
fanotify_mark_entry__init(&entry.ffy); e = xmalloc(sizeof(*e));
entry.ffy.me = &me; if (!e)
goto parse_err;
fanotify_mark_entry__init(&e->ffy.e);
fanotify_mount_mark_entry__init(&e->ffy.me);
e->ffy.e.me = &e->ffy.me;
ret = sscanf(str, ret = sscanf(str,
"fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x", "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x",
&me.mnt_id, &entry.ffy.mflags, &e->ffy.e.me->mnt_id, &e->ffy.e.mflags,
&entry.ffy.mask, &entry.ffy.ignored_mask); &e->ffy.e.mask, &e->ffy.e.ignored_mask);
if (ret != 4) if (ret != 4)
goto parse_err; goto parse_err;
entry.ffy.type = MARK_TYPE__MOUNT; e->ffy.e.type = MARK_TYPE__MOUNT;
ret = cb(&entry, arg); ret = cb(e, arg);
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