Skip to content

Commit

Permalink
Revert "Remove unused filerec compare tree"
Browse files Browse the repository at this point in the history
This reverts commit 9c4b258.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
  • Loading branch information
Mark Fasheh committed Sep 17, 2016
1 parent f061d95 commit f2cfa3d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
65 changes: 64 additions & 1 deletion filerec.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,65 @@ struct filerec_token *filerec_token_new(struct filerec *file)
return token;
}

int filerecs_compared(struct filerec *file1, struct filerec *file2)
{
struct filerec *file = file1;
struct filerec *test = file2;

/*
* We can store only one pointer if we make a rule that we
* always search the filerec with the lower pointer value for
* the one with the higher pointer value.
*/
if (file1 > file2) {
file = file2;
test = file1;
}

if (find_filerec_token_rb(&file->comparisons, test))
return 1;

return 0;
}

int mark_filerecs_compared(struct filerec *file1, struct filerec *file2)
{
struct filerec_token *t;
struct filerec *file = file1;
struct filerec *test = file2;

if (file1 > file2) {
file = file2;
test = file1;
}

if (find_filerec_token_rb(&file->comparisons, test))
return 0;

t = filerec_token_new(test);
if (!t)
return ENOMEM;

insert_filerec_token_rb(&file->comparisons, t);

return 0;
}

static void free_compared_tree(struct filerec *file)
{
struct rb_node *n = rb_first(&file->comparisons);
struct filerec_token *t;

while (n) {
t = rb_entry(n, struct filerec_token, t_node);
n = rb_next(n);
rb_erase(&t->t_node, &file->comparisons);
filerec_token_free(t);
}

abort_on(!RB_EMPTY_ROOT(&file->comparisons));
}

static int cmp_filerecs(struct filerec *file1, uint64_t file2_inum,
uint64_t file2_subvolid)
{
Expand Down Expand Up @@ -254,15 +313,18 @@ static struct filerec *filerec_alloc_insert(const char *filename,

if (file) {
file->filename = strdup(filename);
if (!file->filename)
if (!file->filename) {
free_compared_tree(file);
return NULL;
}

file->fd = -1;
file->block_tree = RB_ROOT;
INIT_LIST_HEAD(&file->tmp_list);
rb_init_node(&file->inum_node);
file->inum = inum;
file->subvolid = subvolid;
file->comparisons = RB_ROOT;
file->size = size;
file->mtime = mtime;
g_mutex_init(&file->extent_tree_mutex);
Expand Down Expand Up @@ -302,6 +364,7 @@ void filerec_free(struct filerec *file)
rb_erase(&file->inum_node, &filerec_by_inum);
if (!RB_EMPTY_NODE(&file->name_node))
rb_erase(&file->name_node, &filerec_by_name);
free_compared_tree(file);
free_filerec(file);
num_filerecs--;
}
Expand Down
10 changes: 9 additions & 1 deletion filerec.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct filerec {

struct list_head tmp_list;

struct rb_root comparisons;

/* interval tree of dup-extents belonging to this file */
GMutex extent_tree_mutex;
struct rb_root extent_tree;
Expand Down Expand Up @@ -120,7 +122,9 @@ int filerec_count_shared(struct filerec *file, uint64_t start, uint64_t len,
uint64_t *first_plen);

/*
* Track unique filerecs in a tree.
* Track unique filerecs in a tree. Two places in the code use this:
* - filerec comparison tracking in filerec.c
* - conversion of large dupe lists in hash-tree.c
* User has to define an rb_root, and a "free all" function.
*/
struct filerec_token {
Expand All @@ -134,6 +138,10 @@ void insert_filerec_token_rb(struct rb_root *root,
void filerec_token_free(struct filerec_token *token);
struct filerec_token *filerec_token_new(struct filerec *file);

int filerecs_compared(struct filerec *file1, struct filerec *file2);
int mark_filerecs_compared(struct filerec *file1, struct filerec *file2);


struct fiemap_ctxt;
struct fiemap_ctxt *alloc_fiemap_ctxt(void);
void fiemap_ctxt_init(struct fiemap_ctxt *ctxt);
Expand Down

0 comments on commit f2cfa3d

Please sign in to comment.