mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Now pread and pwrite use is required for multithread
We need to support concurrent access at the same file handle from multiple threads, and they cannot share the same file pointer.
This commit is contained in:
parent
62b7587c3a
commit
18cc80bd7e
4 changed files with 1 additions and 58 deletions
|
|
@ -272,24 +272,9 @@ int handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsigned c
|
|||
|
||||
read_size = file_block_size(handle->file, file_pos, block_size);
|
||||
|
||||
#if !HAVE_PREAD
|
||||
if (lseek(handle->f, offset, SEEK_SET) != offset) {
|
||||
/* LCOV_EXCL_START */
|
||||
out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", handle->path, offset, strerror(errno));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
#endif
|
||||
|
||||
count = 0;
|
||||
do {
|
||||
|
||||
#if HAVE_PREAD
|
||||
read_ret = pread(handle->f, block_buffer + count, read_size - count, offset + count);
|
||||
#else
|
||||
read_ret = read(handle->f, block_buffer + count, read_size - count);
|
||||
#endif
|
||||
|
||||
if (read_ret < 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", handle->path, offset + count, read_size - count, strerror(errno));
|
||||
|
|
@ -333,18 +318,7 @@ int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned
|
|||
|
||||
write_size = file_block_size(handle->file, file_pos, block_size);
|
||||
|
||||
#if HAVE_PWRITE
|
||||
write_ret = pwrite(handle->f, block_buffer, write_size, offset);
|
||||
#else
|
||||
if (lseek(handle->f, offset, SEEK_SET) != offset) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("Error seeking file '%s'. %s.\n", handle->path, strerror(errno));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
write_ret = write(handle->f, block_buffer, write_size);
|
||||
#endif
|
||||
if (write_ret != (ssize_t)write_size) { /* conversion is safe because block_size is always small */
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("Error writing file '%s'. %s.\n", handle->path, strerror(errno));
|
||||
|
|
|
|||
|
|
@ -109,8 +109,6 @@
|
|||
#define write windows_write
|
||||
#undef lseek
|
||||
#define lseek windows_lseek
|
||||
#define HAVE_PREAD 1
|
||||
#define HAVE_PWRITE 1
|
||||
#undef pread
|
||||
#define pread windows_pread
|
||||
#undef pwrite
|
||||
|
|
|
|||
|
|
@ -433,22 +433,7 @@ int parity_write(struct snapraid_parity_handle* parity, block_off_t pos, unsigne
|
|||
|
||||
offset = pos * (data_off_t)block_size;
|
||||
|
||||
#if HAVE_PWRITE
|
||||
write_ret = pwrite(parity->f, block_buffer, block_size, offset);
|
||||
#else
|
||||
if (lseek(parity->f, offset, SEEK_SET) != offset) {
|
||||
/* LCOV_EXCL_START */
|
||||
if (errno == ENOSPC) {
|
||||
log_fatal("Failed to grow parity file '%s' using lseek due lack of space.\n", parity->path);
|
||||
} else {
|
||||
log_fatal("Error seeking file '%s'. %s.\n", parity->path, strerror(errno));
|
||||
}
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
write_ret = write(parity->f, block_buffer, block_size);
|
||||
#endif
|
||||
if (write_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */
|
||||
/* LCOV_EXCL_START */
|
||||
if (errno == ENOSPC) {
|
||||
|
|
@ -485,23 +470,9 @@ int parity_read(struct snapraid_parity_handle* parity, block_off_t pos, unsigned
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if !HAVE_PREAD
|
||||
if (lseek(parity->f, offset, SEEK_SET) != offset) {
|
||||
/* LCOV_EXCL_START */
|
||||
out("Error seeking file '%s' at offset %" PRIu64 ". %s.\n", parity->path, offset, strerror(errno));
|
||||
return -1;
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
#endif
|
||||
|
||||
count = 0;
|
||||
do {
|
||||
|
||||
#if HAVE_PREAD
|
||||
read_ret = pread(parity->f, block_buffer + count, block_size - count, offset + count);
|
||||
#else
|
||||
read_ret = read(parity->f, block_buffer + count, block_size - count);
|
||||
#endif
|
||||
if (read_ret < 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
out("Error reading file '%s' at offset %" PRIu64 " for size %u. %s.\n", parity->path, offset + count, block_size - count, strerror(errno));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue