First removes files before adding new ones to minimize the parity size.

This commit is contained in:
Andrea Mazzoleni 2011-05-24 21:49:15 +02:00
parent 35f3c092ed
commit 900c0e9297
2 changed files with 31 additions and 7 deletions

View file

@ -5,6 +5,7 @@ SnapRAID HISTORY
==========
* Fixed the restore of directory with unicode chars in Windows.
* Fixed support of file names starting or ending with a space.
* Removes files before inserting new ones to minimize the parity size.
1.2 2011/5
==========

37
scan.c
View file

@ -22,11 +22,16 @@
#include "state.h"
struct snapraid_scan {
/**
* Counters of changes.
*/
unsigned count_equal;
unsigned count_moved;
unsigned count_change;
unsigned count_remove;
unsigned count_insert;
tommy_list insert_list; /**< Files to insert. */
};
/**
@ -151,6 +156,8 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state,
/* otherwise it's equal */
++scan->count_equal;
}
/* nothing more to do */
return;
} else {
/* do a safety check to ensure that the common ext4 case of zeroing */
@ -167,23 +174,26 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state,
}
}
/* remove and reinsert it */
/* remove it */
++scan->count_change;
--scan->count_insert;
scan_file_remove(state, disk, file);
/* continue to insert it */
/* and continue to reinsert it */
}
} else {
/* create the new file */
++scan->count_insert;
/* and continue to insert it */
}
/* create the new file */
++scan->count_insert;
file = file_alloc(state->block_size, sub, st->st_size, st->st_mtime, st->st_ino);
/* mark it as present */
file_flag_set(file, FILE_IS_PRESENT);
/* insert it */
scan_file_insert(state, disk, file);
/* insert it in the delayed insert list */
tommy_list_insert_tail(&scan->insert_list, &file->nodelist, file);
}
/**
@ -300,6 +310,7 @@ void state_scan(struct snapraid_state* state)
scan[i].count_change = 0;
scan[i].count_remove = 0;
scan[i].count_insert = 0;
tommy_list_init(&scan[i].insert_list);
}
for(i=0;i<diskmax;++i) {
@ -325,6 +336,18 @@ void state_scan(struct snapraid_state* state)
}
}
/* insert all the new files, we insert them only after the deletion */
node = scan[i].insert_list;
while (node) {
struct snapraid_file* file = node->data;
/* next node */
node = node->next;
/* insert it */
scan_file_insert(state, disk, file);
}
/* if all the previous file were removed */
if (scan[i].count_equal == 0 && scan[i].count_moved == 0 && scan[i].count_remove != 0) {
if (!state->force_empty) {