mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-25 00:59:45 -05:00
ITS#7682 mdb_env_copy(): Avoid Linux O_DIRECT bug.
Use fcntl() to set the flag. Linux open(,O_DIRECT...) can create the file even on failure, if the filesystem lacks O_DIRECT support.
This commit is contained in:
parent
912e09fd04
commit
3335b25834
1 changed files with 5 additions and 8 deletions
|
|
@ -4246,14 +4246,6 @@ mdb_env_copy(MDB_env *env, const char *path)
|
|||
newfd = CreateFile(lpath, GENERIC_WRITE, 0, NULL, CREATE_NEW,
|
||||
FILE_FLAG_NO_BUFFERING|FILE_FLAG_WRITE_THROUGH, NULL);
|
||||
#else
|
||||
#ifdef O_DIRECT
|
||||
/* The OS supports O_DIRECT, try with it */
|
||||
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL|O_DIRECT, 0666);
|
||||
/* But open can fail if O_DIRECT isn't supported by the file system
|
||||
* so retry without the flag
|
||||
*/
|
||||
if (newfd == INVALID_HANDLE_VALUE && ErrCode() == EINVAL)
|
||||
#endif
|
||||
newfd = open(lpath, O_WRONLY|O_CREAT|O_EXCL, 0666);
|
||||
#endif
|
||||
if (newfd == INVALID_HANDLE_VALUE) {
|
||||
|
|
@ -4261,6 +4253,11 @@ mdb_env_copy(MDB_env *env, const char *path)
|
|||
goto leave;
|
||||
}
|
||||
|
||||
#ifdef O_DIRECT
|
||||
/* Set O_DIRECT if the file system supports it */
|
||||
if ((rc = fcntl(newfd, F_GETFL)) != -1)
|
||||
(void) fcntl(newfd, F_SETFL, rc | O_DIRECT);
|
||||
#endif
|
||||
#ifdef F_NOCACHE /* __APPLE__ */
|
||||
rc = fcntl(newfd, F_NOCACHE, 1);
|
||||
if (rc) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue