* [PATCH 0/4] Simple cleanups
@ 2024-02-22 12:14 David Sterba
2024-02-22 12:14 ` [PATCH 1/4] btrfs: handle transaction commit errors in flush_reservations() David Sterba
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: David Sterba @ 2024-02-22 12:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
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(-)
--
2.42.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] btrfs: handle transaction commit errors in flush_reservations()
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
@ 2024-02-22 12:14 ` David Sterba
2024-02-22 12:14 ` [PATCH 2/4] btrfs: pass btrfs_device to btrfs_scratch_superblocks() David Sterba
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2024-02-22 12:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
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.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/qgroup.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 044331228bd0..3846433d83d9 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -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;
}
--
2.42.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] btrfs: pass btrfs_device to btrfs_scratch_superblocks()
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
2024-02-22 12:14 ` [PATCH 1/4] btrfs: handle transaction commit errors in flush_reservations() David Sterba
@ 2024-02-22 12:14 ` David Sterba
2024-02-22 12:14 ` [PATCH 3/4] btrfs: merge btrfs_del_delalloc_inode() helpers David Sterba
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2024-02-22 12:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
Replace the two parameters bdev and name by one that can be used to get
them both.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/dev-replace.c | 3 +--
fs/btrfs/volumes.c | 13 +++++--------
fs/btrfs/volumes.h | 4 +---
3 files changed, 7 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 1c02d4dc0b72..e24d784898fc 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -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);
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 32312f0de2bb..3cc947a42116 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -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();
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 055e095c2f61..feba8d53526c 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -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);
--
2.42.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] btrfs: merge btrfs_del_delalloc_inode() helpers
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
2024-02-22 12:14 ` [PATCH 1/4] btrfs: handle transaction commit errors in flush_reservations() David Sterba
2024-02-22 12:14 ` [PATCH 2/4] btrfs: pass btrfs_device to btrfs_scratch_superblocks() David Sterba
@ 2024-02-22 12:14 ` David Sterba
2024-02-22 12:14 ` [PATCH 4/4] btrfs: pass a valid extent map cache pointer to __get_extent_map() David Sterba
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2024-02-22 12:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
The 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.
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/btrfs_inode.h | 2 +-
fs/btrfs/disk-io.c | 2 +-
fs/btrfs/inode.c | 14 +++++---------
3 files changed, 7 insertions(+), 11 deletions(-)
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h
index a35adc06ce0c..100020ca4658 100644
--- a/fs/btrfs/btrfs_inode.h
+++ b/fs/btrfs/btrfs_inode.h
@@ -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,
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8ab185182c30..a2e45ed6ef14 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -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);
/*
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f93cb23ae1ee..d931cb40fb7a 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -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) &&
--
2.42.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] btrfs: pass a valid extent map cache pointer to __get_extent_map()
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
` (2 preceding siblings ...)
2024-02-22 12:14 ` [PATCH 3/4] btrfs: merge btrfs_del_delalloc_inode() helpers David Sterba
@ 2024-02-22 12:14 ` David Sterba
2024-02-22 15:44 ` [PATCH 0/4] Simple cleanups Josef Bacik
2024-02-22 21:48 ` Qu Wenruo
5 siblings, 0 replies; 7+ messages in thread
From: David Sterba @ 2024-02-22 12:14 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba
We 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
Signed-off-by: David Sterba <dsterba@suse.com>
---
fs/btrfs/extent_io.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index e2dbadfc082f..43496a07ee42 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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++) {
--
2.42.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Simple cleanups
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
` (3 preceding siblings ...)
2024-02-22 12:14 ` [PATCH 4/4] btrfs: pass a valid extent map cache pointer to __get_extent_map() David Sterba
@ 2024-02-22 15:44 ` Josef Bacik
2024-02-22 21:48 ` Qu Wenruo
5 siblings, 0 replies; 7+ messages in thread
From: Josef Bacik @ 2024-02-22 15:44 UTC (permalink / raw)
To: David Sterba; +Cc: linux-btrfs
On Thu, Feb 22, 2024 at 01:14:07PM +0100, David Sterba wrote:
> 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()
>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] Simple cleanups
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
` (4 preceding siblings ...)
2024-02-22 15:44 ` [PATCH 0/4] Simple cleanups Josef Bacik
@ 2024-02-22 21:48 ` Qu Wenruo
5 siblings, 0 replies; 7+ messages in thread
From: Qu Wenruo @ 2024-02-22 21:48 UTC (permalink / raw)
To: David Sterba, linux-btrfs
在 2024/2/22 22:44, David Sterba 写道:
> 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()
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
>
> 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(-)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-02-22 21:49 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 12:14 [PATCH 0/4] Simple cleanups David Sterba
2024-02-22 12:14 ` [PATCH 1/4] btrfs: handle transaction commit errors in flush_reservations() David Sterba
2024-02-22 12:14 ` [PATCH 2/4] btrfs: pass btrfs_device to btrfs_scratch_superblocks() David Sterba
2024-02-22 12:14 ` [PATCH 3/4] btrfs: merge btrfs_del_delalloc_inode() helpers David Sterba
2024-02-22 12:14 ` [PATCH 4/4] btrfs: pass a valid extent map cache pointer to __get_extent_map() David Sterba
2024-02-22 15:44 ` [PATCH 0/4] Simple cleanups Josef Bacik
2024-02-22 21:48 ` Qu Wenruo
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.