summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2014-08-02 19:18:03 -0400
committerTheodore Ts'o <tytso@mit.edu>2014-08-02 19:18:03 -0400
commitbaa3544609da3c9bbe7e253b83f32df74e1015de (patch)
tree837d6897553dd9fba15353e72eaa39d27c0d850e
parentaf7dbe3a11864e9b515709b62ee6bf2162bfa67b (diff)
downloade2fsprogs-baa3544609da3c9bbe7e253b83f32df74e1015de.tar.gz
libext2fs: have UNIX IO manager use pread/pwrite
If pread/pwrite are present, have the UNIX IO manager use them for aligned IOs (instead of the current seek -> read/write), thereby saving us a (minor) amount of system call overhead. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rwxr-xr-xconfigure2
-rw-r--r--configure.in2
-rw-r--r--lib/config.h.in6
-rw-r--r--lib/ext2fs/unix_io.c24
4 files changed, 33 insertions, 1 deletions
diff --git a/configure b/configure
index 1886f8f0..f0af1d53 100755
--- a/configure
+++ b/configure
@@ -12994,7 +12994,7 @@ if test "$ac_res" != no; then :
fi
fi
-for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime valloc
+for ac_func in __secure_getenv backtrace blkid_probe_get_topology blkid_probe_enable_partitions chflags fadvise64 fallocate fallocate64 fchown fdatasync fstat64 ftruncate64 futimes getcwd getdtablesize getmntinfo getpwuid_r getrlimit getrusage jrand48 llseek lseek64 mallinfo mbstowcs memalign mempcpy mmap msync nanosleep open64 pathconf posix_fadvise posix_fadvise64 posix_memalign prctl pread pwrite secure_getenv setmntent setresgid setresuid snprintf srandom stpcpy strcasecmp strdup strnlen strptime strtoull sync_file_range sysconf usleep utime valloc
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.in b/configure.in
index ed9f691e..b825f3df 100644
--- a/configure.in
+++ b/configure.in
@@ -1059,6 +1059,8 @@ AC_CHECK_FUNCS(m4_flatten([
posix_fadvise64
posix_memalign
prctl
+ pread
+ pwrite
secure_getenv
setmntent
setresgid
diff --git a/lib/config.h.in b/lib/config.h.in
index be415d8a..34fb0cc5 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -325,6 +325,9 @@
/* Define to 1 if you have the `prctl' function. */
#undef HAVE_PRCTL
+/* Define to 1 if you have the `pread' function. */
+#undef HAVE_PREAD
+
/* Define if the <pthread.h> defines PTHREAD_MUTEX_RECURSIVE. */
#undef HAVE_PTHREAD_MUTEX_RECURSIVE
@@ -334,6 +337,9 @@
/* Define to 1 if you have the `putenv' function. */
#undef HAVE_PUTENV
+/* Define to 1 if you have the `pwrite' function. */
+#undef HAVE_PWRITE
+
/* Define to 1 if dirent has d_reclen */
#undef HAVE_RECLEN_DIRENT
diff --git a/lib/ext2fs/unix_io.c b/lib/ext2fs/unix_io.c
index e93684e8..0dd14901 100644
--- a/lib/ext2fs/unix_io.c
+++ b/lib/ext2fs/unix_io.c
@@ -130,6 +130,18 @@ static errcode_t raw_read_blk(io_channel channel,
size = (count < 0) ? -count : count * channel->block_size;
data->io_stats.bytes_read += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
+
+#ifdef HAVE_PREAD
+ /* Try an aligned pread */
+ if ((channel->align == 0) ||
+ (IS_ALIGNED(buf, channel->align) &&
+ IS_ALIGNED(size, channel->align))) {
+ actual = pread(data->dev, buf, size, location);
+ if (actual == size)
+ return 0;
+ }
+#endif /* HAVE_PREAD */
+
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
goto error_out;
@@ -200,6 +212,18 @@ static errcode_t raw_write_blk(io_channel channel,
data->io_stats.bytes_written += size;
location = ((ext2_loff_t) block * channel->block_size) + data->offset;
+
+#ifdef HAVE_PWRITE
+ /* Try an aligned pwrite */
+ if ((channel->align == 0) ||
+ (IS_ALIGNED(buf, channel->align) &&
+ IS_ALIGNED(size, channel->align))) {
+ actual = pwrite(data->dev, buf, size, location);
+ if (actual == size)
+ return 0;
+ }
+#endif /* HAVE_PWRITE */
+
if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
goto error_out;