|
|
902636 |
From 9b5fbc95a287b2ce9448142194b161d8360d5e4e Mon Sep 17 00:00:00 2001
|
|
|
902636 |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
902636 |
Date: Mon, 27 Jan 2020 19:02:15 +0100
|
|
|
902636 |
Subject: [PATCH 104/116] virtiofsd: Fix data corruption with O_APPEND write in
|
|
|
902636 |
writeback mode
|
|
|
902636 |
MIME-Version: 1.0
|
|
|
902636 |
Content-Type: text/plain; charset=UTF-8
|
|
|
902636 |
Content-Transfer-Encoding: 8bit
|
|
|
902636 |
|
|
|
902636 |
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
902636 |
Message-id: <20200127190227.40942-101-dgilbert@redhat.com>
|
|
|
902636 |
Patchwork-id: 93556
|
|
|
902636 |
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 100/112] virtiofsd: Fix data corruption with O_APPEND write in writeback mode
|
|
|
902636 |
Bugzilla: 1694164
|
|
|
902636 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
902636 |
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
902636 |
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
|
|
|
902636 |
|
|
|
902636 |
From: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
|
|
|
902636 |
|
|
|
902636 |
When writeback mode is enabled (-o writeback), O_APPEND handling is
|
|
|
902636 |
done in kernel. Therefore virtiofsd clears O_APPEND flag when open.
|
|
|
902636 |
Otherwise O_APPEND flag takes precedence over pwrite() and write
|
|
|
902636 |
data may corrupt.
|
|
|
902636 |
|
|
|
902636 |
Currently clearing O_APPEND flag is done in lo_open(), but we also
|
|
|
902636 |
need the same operation in lo_create(). So, factor out the flag
|
|
|
902636 |
update operation in lo_open() to update_open_flags() and call it
|
|
|
902636 |
in both lo_open() and lo_create().
|
|
|
902636 |
|
|
|
902636 |
This fixes the failure of xfstest generic/069 in writeback mode
|
|
|
902636 |
(which tests O_APPEND write data integrity).
|
|
|
902636 |
|
|
|
902636 |
Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
|
|
|
902636 |
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
902636 |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
902636 |
(cherry picked from commit 8e4e41e39eac5ee5f378d66f069a2f70a1734317)
|
|
|
902636 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
902636 |
---
|
|
|
902636 |
tools/virtiofsd/passthrough_ll.c | 66 ++++++++++++++++++++--------------------
|
|
|
902636 |
1 file changed, 33 insertions(+), 33 deletions(-)
|
|
|
902636 |
|
|
|
902636 |
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
|
|
|
902636 |
index 948cb19..4c61ac5 100644
|
|
|
902636 |
--- a/tools/virtiofsd/passthrough_ll.c
|
|
|
902636 |
+++ b/tools/virtiofsd/passthrough_ll.c
|
|
|
902636 |
@@ -1692,6 +1692,37 @@ static void lo_releasedir(fuse_req_t req, fuse_ino_t ino,
|
|
|
902636 |
fuse_reply_err(req, 0);
|
|
|
902636 |
}
|
|
|
902636 |
|
|
|
902636 |
+static void update_open_flags(int writeback, struct fuse_file_info *fi)
|
|
|
902636 |
+{
|
|
|
902636 |
+ /*
|
|
|
902636 |
+ * With writeback cache, kernel may send read requests even
|
|
|
902636 |
+ * when userspace opened write-only
|
|
|
902636 |
+ */
|
|
|
902636 |
+ if (writeback && (fi->flags & O_ACCMODE) == O_WRONLY) {
|
|
|
902636 |
+ fi->flags &= ~O_ACCMODE;
|
|
|
902636 |
+ fi->flags |= O_RDWR;
|
|
|
902636 |
+ }
|
|
|
902636 |
+
|
|
|
902636 |
+ /*
|
|
|
902636 |
+ * With writeback cache, O_APPEND is handled by the kernel.
|
|
|
902636 |
+ * This breaks atomicity (since the file may change in the
|
|
|
902636 |
+ * underlying filesystem, so that the kernel's idea of the
|
|
|
902636 |
+ * end of the file isn't accurate anymore). In this example,
|
|
|
902636 |
+ * we just accept that. A more rigorous filesystem may want
|
|
|
902636 |
+ * to return an error here
|
|
|
902636 |
+ */
|
|
|
902636 |
+ if (writeback && (fi->flags & O_APPEND)) {
|
|
|
902636 |
+ fi->flags &= ~O_APPEND;
|
|
|
902636 |
+ }
|
|
|
902636 |
+
|
|
|
902636 |
+ /*
|
|
|
902636 |
+ * O_DIRECT in guest should not necessarily mean bypassing page
|
|
|
902636 |
+ * cache on host as well. If somebody needs that behavior, it
|
|
|
902636 |
+ * probably should be a configuration knob in daemon.
|
|
|
902636 |
+ */
|
|
|
902636 |
+ fi->flags &= ~O_DIRECT;
|
|
|
902636 |
+}
|
|
|
902636 |
+
|
|
|
902636 |
static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
902636 |
mode_t mode, struct fuse_file_info *fi)
|
|
|
902636 |
{
|
|
|
902636 |
@@ -1721,12 +1752,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
|
|
|
902636 |
goto out;
|
|
|
902636 |
}
|
|
|
902636 |
|
|
|
902636 |
- /*
|
|
|
902636 |
- * O_DIRECT in guest should not necessarily mean bypassing page
|
|
|
902636 |
- * cache on host as well. If somebody needs that behavior, it
|
|
|
902636 |
- * probably should be a configuration knob in daemon.
|
|
|
902636 |
- */
|
|
|
902636 |
- fi->flags &= ~O_DIRECT;
|
|
|
902636 |
+ update_open_flags(lo->writeback, fi);
|
|
|
902636 |
|
|
|
902636 |
fd = openat(parent_inode->fd, name, (fi->flags | O_CREAT) & ~O_NOFOLLOW,
|
|
|
902636 |
mode);
|
|
|
902636 |
@@ -1936,33 +1962,7 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
|
|
|
902636 |
fuse_log(FUSE_LOG_DEBUG, "lo_open(ino=%" PRIu64 ", flags=%d)\n", ino,
|
|
|
902636 |
fi->flags);
|
|
|
902636 |
|
|
|
902636 |
- /*
|
|
|
902636 |
- * With writeback cache, kernel may send read requests even
|
|
|
902636 |
- * when userspace opened write-only
|
|
|
902636 |
- */
|
|
|
902636 |
- if (lo->writeback && (fi->flags & O_ACCMODE) == O_WRONLY) {
|
|
|
902636 |
- fi->flags &= ~O_ACCMODE;
|
|
|
902636 |
- fi->flags |= O_RDWR;
|
|
|
902636 |
- }
|
|
|
902636 |
-
|
|
|
902636 |
- /*
|
|
|
902636 |
- * With writeback cache, O_APPEND is handled by the kernel.
|
|
|
902636 |
- * This breaks atomicity (since the file may change in the
|
|
|
902636 |
- * underlying filesystem, so that the kernel's idea of the
|
|
|
902636 |
- * end of the file isn't accurate anymore). In this example,
|
|
|
902636 |
- * we just accept that. A more rigorous filesystem may want
|
|
|
902636 |
- * to return an error here
|
|
|
902636 |
- */
|
|
|
902636 |
- if (lo->writeback && (fi->flags & O_APPEND)) {
|
|
|
902636 |
- fi->flags &= ~O_APPEND;
|
|
|
902636 |
- }
|
|
|
902636 |
-
|
|
|
902636 |
- /*
|
|
|
902636 |
- * O_DIRECT in guest should not necessarily mean bypassing page
|
|
|
902636 |
- * cache on host as well. If somebody needs that behavior, it
|
|
|
902636 |
- * probably should be a configuration knob in daemon.
|
|
|
902636 |
- */
|
|
|
902636 |
- fi->flags &= ~O_DIRECT;
|
|
|
902636 |
+ update_open_flags(lo->writeback, fi);
|
|
|
902636 |
|
|
|
902636 |
sprintf(buf, "%i", lo_fd(req, ino));
|
|
|
902636 |
fd = openat(lo->proc_self_fd, buf, fi->flags & ~O_NOFOLLOW);
|
|
|
902636 |
--
|
|
|
902636 |
1.8.3.1
|
|
|
902636 |
|