diff --git a/HISTORY b/HISTORY index 75225e61..42d6871a 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,8 @@ SnapRAID HISTORY 0.2 2011/3 ========== +* Second public test release of SnapRAID. +* Functionally complete in check and fix. * Files are identified by inode and not anymore by name. * Exclusion list of files and directories. * Precise error management. diff --git a/handle.c b/handle.c index 0d372adf..c65b6536 100644 --- a/handle.c +++ b/handle.c @@ -287,3 +287,28 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u return 0; } +int handle_readahead(struct snapraid_handle* handle, struct snapraid_block* block, unsigned block_size) +{ +#if HAVE_POSIX_FADVISE + data_off_t offset; + unsigned read_size; + int ret; + + /* do nothing if the file is different */ + if (handle->file != block->file) + return 0; + + offset = block_file_pos(block) * (data_off_t)block_size; + + read_size = block_file_size(block, block_size); + + /* advise access of the next block */ + ret = posix_fadvise(handle->f, offset, read_size, POSIX_FADV_WILLNEED); + if (ret != 0) { + fprintf(stderr, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); + return -1; + } +#endif + + return 0; +} diff --git a/handle.h b/handle.h index 19833201..2c48e77f 100644 --- a/handle.h +++ b/handle.h @@ -61,5 +61,12 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un */ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size); +/** + * Readahead optimization where available. + * \note + * It doesn't seem to give any speed improvement over posix_fadvise(POSIX_FADV_SEQUENTIAL). + */ +int handle_readahead(struct snapraid_handle* handle, struct snapraid_block* block, unsigned block_size); + #endif