FAILED: patch "[PATCH] udf: Fix data loss when converting inline inodes to out of" failed to apply to 6.12-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 62333e480d12ab186f89fe2725b372d12f72d5eb
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090408-obliged-concert-25ca@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 62333e480d12ab186f89fe2725b372d12f72d5eb Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Thu, 30 Jul 2026 12:42:29 +0200
Subject: [PATCH] udf: Fix data loss when converting inline inodes to out of
line
When udf_expand_file_adinicb() converts file from inline format to out of line, we use filemap_fdatawrite() to writeout the data to the new blocks. However since 36580ed08776 ("udf: Do not allocate blocks on page writeback") the writeback actually doesn't allocate the new block and the folio dirty bit is just silently cleared. Thus unless the file is written to after the conversion (as it can easily happen in case of truncate up), the data is just lost. Fix the problem by explicitely allocating the block underlying the data before starting writeback.
fs/udf/inode.c +13 -2
@@ -405,6 +405,10 @@ int udf_expand_file_adinicb(struct inode *inode) {struct folio *folio;struct udf_inode_info *iinfo =UDF_I (inode); +struct udf_map_rq map = { + .lblk =0 , + .iflags =UDF_MAP_CREATE , + };int err;WARN_ON_ONCE (!inode_is_locked (inode));
@@ -434,20 +438,27 @@ int udf_expand_file_adinicb(struct inode *inode) iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; else iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; +up_write (&iinfo->i_data_sem); + +/* Allocate the block underlying the data */ + err =udf_map_block (inode, &map); +if (err <0 ) + goto restore; +folio_mark_dirty (folio);folio_unlock (folio); -up_write (&iinfo->i_data_sem); err =filemap_fdatawrite (inode->i_mapping);if (err) {/* Restore everything back so that we don't lose data... */ folio_lock (folio); +restore:down_write (&iinfo->i_data_sem);memcpy_from_folio (iinfo->i_data + iinfo->i_lenEAttr, folio,0 , inode->i_size); -folio_unlock (folio); iinfo->i_alloc_type =ICBTAG_FLAG_AD_IN_ICB ; iinfo->i_lenAlloc = inode->i_size;up_write (&iinfo->i_data_sem); +folio_unlock (folio); }folio_put (folio);mark_inode_dirty (inode);
Sasha Levin
maintainerPATCH 1/2 udf: Move udf_map_block() up
From: Jan Kara <[email protected]>
[ Upstream commit 97e9d759a4193eabe4d8b6ecac093aac664c16e3 ]
Move udf_map_block() in the file to avoid forward declarations.
Stable-dep-of: 62333e480d12 ("udf: Fix data loss when converting inline inodes to out of line")
--- fs/udf/inode.c | 118 ++++++++++++++++++++++++------------------------- 1 file changed, 59 insertions(+), 59 deletions(-)
fs/udf/inode.c +59 -59
@@ -330,65 +330,6 @@ const struct address_space_operations udf_aops = { .migrate_folio = buffer_migrate_folio, }; -/* -* Expand file stored in ICB to a normal one-block-file -* -* This function requires i_mutex held -*/ -int udf_expand_file_adinicb (struct inode *inode) -{ -struct folio *folio; -struct udf_inode_info *iinfo =UDF_I (inode); -int err; - -WARN_ON_ONCE (!inode_is_locked (inode)); -if (!iinfo->i_lenAlloc) { -down_write (&iinfo->i_data_sem); -if (UDF_QUERY_FLAG (inode->i_sb,UDF_FLAG_USE_SHORT_AD )) - iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; -else - iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; -up_write (&iinfo->i_data_sem); -mark_inode_dirty (inode); -return 0 ; - } - - folio =__filemap_get_folio (inode->i_mapping,0 , -FGP_LOCK |FGP_ACCESSED |FGP_CREAT ,GFP_KERNEL ); -if (IS_ERR (folio)) -return PTR_ERR (folio); - -if (!folio_test_uptodate (folio)) -udf_adinicb_read_folio (folio); -down_write (&iinfo->i_data_sem); -memset (iinfo->i_data + iinfo->i_lenEAttr,0x00 , - iinfo->i_lenAlloc); - iinfo->i_lenAlloc =0 ; -if (UDF_QUERY_FLAG (inode->i_sb,UDF_FLAG_USE_SHORT_AD )) - iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; -else - iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; -folio_mark_dirty (folio); -folio_unlock (folio); -up_write (&iinfo->i_data_sem); - err =filemap_fdatawrite (inode->i_mapping); -if (err) { -/* Restore everything back so that we don't lose data... */ -folio_lock (folio); -down_write (&iinfo->i_data_sem); -memcpy_from_folio (iinfo->i_data + iinfo->i_lenEAttr, - folio,0 , inode->i_size); -folio_unlock (folio); - iinfo->i_alloc_type =ICBTAG_FLAG_AD_IN_ICB ; - iinfo->i_lenAlloc = inode->i_size; -up_write (&iinfo->i_data_sem); - } -folio_put (folio); -mark_inode_dirty (inode); - -return err; -} -#define UDF_MAP_CREATE 0x01/* Mapping can allocate new blocks */ #define UDF_MAP_NOPREALLOC 0x02/* Do not preallocate blocks */
@@ -449,6 +390,65 @@ static int udf_map_block(struct inode *inode, struct udf_map_rq *map)return ret; } +/* +* Expand file stored in ICB to a normal one-block-file +* +* This function requires i_mutex held +*/ +int udf_expand_file_adinicb (struct inode *inode) +{ +struct folio *folio; +struct udf_inode_info *iinfo =UDF_I (inode); +int err; + +WARN_ON_ONCE (!inode_is_locked (inode)); +if (!iinfo->i_lenAlloc) { +down_write (&iinfo->i_data_sem); +if (UDF_QUERY_FLAG (inode->i_sb,UDF_FLAG_USE_SHORT_AD )) + iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; +else + iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; +up_write (&iinfo->i_data_sem); +mark_inode_dirty (inode); +return 0 ; + } + + folio =__filemap_get_folio (inode->i_mapping,0 , +FGP_LOCK |FGP_ACCESSED |FGP_CREAT ,GFP_KERNEL ); +if (IS_ERR (folio)) +return PTR_ERR (folio); + +if (!folio_test_uptodate (folio)) +udf_adinicb_read_folio (folio); +down_write (&iinfo->i_data_sem); +memset (iinfo->i_data + iinfo->i_lenEAttr,0x00 , + iinfo->i_lenAlloc); + iinfo->i_lenAlloc =0 ; +if (UDF_QUERY_FLAG (inode->i_sb,UDF_FLAG_USE_SHORT_AD )) + iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; +else + iinfo->i_alloc_type =ICBTAG_FLAG_AD_LONG ; +folio_mark_dirty (folio); +folio_unlock (folio); +up_write (&iinfo->i_data_sem); + err =filemap_fdatawrite (inode->i_mapping); +if (err) { +/* Restore everything back so that we don't lose data... */ +folio_lock (folio); +down_write (&iinfo->i_data_sem); +memcpy_from_folio (iinfo->i_data + iinfo->i_lenEAttr, + folio,0 , inode->i_size); +folio_unlock (folio); + iinfo->i_alloc_type =ICBTAG_FLAG_AD_IN_ICB ; + iinfo->i_lenAlloc = inode->i_size; +up_write (&iinfo->i_data_sem); + } +folio_put (folio); +mark_inode_dirty (inode); + +return err; +} +static int __udf_get_block (struct inode *inode,sector_t block,struct buffer_head *bh_result,int flags) {
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 udf: Fix data loss when converting inline inodes to out of line
From: Jan Kara <[email protected]>
[ Upstream commit 62333e480d12ab186f89fe2725b372d12f72d5eb ]
When udf_expand_file_adinicb() converts file from inline format to out of line, we use filemap_fdatawrite() to writeout the data to the new blocks. However since 36580ed08776 ("udf: Do not allocate blocks on page writeback") the writeback actually doesn't allocate the new block and the folio dirty bit is just silently cleared. Thus unless the file is written to after the conversion (as it can easily happen in case of truncate up), the data is just lost. Fix the problem by explicitely allocating the block underlying the data before starting writeback.
--- fs/udf/inode.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
fs/udf/inode.c +13 -2
@@ -399,6 +399,10 @@ int udf_expand_file_adinicb(struct inode *inode) {struct folio *folio;struct udf_inode_info *iinfo =UDF_I (inode); +struct udf_map_rq map = { + .lblk =0 , + .iflags =UDF_MAP_CREATE , + };int err;WARN_ON_ONCE (!inode_is_locked (inode));
@@ -428,20 +432,27 @@ int udf_expand_file_adinicb(struct inode *inode) iinfo->i_alloc_type =ICBTAG_FLAG_AD_SHORT ; else iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; +up_write (&iinfo->i_data_sem); + +/* Allocate the block underlying the data */ + err =udf_map_block (inode, &map); +if (err <0 ) + goto restore; +folio_mark_dirty (folio);folio_unlock (folio); -up_write (&iinfo->i_data_sem); err =filemap_fdatawrite (inode->i_mapping);if (err) {/* Restore everything back so that we don't lose data... */ folio_lock (folio); +restore:down_write (&iinfo->i_data_sem);memcpy_from_folio (iinfo->i_data + iinfo->i_lenEAttr, folio,0 , inode->i_size); -folio_unlock (folio); iinfo->i_alloc_type =ICBTAG_FLAG_AD_IN_ICB ; iinfo->i_lenAlloc = inode->i_size;up_write (&iinfo->i_data_sem); +folio_unlock (folio); }folio_put (folio);mark_inode_dirty (inode);
Signature · 1 line
2.53.0