Skip to content

Commit 95ef43c

Browse files
committed
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.
1 parent fa11a09 commit 95ef43c

File tree

5 files changed

+17
-16
lines changed

5 files changed

+17
-16
lines changed

src/backend/storage/file/fd.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,28 +1538,28 @@ FilePrefetch(File file, off_t offset, int amount)
15381538
}
15391539

15401540
void
1541-
FileWriteback(File file, off_t offset, int amount)
1541+
FileWriteback(File file, off_t offset, off_t nbytes)
15421542
{
15431543
int returnCode;
15441544

15451545
Assert(FileIsValid(file));
15461546

1547-
DO_DB(elog(LOG, "FileWriteback: %d (%s) " INT64_FORMAT " %d",
1547+
DO_DB(elog(LOG, "FileWriteback: %d (%s) " INT64_FORMAT " " INT64_FORMAT,
15481548
file, VfdCache[file].fileName,
1549-
(int64) offset, amount));
1549+
(int64) offset, (int64) nbytes));
15501550

15511551
/*
1552-
* Caution: do not call pg_flush_data with amount = 0, it could trash the
1553-
* file's seek position.
1552+
* Caution: do not call pg_flush_data with nbytes = 0, it could trash the
1553+
* file's seek position. We prefer to define that as a no-op here.
15541554
*/
1555-
if (amount <= 0)
1555+
if (nbytes <= 0)
15561556
return;
15571557

15581558
returnCode = FileAccess(file);
15591559
if (returnCode < 0)
15601560
return;
15611561

1562-
pg_flush_data(VfdCache[file].fd, offset, amount);
1562+
pg_flush_data(VfdCache[file].fd, offset, nbytes);
15631563
}
15641564

15651565
int

src/backend/storage/smgr/md.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,16 @@ mdprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
669669
* considerably more efficient than doing so individually.
670670
*/
671671
void
672-
mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
672+
mdwriteback(SMgrRelation reln, ForkNumber forknum,
673+
BlockNumber blocknum, BlockNumber nblocks)
673674
{
674675
/*
675676
* Issue flush requests in as few requests as possible; have to split at
676677
* segment boundaries though, since those are actually separate files.
677678
*/
678-
while (nblocks != 0)
679+
while (nblocks > 0)
679680
{
680-
int nflush = nblocks;
681+
BlockNumber nflush = nblocks;
681682
off_t seekpos;
682683
MdfdVec *v;
683684
int segnum_start,
@@ -706,7 +707,7 @@ mdwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nbl
706707

707708
seekpos = (off_t) BLCKSZ *(blocknum % ((BlockNumber) RELSEG_SIZE));
708709

709-
FileWriteback(v->mdfd_vfd, seekpos, BLCKSZ * nflush);
710+
FileWriteback(v->mdfd_vfd, seekpos, (off_t) BLCKSZ * nflush);
710711

711712
nblocks -= nflush;
712713
blocknum += nflush;

src/backend/storage/smgr/smgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct f_smgr
5454
void (*smgr_write) (SMgrRelation reln, ForkNumber forknum,
5555
BlockNumber blocknum, char *buffer, bool skipFsync);
5656
void (*smgr_writeback) (SMgrRelation reln, ForkNumber forknum,
57-
BlockNumber blocknum, int nblocks);
57+
BlockNumber blocknum, BlockNumber nblocks);
5858
BlockNumber (*smgr_nblocks) (SMgrRelation reln, ForkNumber forknum);
5959
void (*smgr_truncate) (SMgrRelation reln, ForkNumber forknum,
6060
BlockNumber nblocks);
@@ -658,7 +658,7 @@ smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
658658
*/
659659
void
660660
smgrwriteback(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
661-
int nblocks)
661+
BlockNumber nblocks)
662662
{
663663
(*(smgrsw[reln->smgr_which].smgr_writeback)) (reln, forknum, blocknum,
664664
nblocks);

src/include/storage/fd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ extern int FileWrite(File file, char *buffer, int amount);
7474
extern int FileSync(File file);
7575
extern off_t FileSeek(File file, off_t offset, int whence);
7676
extern int FileTruncate(File file, off_t offset);
77-
extern void FileWriteback(File file, off_t offset, int amount);
77+
extern void FileWriteback(File file, off_t offset, off_t nbytes);
7878
extern char *FilePathName(File file);
7979
extern int FileGetRawDesc(File file);
8080
extern int FileGetRawFlags(File file);

src/include/storage/smgr.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extern void smgrread(SMgrRelation reln, ForkNumber forknum,
9797
extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,
9898
BlockNumber blocknum, char *buffer, bool skipFsync);
9999
extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
100-
BlockNumber blocknum, int nblocks);
100+
BlockNumber blocknum, BlockNumber nblocks);
101101
extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
102102
extern void smgrtruncate(SMgrRelation reln, ForkNumber forknum,
103103
BlockNumber nblocks);
@@ -125,7 +125,7 @@ extern void mdread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
125125
extern void mdwrite(SMgrRelation reln, ForkNumber forknum,
126126
BlockNumber blocknum, char *buffer, bool skipFsync);
127127
extern void mdwriteback(SMgrRelation reln, ForkNumber forknum,
128-
BlockNumber blocknum, int nblocks);
128+
BlockNumber blocknum, BlockNumber nblocks);
129129
extern BlockNumber mdnblocks(SMgrRelation reln, ForkNumber forknum);
130130
extern void mdtruncate(SMgrRelation reln, ForkNumber forknum,
131131
BlockNumber nblocks);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy