[PATCH] fsnotify: fanotify -- Group objects in image
Cyrill Gorcunov
gorcunov at openvz.org
Tue Jan 15 10:17:22 EST 2013
As Pavel proposed we can refine fanotify image objects
squeezing common part in separate entry. Finally the objects
are grouped as
enum mark_type {
INODE = 1;
MOUNT = 2;
}
message fanotify_inode_mark_entry {
required uint64 i_ino = 1;
required fh_entry f_handle = 2;
}
message fanotify_mount_mark_entry {
required uint32 mnt_id = 1;
}
message fanotify_mark_entry {
required uint32 id = 1;
required mark_type type = 2;
required uint32 mflags = 3;
required uint32 mask = 4;
required uint32 ignored_mask = 5;
required uint32 s_dev = 6;
optional fanotify_inode_mark_entry ie = 7;
optional fanotify_mount_mark_entry me = 8;
}
This required some tuning in fdinfo parsing and
fsnotify code itself, but result looks good to me.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
fsnotify.c | 30 +++++++++++++++++++++---------
proc_parse.c | 17 ++++++++++-------
protobuf/fsnotify.proto | 22 +++++++++++++++-------
3 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/fsnotify.c b/fsnotify.c
index 0dff2f5..17c8296 100644
--- a/fsnotify.c
+++ b/fsnotify.c
@@ -142,23 +142,33 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
fme->id = fsn_params->id;
- pr_info("mark: s_dev 0x%08x i_ino 0x%016lx mask 0x%08x\n",
- fme->s_dev, fme->i_ino, fme->mask);
+ if (fme->type == MARK_TYPE__INODE) {
+
+ BUG_ON(!fme->ie);
+
+ pr_info("mark: s_dev 0x%08x i_ino 0x%016lx mask 0x%08x\n",
+ fme->s_dev, fme->ie->i_ino, fme->mask);
- if (fme->type == MARK_TYPE__INODE)
pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016lx:0x%016lx\n",
- fme->f_handle->bytes, fme->f_handle->type,
- fme->f_handle->handle[0], fme->f_handle->handle[1]);
+ fme->ie->f_handle->bytes, fme->ie->f_handle->type,
+ fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]);
+ }
if (fme->type == MARK_TYPE__MOUNT) {
struct mount_info *m;
- m = lookup_mnt_id(fme->mnt_id);
+ BUG_ON(!fme->me);
+
+ m = lookup_mnt_id(fme->me->mnt_id);
if (!m) {
- pr_err("Can't find mnt_id %x\n", fme->mnt_id);
+ pr_err("Can't find mnt_id %x\n", fme->me->mnt_id);
return -1;
}
fme->s_dev = m->s_dev;
+
+ pr_info("mark: s_dev 0x%08x mnt_id 0x%08x mask 0x%08x\n",
+ fme->s_dev, fme->me->mnt_id, fme->mask);
+
}
return pb_write_one(fdset_fd(glob_fdset, CR_FD_FANOTIFY_MARK), fme, PB_FANOTIFY_MARK);
@@ -304,7 +314,7 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark)
path = m->mountpoint;
} else if (fme->type == MARK_TYPE__INODE) {
path = get_mark_path("fanotify", mark->remap,
- fme->f_handle, fme->i_ino,
+ fme->ie->f_handle, fme->ie->i_ino,
fme->s_dev, buf, sizeof(buf), &target);
if (!path)
goto err;
@@ -436,7 +446,9 @@ static int collect_fanotify_mark(struct fsnotify_mark_info *mark)
list_for_each_entry(p, &fanotify_info_head, list) {
if (p->ffe->id == mark->fme->id) {
list_add(&mark->list, &p->marks);
- mark->remap = lookup_ghost_remap(mark->fme->s_dev, mark->fme->i_ino);
+ if (mark->fme->type == MARK_TYPE__INODE)
+ mark->remap = lookup_ghost_remap(mark->fme->s_dev,
+ mark->fme->ie->i_ino);
return 0;
}
}
diff --git a/proc_parse.c b/proc_parse.c
index 337e96e..e641cb4 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -937,6 +937,7 @@ int parse_fdinfo(int fd, int type,
continue;
}
if (fdinfo_field(str, "fanotify ino")) {
+ FanotifyInodeMarkEntry ie = FANOTIFY_INODE_MARK_ENTRY__INIT;
FhEntry f_handle = FH_ENTRY__INIT;
int hoff;
@@ -944,14 +945,15 @@ int parse_fdinfo(int fd, int type,
goto parse_err;
fanotify_mark_entry__init(&entry.ffy);
- entry.ffy.f_handle = &f_handle;
+ ie.f_handle = &f_handle;
+ entry.ffy.ie = &ie;
ret = sscanf(str,
"fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x "
"fhandle-bytes:%x fhandle-type:%x f_handle: %n",
- &entry.ffy.i_ino, &entry.ffy.s_dev,
+ &ie.i_ino, &entry.ffy.s_dev,
&entry.ffy.mflags, &entry.ffy.mask, &entry.ffy.ignored_mask,
- &entry.ffy.f_handle->bytes, &entry.ffy.f_handle->type,
+ &f_handle.bytes, &f_handle.type,
&hoff);
if (ret != 7)
goto parse_err;
@@ -961,9 +963,8 @@ int parse_fdinfo(int fd, int type,
if (!f_handle.handle)
return -1;
- parse_fhandle_encoded(str + hoff, entry.ffy.f_handle);
+ parse_fhandle_encoded(str + hoff, &f_handle);
- entry.ffy.has_mnt_id = false;
entry.ffy.type = MARK_TYPE__INODE;
ret = cb(&entry, arg);
@@ -976,19 +977,21 @@ int parse_fdinfo(int fd, int type,
continue;
}
if (fdinfo_field(str, "fanotify mnt_id")) {
+ FanotifyMountMarkEntry me = FANOTIFY_MOUNT_MARK_ENTRY__INIT;
+
if (type != FD_TYPES__FANOTIFY)
goto parse_err;
fanotify_mark_entry__init(&entry.ffy);
+ entry.ffy.me = &me;
ret = sscanf(str,
"fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x",
- &entry.ffy.mnt_id, &entry.ffy.mflags,
+ &me.mnt_id, &entry.ffy.mflags,
&entry.ffy.mask, &entry.ffy.ignored_mask);
if (ret != 4)
goto parse_err;
- entry.ffy.has_mnt_id = true;
entry.ffy.type = MARK_TYPE__MOUNT;
ret = cb(&entry, arg);
if (ret)
diff --git a/protobuf/fsnotify.proto b/protobuf/fsnotify.proto
index 1c8ae4c..073fa79 100644
--- a/protobuf/fsnotify.proto
+++ b/protobuf/fsnotify.proto
@@ -22,18 +22,26 @@ enum mark_type {
MOUNT = 2;
}
+message fanotify_inode_mark_entry {
+ required uint64 i_ino = 1;
+ required fh_entry f_handle = 2;
+}
+
+message fanotify_mount_mark_entry {
+ required uint32 mnt_id = 1;
+}
+
message fanotify_mark_entry {
required uint32 id = 1;
required mark_type type = 2;
- required uint64 i_ino = 3;
- required uint32 s_dev = 4;
- required uint32 mflags = 5;
- required uint32 mask = 6;
- required uint32 ignored_mask = 7;
+ required uint32 mflags = 3;
+ required uint32 mask = 4;
+ required uint32 ignored_mask = 5;
+ required uint32 s_dev = 6;
- optional uint32 mnt_id = 8;
- optional fh_entry f_handle = 9;
+ optional fanotify_inode_mark_entry ie = 7;
+ optional fanotify_mount_mark_entry me = 8;
}
message fanotify_file_entry {
--
1.8.0.2
--bp/iNruPH9dso1Pn--
More information about the CRIU
mailing list