[CRIU] [PATCH 07/12] dump: files tree - "type forest" introduced
Kinsbursky Stanislav
skinsbursky at openvz.org
Fri Mar 23 12:23:51 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
One tree per file type (fd, vma, cwd, exe, etc).
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
cr-dump.c | 2 +-
file-ids.c | 24 +++++++++++++++---------
include/file-ids.h | 3 ++-
3 files changed, 18 insertions(+), 11 deletions(-)
-------------- next part --------------
diff --git a/cr-dump.c b/cr-dump.c
index abc3671..d74efd7 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -123,7 +123,7 @@ static int dump_one_reg_file(const struct file_entry *p, pid_t pid,
if (likely(!fd_is_special(&e.fde))) {
long id;
- id = fd_id_entry_collect((u32)p->id, pid, target_fd);
+ id = fd_id_entry_collect(p, pid, target_fd);
if (id < 0)
goto err;
diff --git a/file-ids.c b/file-ids.c
index c5cc29f..39caaad 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -75,8 +75,7 @@ struct fd_id_entry {
struct file_info info;
} __aligned(sizeof(long));
-
-struct rb_root fd_id_root;
+static struct rb_root dump_file_forest[FD_INFO_MAX];
static unsigned long fd_id_entries_subid = 1;
static struct fd_id_entry *alloc_fd_id_entry(u32 genid, pid_t pid, int fd)
@@ -133,14 +132,19 @@ err:
return sub;
}
-static struct fd_id_entry *lookup_alloc_node(u64 genid, pid_t pid, int fd)
+static struct fd_id_entry *lookup_alloc_node(u8 type, u64 genid, pid_t pid, int fd)
{
- struct rb_node *node = fd_id_root.rb_node;
+ struct rb_root *fd_root;
+ struct rb_node *node;
struct fd_id_entry *e = NULL;
- struct rb_node **new = &fd_id_root.rb_node;
+ struct rb_node **new;
struct rb_node *parent = NULL;
+ fd_root = &dump_file_forest[type];
+ node = fd_root->rb_node;
+ new = &fd_root->rb_node;
+
while (node) {
struct fd_id_entry *this = rb_entry(node, struct fd_id_entry, node);
@@ -157,17 +161,19 @@ static struct fd_id_entry *lookup_alloc_node(u64 genid, pid_t pid, int fd)
if (!e)
goto err;
- rb_link_and_balance(&fd_id_root, &e->node, parent, new);
+ rb_link_and_balance(fd_root, &e->node, parent, new);
err:
return e;
-
}
-long fd_id_entry_collect(u64 genid, pid_t pid, int fd)
+long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd)
{
struct fd_id_entry *e = NULL;
- e = lookup_alloc_node(genid, pid, fd);
+ if (p->type >= FD_INFO_MAX)
+ return -ENOTSUP;
+
+ e = lookup_alloc_node(p->type, p->id, pid, fd);
if (e == NULL)
return -ENOMEM;
return e->u.id;
diff --git a/include/file-ids.h b/include/file-ids.h
index 1725545..3b8993d 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -16,6 +16,7 @@ struct file_info {
#define MAKE_FD_GENID(dev, ino, pos) \
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
-extern long fd_id_entry_collect(u64 genid, pid_t pid, int fd);
+struct file_entry;
+extern long fd_id_entry_collect(const struct file_entry *p, pid_t pid, int fd);
#endif /* FILE_IDS_H__ */
More information about the CRIU
mailing list