Skip to content

Commit 13a1821

Browse files
committed
Merge branch 'master' into release_2_5
2 parents 02ca67d + 8ae217b commit 13a1821

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

src/archive.c

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
568568
}
569569

570570
/* copy content */
571+
errno = 0;
571572
for (;;)
572573
{
573574
size_t read_len = 0;

src/utils/file.c

+32-10
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,34 @@ fio_fwrite_async(FILE* f, void const* buf, size_t size)
814814
: fwrite(buf, 1, size, f);
815815
}
816816

817+
/*
818+
* Write buffer to descriptor by calling write(),
819+
* If size of written data is less than buffer size,
820+
* then try to write what is left.
821+
* We do this to get honest errno if there are some problems
822+
* with filesystem, since writing less than buffer size
823+
* is not considered an error.
824+
*/
825+
static ssize_t
826+
durable_write(int fd, const char* buf, size_t size)
827+
{
828+
off_t current_pos = 0;
829+
size_t bytes_left = size;
830+
831+
while (bytes_left > 0)
832+
{
833+
int rc = write(fd, buf + current_pos, bytes_left);
834+
835+
if (rc <= 0)
836+
return rc;
837+
838+
bytes_left -= rc;
839+
current_pos += rc;
840+
}
841+
842+
return size;
843+
}
844+
817845
/* Write data to the file */
818846
/* TODO: support async report error */
819847
ssize_t
@@ -832,27 +860,21 @@ fio_write_async(int fd, void const* buf, size_t size)
832860

833861
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
834862
IO_CHECK(fio_write_all(fio_stdout, buf, size), size);
835-
836-
return size;
837863
}
838864
else
839-
{
840-
return write(fd, buf, size);
841-
}
865+
return durable_write(fd, buf, size);
866+
867+
return size;
842868
}
843869

844870
static void
845871
fio_write_async_impl(int fd, void const* buf, size_t size, int out)
846872
{
847-
int rc;
848-
849873
/* Quick exit if agent is tainted */
850874
if (async_errormsg)
851875
return;
852876

853-
rc = write(fd, buf, size);
854-
855-
if (rc <= 0)
877+
if (durable_write(fd, buf, size) <= 0)
856878
{
857879
async_errormsg = pgut_malloc(ERRMSG_MAX_LEN);
858880
snprintf(async_errormsg, ERRMSG_MAX_LEN, "%s", strerror(errno));

0 commit comments

Comments
 (0)