Skip to content

Commit

Permalink
block: preserve errno from fdatasync failures
Browse files Browse the repository at this point in the history
When fdatasync() fails on a file backend we set a flag that
short-circuits any future attempts to call fdatasync(). The
first failure returns the true errno, but the later short-
circuited calls return a generic EIO. The latter is unhelpful
because fdatasync() can return a variety of errnos, including
EACCESS.

Reviewed-by: Connor Kuehl <ckuehl@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
  • Loading branch information
berrange committed Jun 14, 2021
1 parent 8af3f5c commit c7ddc88
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions block/file-posix.c
Expand Up @@ -160,7 +160,7 @@ typedef struct BDRVRawState {
bool discard_zeroes:1;
bool use_linux_aio:1;
bool use_linux_io_uring:1;
bool page_cache_inconsistent:1;
int page_cache_inconsistent; /* errno from fdatasync failure */
bool has_fallocate;
bool needs_alignment;
bool drop_cache;
Expand Down Expand Up @@ -1333,7 +1333,7 @@ static int handle_aiocb_flush(void *opaque)
int ret;

if (s->page_cache_inconsistent) {
return -EIO;
return -s->page_cache_inconsistent;
}

ret = qemu_fdatasync(aiocb->aio_fildes);
Expand All @@ -1352,7 +1352,7 @@ static int handle_aiocb_flush(void *opaque)
* Obviously, this doesn't affect O_DIRECT, which bypasses the page
* cache. */
if ((s->open_flags & O_DIRECT) == 0) {
s->page_cache_inconsistent = true;
s->page_cache_inconsistent = errno;
}
return -errno;
}
Expand Down

0 comments on commit c7ddc88

Please sign in to comment.