summaryrefslogtreecommitdiff
path: root/src/port
diff options
context:
space:
mode:
authorThomas Munro <tmunro@postgresql.org>2022-08-05 11:43:14 +1200
committerThomas Munro <tmunro@postgresql.org>2022-08-05 14:04:02 +1200
commita0dc82711221aa220c5246fe788e5ed28924a4ea (patch)
tree09548e065aea773708922bf263e7cb51d261a6c2 /src/port
parent718fe0a14add0fadb17d715d7aa24ebcf3fb35c4 (diff)
downloadpostgresql-a0dc82711221aa220c5246fe788e5ed28924a4ea.tar.gz
Simplify replacement code for preadv and pwritev.
preadv() and pwritev() are not standardized by POSIX, but appeared in NetBSD in 1999 and were adopted by at least OpenBSD, FreeBSD, DragonFlyBSD, Linux, AIX, illumos and macOS. We don't use them much yet, but an active proposal uses them heavily. In 15, we had two replacement implementations for other OSes: one based on lseek() + -v function if available for true vector I/O, and the other based on a loop over p- function. The former would be an obstacle to hypothetical future multi-threaded code sharing file descriptors, while the latter would not, since commit cf112c12. Furthermore, the number of targeted systems that could benefit from the former's potential upside has dwindled to just one niche OS, since macOS added the functions and we de-supported HP-UX. That doesn't seem like a good trade-off. Therefore, drop the lseek()-based variant, and also the pg_ prefix now that the file position portability hazard is gone. At the time of writing, the only systems in our build farm that lack native preadv/pwritev and thus use fallback code are: * Solaris (but not illumos) * macOS before release 11.0 * Windows With this commit, the above systems will now use the *same* fallback code, the version that loops over pread()/pwrite(). Windows already used that (though a later proposal may include true vector I/O for Windows), so this decision really only affects Solaris, until it gets around to adding these system calls. Also remove some useless includes while here. Reviewed-by: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CA+hUKGJ3LHeP9w5Fgzdr4G8AnEtJ=z=p6hGDEm4qYGEUX5B6fQ@mail.gmail.com
Diffstat (limited to 'src/port')
-rw-r--r--src/port/preadv.c17
-rw-r--r--src/port/pwritev.c17
2 files changed, 2 insertions, 32 deletions
diff --git a/src/port/preadv.c b/src/port/preadv.c
index aa7537503f..48b64d4593 100644
--- a/src/port/preadv.c
+++ b/src/port/preadv.c
@@ -8,33 +8,19 @@
* IDENTIFICATION
* src/port/preadv.c
*
- * Note that this implementation changes the current file position, unlike
- * the POSIX-like function, so we use the name pg_preadv().
- *
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#ifdef WIN32
-#include <windows.h>
-#else
#include <unistd.h>
-#endif
#include "port/pg_iovec.h"
ssize_t
-pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
+preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
-#ifdef HAVE_READV
- if (iovcnt == 1)
- return pread(fd, iov[0].iov_base, iov[0].iov_len, offset);
- if (lseek(fd, offset, SEEK_SET) < 0)
- return -1;
- return readv(fd, iov, iovcnt);
-#else
ssize_t sum = 0;
ssize_t part;
@@ -54,5 +40,4 @@ pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
return sum;
}
return sum;
-#endif
}
diff --git a/src/port/pwritev.c b/src/port/pwritev.c
index cb7421381e..8b303fcbcd 100644
--- a/src/port/pwritev.c
+++ b/src/port/pwritev.c
@@ -8,33 +8,19 @@
* IDENTIFICATION
* src/port/pwritev.c
*
- * Note that this implementation changes the current file position, unlike
- * the POSIX-like function, so we use the name pg_pwritev().
- *
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#ifdef WIN32
-#include <windows.h>
-#else
#include <unistd.h>
-#endif
#include "port/pg_iovec.h"
ssize_t
-pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
+pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
{
-#ifdef HAVE_WRITEV
- if (iovcnt == 1)
- return pwrite(fd, iov[0].iov_base, iov[0].iov_len, offset);
- if (lseek(fd, offset, SEEK_SET) < 0)
- return -1;
- return writev(fd, iov, iovcnt);
-#else
ssize_t sum = 0;
ssize_t part;
@@ -54,5 +40,4 @@ pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
return sum;
}
return sum;
-#endif
}