mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 02:49:02 -04:00
Add the "maybe" function also to par2block
This commit is contained in:
parent
83889b4fbb
commit
74fa6e9274
10 changed files with 41 additions and 24 deletions
|
|
@ -620,7 +620,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
|
|||
continue;
|
||||
}
|
||||
|
||||
block = fs_par2block_get(disk, i);
|
||||
block = fs_par2block_maybe(disk, i);
|
||||
if (!block_has_file(block)) {
|
||||
/* if no file, nothing to do */
|
||||
continue;
|
||||
|
|
@ -827,7 +827,7 @@ static int block_is_enabled(struct snapraid_state* state, block_off_t i, struct
|
|||
if (!handle[j].disk)
|
||||
continue;
|
||||
|
||||
block = fs_par2block_get(handle[j].disk, i);
|
||||
block = fs_par2block_maybe(handle[j].disk, i);
|
||||
|
||||
/* try to recover all files, even the ones without hash */
|
||||
/* because in some cases we can recover also them */
|
||||
|
|
@ -948,7 +948,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
|
|||
}
|
||||
|
||||
/* if the disk block is not used */
|
||||
block = fs_par2block_get(disk, i);
|
||||
block = fs_par2block_maybe(disk, i);
|
||||
if (block == BLOCK_EMPTY) {
|
||||
/* use an empty block */
|
||||
memset(buffer[j], 0, state->block_size);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task
|
|||
}
|
||||
|
||||
/* get the block */
|
||||
task->block = fs_par2block_get(disk, blockcur);
|
||||
task->block = fs_par2block_maybe(disk, blockcur);
|
||||
|
||||
/* if the block is not used */
|
||||
if (!block_has_file(task->block)) {
|
||||
|
|
|
|||
|
|
@ -1353,7 +1353,7 @@ struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t
|
|||
return &file->blockvec[file_pos];
|
||||
}
|
||||
|
||||
struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk, block_off_t parity_pos)
|
||||
struct snapraid_block* fs_par2block_maybe(struct snapraid_disk* disk, block_off_t parity_pos)
|
||||
{
|
||||
struct snapraid_file* file;
|
||||
block_off_t file_pos;
|
||||
|
|
|
|||
|
|
@ -946,7 +946,7 @@ static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk,
|
|||
ret = fs_par2file_maybe(disk, parity_pos, file_pos);
|
||||
if (ret == 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("Internal inconsistency when deresolving parity position '%u' in disk '%s'\n", parity_pos, disk->name);
|
||||
log_fatal("Internal inconsistency when deresolving parity to file at position '%u' in disk '%s'\n", parity_pos, disk->name);
|
||||
os_abort();
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
|
@ -981,9 +981,26 @@ static inline block_off_t fs_file2par_get(struct snapraid_disk* disk, struct sna
|
|||
/**
|
||||
* Get the block from the parity position.
|
||||
* Return BLOCK_EMPTY==0 if the block is over the end of the disk or not used.
|
||||
* \note This function is NOT thread-safe as it uses the the disk cache.
|
||||
*/
|
||||
struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk, block_off_t parity_pos);
|
||||
struct snapraid_block* fs_par2block_maybe(struct snapraid_disk* disk, block_off_t parity_pos);
|
||||
|
||||
/**
|
||||
* Get the block from the parity position.
|
||||
*/
|
||||
static inline struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk, block_off_t parity_pos)
|
||||
{
|
||||
struct snapraid_block* ret;
|
||||
|
||||
ret = fs_par2block_maybe(disk, parity_pos);
|
||||
if (ret == BLOCK_EMPTY) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("Internal inconsistency when deresolving parity to block at position '%u' in disk '%s'\n", parity_pos, disk->name);
|
||||
os_abort();
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a disk mapping.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ block_off_t parity_allocated_size(struct snapraid_state* state)
|
|||
/* decrease the block until an allocated one, but part of a file */
|
||||
/* we don't stop at deleted blocks, because we want to have them cleared */
|
||||
/* if they are at the end of the parity */
|
||||
while (block > parity_block && !block_has_file(fs_par2block_get(disk, block - 1)))
|
||||
while (block > parity_block && !block_has_file(fs_par2block_maybe(disk, block - 1)))
|
||||
--block;
|
||||
|
||||
/* get the highest value */
|
||||
|
|
@ -67,7 +67,7 @@ block_off_t parity_used_size(struct snapraid_state* state)
|
|||
block_off_t block = fs_size(disk);
|
||||
|
||||
/* decrease the block until an used one */
|
||||
while (block > parity_block && !block_has_file_and_valid_parity(fs_par2block_get(disk, block - 1)))
|
||||
while (block > parity_block && !block_has_file_and_valid_parity(fs_par2block_maybe(disk, block - 1)))
|
||||
--block;
|
||||
|
||||
/* get the highest value */
|
||||
|
|
@ -95,7 +95,7 @@ int parity_is_invalid(struct snapraid_state* state)
|
|||
one_valid = 0;
|
||||
for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
|
||||
struct snapraid_disk* disk = node_disk->data;
|
||||
struct snapraid_block* block = fs_par2block_get(disk, i);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, i);
|
||||
|
||||
if (block_has_file(block))
|
||||
one_valid = 1;
|
||||
|
|
|
|||
|
|
@ -175,11 +175,11 @@ static void scan_file_allocate(struct snapraid_scan* scan, struct snapraid_file*
|
|||
snapraid_info info;
|
||||
|
||||
/* increment the position until the first really free block */
|
||||
while (block_has_file(fs_par2block_get(disk, parity_pos)))
|
||||
while (block_has_file(fs_par2block_maybe(disk, parity_pos)))
|
||||
++parity_pos;
|
||||
|
||||
/* get block we are going to overwrite, if any */
|
||||
over_block = fs_par2block_get(disk, parity_pos);
|
||||
over_block = fs_par2block_maybe(disk, parity_pos);
|
||||
|
||||
/* deallocate it */
|
||||
if (over_block != BLOCK_EMPTY)
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta
|
|||
}
|
||||
|
||||
/* get the block */
|
||||
task->block = fs_par2block_get(disk, blockcur);
|
||||
task->block = fs_par2block_maybe(disk, blockcur);
|
||||
|
||||
/* if the block is not used */
|
||||
if (!block_has_file(task->block)) {
|
||||
|
|
|
|||
|
|
@ -1541,7 +1541,7 @@ static int fs_position_is_required(struct snapraid_state* state, block_off_t pos
|
|||
/* check for each disk */
|
||||
for (i = state->disklist; i != 0; i = i->next) {
|
||||
struct snapraid_disk* disk = i->data;
|
||||
struct snapraid_block* block = fs_par2block_get(disk, pos);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, pos);
|
||||
|
||||
/* if we have at least one file, the position is needed */
|
||||
if (block_has_file(block))
|
||||
|
|
@ -1570,7 +1570,7 @@ static int fs_info_is_required(struct snapraid_state* state, block_off_t pos)
|
|||
/* check for each disk */
|
||||
for (i = state->disklist; i != 0; i = i->next) {
|
||||
struct snapraid_disk* disk = i->data;
|
||||
struct snapraid_block* block = fs_par2block_get(disk, pos);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, pos);
|
||||
|
||||
/* if we have at least one synced file, the info is required */
|
||||
if (block_state_get(block) == BLOCK_STATE_BLK)
|
||||
|
|
@ -1587,7 +1587,7 @@ static void fs_position_clear_deleted(struct snapraid_state* state, block_off_t
|
|||
/* check for each disk if block is really used */
|
||||
for (i = state->disklist; i != 0; i = i->next) {
|
||||
struct snapraid_disk* disk = i->data;
|
||||
struct snapraid_block* block = fs_par2block_get(disk, pos);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, pos);
|
||||
|
||||
/* if the block is deleted */
|
||||
if (block_state_get(block) == BLOCK_STATE_DELETED) {
|
||||
|
|
@ -1602,7 +1602,7 @@ static void fs_position_clear_deleted(struct snapraid_state* state, block_off_t
|
|||
*/
|
||||
static int fs_is_block_deleted(struct snapraid_disk* disk, block_off_t pos)
|
||||
{
|
||||
struct snapraid_block* block = fs_par2block_get(disk, pos);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, pos);
|
||||
|
||||
return block_state_get(block) == BLOCK_STATE_DELETED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ int state_status(struct snapraid_state* state)
|
|||
one_valid = 0;
|
||||
for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
|
||||
struct snapraid_disk* disk = node_disk->data;
|
||||
struct snapraid_block* block = fs_par2block_get(disk, i);
|
||||
struct snapraid_block* block = fs_par2block_maybe(disk, i);
|
||||
|
||||
if (block_has_file(block))
|
||||
one_valid = 1;
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
struct snapraid_block* block;
|
||||
unsigned block_state;
|
||||
|
||||
block = fs_par2block_get(disk, i);
|
||||
block = fs_par2block_maybe(disk, i);
|
||||
|
||||
/* get the state of the block */
|
||||
block_state = block_state_get(block);
|
||||
|
|
@ -106,7 +106,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
struct snapraid_file* file;
|
||||
block_off_t file_pos;
|
||||
|
||||
block = fs_par2block_get(disk, i);
|
||||
block = fs_par2block_maybe(disk, i);
|
||||
|
||||
/* get the state of the block */
|
||||
block_state = block_state_get(block);
|
||||
|
|
@ -450,7 +450,7 @@ static int block_is_enabled(void* void_plan, block_off_t i)
|
|||
if (!disk)
|
||||
continue;
|
||||
|
||||
block = fs_par2block_get(disk, i);
|
||||
block = fs_par2block_maybe(disk, i);
|
||||
|
||||
if (block_has_file(block))
|
||||
one_valid = 1;
|
||||
|
|
@ -485,7 +485,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas
|
|||
}
|
||||
|
||||
/* get the block */
|
||||
task->block = fs_par2block_get(disk, blockcur);
|
||||
task->block = fs_par2block_maybe(disk, blockcur);
|
||||
|
||||
/* if the block has no file, meanining that it's EMPTY or DELETED, */
|
||||
/* it doesn't partecipate in the new parity computation */
|
||||
|
|
@ -1137,7 +1137,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
if (!handle[j].disk)
|
||||
continue;
|
||||
|
||||
block = fs_par2block_get(handle[j].disk, blockcur);
|
||||
block = fs_par2block_maybe(handle[j].disk, blockcur);
|
||||
|
||||
if (block == BLOCK_EMPTY) {
|
||||
/* nothing to do */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue