Simple cleanups
David Sterba
maintainercover Simple cleanups
David Sterba (4):
btrfs: handle transaction commit errors in flush_reservations()
btrfs: pass btrfs_device to btrfs_scratch_superblocks()
btrfs: merge btrfs_del_delalloc_inode() helpers
btrfs: pass a valid extent map cache pointer to __get_extent_map()
fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/dev-replace.c | 3 +-- fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent_io.c | 11 ++++++++--- fs/btrfs/inode.c | 14 +++++--------- fs/btrfs/qgroup.c | 2 +- fs/btrfs/volumes.c | 13 +++++-------- fs/btrfs/volumes.h | 4 +--- 8 files changed, 23 insertions(+), 28 deletions(-)
Signature · 1 line
2.42.1
David Sterba
maintainerPATCH 1/4 btrfs: handle transaction commit errors in flush_reservations()
Other errors in flush_reservations() are handled and also in the caller. Ignoring commit might make some sense as it's called right after join so it's to poke the whole commit machinery to free space.
However for consistency return the error. The caller btrfs_quota_disable() would try to start the transaction which would in turn fail too so there's no effective change.
--- fs/btrfs/qgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/qgroup.c +1 -1
@@ -1324,7 +1324,7 @@ static int flush_reservations(struct btrfs_fs_info *fs_info) trans =btrfs_join_transaction (fs_info->tree_root);if (IS_ERR (trans))return PTR_ERR (trans); -btrfs_commit_transaction (trans); + ret =btrfs_commit_transaction (trans);return ret; }
Signature · 1 line
2.42.1
David Sterba
maintainerPATCH 2/4 btrfs: pass btrfs_device to btrfs_scratch_superblocks()
In reply to David SterbaReplace the two parameters bdev and name by one that can be used to get them both.
--- fs/btrfs/dev-replace.c | 3 +-- fs/btrfs/volumes.c | 13 +++++-------- fs/btrfs/volumes.h | 4 +--- 3 files changed, 7 insertions(+), 13 deletions(-)
fs/btrfs/dev-replace.c +1 -2
@@ -998,8 +998,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,btrfs_sysfs_remove_device (src_device);btrfs_sysfs_update_devid (tgt_device);if (test_bit (BTRFS_DEV_STATE_WRITEABLE , &src_device->dev_state)) -btrfs_scratch_superblocks (fs_info, src_device->bdev, - src_device->name->str); +btrfs_scratch_superblocks (fs_info, src_device);/* write back the superblocks */ trans =btrfs_start_transaction (root,0 );
fs/btrfs/volumes.c +5 -8
@@ -2030,11 +2030,10 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info, copy_num, ret); } -void btrfs_scratch_superblocks (struct btrfs_fs_info *fs_info, -struct block_device *bdev, -const char *device_path) +void btrfs_scratch_superblocks (struct btrfs_fs_info *fs_info,struct btrfs_device *device) {int copy_num; +struct block_device *bdev = device->bdev;if (!bdev)return ;
@@ -2050,7 +2049,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,btrfs_kobject_uevent (bdev,KOBJ_CHANGE );/* Update ctime/mtime for device path for libblkid */ -update_dev_time (device_path); +update_dev_time (device->name->str); } int btrfs_rm_device(struct btrfs_fs_info *fs_info,
@@ -2185,8 +2184,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info,* device and let the caller do the final bdev_release. */ if (test_bit (BTRFS_DEV_STATE_WRITEABLE , &device->dev_state)) { -btrfs_scratch_superblocks (fs_info, device->bdev, - device->name->str); +btrfs_scratch_superblocks (fs_info, device);if (device->bdev) {sync_blockdev (device->bdev);invalidate_bdev (device->bdev);
@@ -2299,8 +2297,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)mutex_unlock (&fs_devices->device_list_mutex); -btrfs_scratch_superblocks (tgtdev->fs_info, tgtdev->bdev, - tgtdev->name->str); +btrfs_scratch_superblocks (tgtdev->fs_info, tgtdev);btrfs_close_bdev (tgtdev);synchronize_rcu ();
fs/btrfs/volumes.h +1 -3
@@ -817,9 +817,7 @@ void btrfs_commit_device_sizes(struct btrfs_transaction *trans); struct list_head * __attribute_const__ btrfs_get_fs_uuids(void);bool btrfs_check_rw_degradable (struct btrfs_fs_info *fs_info,struct btrfs_device *failing_dev); -void btrfs_scratch_superblocks (struct btrfs_fs_info *fs_info, -struct block_device *bdev, -const char *device_path); +void btrfs_scratch_superblocks (struct btrfs_fs_info *fs_info,struct btrfs_device *device); enum btrfs_raid_types __attribute_const__ btrfs_bg_flags_to_raid_index(u64 flags);int btrfs_bg_type_to_factor (u64 flags);
Signature · 1 line
2.42.1
David Sterba
maintainerPATCH 3/4 btrfs: merge btrfs_del_delalloc_inode() helpers
In reply to David SterbaThe helpers btrfs_del_delalloc_inode() and __btrfs_del_delalloc_inode() don't follow the pattern when the "__" helper does a special case and are in fact reversed regarding the naming. We can merge them into one as there's only one place that needs to be open coded.
--- fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/disk-io.c | 2 +- fs/btrfs/inode.c | 14 +++++--------- 3 files changed, 7 insertions(+), 11 deletions(-)
fs/btrfs/btrfs_inode.h +1 -1
@@ -446,7 +446,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, u64 *orig_start, u64 *orig_block_len, u64 *ram_bytes, bool nowait, bool strict); -void __btrfs_del_delalloc_inode (struct btrfs_inode *inode); +void btrfs_del_delalloc_inode (struct btrfs_inode *inode);struct inode *btrfs_lookup_dentry (struct inode *dir,struct dentry *dentry);int btrfs_set_inode_index (struct btrfs_inode *dir,u64 *index); int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
fs/btrfs/disk-io.c +1 -1
@@ -4629,7 +4629,7 @@ static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root)struct inode *inode =NULL ; btrfs_inode = list_first_entry(&splice, struct btrfs_inode, delalloc_inodes); -__btrfs_del_delalloc_inode (btrfs_inode); +btrfs_del_delalloc_inode (btrfs_inode);spin_unlock (&root->delalloc_lock);/*
fs/btrfs/inode.c +5 -9
@@ -2410,7 +2410,7 @@ static void btrfs_add_delalloc_inode(struct btrfs_inode *inode)spin_unlock (&root->delalloc_lock); } -void __btrfs_del_delalloc_inode (struct btrfs_inode *inode) +void btrfs_del_delalloc_inode (struct btrfs_inode *inode) {struct btrfs_root *root = inode->root;struct btrfs_fs_info *fs_info = root->fs_info;
@@ -2436,13 +2436,6 @@ void __btrfs_del_delalloc_inode(struct btrfs_inode *inode) } } -static void btrfs_del_delalloc_inode (struct btrfs_inode *inode) -{ -spin_lock (&inode->root->delalloc_lock); -__btrfs_del_delalloc_inode (inode); -spin_unlock (&inode->root->delalloc_lock); -} -/* * Properly track delayed allocation bytes in the inode and to maintain the * list of inodes that have pending delalloc work to be done.
@@ -2565,8 +2558,11 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,* and are therefore protected against concurrent calls of this * function and btrfs_set_delalloc_extent(). */ -if (!btrfs_is_free_space_inode (inode) && new_delalloc_bytes ==0 ) +if (!btrfs_is_free_space_inode (inode) && new_delalloc_bytes ==0 ) { +spin_lock (&root->delalloc_lock);btrfs_del_delalloc_inode (inode); +spin_unlock (&root->delalloc_lock); + } } if ((state->state & EXTENT_DELALLOC_NEW) &&
Signature · 1 line
2.42.1
David Sterba
maintainerPATCH 4/4 btrfs: pass a valid extent map cache pointer to __get_extent_map()
In reply to David SterbaWe can pass a valid em cache pointer down to __get_extent_map() and drop the validity check. This avoids the special case, the call stacks are simple:
btrfs_read_folio
btrfs_do_readpage
__get_extent_map
extent_readahead
contiguous_readpages
btrfs_do_readpage
__get_extent_map
--- fs/btrfs/extent_io.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/btrfs/extent_io.c +8 -3
@@ -970,7 +970,9 @@ static struct extent_map *__get_extent_map(struct inode *inode, struct page *pag {struct extent_map *em; -if (em_cached && *em_cached) { +ASSERT (em_cached); + +if (*em_cached) { em = *em_cached;if (extent_map_in_tree (em) && start >= em->start && start <extent_map_end (em)) {
@@ -983,7 +985,7 @@ static struct extent_map *__get_extent_map(struct inode *inode, struct page *pag } em =btrfs_get_extent (BTRFS_I (inode), page, start, len); -if (em_cached && !IS_ERR (em)) { +if (!IS_ERR (em)) {BUG_ON (*em_cached);refcount_inc (&em->refs); *em_cached = em;
@@ -1154,11 +1156,12 @@ int btrfs_read_folio(struct file *file, struct folio *folio)u64 start =page_offset (page);u64 end = start +PAGE_SIZE -1 ;struct btrfs_bio_ctrl bio_ctrl = { .opf =REQ_OP_READ }; +struct extent_map *em_cached =NULL ;int ret;btrfs_lock_and_flush_ordered_range (inode, start, end,NULL ); - ret =btrfs_do_readpage (page,NULL , &bio_ctrl,NULL ); + ret =btrfs_do_readpage (page, &em_cached, &bio_ctrl,NULL );/* * If btrfs_do_readpage() failed we will want to submit the assembled * bio to do the cleanup.
@@ -1176,6 +1179,8 @@ static inline void contiguous_readpages(struct page *pages[], int nr_pages,struct btrfs_inode *inode =page_to_inode (pages[0 ]);int index; +ASSERT (em_cached); +btrfs_lock_and_flush_ordered_range (inode, start, end,NULL );for (index =0 ; index < nr_pages; index++) {
Signature · 1 line
2.42.1
Quoted 6 lines · David Sterba
David Sterba (4):
btrfs: handle transaction commit errors inflush_reservations()
btrfs: passbtrfs_devicetobtrfs_scratch_superblocks()
btrfs: mergebtrfs_del_delalloc_inode()helpers
btrfs: pass a valid extent map cache pointer to__get_extent_map()
Thanks,
Josef
Quoted 5 lines · David Sterba
David Sterba (4):
btrfs: handle transaction commit errors inflush_reservations()
btrfs: passbtrfs_devicetobtrfs_scratch_superblocks()
btrfs: mergebtrfs_del_delalloc_inode()helpers
btrfs: pass a valid extent map cache pointer to__get_extent_map()
Thanks,
Qu
Quoted 11 lines
fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/dev-replace.c | 3 +-- fs/btrfs/disk-io.c | 2 +- fs/btrfs/extent_io.c | 11 ++++++++--- fs/btrfs/inode.c | 14 +++++--------- fs/btrfs/qgroup.c | 2 +- fs/btrfs/volumes.c | 13 +++++-------- fs/btrfs/volumes.h | 4 +--- 8 files changed, 23 insertions(+), 28 deletions(-)