Commit 12c58017 authored by Stanislav Kinsbursky's avatar Stanislav Kinsbursky Committed by Pavel Emelyanov

dump: files tree - return id upon collect instead on inner structure

Hide the structure - it's not required.

[ xemul: Ranem long id into u32 id and adopt to current tree ]
Signed-off-by: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b68b3d5d
...@@ -128,20 +128,14 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd, ...@@ -128,20 +128,14 @@ static int dump_one_reg_file(const struct fd_parms *p, int lfd,
e.id = FD_ID_INVALID; e.id = FD_ID_INVALID;
if (likely(!fd_is_special(&e))) { if (likely(!fd_is_special(&e))) {
struct fd_id_entry *entry; u64 id;
/* id = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
* Make sure the union is still correlate with structure if (id < 0)
* we write to disk.
*/
BUILD_BUG_ON(sizeof(entry->u.key) != sizeof(e.id));
entry = fd_id_entry_collect((u32)p->id, p->pid, p->fd_name);
if (!entry)
goto err; goto err;
/* Now it might have completely new ID here */ /* Now it might have completely new ID here */
e.id = entry->u.id; e.id = id;
} }
pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n", pr_info("fdinfo: type: %2x len: %2x flags: %4x pos: %8lx addr: %16lx\n",
......
...@@ -58,6 +58,25 @@ ...@@ -58,6 +58,25 @@
* in one pass. * in one pass.
*/ */
struct fd_id_entry {
struct rb_node node;
struct rb_root subtree_root;
struct rb_node subtree_node;
union {
struct {
u32 genid; /* generic id, may have duplicates */
u32 subid; /* subid is always unique */
} key;
u64 id;
} u;
pid_t pid;
int fd;
} __aligned(sizeof(long));
struct rb_root fd_id_root = RB_ROOT; struct rb_root fd_id_root = RB_ROOT;
static unsigned long fd_id_entries_subid = 1; static unsigned long fd_id_entries_subid = 1;
...@@ -115,7 +134,7 @@ err: ...@@ -115,7 +134,7 @@ err:
return sub; return sub;
} }
struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd) static struct fd_id_entry *lookup_alloc_node(u64 genid, pid_t pid, int fd)
{ {
struct rb_node *node = fd_id_root.rb_node; struct rb_node *node = fd_id_root.rb_node;
struct fd_id_entry *e = NULL; struct fd_id_entry *e = NULL;
...@@ -142,4 +161,16 @@ struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd) ...@@ -142,4 +161,16 @@ struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd)
rb_link_and_balance(&fd_id_root, &e->node, parent, new); rb_link_and_balance(&fd_id_root, &e->node, parent, new);
err: err:
return e; return e;
}
long fd_id_entry_collect(u64 genid, pid_t pid, int fd)
{
struct fd_id_entry *e = NULL;
e = lookup_alloc_node(genid, pid, fd);
if (e == NULL)
return -ENOMEM;
return e->u.id;
} }
...@@ -8,27 +8,9 @@ ...@@ -8,27 +8,9 @@
#define FD_ID_INVALID (-1UL) #define FD_ID_INVALID (-1UL)
#define FD_PID_INVALID ((int)-2UL) #define FD_PID_INVALID ((int)-2UL)
struct fd_id_entry {
struct rb_node node;
struct rb_root subtree_root;
struct rb_node subtree_node;
union {
struct {
u32 genid; /* generic id, may have duplicates */
u32 subid; /* subid is always unique */
} key;
u64 id;
} u;
pid_t pid;
int fd;
} __aligned(sizeof(long));
#define MAKE_FD_GENID(dev, ino, pos) \ #define MAKE_FD_GENID(dev, ino, pos) \
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos))) (((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
extern struct fd_id_entry *fd_id_entry_collect(u32 genid, pid_t pid, int fd); extern long fd_id_entry_collect(u64 genid, pid_t pid, int fd);
#endif /* FILE_IDS_H__ */ #endif /* FILE_IDS_H__ */
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