aboutsummaryrefslogtreecommitdiff
path: root/src/port/open.c
Commit message (Collapse)AuthorAge
* Update copyright for 2025Bruce Momjian2025-01-01
| | | | Backpatch-through: 13
* Update copyright for 2024Bruce Momjian2024-01-03
| | | | | | | | Reported-by: Michael Paquier Discussion: https://postgr.es/m/ZZKTDPxBBMt3C0J9@paquier.xyz Backpatch-through: 12
* Update copyright for 2023Bruce Momjian2023-01-02
| | | | Backpatch-through: 11
* windows: Set UMDF_USING_NTSTATUS globally, include ntstatus.hAndres Freund2022-09-28
| | | | | | | | | | | | | | | | We'd like to use precompiled headers on windows to reduce compile times. Right now we rely on defining UMDF_USING_NTSTATUS before including postgres.h in a few select places - which doesn't work with precompiled headers. Instead define it globally. When UMDF_USING_NTSTATUS is defined we need to explicitly include ntstatus.h, winternl.h to get a comparable set of symbols. Right now these includes would be required in a number of non-platform-specific .c files - to avoid that, include them in win32_port.h. Based on my measurements that doesn't increase compile times measurably. Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Discussion: https://postgr.es/m/20220927011951.j3h4o7n6bhf7dwau@awork3.anarazel.de
* Update copyright for 2022Bruce Momjian2022-01-07
| | | | Backpatch-through: 10
* Check for STATUS_DELETE_PENDING on Windows.Thomas Munro2021-12-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. Update our open() wrapper to check for NT's STATUS_DELETE_PENDING and translate it to Unix-like errors. This is done with RtlGetLastNtStatus(), which is dynamically loaded from ntdll. A new file win32ntdll.c centralizes lookup of NT functions, in case we decide to add more in the future. 2. Remove non-working code that was trying to do something similar for stat(), and just reuse the open() wrapper code. As a side effect, stat() also gains resilience against "sharing violation" errors. 3. Since stat() is used very early in process startup, remove the requirement that the Win32 signal event has been created before pgwin32_open_handle() is reached. Instead, teach pg_usleep() to fall back to a non-interruptible sleep if reached before the signal event is available. This could be back-patched, but for now it's in master only. The problem has apparently been with us for a long time and generated only a few complaints. Proposed patches trigger it more often, which led to this investigation and fix. Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGJz_pZTF9mckn6XgSv69%2BjGwdgLkxZ6b3NWGLBCVjqUZA%40mail.gmail.com
* Revert "Fix issues with Windows' stat() for files pending on deletion"Michael Paquier2021-07-12
| | | | | | | | | | | | | | | This reverts commit 54fb8c7, as per the issues reported by fairywren when it comes to MinGW because of the lack of microsoft_native_stat() there. Using just stat() for MSVC is not sufficient to take care of the concurrency problems with files pending on deletion. It may be possible to paint some __MINGW64__ in the code to switch to a different implementation of stat() in this build context, but I am not sure either if relying on the implementation of stat() in MinGW to take care of the problems we are trying to fix is enough or not. So this needs more study. Discussion: https://postgr.es/m/YOvOlfRrIO0yGtgw@paquier.xyz Backpatch-through: 14
* Fix issues with Windows' stat() for files pending on deletionMichael Paquier2021-07-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code introduced by bed9075 to enhance the stat() implementation on Windows for file sizes larger than 4GB fails to properly detect files pending for deletion with its method based on NtQueryInformationFile() or GetFileInformationByHandleEx(), as proved by Alexander Lakhin in a custom TAP test of his own. The method used in the implementation of open() to sleep and loop when when failing on ERROR_ACCESS_DENIED (EACCES) is showing much more stability, so switch to this method. This could still lead to issues if the permission problem stays around for much longer than the timeout of 1 second used, but that should (hopefully) never happen in performance-critical paths. Still, there could be a point in increasing the timeouts for the sake of machines that handle heavy loads. Note that WIN32's open() now uses microsoft_native_stat() as it should be similar to stat() when working around issues with concurrent file deletions. I have spent some time testing this patch with pgbench in combination of the SQL functions from genfile.c, as well as running the TAP test provided on the thread with MSVC builds, and this looks much more stable than the previous method. Author: Alexander Lakhin Reviewed-by: Tom Lane, Michael Paquier, Justin Pryzby Discussion: https://postgr.es/m/c3427edf-d7c0-ff57-90f6-b5de3bb62709@gmail.com Backpatch-through: 14
* Update copyright for 2021Bruce Momjian2021-01-02
| | | | Backpatch-through: 9.5
* Update copyrights for 2020Bruce Momjian2020-01-01
| | | | Backpatch-through: update all files in master, backpatch legal files through 9.4
* In pgwin32_open, loop after ERROR_ACCESS_DENIED only if we can't stat.Tom Lane2019-12-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a performance problem introduced by commit 6d7547c21. ERROR_ACCESS_DENIED is returned in some other cases besides the delete-pending case considered by that commit; notably, if the given path names a directory instead of a plain file. In that case we'll uselessly loop for 1 second before returning the failure condition. That slows down some usage scenarios enough to cause test timeout failures on our Windows buildfarm critters. To fix, try to stat() the file, and sleep/loop only if that fails. It will fail in the delete-pending case, and also in the case where the deletion completed before we could stat(), so we have the cases where we want to loop covered. In the directory case, the stat() should succeed, letting us exit without a wait. One case where we'll still wait uselessly is if the access-denied problem pertains to a directory in the given pathname. But we don't expect that to happen in any performance-critical code path. There might be room to refine this further, but I'll push it now in hopes of making the buildfarm green again. Back-patch, like the preceding commit. Alexander Lakhin and Tom Lane Discussion: https://postgr.es/m/23073.1576626626@sss.pgh.pa.us
* On Windows, wait a little to see if ERROR_ACCESS_DENIED goes away.Tom Lane2019-12-16
| | | | | | | | | | | | | | | | | | | | | | | Attempting to open a file fails with ERROR_ACCESS_DENIED if the file is flagged for deletion but not yet actually gone (another in a long list of reasons why Windows is broken, if you ask me). This seems likely to explain a lot of irreproducible failures we see in the buildfarm. This state generally persists for only a millisecond or so, so just wait a bit and retry. If it's a real permissions problem, we'll eventually give up and report it as such. If it's the pending deletion case, we'll see file-not-found and report that after the deletion completes, and the caller will treat that in an appropriate way. In passing, rejigger the existing retry logic for some other error cases so that we don't uselessly wait an extra time when we're not going to retry anymore. Alexander Lakhin (with cosmetic tweaks by me). Back-patch to all supported branches, since this seems like a pretty safe change and the problem is definitely real. Discussion: https://postgr.es/m/16161-7a985d2f1bbe8f71@postgresql.org
* Assert that pgwin32_signal_initialize() has been called early enough.Noah Misch2019-04-03
| | | | | | | | Before the pgwin32_signal_initialize() call, the backend version of pg_usleep() has no effect. No in-tree code falls afoul of that today, but temporary commit 23078689a9921968ac0873b017be6e7f772f10bc did so. Discussion: https://postgr.es/m/20190402135442.GA1173872@rfd.leadboat.com
* Update copyright for 2019Bruce Momjian2019-01-02
| | | | Backpatch-through: certain files through 9.4
* Enforce translation mode for Windows frontends to text with open/fopenMichael Paquier2018-09-20
| | | | | | | | | | | | | Allowing frontends to use concurrent-safe open() and fopen() via 0ba06e0 has the side-effect of switching the default translation mode from text to binary, so the switch can cause breakages for frontend tools when the caller of those new versions specifies neither binary and text. This commit makes sure to maintain strict compatibility with past versions, so as no frontends should see a difference when upgrading. Author: Laurenz Albe Reviewed-by: Michael Paquier, Tom Lane Discussion: https://postgr.es/m/20180917140202.GF31460@paquier.xyz
* Update copyright for 2018Bruce Momjian2018-01-02
| | | | Backpatch-through: certain files through 9.3
* Phase 3 of pgindent updates.Tom Lane2017-06-21
| | | | | | | | | | | | | | | | | | | | | | | | | Don't move parenthesized lines to the left, even if that means they flow past the right margin. By default, BSD indent lines up statement continuation lines that are within parentheses so that they start just to the right of the preceding left parenthesis. However, traditionally, if that resulted in the continuation line extending to the right of the desired right margin, then indent would push it left just far enough to not overrun the margin, if it could do so without making the continuation line start to the left of the current statement indent. That makes for a weird mix of indentations unless one has been completely rigid about never violating the 80-column limit. This behavior has been pretty universally panned by Postgres developers. Hence, disable it with indent's new -lpl switch, so that parenthesized lines are always lined up with the preceding left paren. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
* Remove useless duplicate inclusions of system header files.Tom Lane2017-02-25
| | | | | | | | | | | | | | | | c.h #includes a number of core libc header files, such as <stdio.h>. There's no point in re-including these after having read postgres.h, postgres_fe.h, or c.h; so remove code that did so. While at it, also fix some places that were ignoring our standard pattern of "include postgres[_fe].h, then system header files, then other Postgres header files". While there's not any great magic in doing it that way rather than system headers last, it's silly to have just a few files deviating from the general pattern. (But I didn't attempt to enforce this globally, only in files I was touching anyway.) I'd be the first to say that this is mostly compulsive neatnik-ism, but over time it might save enough compile cycles to be useful.
* Update copyright via script for 2017Bruce Momjian2017-01-03
|
* Update copyright for 2016Bruce Momjian2016-01-02
| | | | Backpatch certain files through 9.1
* Update copyright for 2015Bruce Momjian2015-01-06
| | | | Backpatch certain files through 9.0
* Update copyright for 2014Bruce Momjian2014-01-07
| | | | | Update all files in head, and files COPYRIGHT and legal.sgml in all back branches.
* Update copyrights for 2013Bruce Momjian2013-01-01
| | | | | Fully update git head, and update back branches in ./COPYRIGHT and legal.sgml files.
* Update copyright notices for year 2012.Bruce Momjian2012-01-01
|
* Stamp copyrights for year 2011.Bruce Momjian2011-01-01
|
* Remove cvs keywords from all files.Magnus Hagander2010-09-20
|
* Update copyright for the year 2010.Bruce Momjian2010-01-02
|
* Fix cast for _open_osfhandle().Magnus Hagander2010-01-02
| | | | Tsutomu Yamada
* 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef listBruce Momjian2009-06-11
| | | | provided by Andrew.
* Update copyright for 2009.Bruce Momjian2009-01-01
|
* Update copyrights in source tree to 2008.Bruce Momjian2008-01-01
|
* may -> mightPeter Eisentraut2007-12-28
|
* Wording improvementsPeter Eisentraut2007-12-27
|
* On win32, loop when opening files if sharing- och lock-violation errorsMagnus Hagander2007-12-20
| | | | | occur. Hopefully, this will make it possible to recover from broken antivirus and/or backup software that locks our files.
* Use _dosmaperr() to deal with errors opening files in pgwin32_open().Magnus Hagander2007-11-30
| | | | Per complaint from Alvaro and subsequent discussion.
* pgindent run for 8.3.Bruce Momjian2007-11-15
|
* Add O_DIRECT support on Windows.Magnus Hagander2007-04-13
| | | | ITAGAKI Takahiro
* Add comment to explain why O_EXCL and O_TRUNC can be ignored inBruce Momjian2007-02-13
| | | | openFlagsToCreateFileFlags() in certain cases.
* Update CVS HEAD for 2007 copyright. Back branches are typically notBruce Momjian2007-01-05
| | | | back-stamped for this.
* pgindent run for 8.2.Bruce Momjian2006-10-04
|
* Cleanup pgwin32_open() 'if' test, and avoid possible error.Bruce Momjian2006-10-03
|
* Fix incorrect mapping of fopen mode 'a' in recently-added code toTom Lane2006-09-24
| | | | make fopen work safely on Windows. Magnus
* Fix things so that fopen's, not only open's, pass FILE_SHARE_DELETETom Lane2006-08-30
| | | | | and other special flags on Windows. May fix intermittent 'Permission denied' errors. Magnus Hagander
* Fix Win32/Cygwin problems:Bruce Momjian2006-06-25
| | | | | | | | | | | | | | After updating to the latest cvs, and also building most of the addons (like PLs), the following patch is neededf for win32 + Visual C++. * Switch to use the new win32 semaphore code * Rename win32_open to pgwin32_open. win32_open collides with symbols defined in Perl. MingW didn't detect ig, MSVC did. And it's a bit too generic a name to export globally, imho... * Python defines some partially broken #pragmas in the headers when doing a debug build. Workaround. Magnus Hagander
* Update copyright for 2006. Update scripts.Bruce Momjian2006-03-05
|
* Standard pgindent run for 8.1.Bruce Momjian2005-10-15
|
* Fix a whole bunch of #includes that were either wrong or redundant.Tom Lane2005-07-28
| | | | | | | | The first rule of portability for us is 'thou shalt have no other gods before c.h', and a whole lot of these files were either not including c.h at all, or including random system headers beforehand, either of which sins can mess up largefile support nicely. Once you have included c.h, there is no need to re-include what it includes, either.
* Change Win32 O_SYNC method to O_DSYNC because that is what the methodBruce Momjian2005-03-24
| | | | | | | | | | | currently does. This is now the default Win32 wal sync method because we perfer o_datasync to fsync. Also, change Win32 fsync to a new wal sync method called fsync_writethrough because that is the behavior of _commit, which is what is used for fsync on Win32. Backpatch to 8.0.X.
* Allow Win32 to support the O_SYNC open flag as an wal_sync_method method.Bruce Momjian2005-02-27
| | | | Magnus Hagander
* Tag appropriate files for rc3PostgreSQL Daemon2004-12-31
| | | | | | | | Also performed an initial run through of upgrading our Copyright date to extend to 2005 ... first run here was very simple ... change everything where: grep 1996-2004 && the word 'Copyright' ... scanned through the generated list with 'less' first, and after, to make sure that I only picked up the right entries ...