Add mutex protection at the filesystem structure

In sync we need to modify the filesystem, like to call
fs_deallocate(). We need then proper protection.
This also removes the need of multiple fs_last cached value.
This commit is contained in:
Andrea Mazzoleni 2016-01-01 10:00:18 +01:00
parent 74204a42d7
commit cbf2040b89
8 changed files with 117 additions and 91 deletions

View file

@ -1599,9 +1599,9 @@ static void fs_position_clear_deleted(struct snapraid_state* state, block_off_t
/**
* Check if a block position in a disk is deleted.
*/
static int fs_is_block_deleted_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, block_off_t pos)
static int fs_is_block_deleted(struct snapraid_disk* disk, block_off_t pos)
{
struct snapraid_block* block = fs_par2block_get_ts(disk, fs_last, pos);
struct snapraid_block* block = fs_par2block_get(disk, pos);
return block_state_get(block) == BLOCK_STATE_DELETED;
}
@ -2735,14 +2735,6 @@ static void* state_write_thread(void* arg)
for (i = state->disklist; i != 0; i = i->next) {
tommy_node* j;
struct snapraid_disk* disk = i->data;
struct snapraid_chunk* fs_last;
/**
* This is the last accessed chunk in the tree operations.
* Here we are inside a thread, and we cannot use the
* ::disk member to store this information.
*/
fs_last = 0;
/* if the disk is not mapped, skip it */
if (disk->mapping_idx < 0)
@ -2783,7 +2775,7 @@ static void* state_write_thread(void* arg)
begin = 0;
while (begin < file->blockmax) {
unsigned v_state = block_state_get(fs_file2block_get(file, begin));
block_off_t v_pos = fs_file2par_get_ts(disk, &fs_last, file, begin);
block_off_t v_pos = fs_file2par_get(disk, file, begin);
uint32_t v_count;
block_off_t end;
@ -2793,7 +2785,7 @@ static void* state_write_thread(void* arg)
while (end < file->blockmax) {
if (v_state != block_state_get(fs_file2block_get(file, end)))
break;
if (v_pos + (end - begin) != fs_file2par_get_ts(disk, &fs_last, file, end))
if (v_pos + (end - begin) != fs_file2par_get(disk,file, end))
break;
++end;
}
@ -2898,12 +2890,12 @@ static void* state_write_thread(void* arg)
int is_deleted;
block_off_t end;
is_deleted = fs_is_block_deleted_ts(disk, &fs_last, begin);
is_deleted = fs_is_block_deleted(disk, begin);
/* find the end of run of blocks */
end = begin + 1;
while (end < blockmax
&& is_deleted == fs_is_block_deleted_ts(disk, &fs_last, end)
&& is_deleted == fs_is_block_deleted(disk, end)
) {
++end;
}
@ -2916,7 +2908,7 @@ static void* state_write_thread(void* arg)
/* write all the hash */
while (begin < end) {
struct snapraid_block* block = fs_par2block_get_ts(disk, &fs_last, begin);
struct snapraid_block* block = fs_par2block_get(disk, begin);
swrite(block->hash, HASH_SIZE, f);
@ -3108,7 +3100,7 @@ static void state_write_content(struct snapraid_state* state, uint32_t* out_crc)
}
/* save the mapping only for not empty disks */
if (!disk_is_empty(disk, blockmax)) {
if (!fs_is_empty(disk, blockmax)) {
/* assign the mapping index used to identify disks */
disk->mapping_idx = mapping_idx;
++mapping_idx;