Move the error handling for mpage_map_one_extent() failures after the mapping loop in mpage_map_and_submit_extent(). Keep buffer-processing errors on the existing update_disksize path and preserve progress tracking and return values. This prepares for reusing partial-folio submission when buffer processing fails. No functional change. Signed-off-by: Julian Sun --- fs/ext4/inode.c | 83 +++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6ede3644a738..de6fe4f0117c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2599,46 +2599,8 @@ static int mpage_map_and_submit_extent(handle_t *handle, io_end_vec->offset = EXT4_LBLK_TO_B(inode, map->m_lblk); do { err = mpage_map_one_extent(handle, mpd); - if (err < 0) { - struct super_block *sb = inode->i_sb; - - if (ext4_emergency_state(sb)) - goto invalidate_dirty_pages; - /* - * Let the uper layers retry transient errors. - * In the case of ENOSPC, if ext4_count_free_blocks() - * is non-zero, a commit should free up blocks. - */ - if ((err == -ENOMEM) || (err == -EAGAIN) || - (err == -ENOSPC && ext4_count_free_clusters(sb))) { - /* - * We may have already allocated extents for - * some bhs inside the folio, issue the - * corresponding data to prevent stale data. - */ - if (progress) { - if (mpage_submit_partial_folio(mpd)) - goto invalidate_dirty_pages; - goto update_disksize; - } - return err; - } - ext4_msg(sb, KERN_CRIT, - "Delayed block allocation failed for " - "inode %llu at logical offset %llu with" - " max blocks %u with error %d", - inode->i_ino, - (unsigned long long)map->m_lblk, - (unsigned)map->m_len, -err); - ext4_msg(sb, KERN_CRIT, - "This should not happen!! Data will " - "be lost\n"); - if (err == -ENOSPC) - ext4_print_free_blocks(inode); - invalidate_dirty_pages: - *give_up_on_write = true; - return err; - } + if (err < 0) + break; progress = 1; /* * Update buffer state, submit mapped pages, and get us new @@ -2649,6 +2611,47 @@ static int mpage_map_and_submit_extent(handle_t *handle, goto update_disksize; } while (map->m_len); + if (err < 0) { + struct super_block *sb = inode->i_sb; + + if (ext4_emergency_state(sb)) + goto invalidate_dirty_pages; + /* + * Let the uper layers retry transient errors. + * In the case of ENOSPC, if ext4_count_free_blocks() + * is non-zero, a commit should free up blocks. + */ + if ((err == -ENOMEM) || (err == -EAGAIN) || + (err == -ENOSPC && ext4_count_free_clusters(sb))) { + /* + * We may have already allocated extents for + * some bhs inside the folio, issue the + * corresponding data to prevent stale data. + */ + if (progress) { + if (mpage_submit_partial_folio(mpd)) + goto invalidate_dirty_pages; + goto update_disksize; + } + return err; + } + ext4_msg(sb, KERN_CRIT, + "Delayed block allocation failed for " + "inode %llu at logical offset %llu with" + " max blocks %u with error %d", + inode->i_ino, + (unsigned long long)map->m_lblk, + (unsigned)map->m_len, -err); + ext4_msg(sb, KERN_CRIT, + "This should not happen!! Data will " + "be lost\n"); + if (err == -ENOSPC) + ext4_print_free_blocks(inode); +invalidate_dirty_pages: + *give_up_on_write = true; + return err; + } + update_disksize: /* * Update on-disk size after IO is submitted. Races with -- 2.39.5