Unified the two --force-realloc logics

This commit is contained in:
Andrea Mazzoleni 2026-02-09 11:46:38 +01:00
parent 966583e6f0
commit f89d5fa4f3
3 changed files with 25 additions and 18 deletions

View file

@ -125,8 +125,13 @@ void state_locate_info(struct snapraid_state* state, uint64_t parity_tail, struc
info->block_max = parity_allocated_size(state);
info->parity_size = info->block_max * (uint64_t)block_size;
info->tail_block = (parity_tail + block_size - 1) / block_size;
info->low_to_free_tail_block = info->block_max - info->tail_block;
if (info->tail_block > info->block_max)
info->low_to_free_tail_block = 0;
else
info->low_to_free_tail_block = info->block_max - info->tail_block;
}
void state_locate(struct snapraid_state* state, uint64_t parity_tail)
@ -148,9 +153,8 @@ void state_locate(struct snapraid_state* state, uint64_t parity_tail)
state_locate_info(state, parity_tail, &info);
printf("Current parity size is %sB\n", fmt_size(info.parity_size, buf, sizeof(buf)));
if (info.tail_block >= info.block_max) {
printf("Specified tail greater than the parity size!\n");
return;
if (info.tail_block > info.block_max) {
printf("Specified tail greater than the parity size! Operate on the full parity\n");
}
low_to_free_tail_block = info.low_to_free_tail_block;
@ -196,12 +200,24 @@ void state_locate_mark_tail_blocks_for_resync(struct snapraid_state* state, uint
{
char buf[64];
uint32_t block_size = state->block_size;
block_off_t low_to_free_tail_block;
struct snapraid_locate_info info;
state_locate_info(state, parity_tail, &info);
block_off_t low_to_free_tail_block = info.low_to_free_tail_block;
if (parity_tail == 0) {
printf("Forcing reallocation of all files\n\n");
low_to_free_tail_block = 0;
} else {
msg_progress("Forcing reallocation of all files within the tail of %sB of the parity\n\n", fmt_size(parity_tail, buf, sizeof(buf)));
msg_progress("Forcing reallocation of all files within the tail of %sB of the parity\n\n", fmt_size(parity_tail, buf, sizeof(buf)));
struct snapraid_locate_info info;
state_locate_info(state, parity_tail, &info);
printf("Current parity size is %sB\n", fmt_size(info.parity_size, buf, sizeof(buf)));
if (info.tail_block > info.block_max) {
printf("Specified tail greater than the parity size! Operate on the full parity\n");
}
low_to_free_tail_block = info.low_to_free_tail_block;
}
msg_progress("Collecting files with offset greater or equal to %" PRIu64 "\n", low_to_free_tail_block * (uint64_t)block_size);

View file

@ -1820,7 +1820,7 @@ int snapraid_main(int argc, char* argv[])
/* mark the files that have to be reallocated */
/* it will happen in inside scan_file_keep() called in state_scan() */
if (state.opt.force_realloc && opt.parity_tail != 0)
if (state.opt.force_realloc)
state_locate_mark_tail_blocks_for_resync(&state, opt.parity_tail);
state_scan(&state);

View file

@ -2232,15 +2232,6 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
block_state_set(block, BLOCK_STATE_CHG);
}
/* if we want a full reallocation, marks block as invalid parity */
/* note that we do this after the force_nocopy option */
/* to avoid to mixup the two things */
if (state->opt.force_realloc && state->opt.parity_tail == 0
&& block_state_get(block) == BLOCK_STATE_BLK) {
/* convert from BLK to REP */
block_state_set(block, BLOCK_STATE_REP);
}
/* set the parity association */
fs_allocate(disk, v_pos, file, v_idx);