Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08d285e

Browse files
macdicepull[bot]
authored andcommitted
Simplify replacement code for preadv and pwritev.
preadv() and pwritev() are not standardized by POSIX, but appeared inNetBSD in 1999 and were adopted by at least OpenBSD, FreeBSD,DragonFlyBSD, Linux, AIX, illumos and macOS. We don't use them muchyet, but an active proposal uses them heavily.In 15, we had two replacement implementations for other OSes: one basedon lseek() + -v function if available for true vector I/O, and the otherbased on a loop over p- function.The former would be an obstacle to hypothetical future multi-threadedcode sharing file descriptors, while the latter would not, since commitcf112c1. Furthermore, the number of targeted systems that couldbenefit from the former's potential upside has dwindled to just oneniche 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 nowthat the file position portability hazard is gone.At the time of writing, the only systems in our build farm that lacknative preadv/pwritev and thus use fallback code are: * Solaris (but not illumos) * macOS before release 11.0 * WindowsWith this commit, the above systems will now use the *same* fallbackcode, the version that loops over pread()/pwrite(). Windows alreadyused that (though a later proposal may include true vector I/O forWindows), so this decision really only affects Solaris, until it getsaround 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
1 parent9509ea9 commit08d285e

File tree

8 files changed

+9
-53
lines changed

8 files changed

+9
-53
lines changed

‎configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16039,7 +16039,7 @@ fi
1603916039
LIBS_including_readline="$LIBS"
1604016040
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1604116041

16042-
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_npreadvsetproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l writev
16042+
for ac_func in backtrace_symbols clock_gettime copyfile fdatasync getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l
1604316043
do :
1604416044
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
1604516045
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

