1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2024-12-03 09:59:53 +02:00

[Issue #394] correctly detect ENOSPC when using write(): durable_write is implemented

This commit is contained in:
Grigory Smolkin 2021-06-14 13:34:05 +03:00
parent 477e5bcb4f
commit 8ae217bae5
2 changed files with 33 additions and 10 deletions

View File

@ -568,6 +568,7 @@ part_opened:
}
/* copy content */
errno = 0;
for (;;)
{
size_t read_len = 0;

View File

@ -796,6 +796,34 @@ fio_fwrite_async(FILE* f, void const* buf, size_t size)
: fwrite(buf, 1, size, f);
}
/*
* Write buffer to descriptor by calling write(),
* If size of written data is less than buffer size,
* then try to write what is left.
* We do this to get honest errno if there are some problems
* with filesystem, since writing less than buffer size
* is not considered an error.
*/
static ssize_t
durable_write(int fd, const char* buf, size_t size)
{
off_t current_pos = 0;
size_t bytes_left = size;
while (bytes_left > 0)
{
int rc = write(fd, buf + current_pos, bytes_left);
if (rc <= 0)
return rc;
bytes_left -= rc;
current_pos += rc;
}
return size;
}
/* Write data to the file */
/* TODO: support async report error */
ssize_t
@ -814,27 +842,21 @@ fio_write_async(int fd, void const* buf, size_t size)
IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
IO_CHECK(fio_write_all(fio_stdout, buf, size), size);
return size;
}
else
{
return write(fd, buf, size);
}
return durable_write(fd, buf, size);
return size;
}
static void
fio_write_async_impl(int fd, void const* buf, size_t size, int out)
{
int rc;
/* Quick exit if agent is tainted */
if (async_errormsg)
return;
rc = write(fd, buf, size);
if (rc <= 0)
if (durable_write(fd, buf, size) <= 0)
{
async_errormsg = pgut_malloc(ERRMSG_MAX_LEN);
snprintf(async_errormsg, ERRMSG_MAX_LEN, "%s", strerror(errno));