From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Lukas Czerner <lczerner@redhat.com>,
Theodore Tso <tytso@mit.edu>
Subject: [PATCH 3.10 09/19] ext4: fix data corruption caused by unwritten and delayed extents
Date: Mon, 11 May 2015 10:55:24 -0700 [thread overview]
Message-ID: <20150511175453.283966641@linuxfoundation.org> (raw)
In-Reply-To: <20150511175453.015424013@linuxfoundation.org>
3.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Czerner <lczerner@redhat.com>
commit d2dc317d564a46dfc683978a2e5a4f91434e9711 upstream.
Currently it is possible to lose whole file system block worth of data
when we hit the specific interaction with unwritten and delayed extents
in status extent tree.
The problem is that when we insert delayed extent into extent status
tree the only way to get rid of it is when we write out delayed buffer.
However there is a limitation in the extent status tree implementation
so that when inserting unwritten extent should there be even a single
delayed block the whole unwritten extent would be marked as delayed.
At this point, there is no way to get rid of the delayed extents,
because there are no delayed buffers to write out. So when a we write
into said unwritten extent we will convert it to written, but it still
remains delayed.
When we try to write into that block later ext4_da_map_blocks() will set
the buffer new and delayed and map it to invalid block which causes
the rest of the block to be zeroed loosing already written data.
For now we can fix this by simply not allowing to set delayed status on
written extent in the extent status tree. Also add WARN_ON() to make
sure that we notice if this happens in the future.
This problem can be easily reproduced by running the following xfs_io.
xfs_io -f -c "pwrite -S 0xaa 4096 2048" \
-c "falloc 0 131072" \
-c "pwrite -S 0xbb 65536 2048" \
-c "fsync" /mnt/test/fff
echo 3 > /proc/sys/vm/drop_caches
xfs_io -c "pwrite -S 0xdd 67584 2048" /mnt/test/fff
This can be theoretically also reproduced by at random by running fsx,
but it's not very reliable, though on machines with bigger page size
(like ppc) this can be seen more often (especially xfstest generic/127)
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/ext4/extents_status.c | 8 ++++++++
fs/ext4/inode.c | 2 ++
2 files changed, 10 insertions(+)
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -655,6 +655,14 @@ int ext4_es_insert_extent(struct inode *
BUG_ON(end < lblk);
+ if ((status & EXTENT_STATUS_DELAYED) &&
+ (status & EXTENT_STATUS_WRITTEN)) {
+ ext4_warning(inode->i_sb, "Inserting extent [%u/%u] as "
+ " delayed and written which can potentially "
+ " cause data loss.\n", lblk, len);
+ WARN_ON(1);
+ }
+
newes.es_lblk = lblk;
newes.es_len = len;
ext4_es_store_pblock(&newes, pblk);
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -626,6 +626,7 @@ int ext4_map_blocks(handle_t *handle, st
status = map->m_flags & EXT4_MAP_UNWRITTEN ?
EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
+ !(status & EXTENT_STATUS_WRITTEN) &&
ext4_find_delalloc_range(inode, map->m_lblk,
map->m_lblk + map->m_len - 1))
status |= EXTENT_STATUS_DELAYED;
@@ -736,6 +737,7 @@ found:
status = map->m_flags & EXT4_MAP_UNWRITTEN ?
EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN;
if (!(flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE) &&
+ !(status & EXTENT_STATUS_WRITTEN) &&
ext4_find_delalloc_range(inode, map->m_lblk,
map->m_lblk + map->m_len - 1))
status |= EXTENT_STATUS_DELAYED;
next prev parent reply other threads:[~2015-05-11 18:47 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-11 17:55 [PATCH 3.10 00/19] 3.10.78-stable review Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 01/19] [PATCH] ipv4: Missing sk_nulls_node_init() in ping_unhash() Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 02/19] ALSA: emux: Fix mutex deadlock at unloading Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 03/19] ALSA: emux: Fix mutex deadlock in OSS emulation Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 04/19] ALSA: emu10k1: Fix card shortname string buffer overflow Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 05/19] ALSA: emu10k1: Emu10k2 32 bit DMA mode Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 07/19] serial: of-serial: Remove device_type = "serial" registration Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 08/19] rbd: end I/O the entire obj_request on error Greg Kroah-Hartman
2015-05-11 17:55 ` Greg Kroah-Hartman [this message]
2015-05-11 17:55 ` [PATCH 3.10 10/19] 3w-xxxx: fix command completion race Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 11/19] 3w-9xxx: " Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 12/19] 3w-sas: " Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 13/19] usb: host: oxu210hp: use new USB_RESUME_TIMEOUT Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 14/19] usb: gadget: printer: enqueue printers response for setup request Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 15/19] staging: panel: fix lcd type Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 16/19] ARM: dts: dove: Fix uart[23] reg property Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 17/19] Drivers: hv: vmbus: Dont wait after requesting offers Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 18/19] UBI: fix soft lockup in ubi_check_volume() Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 19/19] ARC: signal handling robustify Greg Kroah-Hartman
2015-05-11 20:02 ` [PATCH 3.10 00/19] 3.10.78-stable review Guenter Roeck
2015-05-11 23:41 ` Shuah Khan
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=20150511175453.283966641@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=lczerner@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=tytso@mit.edu \
/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