Function renaming to get better consistency

This commit is contained in:
Andrea Mazzoleni 2016-01-16 14:26:05 +01:00
parent 9ade11483e
commit d2991f736c
10 changed files with 50 additions and 50 deletions

View file

@ -620,7 +620,7 @@ static int file_post(struct snapraid_state* state, int fix, unsigned i, struct s
continue; continue;
} }
block = fs_par2block_maybe(disk, i); block = fs_par2block_find(disk, i);
if (!block_has_file(block)) { if (!block_has_file(block)) {
/* if no file, nothing to do */ /* if no file, nothing to do */
continue; continue;
@ -827,7 +827,7 @@ static int block_is_enabled(struct snapraid_state* state, block_off_t i, struct
if (!handle[j].disk) if (!handle[j].disk)
continue; continue;
block = fs_par2block_maybe(handle[j].disk, i); block = fs_par2block_find(handle[j].disk, i);
/* try to recover all files, even the ones without hash */ /* try to recover all files, even the ones without hash */
/* because in some cases we can recover also them */ /* because in some cases we can recover also them */
@ -948,8 +948,8 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
} }
/* if the disk block is not used */ /* if the disk block is not used */
block = fs_par2block_maybe(disk, i); block = fs_par2block_find(disk, i);
if (block == BLOCK_EMPTY) { if (block == BLOCK_NULL) {
/* use an empty block */ /* use an empty block */
memset(buffer[j], 0, state->block_size); memset(buffer[j], 0, state->block_size);
continue; continue;

View file

@ -57,7 +57,7 @@ static void dry_data_reader(struct snapraid_worker* worker, struct snapraid_task
} }
/* get the block */ /* get the block */
task->block = fs_par2block_maybe(disk, blockcur); task->block = fs_par2block_find(disk, blockcur);
/* if the block is not used */ /* if the block is not used */
if (!block_has_file(task->block)) { if (!block_has_file(task->block)) {

View file

@ -1171,7 +1171,7 @@ static struct snapraid_chunk* fs_file2chunk_get_unlock(struct snapraid_disk* dis
return chunk; return chunk;
} }
struct snapraid_file* fs_par2file_maybe(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos) struct snapraid_file* fs_par2file_find(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos)
{ {
struct snapraid_chunk* chunk; struct snapraid_chunk* chunk;
struct snapraid_file* file; struct snapraid_file* file;
@ -1194,7 +1194,7 @@ struct snapraid_file* fs_par2file_maybe(struct snapraid_disk* disk, block_off_t
return file; return file;
} }
block_off_t fs_file2par_maybe(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos) block_off_t fs_file2par_find(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos)
{ {
struct snapraid_chunk* chunk; struct snapraid_chunk* chunk;
block_off_t ret; block_off_t ret;
@ -1204,7 +1204,7 @@ block_off_t fs_file2par_maybe(struct snapraid_disk* disk, struct snapraid_file*
chunk = fs_file2chunk_get_unlock(disk, &disk->fs_last, file, file_pos); chunk = fs_file2chunk_get_unlock(disk, &disk->fs_last, file, file_pos);
if (!chunk) { if (!chunk) {
fs_unlock(disk); fs_unlock(disk);
return POS_INVALID; return POS_NULL;
} }
ret = chunk->parity_pos + (file_pos - chunk->file_pos); ret = chunk->parity_pos + (file_pos - chunk->file_pos);
@ -1353,14 +1353,14 @@ struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t
return &file->blockvec[file_pos]; return &file->blockvec[file_pos];
} }
struct snapraid_block* fs_par2block_maybe(struct snapraid_disk* disk, block_off_t parity_pos) struct snapraid_block* fs_par2block_find(struct snapraid_disk* disk, block_off_t parity_pos)
{ {
struct snapraid_file* file; struct snapraid_file* file;
block_off_t file_pos; block_off_t file_pos;
file = fs_par2file_maybe(disk, parity_pos, &file_pos); file = fs_par2file_find(disk, parity_pos, &file_pos);
if (file == 0) if (file == 0)
return BLOCK_EMPTY; return BLOCK_NULL;
return fs_file2block_get(file, file_pos); return fs_file2block_get(file, file_pos);
} }

View file

@ -39,7 +39,7 @@
/** /**
* Invalid position. * Invalid position.
*/ */
#define POS_INVALID ((block_off_t)-1) #define POS_NULL ((block_off_t)-1)
/** /**
* Basic block position type. * Basic block position type.
@ -78,11 +78,11 @@ struct snapraid_filter {
/** /**
* Block pointer used to represent unused blocks. * Block pointer used to represent unused blocks.
*/ */
#define BLOCK_EMPTY 0 #define BLOCK_NULL 0
/** /**
* This block is an empty one. * This block is an empty one.
* Note that an empty block is represent with ::BLOCK_EMPTY. * Note that an empty block is represent with ::BLOCK_NULL.
*/ */
#define BLOCK_STATE_EMPTY 0 #define BLOCK_STATE_EMPTY 0
@ -574,7 +574,7 @@ static inline void hash_zero_set(unsigned char* hash)
*/ */
static inline unsigned block_state_get(const struct snapraid_block* block) static inline unsigned block_state_get(const struct snapraid_block* block)
{ {
if (block == BLOCK_EMPTY) if (block == BLOCK_NULL)
return BLOCK_STATE_EMPTY; return BLOCK_STATE_EMPTY;
return block->state; return block->state;
@ -934,7 +934,7 @@ struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t
* Get the file position from the parity position. * Get the file position from the parity position.
* Return 0 if no file is using it. * Return 0 if no file is using it.
*/ */
struct snapraid_file* fs_par2file_maybe(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos); struct snapraid_file* fs_par2file_find(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos);
/** /**
* Get the file position from the parity position. * Get the file position from the parity position.
@ -943,7 +943,7 @@ static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk,
{ {
struct snapraid_file* ret; struct snapraid_file* ret;
ret = fs_par2file_maybe(disk, parity_pos, file_pos); ret = fs_par2file_find(disk, parity_pos, file_pos);
if (ret == 0) { if (ret == 0) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal("Internal inconsistency when deresolving parity to file at 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);
@ -956,9 +956,9 @@ static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk,
/** /**
* Get the parity position from the file position. * Get the parity position from the file position.
* Return POS_INVALID if no parity is allocated. * Return POS_NULL if no parity is allocated.
*/ */
block_off_t fs_file2par_maybe(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos); block_off_t fs_file2par_find(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos);
/** /**
* Get the parity position from the file position. * Get the parity position from the file position.
@ -967,8 +967,8 @@ static inline block_off_t fs_file2par_get(struct snapraid_disk* disk, struct sna
{ {
block_off_t ret; block_off_t ret;
ret = fs_file2par_maybe(disk, file, file_pos); ret = fs_file2par_find(disk, file, file_pos);
if (ret == POS_INVALID) { if (ret == POS_NULL) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal("Internal inconsistency when resolving file '%s' at position '%u/%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, disk->name); log_fatal("Internal inconsistency when resolving file '%s' at position '%u/%u' in disk '%s'\n", file->sub, file_pos, file->blockmax, disk->name);
os_abort(); os_abort();
@ -980,9 +980,9 @@ static inline block_off_t fs_file2par_get(struct snapraid_disk* disk, struct sna
/** /**
* Get the block from the parity position. * Get the block from the parity position.
* Return BLOCK_EMPTY==0 if the block is over the end of the disk or not used. * Return BLOCK_NULL==0 if the block is over the end of the disk or not used.
*/ */
struct snapraid_block* fs_par2block_maybe(struct snapraid_disk* disk, block_off_t parity_pos); struct snapraid_block* fs_par2block_find(struct snapraid_disk* disk, block_off_t parity_pos);
/** /**
* Get the block from the parity position. * Get the block from the parity position.
@ -991,8 +991,8 @@ static inline struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk
{ {
struct snapraid_block* ret; struct snapraid_block* ret;
ret = fs_par2block_maybe(disk, parity_pos); ret = fs_par2block_find(disk, parity_pos);
if (ret == BLOCK_EMPTY) { if (ret == BLOCK_NULL) {
/* LCOV_EXCL_START */ /* LCOV_EXCL_START */
log_fatal("Internal inconsistency when deresolving parity to block at position '%u' in disk '%s'\n", parity_pos, disk->name); log_fatal("Internal inconsistency when deresolving parity to block at position '%u' in disk '%s'\n", parity_pos, disk->name);
os_abort(); os_abort();
@ -1094,7 +1094,7 @@ static inline snapraid_info info_set_rehash(snapraid_info info)
* Set the info at the specified position. * Set the info at the specified position.
* The position is allocated if not yet done. * The position is allocated if not yet done.
*/ */
static inline void info_set(tommy_arrayblkof* array, unsigned pos, snapraid_info info) static inline void info_set(tommy_arrayblkof* array, block_off_t pos, snapraid_info info)
{ {
tommy_arrayblkof_grow(array, pos + 1); tommy_arrayblkof_grow(array, pos + 1);
@ -1105,7 +1105,7 @@ static inline void info_set(tommy_arrayblkof* array, unsigned pos, snapraid_info
* Get the info at the specified position. * Get the info at the specified position.
* For not allocated position, 0 is returned. * For not allocated position, 0 is returned.
*/ */
static inline snapraid_info info_get(tommy_arrayblkof* array, unsigned pos) static inline snapraid_info info_get(tommy_arrayblkof* array, block_off_t pos)
{ {
snapraid_info info; snapraid_info info;

View file

@ -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 */ /* 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 */ /* we don't stop at deleted blocks, because we want to have them cleared */
/* if they are at the end of the parity */ /* if they are at the end of the parity */
while (block > parity_block && !block_has_file(fs_par2block_maybe(disk, block - 1))) while (block > parity_block && !block_has_file(fs_par2block_find(disk, block - 1)))
--block; --block;
/* get the highest value */ /* 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); block_off_t block = fs_size(disk);
/* decrease the block until an used one */ /* decrease the block until an used one */
while (block > parity_block && !block_has_file_and_valid_parity(fs_par2block_maybe(disk, block - 1))) while (block > parity_block && !block_has_file_and_valid_parity(fs_par2block_find(disk, block - 1)))
--block; --block;
/* get the highest value */ /* get the highest value */
@ -95,7 +95,7 @@ int parity_is_invalid(struct snapraid_state* state)
one_valid = 0; one_valid = 0;
for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) { for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
struct snapraid_disk* disk = node_disk->data; struct snapraid_disk* disk = node_disk->data;
struct snapraid_block* block = fs_par2block_maybe(disk, i); struct snapraid_block* block = fs_par2block_find(disk, i);
if (block_has_file(block)) if (block_has_file(block))
one_valid = 1; one_valid = 1;

View file

@ -175,14 +175,14 @@ static void scan_file_allocate(struct snapraid_scan* scan, struct snapraid_file*
snapraid_info info; snapraid_info info;
/* increment the position until the first really free block */ /* increment the position until the first really free block */
while (block_has_file(fs_par2block_maybe(disk, parity_pos))) while (block_has_file(fs_par2block_find(disk, parity_pos)))
++parity_pos; ++parity_pos;
/* get block we are going to overwrite, if any */ /* get block we are going to overwrite, if any */
over_block = fs_par2block_maybe(disk, parity_pos); over_block = fs_par2block_find(disk, parity_pos);
/* deallocate it */ /* deallocate it */
if (over_block != BLOCK_EMPTY) if (over_block != BLOCK_NULL)
fs_deallocate(disk, parity_pos); fs_deallocate(disk, parity_pos);
/* get block specific info */ /* get block specific info */
@ -383,12 +383,12 @@ static int file_is_full_invalid_parity_and_stable(struct snapraid_state* state,
* Note that here we expect to always have mapped * Note that here we expect to always have mapped
* parity, because kept files always have it. * parity, because kept files always have it.
* *
* Anyway, checking for POS_INVALID doesn't hurt. * Anyway, checking for POS_NULL doesn't hurt.
*/ */
parity_pos = fs_file2par_maybe(disk, file, i); parity_pos = fs_file2par_find(disk, file, i);
/* if it's not mapped, it cannot have rehash */ /* if it's not mapped, it cannot have rehash */
if (parity_pos != POS_INVALID) { if (parity_pos != POS_NULL) {
/* get block specific info */ /* get block specific info */
info = info_get(&state->infoarr, parity_pos); info = info_get(&state->infoarr, parity_pos);
@ -437,10 +437,10 @@ static int file_is_full_hashed_and_stable(struct snapraid_state* state, struct s
* that such files are used as 'source' to copy * that such files are used as 'source' to copy
* hashes, and then to get them inside this function. * hashes, and then to get them inside this function.
*/ */
parity_pos = fs_file2par_maybe(disk, file, i); parity_pos = fs_file2par_find(disk, file, i);
/* if it's not mapped, it cannot have rehash */ /* if it's not mapped, it cannot have rehash */
if (parity_pos != POS_INVALID) { if (parity_pos != POS_NULL) {
/* get block specific info */ /* get block specific info */
info = info_get(&state->infoarr, parity_pos); info = info_get(&state->infoarr, parity_pos);

View file

@ -121,7 +121,7 @@ static void scrub_data_reader(struct snapraid_worker* worker, struct snapraid_ta
} }
/* get the block */ /* get the block */
task->block = fs_par2block_maybe(disk, blockcur); task->block = fs_par2block_find(disk, blockcur);
/* if the block is not used */ /* if the block is not used */
if (!block_has_file(task->block)) { if (!block_has_file(task->block)) {

View file

@ -1541,7 +1541,7 @@ static int fs_position_is_required(struct snapraid_state* state, block_off_t pos
/* check for each disk */ /* check for each disk */
for (i = state->disklist; i != 0; i = i->next) { for (i = state->disklist; i != 0; i = i->next) {
struct snapraid_disk* disk = i->data; struct snapraid_disk* disk = i->data;
struct snapraid_block* block = fs_par2block_maybe(disk, pos); struct snapraid_block* block = fs_par2block_find(disk, pos);
/* if we have at least one file, the position is needed */ /* if we have at least one file, the position is needed */
if (block_has_file(block)) 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 */ /* check for each disk */
for (i = state->disklist; i != 0; i = i->next) { for (i = state->disklist; i != 0; i = i->next) {
struct snapraid_disk* disk = i->data; struct snapraid_disk* disk = i->data;
struct snapraid_block* block = fs_par2block_maybe(disk, pos); struct snapraid_block* block = fs_par2block_find(disk, pos);
/* if we have at least one synced file, the info is required */ /* if we have at least one synced file, the info is required */
if (block_state_get(block) == BLOCK_STATE_BLK) 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 */ /* check for each disk if block is really used */
for (i = state->disklist; i != 0; i = i->next) { for (i = state->disklist; i != 0; i = i->next) {
struct snapraid_disk* disk = i->data; struct snapraid_disk* disk = i->data;
struct snapraid_block* block = fs_par2block_maybe(disk, pos); struct snapraid_block* block = fs_par2block_find(disk, pos);
/* if the block is deleted */ /* if the block is deleted */
if (block_state_get(block) == BLOCK_STATE_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) static int fs_is_block_deleted(struct snapraid_disk* disk, block_off_t pos)
{ {
struct snapraid_block* block = fs_par2block_maybe(disk, pos); struct snapraid_block* block = fs_par2block_find(disk, pos);
return block_state_get(block) == BLOCK_STATE_DELETED; return block_state_get(block) == BLOCK_STATE_DELETED;
} }

View file

@ -303,7 +303,7 @@ int state_status(struct snapraid_state* state)
one_valid = 0; one_valid = 0;
for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) { for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
struct snapraid_disk* disk = node_disk->data; struct snapraid_disk* disk = node_disk->data;
struct snapraid_block* block = fs_par2block_maybe(disk, i); struct snapraid_block* block = fs_par2block_find(disk, i);
if (block_has_file(block)) if (block_has_file(block))
one_valid = 1; one_valid = 1;

View file

@ -68,7 +68,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
struct snapraid_block* block; struct snapraid_block* block;
unsigned block_state; unsigned block_state;
block = fs_par2block_maybe(disk, i); block = fs_par2block_find(disk, i);
/* get the state of the block */ /* get the state of the block */
block_state = block_state_get(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; struct snapraid_file* file;
block_off_t file_pos; block_off_t file_pos;
block = fs_par2block_maybe(disk, i); block = fs_par2block_find(disk, i);
/* get the state of the block */ /* get the state of the block */
block_state = block_state_get(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) if (!disk)
continue; continue;
block = fs_par2block_maybe(disk, i); block = fs_par2block_find(disk, i);
if (block_has_file(block)) if (block_has_file(block))
one_valid = 1; one_valid = 1;
@ -485,7 +485,7 @@ static void sync_data_reader(struct snapraid_worker* worker, struct snapraid_tas
} }
/* get the block */ /* get the block */
task->block = fs_par2block_maybe(disk, blockcur); task->block = fs_par2block_find(disk, blockcur);
/* if the block has no file, meanining that it's EMPTY or DELETED, */ /* if the block has no file, meanining that it's EMPTY or DELETED, */
/* it doesn't partecipate in the new parity computation */ /* it doesn't partecipate in the new parity computation */
@ -1137,9 +1137,9 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
if (!handle[j].disk) if (!handle[j].disk)
continue; continue;
block = fs_par2block_maybe(handle[j].disk, blockcur); block = fs_par2block_find(handle[j].disk, blockcur);
if (block == BLOCK_EMPTY) { if (block == BLOCK_NULL) {
/* nothing to do */ /* nothing to do */
continue; continue;
} }