From 18cc80bd7eccd21c6445c146e9aedb8cd595c712 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 4 Jan 2016 17:53:04 +0100 Subject: [PATCH] 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. --- cmdline/handle.c | 26 -------------------------- cmdline/mingw.h | 2 -- cmdline/parity.c | 29 ----------------------------- configure.ac | 2 +- 4 files changed, 1 insertion(+), 58 deletions(-) diff --git a/cmdline/handle.c b/cmdline/handle.c index 531ba1e7..69e9f386 100644 --- a/cmdline/handle.c +++ b/cmdline/handle.c @@ -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)); diff --git a/cmdline/mingw.h b/cmdline/mingw.h index 21f309e1..aeb34def 100644 --- a/cmdline/mingw.h +++ b/cmdline/mingw.h @@ -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 diff --git a/cmdline/parity.c b/cmdline/parity.c index 92d2db8c..ab7ce9ac 100644 --- a/cmdline/parity.c +++ b/cmdline/parity.c @@ -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)); diff --git a/configure.ac b/configure.ac index 03244d1b..b5adb42f 100644 --- a/configure.ac +++ b/configure.ac @@ -82,7 +82,7 @@ dnl Checks for library functions. AC_CHECK_FUNCS([memset strchr strerror strrchr mkdir gettimeofday strtoul]) AC_CHECK_FUNCS([getopt getopt_long snprintf vsnprintf sigaction]) AC_CHECK_FUNCS([ftruncate fallocate fsync access posix_fallocate posix_fadvise]) -AC_CHECK_FUNCS([pread pwrite getc_unlocked ferror_unlocked fnmatch]) +AC_CHECK_FUNCS([getc_unlocked ferror_unlocked fnmatch]) AC_CHECK_FUNCS([futimes futimens futimesat localtime_r]) AC_CHECK_FUNCS([fstatat flock statfs]) AC_CHECK_FUNCS([mach_absolute_time])