|
|
f239de |
From d80424f5ceaa3a7a8ce7dbf6bacca32f2f05fdeb Mon Sep 17 00:00:00 2001
|
|
|
f239de |
From: Lukas Czerner <lczerner@redhat.com>
|
|
|
f239de |
Date: Thu, 18 Feb 2021 10:51:46 +0100
|
|
|
f239de |
Subject: [PATCH 23/46] mmp: do not use O_DIRECT when working with regular file
|
|
|
f239de |
Content-Type: text/plain
|
|
|
f239de |
|
|
|
f239de |
Currently the mmp block is read using O_DIRECT to avoid any caching that
|
|
|
f239de |
may be done by the VM. However when working with regular files this
|
|
|
f239de |
creates alignment issues when the device of the host file system has
|
|
|
f239de |
sector size larger than the blocksize of the file system in the file
|
|
|
f239de |
we're working with.
|
|
|
f239de |
|
|
|
f239de |
This can be reproduced with t_mmp_fail test when run on the device with
|
|
|
f239de |
4k sector size because the mke2fs fails when trying to read the mmp
|
|
|
f239de |
block.
|
|
|
f239de |
|
|
|
f239de |
Fix it by disabling O_DIRECT when working with regular files. I don't
|
|
|
f239de |
think there is any risk of doing so since the file system layer, unlike
|
|
|
f239de |
shared block device, should guarantee cache consistency.
|
|
|
f239de |
|
|
|
f239de |
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
|
|
|
f239de |
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
|
|
|
f239de |
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
|
|
|
f239de |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
f239de |
---
|
|
|
f239de |
lib/ext2fs/mmp.c | 22 +++++++++++-----------
|
|
|
f239de |
1 file changed, 11 insertions(+), 11 deletions(-)
|
|
|
f239de |
|
|
|
f239de |
diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
|
|
|
f239de |
index eddc66a7..626fe395 100644
|
|
|
f239de |
--- a/lib/ext2fs/mmp.c
|
|
|
f239de |
+++ b/lib/ext2fs/mmp.c
|
|
|
f239de |
@@ -57,21 +57,21 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
|
|
|
f239de |
* regardless of how the io_manager is doing reads, to avoid caching of
|
|
|
f239de |
* the MMP block by the io_manager or the VM. It needs to be fresh. */
|
|
|
f239de |
if (fs->mmp_fd <= 0) {
|
|
|
f239de |
+ struct stat st;
|
|
|
f239de |
int flags = O_RDWR | O_DIRECT;
|
|
|
f239de |
|
|
|
f239de |
-retry:
|
|
|
f239de |
+ /*
|
|
|
f239de |
+ * There is no reason for using O_DIRECT if we're working with
|
|
|
f239de |
+ * regular file. Disabling it also avoids problems with
|
|
|
f239de |
+ * alignment when the device of the host file system has sector
|
|
|
f239de |
+ * size larger than blocksize of the fs we're working with.
|
|
|
f239de |
+ */
|
|
|
f239de |
+ if (stat(fs->device_name, &st) == 0 &&
|
|
|
f239de |
+ S_ISREG(st.st_mode))
|
|
|
f239de |
+ flags &= ~O_DIRECT;
|
|
|
f239de |
+
|
|
|
f239de |
fs->mmp_fd = open(fs->device_name, flags);
|
|
|
f239de |
if (fs->mmp_fd < 0) {
|
|
|
f239de |
- struct stat st;
|
|
|
f239de |
-
|
|
|
f239de |
- /* Avoid O_DIRECT for filesystem image files if open
|
|
|
f239de |
- * fails, since it breaks when running on tmpfs. */
|
|
|
f239de |
- if (errno == EINVAL && (flags & O_DIRECT) &&
|
|
|
f239de |
- stat(fs->device_name, &st) == 0 &&
|
|
|
f239de |
- S_ISREG(st.st_mode)) {
|
|
|
f239de |
- flags &= ~O_DIRECT;
|
|
|
f239de |
- goto retry;
|
|
|
f239de |
- }
|
|
|
f239de |
retval = EXT2_ET_MMP_OPEN_DIRECT;
|
|
|
f239de |
goto out;
|
|
|
f239de |
}
|
|
|
f239de |
--
|
|
|
f239de |
2.35.1
|
|
|
f239de |
|