Skip to content

Commit 324076a

Browse files
committed
Correct handling of fsync failures with tar mode of walmethods.c
This file has been missing the fact that it needs to report back to callers a proper failure on fsync calls. I have spotted the one in tar_finish() while Kuntal has spotted the one in tar_close(). Backpatch down to 10 where this code has been introduced. Reported by: Michael Paquier, Kuntal Ghosh Author: Michael Paquier Reviewed-by: Kuntal Ghosh, Magnus Hagander Discussion: https://postgr.es/m/20180625024356.GD1146@paquier.xyz
1 parent 99fb443 commit 324076a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/bin/pg_basebackup/walmethods.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,8 @@ tar_close(Walfile f, WalCloseMethod method)
863863
return -1;
864864

865865
/* Always fsync on close, so the padding gets fsynced */
866-
tar_sync(f);
866+
if (tar_sync(f) < 0)
867+
return -1;
867868

868869
/* Clean up and done */
869870
pg_free(tf->pathname);
@@ -894,7 +895,7 @@ tar_finish(void)
894895
return false;
895896
}
896897

897-
/* A tarfile always ends with two empty blocks */
898+
/* A tarfile always ends with two empty blocks */
898899
MemSet(zerobuf, 0, sizeof(zerobuf));
899900
if (!tar_data->compression)
900901
{
@@ -955,7 +956,10 @@ tar_finish(void)
955956

956957
/* sync the empty blocks as well, since they're after the last file */
957958
if (tar_data->sync)
958-
fsync(tar_data->fd);
959+
{
960+
if (fsync(tar_data->fd) != 0)
961+
return false;
962+
}
959963

960964
if (close(tar_data->fd) != 0)
961965
return false;

0 commit comments

Comments
 (0)