Adds initial readahead support.

This commit is contained in:
Andrea Mazzoleni 2011-03-23 19:22:56 +01:00
parent 87bb5c7a66
commit d24df4257e
3 changed files with 34 additions and 0 deletions

View file

@ -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.

View file

@ -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;
}

View file

@ -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