Commit 95ef43c4 authored by Tom Lane's avatar Tom Lane

Widen amount-to-flush arguments of FileWriteback and callers.

It's silly to define these counts as narrower than they might someday
need to be.  Also, I believe that the BLCKSZ * nflush calculation in
mdwriteback was capable of overflowing an int.
parent fa11a09f
...@@ -1538,28 +1538,28 @@ FilePrefetch(File file, off_t offset, int amount) ...@@ -1538,28 +1538,28 @@ FilePrefetch(File file, off_t offset, int amount)
} }
void void
FileWriteback(File file, off_t offset, int amount) FileWriteback(File file, off_t offset, off_t nbytes)
{ {
int returnCode; int returnCode;
Assert(FileIsValid(file)); Assert(FileIsValid(file));
DO_DB(elog(LOG, "FileWriteback: %d (%s) " INT64_FORMAT " %d", DO_DB(elog(LOG, "FileWriteback: %d (%s) " INT64_FORMAT " " INT64_FORMAT,
file, VfdCache[file].fileName, file, VfdCache[file].fileName,
(int64) offset, amount)); (int64) offset, (int64) nbytes));
/* /*
* Caution: do not call pg_flush_data with amount = 0, it could trash the * Caution: do not call pg_flush_data with nbytes = 0, it could trash the
* file's seek position. * file's seek position. We prefer to define that as a no-op here.
*/ */
if (amount <= 0) if (nbytes <= 0)
return; return;
returnCode = FileAccess(file); returnCode = FileAccess(file);
if (returnCode < 0) if (returnCode < 0)
return; return;
pg_flush_data(VfdCache[file].fd, offset, amount); pg_flush_data(VfdCache[file].fd, offset, nbytes);
} }
int int
......
...@@ -669,15 +669,16 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) ...@@ -669,15 +669,16 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
* considerably more efficient than doing so individually. * considerably more efficient than doing so individually.
*/ */
void void
mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks) mdwriteback(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, BlockNumber nblocks)
{ {
/* /*
* Issue flush requests in as few requests as possible; have to split at * Issue flush requests in as few requests as possible; have to split at
* segment boundaries though, since those are actually separate files. * segment boundaries though, since those are actually separate files.
*/ */
while (nblocks != 0) while (nblocks > 0)
{ {
int nflush = nblocks; BlockNumber nflush = nblocks;
off_t seekpos; off_t seekpos;
MdfdVec *v; MdfdVec *v;
int segnum_start, int segnum_start,
...@@ -706,7 +707,7 @@ mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nbl ...@@ -706,7 +707,7 @@ mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nbl
seekpos = (off_t) BLCKSZ *(blocknum % ((BlockNumber) RELSEG_SIZE)); seekpos = (off_t) BLCKSZ *(blocknum % ((BlockNumber) RELSEG_SIZE));
FileWriteback(v->mdfd_vfd, seekpos, BLCKSZ * nflush); FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush);
nblocks -= nflush; nblocks -= nflush;
blocknum += nflush; blocknum += nflush;
......
...@@ -54,7 +54,7 @@ typedef struct f_smgr ...@@ -54,7 +54,7 @@ typedef struct f_smgr
void (*smgr_write) (SMgrRelation reln, ForkNumber forknum, void (*smgr_write) (SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, char *buffer, bool skipFsync); BlockNumber blocknum, char *buffer, bool skipFsync);
void (*smgr_writeback) (SMgrRelation reln, ForkNumber forknum, void (*smgr_writeback) (SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, int nblocks); BlockNumber blocknum, BlockNumber nblocks);
BlockNumber (*smgr_nblocks) (SMgrRelation reln, ForkNumber forknum); BlockNumber (*smgr_nblocks) (SMgrRelation reln, ForkNumber forknum);
void (*smgr_truncate) (SMgrRelation reln, ForkNumber forknum, void (*smgr_truncate) (SMgrRelation reln, ForkNumber forknum,
BlockNumber nblocks); BlockNumber nblocks);
...@@ -658,7 +658,7 @@ smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, ...@@ -658,7 +658,7 @@ smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
*/ */
void void
smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
int nblocks) BlockNumber nblocks)
{ {
(*(smgrsw[reln->smgr_which].smgr_writeback)) (reln, forknum, blocknum, (*(smgrsw[reln->smgr_which].smgr_writeback)) (reln, forknum, blocknum,
nblocks); nblocks);
......
...@@ -74,7 +74,7 @@ extern int FileWrite(File file, char *buffer, int amount); ...@@ -74,7 +74,7 @@ extern int FileWrite(File file, char *buffer, int amount);
extern int FileSync(File file); extern int FileSync(File file);
extern off_t FileSeek(File file, off_t offset, int whence); extern off_t FileSeek(File file, off_t offset, int whence);
extern int FileTruncate(File file, off_t offset); extern int FileTruncate(File file, off_t offset);
extern void FileWriteback(File file, off_t offset, int amount); extern void FileWriteback(File file, off_t offset, off_t nbytes);
extern char *FilePathName(File file); extern char *FilePathName(File file);
extern int FileGetRawDesc(File file); extern int FileGetRawDesc(File file);
extern int FileGetRawFlags(File file); extern int FileGetRawFlags(File file);
......
...@@ -97,7 +97,7 @@ extern void smgrread(SMgrRelation reln, ForkNumber forknum, ...@@ -97,7 +97,7 @@ extern void smgrread(SMgrRelation reln, ForkNumber forknum,
extern void smgrwrite(SMgrRelation reln, ForkNumber forknum, extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, char *buffer, bool skipFsync); BlockNumber blocknum, char *buffer, bool skipFsync);
extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum, extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, int nblocks); BlockNumber blocknum, BlockNumber nblocks);
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum); extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum, extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
BlockNumber nblocks); BlockNumber nblocks);
...@@ -125,7 +125,7 @@ extern void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, ...@@ -125,7 +125,7 @@ extern void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
extern void mdwrite(SMgrRelation reln, ForkNumber forknum, extern void mdwrite(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, char *buffer, bool skipFsync); BlockNumber blocknum, char *buffer, bool skipFsync);
extern void mdwriteback(SMgrRelation reln, ForkNumber forknum, extern void mdwriteback(SMgrRelation reln, ForkNumber forknum,
BlockNumber blocknum, int nblocks); BlockNumber blocknum, BlockNumber nblocks);
extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum); extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum);
extern void mdtruncate(SMgrRelation reln, ForkNumber forknum, extern void mdtruncate(SMgrRelation reln, ForkNumber forknum,
BlockNumber nblocks); BlockNumber nblocks);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment