mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-30 11:56:33 -05:00
Adds initial readahead support.
This commit is contained in:
parent
87bb5c7a66
commit
d24df4257e
3 changed files with 34 additions and 0 deletions
25
handle.c
25
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue