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

Commitb0a48e9

Browse files
committed
Backport "Expose fsync_fname as a public API".
Backport commitcc52d5b back to 9.1to allow backpatching some unlogged table fixes that use fsync_fname.
1 parent79b2fa5 commitb0a48e9

File tree

3 files changed

+57
-59
lines changed

3 files changed

+57
-59
lines changed

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
#endif
3939

4040

41-
staticvoidfsync_fname(char*fname,boolisdir);
42-
43-
4441
/*
4542
* copydir: copy a directory
4643
*
@@ -214,59 +211,3 @@ copy_file(char *fromfile, char *tofile)
214211

215212
pfree(buffer);
216213
}
217-
218-
219-
/*
220-
* fsync a file
221-
*
222-
* Try to fsync directories but ignore errors that indicate the OS
223-
* just doesn't allow/require fsyncing directories.
224-
*/
225-
staticvoid
226-
fsync_fname(char*fname,boolisdir)
227-
{
228-
intfd;
229-
intreturncode;
230-
231-
/*
232-
* Some OSs require directories to be opened read-only whereas other
233-
* systems don't allow us to fsync files opened read-only; so we need both
234-
* cases here
235-
*/
236-
if (!isdir)
237-
fd=BasicOpenFile(fname,
238-
O_RDWR |PG_BINARY,
239-
S_IRUSR |S_IWUSR);
240-
else
241-
fd=BasicOpenFile(fname,
242-
O_RDONLY |PG_BINARY,
243-
S_IRUSR |S_IWUSR);
244-
245-
/*
246-
* Some OSs don't allow us to open directories at all (Windows returns
247-
* EACCES)
248-
*/
249-
if (fd<0&&isdir&& (errno==EISDIR||errno==EACCES))
250-
return;
251-
252-
elseif (fd<0)
253-
ereport(ERROR,
254-
(errcode_for_file_access(),
255-
errmsg("could not open file \"%s\": %m",fname)));
256-
257-
returncode=pg_fsync(fd);
258-
259-
/* Some OSs don't allow us to fsync directories at all */
260-
if (returncode!=0&&isdir&&errno==EBADF)
261-
{
262-
close(fd);
263-
return;
264-
}
265-
266-
if (returncode!=0)
267-
ereport(ERROR,
268-
(errcode_for_file_access(),
269-
errmsg("could not fsync file \"%s\": %m",fname)));
270-
271-
close(fd);
272-
}

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,62 @@ pg_flush_data(int fd, off_t offset, off_t amount)
345345
}
346346

347347

348+
/*
349+
* fsync_fname -- fsync a file or directory, handling errors properly
350+
*
351+
* Try to fsync a file or directory. When doing the latter, ignore errors that
352+
* indicate the OS just doesn't allow/require fsyncing directories.
353+
*/
354+
void
355+
fsync_fname(char*fname,boolisdir)
356+
{
357+
intfd;
358+
intreturncode;
359+
360+
/*
361+
* Some OSs require directories to be opened read-only whereas other
362+
* systems don't allow us to fsync files opened read-only; so we need both
363+
* cases here
364+
*/
365+
if (!isdir)
366+
fd=BasicOpenFile(fname,
367+
O_RDWR |PG_BINARY,
368+
S_IRUSR |S_IWUSR);
369+
else
370+
fd=BasicOpenFile(fname,
371+
O_RDONLY |PG_BINARY,
372+
S_IRUSR |S_IWUSR);
373+
374+
/*
375+
* Some OSs don't allow us to open directories at all (Windows returns
376+
* EACCES)
377+
*/
378+
if (fd<0&&isdir&& (errno==EISDIR||errno==EACCES))
379+
return;
380+
381+
elseif (fd<0)
382+
ereport(ERROR,
383+
(errcode_for_file_access(),
384+
errmsg("could not open file \"%s\": %m",fname)));
385+
386+
returncode=pg_fsync(fd);
387+
388+
/* Some OSs don't allow us to fsync directories at all */
389+
if (returncode!=0&&isdir&&errno==EBADF)
390+
{
391+
close(fd);
392+
return;
393+
}
394+
395+
if (returncode!=0)
396+
ereport(ERROR,
397+
(errcode_for_file_access(),
398+
errmsg("could not fsync file \"%s\": %m",fname)));
399+
400+
close(fd);
401+
}
402+
403+
348404
/*
349405
* InitFileAccess --- initialize this module during backend startup
350406
*

‎src/include/storage/fd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extern intpg_fsync_no_writethrough(int fd);
9999
externintpg_fsync_writethrough(intfd);
100100
externintpg_fdatasync(intfd);
101101
externintpg_flush_data(intfd,off_toffset,off_tamount);
102+
externvoidfsync_fname(char*fname,boolisdir);
102103

103104
/* Filename components for OpenTemporaryFile */
104105
#definePG_TEMP_FILES_DIR "pgsql_tmp"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp