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

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