Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ext4: pass out extent seq counter when mapping blocks

When creating or querying mapping blocks using the ext4_map_blocks() and
ext4_map_{query|create}_blocks() helpers, also pass out the extent
sequence number of the block mapping info through the ext4_map_blocks
structure. This sequence number can later serve as a valid cookie within
iomap infrastructure and the move extents procedure.

Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Message-ID: <20251013015128.499308-5-yi.zhang@huaweicloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Zhang Yi and committed by
Theodore Ts'o
07c440e8 7da5565c

+17 -8
+1
fs/ext4/ext4.h
··· 260 260 ext4_lblk_t m_lblk; 261 261 unsigned int m_len; 262 262 unsigned int m_flags; 263 + u64 m_seq; 263 264 }; 264 265 265 266 /*
+16 -8
fs/ext4/inode.c
··· 550 550 retval = ext4_ext_map_blocks(handle, inode, map, flags); 551 551 else 552 552 retval = ext4_ind_map_blocks(handle, inode, map, flags); 553 - 554 - if (retval <= 0) 553 + if (retval < 0) 555 554 return retval; 555 + 556 + /* A hole? */ 557 + if (retval == 0) 558 + goto out; 556 559 557 560 if (unlikely(retval != map->m_len)) { 558 561 ext4_warning(inode->i_sb, ··· 576 573 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; 577 574 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, 578 575 map->m_pblk, status, false); 579 - return retval; 576 + } else { 577 + retval = ext4_map_query_blocks_next_in_leaf(handle, inode, map, 578 + orig_mlen); 580 579 } 581 - 582 - return ext4_map_query_blocks_next_in_leaf(handle, inode, map, 583 - orig_mlen); 580 + out: 581 + map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq); 582 + return retval; 584 583 } 585 584 586 585 static int ext4_map_create_blocks(handle_t *handle, struct inode *inode, ··· 654 649 * extent status tree. 655 650 */ 656 651 if (flags & EXT4_GET_BLOCKS_PRE_IO && 657 - ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, NULL)) { 652 + ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, &map->m_seq)) { 658 653 if (ext4_es_is_written(&es)) 659 654 return retval; 660 655 } ··· 663 658 EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; 664 659 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, 665 660 status, flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE); 661 + map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq); 666 662 667 663 return retval; 668 664 } ··· 729 723 ext4_check_map_extents_env(inode); 730 724 731 725 /* Lookup extent status tree firstly */ 732 - if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, NULL)) { 726 + if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es, &map->m_seq)) { 733 727 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { 734 728 map->m_pblk = ext4_es_pblock(&es) + 735 729 map->m_lblk - es.es_lblk; ··· 1985 1979 1986 1980 map->m_flags |= EXT4_MAP_DELAYED; 1987 1981 retval = ext4_insert_delayed_blocks(inode, map->m_lblk, map->m_len); 1982 + if (!retval) 1983 + map->m_seq = READ_ONCE(EXT4_I(inode)->i_es_seq); 1988 1984 up_write(&EXT4_I(inode)->i_data_sem); 1989 1985 1990 1986 return retval;