mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-09 04:11:27 +08:00
52bd938169
This patch adds support of preadv2 and pwritev2 which are similar to preadv/pwritev but with an extra flag argument. As for preadv/pwritev both interfaces are added a non-standard GNU API. For default 'posix' implementation trying to emulate the Linux supported flags is troublesome: * We can not temporary change the file state of the O_DSYNC and O_SYNC flags to emulate RWF_{D}SYNC (attempts to change the state of using fcntl are silently ignored). * IOCB_HIPRI requires the file opened in O_DIRECT and uses an internal semantic not provided by any other flag (O_NONBLOCK for instance). So default sysdeps/posix implementations fails with EOPNOTSUPP for any non supported flag (which are none currently) calls generic preadv/pwritev. Basically this implementation supports only preadv2 called as preadv (with flags sets to 0). The Linux one uses the preadv2/pwritev2 syscall if defined, otherwise it call preadv/writev. Instead of using the previous __ASSUME_* to unconditionally issue the syscall (and avoid building the fallback routine), it call pread/write if the preadv2/pwritev2 syscalls fails. The idea is just avoid adding another __ASSUME_* and checking each architecture on every kernel bump and simplify code conditionals. Checked on x86_64-linux-gnu and on i686-linux-gnu and a check with run-built-tests=no on aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf, ia64-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu, mips{64,64n32}-linux-gnu, nios2-linux-gnu, powerpc{64,64le}-linux-gnu, s390{x}-linux-gnu, sparc{64,v9}-linux-gnu, tile{gx,pro}-linux-gnu, and sh4-linux-gnu (all using gcc 6.3). * NEWS: Add note about pwritev2 and preadv2 inclusion. * misc/Makefile (routines): Add preadv2, preadv64v2, pwritev2, and pwritev64v2. (tests): Add tst-preadvwritev2 and tst-preadvwritev64v2. * misc/Versions (GLIBC_2.26): Add preadv2, preadv64v2, pwritev2, and pwritev64v2. * misc/preadv2.c: New file. * misc/preadv64v2.c: Likewise. * misc/pwritev2.c: Likewise. * misc/pwritev64v2.c: Likewise. * misc/tst-preadvwritev2.c: Likewise. * misc/tst-preadvwritev64v2.c: Likewise. * manual/llio.texi: Add preadv2 and pwritev2 documentation. * misc/sys/uio.h [__USE_GNU && !__USE_FILE_OFFSET64] (preadv2): New prototype. [__USE_GNU && !__USE_FILE_OFFSET64] (pwritev2): Likewise. [__USE_GNU && __USE_FILE_OFFSET64] (preadv64v2): Likewise. [__USE_GNU && __USE_FILE_OFFSET64] (pwritev64v2): Likewise. * misc/tst-preadvwritev-common.c (PREADV): Define if not defined. (PWRITEV): Likewise. (do_test_with_offset): Use PREADV and PWRITEV macros and check for ENOSYS. * nptl/tst-cancel4.c (tf_pwritev2): New test. (tf_preadv2): Likewise. (tf_fsync): Add tf_pwritev2 and tf_preadv2. * sysdeps/posix/preadv2.c: Likewise. * sysdeps/posix/preadv64v2.c: Likewise. * sysdeps/posix/pwritev2.c: Likewise. * sysdeps/posix/pwritev64v2.c: Likewise. * sysdeps/unix/sysv/linux/kernel-features.h: Add comment for syscall support in kernel. * sysdeps/unix/sysv/linux/preadv2.c: Likewise. * sysdeps/unix/sysv/linux/preadv64v2.c: Likewise. * sysdeps/unix/sysv/linux/pwritev2.c: Likewise. * sysdeps/unix/sysv/linux/pwritev64v2.c: Likewise. * sysdeps/unix/sysv/linux/preadv.c (preadv): Add libc_hidden_def. * sysdeps/unix/sysv/linux/preadv64.c (preadv64): Likewise. * sysdeps/unix/sysv/linux/pwritev.c (pwritev): Likewise. * sysdeps/unix/sysv/linux/pwritev64.c (pwritev64): Likewise. * sysdeps/unix/sysv/linux/bits/uio.h: Add supported preadv2/pwritev2 support flags on Linux. * sysdeps/unix/sysv/linux/aarch64/libc.abilist (GLIBC_2.26): Add preadv2, preadv64v2, pwritev2, pwritev64v2. * sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/sysv/linux/tile/tilegx/tilegx32/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/sysv/linux/tile/tilegx/tilegx64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.26): Likewise. * sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.26): Likewise.
123 lines
3.6 KiB
C
123 lines
3.6 KiB
C
/* Common definitions for preadv and pwritev.
|
|
Copyright (C) 2016-2017 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <sys/uio.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <support/check.h>
|
|
#include <support/temp_file.h>
|
|
|
|
static char *temp_filename;
|
|
static int temp_fd;
|
|
|
|
static int do_test (void);
|
|
|
|
static void
|
|
do_prepare (int argc, char **argv)
|
|
{
|
|
temp_fd = create_temp_file ("tst-preadvwritev.", &temp_filename);
|
|
if (temp_fd == -1)
|
|
FAIL_EXIT1 ("cannot create temporary file");
|
|
}
|
|
#define PREPARE do_prepare
|
|
|
|
#ifndef PREADV
|
|
# define PREADV(__fd, __iov, __iovcnt, __offset) \
|
|
preadv (__fd, __iov, __iovcnt, __offset)
|
|
#endif
|
|
|
|
#ifndef PWRITEV
|
|
# define PWRITEV(__fd, __iov, __iovcnt, __offset) \
|
|
pwritev (__fd, __iov, __iovcnt, __offset)
|
|
#endif
|
|
|
|
static int
|
|
do_test_with_offset (off_t offset)
|
|
{
|
|
struct iovec iov[2];
|
|
ssize_t ret;
|
|
|
|
char buf1[32];
|
|
char buf2[64];
|
|
|
|
memset (buf1, 0xf0, sizeof buf1);
|
|
memset (buf2, 0x0f, sizeof buf2);
|
|
|
|
/* Write two buffer with 32 and 64 bytes respectively. */
|
|
memset (iov, 0, sizeof iov);
|
|
iov[0].iov_base = buf1;
|
|
iov[0].iov_len = sizeof buf1;
|
|
iov[1].iov_base = buf2;
|
|
iov[1].iov_len = sizeof buf2;
|
|
|
|
ret = PWRITEV (temp_fd, iov, 2, offset);
|
|
if (ret == -1)
|
|
FAIL_RET ("first pwritev returned -1");
|
|
if (ret != (sizeof buf1 + sizeof buf2))
|
|
FAIL_RET ("first pwritev returned an unexpected value");
|
|
|
|
ret = PWRITEV (temp_fd, iov, 2, sizeof buf1 + sizeof buf2 + offset);
|
|
if (ret == -1)
|
|
FAIL_RET ("second pwritev returned -1");
|
|
if (ret != (sizeof buf1 + sizeof buf2))
|
|
FAIL_RET ("second pwritev returned an unexpected value");
|
|
|
|
char buf3[32];
|
|
char buf4[64];
|
|
|
|
memset (buf3, 0x0f, sizeof buf3);
|
|
memset (buf4, 0xf0, sizeof buf4);
|
|
|
|
iov[0].iov_base = buf3;
|
|
iov[0].iov_len = sizeof buf3;
|
|
iov[1].iov_base = buf4;
|
|
iov[1].iov_len = sizeof buf4;
|
|
|
|
/* Now read two buffer with 32 and 64 bytes respectively. */
|
|
ret = PREADV (temp_fd, iov, 2, offset);
|
|
if (ret == -1)
|
|
FAIL_RET ("first preadv returned -1");
|
|
if (ret != (sizeof buf3 + sizeof buf4))
|
|
FAIL_RET ("first preadv returned an unexpected value");
|
|
|
|
if (memcmp (buf1, buf3, sizeof buf1) != 0)
|
|
FAIL_RET ("first buffer from first preadv different than expected");
|
|
if (memcmp (buf2, buf4, sizeof buf2) != 0)
|
|
FAIL_RET ("second buffer from first preadv different than expected");
|
|
|
|
ret = PREADV (temp_fd, iov, 2, sizeof buf3 + sizeof buf4 + offset);
|
|
if (ret == -1)
|
|
FAIL_RET ("second preadv returned -1");
|
|
if (ret != (sizeof buf3 + sizeof buf4))
|
|
FAIL_RET ("second preadv returned an unexpected value");
|
|
|
|
/* And compare the buffers read and written to check if there are equal. */
|
|
if (memcmp (buf1, buf3, sizeof buf1) != 0)
|
|
FAIL_RET ("first buffer from second preadv different than expected");
|
|
if (memcmp (buf2, buf4, sizeof buf2) != 0)
|
|
FAIL_RET ("second buffer from second preadv different than expected");
|
|
|
|
return 0;
|
|
}
|
|
|
|
#include <support/test-driver.c>
|