]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix mdsyncfiletag(), take II.
authorThomas Munro <tmunro@postgresql.org>
Sat, 14 Dec 2019 04:38:09 +0000 (17:38 +1300)
committerThomas Munro <tmunro@postgresql.org>
Sat, 14 Dec 2019 06:03:44 +0000 (19:03 +1300)
The previous commit failed to consider that FileGetRawDesc() might
not return a valid fd, as discovered on the build farm.  Switch to
using the File interface only.

Back-patch to 12, like the previous commit.

src/backend/storage/smgr/md.c

index 459af38b4872d596cc079e3049695286a0a784f4..101fe6c399d560a0e8e9c9b1166b77a3e8d58acf 100644 (file)
@@ -1258,19 +1258,16 @@ int
 mdsyncfiletag(const FileTag *ftag, char *path)
 {
        SMgrRelation reln = smgropen(ftag->rnode, InvalidBackendId);
-       int                     fd,
-                               result,
-                               save_errno;
+       File            file;
        bool            need_to_close;
+       int                     result,
+                               save_errno;
 
        /* See if we already have the file open, or need to open it. */
        if (ftag->segno < reln->md_num_open_segs[ftag->forknum])
        {
-               File            file;
-
                file = reln->md_seg_fds[ftag->forknum][ftag->segno].mdfd_vfd;
                strlcpy(path, FilePathName(file), MAXPGPATH);
-               fd = FileGetRawDesc(file);
                need_to_close = false;
        }
        else
@@ -1281,24 +1278,20 @@ mdsyncfiletag(const FileTag *ftag, char *path)
                strlcpy(path, p, MAXPGPATH);
                pfree(p);
 
-               fd = OpenTransientFile(path, O_RDWR);
-               if (fd < 0)
+               file = PathNameOpenFile(path, O_RDWR | PG_BINARY);
+               if (file < 0)
                        return -1;
                need_to_close = true;
        }
 
        /* Sync the file. */
-       pgstat_report_wait_start(WAIT_EVENT_DATA_FILE_SYNC);
-       result = pg_fsync(fd);
+       result = FileSync(file, WAIT_EVENT_DATA_FILE_SYNC);
        save_errno = errno;
-       pgstat_report_wait_end();
 
-       if (need_to_close && CloseTransientFile(fd) != 0)
-               ereport(WARNING,
-                               (errcode_for_file_access(),
-                                errmsg("could not close file \"%s\": %m", path)));
-       errno = save_errno;
+       if (need_to_close)
+               FileClose(file);
 
+       errno = save_errno;
        return result;
 }