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>,
	Alberto Garcia <berto@igalia.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [RFC 3/3] block/file-posix: Let post-EOF fallocate serialize
Date: Fri, 25 Oct 2019 11:58:49 +0200	[thread overview]
Message-ID: <20191025095849.25283-4-mreitz@redhat.com> (raw)
In-Reply-To: <20191025095849.25283-1-mreitz@redhat.com>

The XFS kernel driver has a bug that may cause data corruption for qcow2
images as of qemu commit c8bb23cbdbe32f.  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 | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index 5cd54c8bff..1f5a01df70 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2713,6 +2713,48 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes,
     RawPosixAIOData acb;
     ThreadPoolFunc *handler;
 
+#ifdef CONFIG_FALLOCATE
+    if (s->is_xfs && s->use_linux_aio &&
+        offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE)
+    {
+        BdrvTrackedRequest *req;
+        uint64_t end;
+
+        /*
+         * The Linux XFS driver has a bug where it will discard writes
+         * submitted through the AIO interface 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 look for the tracked request for this
+         * zero write, extend it until INT64_MAX (effectively
+         * infinity), and mark it as serializing.
+         *
+         * TODO: Detect whether this has been fixed in the XFS driver.
+         */
+
+        QLIST_FOREACH(req, &bs->tracked_requests, list) {
+            if (req->co == qemu_coroutine_self() &&
+                req->type == BDRV_TRACKED_WRITE)
+            {
+                break;
+            }
+        }
+
+        assert(req);
+        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-10-25 10:32 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25  9:58 [RFC 0/3] block/file-posix: Work around XFS bug Max Reitz
2019-10-25  9:58 ` [RFC 1/3] block: Make wait/mark serialising requests public Max Reitz
2019-10-25  9:58 ` [RFC 2/3] block/file-posix: Detect XFS with CONFIG_FALLOCATE Max Reitz
2019-10-25 10:19   ` Kevin Wolf
2019-10-25 10:22     ` Max Reitz
2019-10-25 10:35       ` Kevin Wolf
2019-10-25 10:41         ` Max Reitz
2019-10-26 17:26   ` Nir Soffer
2019-10-25  9:58 ` Max Reitz [this message]
2019-10-26 17:28   ` [RFC 3/3] block/file-posix: Let post-EOF fallocate serialize Nir Soffer
2019-10-25 13:40 ` [RFC 0/3] block/file-posix: Work around XFS bug Vladimir Sementsov-Ogievskiy
2019-10-25 13:56   ` Vladimir Sementsov-Ogievskiy
2019-10-25 14:19     ` Max Reitz
2019-10-25 14:35       ` Kevin Wolf
2019-10-25 14:36       ` Vladimir Sementsov-Ogievskiy
2019-10-27 12:21         ` Stefan Hajnoczi
2019-11-04 14:03       ` Alberto Garcia
2019-11-04 14:25         ` Max Reitz
2019-11-04 15:12           ` Alberto Garcia
2019-11-04 15:14             ` Max Reitz
2019-11-04 15:49               ` Alberto Garcia
2019-11-04 16:07                 ` Max Reitz
2019-10-25 13:46 ` Peter Maydell
2019-10-25 14:16   ` Max Reitz
2019-10-25 14:17     ` Peter Maydell
2019-10-25 14:21       ` Max Reitz
2019-10-25 14:56         ` Peter Maydell
2019-10-26  0:14 ` no-reply
2019-10-26 17:37 ` Nir Soffer
2019-10-26 17:52   ` Vladimir Sementsov-Ogievskiy
2019-10-28  8:56     ` Max Reitz
2019-10-27 12:35 ` Stefan Hajnoczi
2019-10-28  9:24   ` Max Reitz
2019-10-28  9:30     ` Max Reitz
2019-10-28  9:56       ` Max Reitz
2019-10-28 10:07         ` Vladimir Sementsov-Ogievskiy
2019-10-28 10:10           ` Max Reitz
2019-10-28 11:19             ` Vladimir Sementsov-Ogievskiy
2019-10-28 11:04   ` Kevin Wolf
2019-10-28 11:25     ` Vladimir Sementsov-Ogievskiy
2019-10-29  8:50       ` Max Reitz
2019-10-29 11:48         ` Vladimir Sementsov-Ogievskiy
2019-10-29 11:55           ` Max Reitz
2019-10-29 12:05             ` Vladimir Sementsov-Ogievskiy
2019-10-29 12:11               ` Max Reitz
2019-10-29 12:19                 ` Vladimir Sementsov-Ogievskiy
2019-10-29 12:23                   ` 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=20191025095849.25283-4-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=anton.nefedov@virtuozzo.com \
    --cc=berto@igalia.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).