From ea045dac61028dbb5dc749b77de9c037b6dc576f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Sun, 25 Mar 2012 16:02:21 +0400 Subject: [PATCH] file-ids: Report whether a new id was generated This will be required to determine whether we should dump the respective file, or it was already dumped and we just re-use its id in fdinfo_entry. For special fd-s the ID is always new. Signed-off-by: Pavel Emelyanov --- file-ids.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/file-ids.c b/file-ids.c index a0cadbbc4..3f7f1794f 100644 --- a/file-ids.c +++ b/file-ids.c @@ -154,7 +154,7 @@ err: } static struct fd_id_entry *fd_id_generate_sub(struct fd_id_entry *e, - pid_t pid, struct fdinfo_entry *fe) + pid_t pid, struct fdinfo_entry *fe, int *new_id) { struct rb_node *node = e->subtree_root.rb_node; struct fd_id_entry *sub = NULL; @@ -182,10 +182,12 @@ static struct fd_id_entry *fd_id_generate_sub(struct fd_id_entry *e, return NULL; rb_link_and_balance(&e->subtree_root, &sub->subtree_node, parent, new); + *new_id = 1; return sub; } -static struct fd_id_entry *fd_id_generate_gen(pid_t pid, struct fdinfo_entry *fe) +static struct fd_id_entry *fd_id_generate_gen(pid_t pid, + struct fdinfo_entry *fe, int *new_id) { struct rb_node *node = fd_id_root.rb_node; struct fd_id_entry *e = NULL; @@ -202,7 +204,7 @@ static struct fd_id_entry *fd_id_generate_gen(pid_t pid, struct fdinfo_entry *fe else if (fe->id > this->genid) node = node->rb_right, new = &((*new)->rb_right); else - return fd_id_generate_sub(this, pid, fe); + return fd_id_generate_sub(this, pid, fe, new_id); } e = alloc_fd_id_entry(pid, fe); @@ -210,6 +212,7 @@ static struct fd_id_entry *fd_id_generate_gen(pid_t pid, struct fdinfo_entry *fe return NULL; rb_link_and_balance(&fd_id_root, &e->node, parent, new); + *new_id = 1; return e; } @@ -217,16 +220,17 @@ static struct fd_id_entry *fd_id_generate_gen(pid_t pid, struct fdinfo_entry *fe int fd_id_generate(pid_t pid, struct fdinfo_entry *fe) { struct fd_id_entry *fid; + int new_id = 0; if (fd_is_special(fe)) { fe->id = fd_id_entries_subid++; - return 0; + return 1; } - fid = fd_id_generate_gen(pid, fe); + fid = fd_id_generate_gen(pid, fe, &new_id); if (!fid) return -ENOMEM; fe->id = fid->subid; - return 0; + return new_id; }