From eaa89473b47b6543939ec7e9ec11a29c14699973 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 15 Jan 2016 20:05:38 +0100 Subject: [PATCH] Keep different the functions that may not find the parity --- cmdline/elem.c | 2 +- cmdline/elem.h | 29 ++++++++++++++++++++++++++++- cmdline/scan.c | 4 ++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/cmdline/elem.c b/cmdline/elem.c index b3185c97..5dc6af18 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -1155,7 +1155,7 @@ struct snapraid_file* fs_par2file_get_ts(struct snapraid_disk* disk, struct snap return chunk->file; } -block_off_t fs_file2par_get_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, struct snapraid_file* file, block_off_t file_pos) +block_off_t fs_file2par_maybe_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, struct snapraid_file* file, block_off_t file_pos) { struct snapraid_chunk* chunk; diff --git a/cmdline/elem.h b/cmdline/elem.h index 972342e4..c50c9052 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -937,13 +937,40 @@ static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk, /** * Like fs_file2par_get() but thread-safe. */ -block_off_t fs_file2par_get_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, struct snapraid_file* file, block_off_t file_pos); +block_off_t fs_file2par_maybe_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, struct snapraid_file* file, block_off_t file_pos); /** * Get the parity position from the file position. * Return POS_INVALID if no parity is allocated. * \note This function is NOT thread-safe as it uses the the disk cache. */ +static inline block_off_t fs_file2par_maybe(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos) +{ + return fs_file2par_maybe_ts(disk, &disk->fs_last, file, file_pos); +} + +/** + * Like fs_file2par_get() but thread-safe. + */ +static inline block_off_t fs_file2par_get_ts(struct snapraid_disk* disk, struct snapraid_chunk** fs_last, struct snapraid_file* file, block_off_t file_pos) +{ + block_off_t ret; + + ret = fs_file2par_maybe_ts(disk, fs_last, file, file_pos); + if (ret == POS_INVALID) { + /* 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); + os_abort(); + /* LCOV_EXCL_STOP */ + } + + return ret; +} + +/** + * Get the parity position from the file position. + * \note This function is NOT thread-safe as it uses the the disk cache. + */ static inline block_off_t fs_file2par_get(struct snapraid_disk* disk, struct snapraid_file* file, block_off_t file_pos) { return fs_file2par_get_ts(disk, &disk->fs_last, file, file_pos); diff --git a/cmdline/scan.c b/cmdline/scan.c index 5a2ef66e..c3eeff1f 100644 --- a/cmdline/scan.c +++ b/cmdline/scan.c @@ -385,7 +385,7 @@ static int file_is_full_invalid_parity_and_stable(struct snapraid_state* state, * * Anyway, checking for POS_INVALID doesn't hurt. */ - parity_pos = fs_file2par_get(disk, file, i); + parity_pos = fs_file2par_maybe(disk, file, i); /* if it's not mapped, it cannot have rehash */ if (parity_pos != POS_INVALID) { @@ -437,7 +437,7 @@ static int file_is_full_hashed_and_stable(struct snapraid_state* state, struct s * that such files are used as 'source' to copy * hashes, and then to get them inside this function. */ - parity_pos = fs_file2par_get(disk, file, i); + parity_pos = fs_file2par_maybe(disk, file, i); /* if it's not mapped, it cannot have rehash */ if (parity_pos != POS_INVALID) {