qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anton Nefedov <anton.nefedov@virtuozzo.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH for-4.2 4/4] block/file-posix: Let post-EOF fallocate serialize
Date: Fri,  1 Nov 2019 11:00:19 +0100	[thread overview]
Message-ID: <20191101100019.9512-5-mreitz@redhat.com> (raw)
In-Reply-To: <20191101100019.9512-1-mreitz@redhat.com>

The XFS kernel driver has a bug that may cause data loss when using
fallocate() in an I/O path, i.e. writing zeroes.  We can work around it
by treating post-EOF fallocates as serializing up until infinity
(INT64_MAX in practice).

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/file-posix.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 0b7e904d48..d5460f3e45 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2721,6 +2721,44 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes,
     RawPosixAIOData acb;
     ThreadPoolFunc *handler;
 
+#ifdef CONFIG_FALLOCATE
+    if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) {
+        BdrvTrackedRequest *req;
+        uint64_t end;
+
+        /*
+         * This is a workaround for a bug in the Linux XFS driver,
+         * where writes submitted through the AIO interface will be
+         * discarded if they happen beyond a concurrently running
+         * fallocate() that increases the file length (i.e., both the
+         * write and the fallocate() happen beyond the EOF).
+         *
+         * To work around it, we extend the tracked request for this
+         * zero write until INT64_MAX (effectively infinity), and mark
+         * it as serializing.
+         *
+         * We have to enable this workaround for all filesystems and
+         * AIO modes (not just XFS with aio=native), because for
+         * remote filesystems we do not know the host configuration.
+         * However, this should have no effect as long as no block
+         * driver submits zero writes beyond the EOF.
+         */
+
+        req = bdrv_co_get_self_request(bs);
+        assert(req);
+        assert(req->type == BDRV_TRACKED_WRITE);
+        assert(req->offset <= offset);
+        assert(req->offset + req->bytes >= offset + bytes);
+
+        end = INT64_MAX & -(uint64_t)bs->bl.request_alignment;
+        req->bytes = end - req->offset;
+        req->overlap_bytes = req->bytes;
+
+        bdrv_mark_request_serialising(req, bs->bl.request_alignment);
+        bdrv_wait_serialising_requests(req);
+    }
+#endif
+
     acb = (RawPosixAIOData) {
         .bs             = bs,
         .aio_fildes     = s->fd,
-- 
2.21.0



  parent reply	other threads:[~2019-11-01 10:07 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-01 10:00 [PATCH for-4.2 0/4] qcow2: Fix data corruption on XFS Max Reitz
2019-11-01 10:00 ` [PATCH for-4.2 1/4] Revert "qcow2: skip writing zero buffers to empty COW areas" Max Reitz
2019-11-01 10:22   ` Vladimir Sementsov-Ogievskiy
2019-11-01 12:40   ` Eric Blake
2019-11-01 14:01     ` Max Reitz
2019-11-01 15:42       ` Kevin Wolf
2019-11-01 16:02         ` Max Reitz
2019-11-01 10:00 ` [PATCH for-4.2 2/4] block: Make wait/mark serialising requests public Max Reitz
2019-11-01 10:00 ` [PATCH for-4.2 3/4] block: Add bdrv_co_get_self_request() Max Reitz
2019-11-01 10:00 ` Max Reitz [this message]
2019-11-01 10:20 ` [PATCH for-4.2 0/4] qcow2: Fix data corruption on XFS Max Reitz
2019-11-01 10:28   ` Vladimir Sementsov-Ogievskiy
2019-11-01 11:12     ` Max Reitz
2019-11-01 11:16       ` Vladimir Sementsov-Ogievskiy
2019-11-01 11:20         ` Max Reitz
2019-11-01 12:34           ` Max Reitz
2019-11-01 13:09             ` Vladimir Sementsov-Ogievskiy
2019-11-01 13:36               ` Denis Lunev
2019-11-01 13:40                 ` Max Reitz
2019-11-01 13:30             ` Max Reitz
2019-11-01 15:06               ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191101100019.9512-5-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=anton.nefedov@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).