‎configure.ac

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,6 @@ AC_CHECK_FUNCS(m4_normalize([
18031803
posix_fallocate
18041804
ppoll
18051805
pthread_is_threaded_np
1806-
readv
18071806
setproctitle
18081807
setproctitle_fast
18091808
strchrnul
@@ -1812,7 +1811,6 @@ AC_CHECK_FUNCS(m4_normalize([
18121811
sync_file_range
18131812
uselocale
18141813
wcstombs_l
1815-
writev
18161814
]))
18171815

18181816
# These typically are compiler builtins, for which AC_CHECK_FUNCS fails.

‎src/backend/storage/file/fd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,7 @@ data_sync_elevel(int elevel)
37623762
}
37633763

37643764
/*
3765-
* A convenience wrapper forpg_pwritev() that retries on partial write. If an
3765+
* A convenience wrapper forpwritev() that retries on partial write. If an
37663766
* error is returned, it is unspecified how much has been written.
37673767
*/
37683768
ssize_t
@@ -3782,7 +3782,7 @@ pg_pwritev_with_retry(int fd, const struct iovec *iov, int iovcnt, off_t offset)
37823782
for (;;)
37833783
{
37843784
/* Write as much as we can. */
3785-
part=pg_pwritev(fd,iov,iovcnt,offset);
3785+
part=pwritev(fd,iov,iovcnt,offset);
37863786
if (part<0)
37873787
return-1;
37883788

‎src/include/pg_config.h.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,6 @@
412412
/* Define to 1 if you have the <readline/readline.h> header file. */
413413
#undef HAVE_READLINE_READLINE_H
414414

415-
/* Define to 1 if you have the `readv' function. */
416-
#undef HAVE_READV
417-
418415
/* Define to 1 if you have the `rl_completion_matches' function. */
419416
#undef HAVE_RL_COMPLETION_MATCHES
420417

@@ -643,9 +640,6 @@
643640
/* Define to 1 if you have the <winldap.h> header file. */
644641
#undef HAVE_WINLDAP_H
645642

646-
/* Define to 1 if you have the `writev' function. */
647-
#undef HAVE_WRITEV
648-
649643
/* Define to 1 if you have the `X509_get_signature_nid' function. */
650644
#undef HAVE_X509_GET_SIGNATURE_NID
651645

‎src/include/port/pg_iovec.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,12 @@ struct iovec
3939
/* Define a reasonable maximum that is safe to use on the stack. */
4040
#definePG_IOV_MAX Min(IOV_MAX, 32)
4141

42-
#ifHAVE_DECL_PREADV
43-
#definepg_preadv preadv
44-
#else
45-
externssize_tpg_preadv(intfd,conststructiovec*iov,intiovcnt,off_toffset);
42+
#if !HAVE_DECL_PREADV
43+
externssize_tpreadv(intfd,conststructiovec*iov,intiovcnt,off_toffset);
4644
#endif
4745

48-
#ifHAVE_DECL_PWRITEV
49-
#definepg_pwritev pwritev
50-
#else
51-
externssize_tpg_pwritev(intfd,conststructiovec*iov,intiovcnt,off_toffset);
46+
#if !HAVE_DECL_PWRITEV
47+
externssize_tpwritev(intfd,conststructiovec*iov,intiovcnt,off_toffset);
5248
#endif
5349

5450
#endif/* PG_IOVEC_H */

‎src/port/preadv.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,19 @@
88
* IDENTIFICATION
99
* src/port/preadv.c
1010
*
11-
* Note that this implementation changes the current file position, unlike
12-
* the POSIX-like function, so we use the name pg_preadv().
13-
*
1411
*-------------------------------------------------------------------------
1512
*/
1613

1714

1815
#include"postgres.h"
1916

20-
#ifdefWIN32
21-
#include<windows.h>
22-
#else
2317
#include<unistd.h>
24-
#endif
2518

2619
#include"port/pg_iovec.h"
2720

2821
ssize_t
29-
pg_preadv(intfd,conststructiovec*iov,intiovcnt,off_toffset)
22+
preadv(intfd,conststructiovec*iov,intiovcnt,off_toffset)
3023
{
31-
#ifdefHAVE_READV
32-
if (iovcnt==1)
33-
returnpread(fd,iov[0].iov_base,iov[0].iov_len,offset);
34-
if (lseek(fd,offset,SEEK_SET)<0)
35-
return-1;
36-
returnreadv(fd,iov,iovcnt);
37-
#else
3824
ssize_tsum=0;
3925
ssize_tpart;
4026

@@ -54,5 +40,4 @@ pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
5440
returnsum;
5541
}
5642
returnsum;
57-
#endif
5843
}

‎src/port/pwritev.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,19 @@
88
* IDENTIFICATION
99
* src/port/pwritev.c
1010
*
11-
* Note that this implementation changes the current file position, unlike
12-
* the POSIX-like function, so we use the name pg_pwritev().
13-
*
1411
*-------------------------------------------------------------------------
1512
*/
1613

1714

1815
#include"postgres.h"
1916

20-
#ifdefWIN32
21-
#include<windows.h>
22-
#else
2317
#include<unistd.h>
24-
#endif
2518

2619
#include"port/pg_iovec.h"
2720

2821
ssize_t
29-
pg_pwritev(intfd,conststructiovec*iov,intiovcnt,off_toffset)
22+
pwritev(intfd,conststructiovec*iov,intiovcnt,off_toffset)
3023
{
31-
#ifdefHAVE_WRITEV
32-
if (iovcnt==1)
33-
returnpwrite(fd,iov[0].iov_base,iov[0].iov_len,offset);
34-
if (lseek(fd,offset,SEEK_SET)<0)
35-
return-1;
36-
returnwritev(fd,iov,iovcnt);
37-
#else
3824
ssize_tsum=0;
3925
ssize_tpart;
4026

@@ -54,5 +40,4 @@ pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
5440
returnsum;
5541
}
5642
returnsum;
57-
#endif
5843
}

‎src/tools/msvc/Solution.pm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ sub GenerateFiles
332332
HAVE_READLINE_H=>undef,
333333
HAVE_READLINE_HISTORY_H=>undef,
334334
HAVE_READLINE_READLINE_H=>undef,
335-
HAVE_READV=>undef,
336335
HAVE_RL_COMPLETION_MATCHES=>undef,
337336
HAVE_RL_COMPLETION_SUPPRESS_QUOTE=>undef,
338337
HAVE_RL_FILENAME_COMPLETION_FUNCTION=>undef,
@@ -408,7 +407,6 @@ sub GenerateFiles
408407
HAVE_WINLDAP_H=>undef,
409408
HAVE_WCSTOMBS_L=> 1,
410409
HAVE_VISIBILITY_ATTRIBUTE=>undef,
411-
HAVE_WRITEV=>undef,
412410
HAVE_X509_GET_SIGNATURE_NID=> 1,
413411
HAVE_X86_64_POPCNTQ=>undef,
414412
HAVE__BOOL=>undef,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp