Skip to content

Commit 869f4cd

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: encapsulate inode locking for zoned relocation
Encapsulate the inode lock needed for serializing the data relocation writes on a zoned filesystem into a helper. This streamlines the code reading flow and hides special casing for zoned filesystems. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent a26d60d commit 869f4cd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

fs/btrfs/extent_io.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,8 +5184,6 @@ int extent_writepages(struct address_space *mapping,
51845184
struct writeback_control *wbc)
51855185
{
51865186
struct inode *inode = mapping->host;
5187-
const bool data_reloc = btrfs_is_data_reloc_root(BTRFS_I(inode)->root);
5188-
const bool zoned = btrfs_is_zoned(BTRFS_I(inode)->root->fs_info);
51895187
int ret = 0;
51905188
struct extent_page_data epd = {
51915189
.bio_ctrl = { 0 },
@@ -5197,11 +5195,9 @@ int extent_writepages(struct address_space *mapping,
51975195
* Allow only a single thread to do the reloc work in zoned mode to
51985196
* protect the write pointer updates.
51995197
*/
5200-
if (data_reloc && zoned)
5201-
btrfs_inode_lock(inode, 0);
5198+
btrfs_zoned_data_reloc_lock(BTRFS_I(inode));
52025199
ret = extent_write_cache_pages(mapping, wbc, &epd);
5203-
if (data_reloc && zoned)
5204-
btrfs_inode_unlock(inode, 0);
5200+
btrfs_zoned_data_reloc_unlock(BTRFS_I(inode));
52055201
ASSERT(ret <= 0);
52065202
if (ret < 0) {
52075203
end_write_bio(&epd, ret);

fs/btrfs/zoned.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "volumes.h"
99
#include "disk-io.h"
1010
#include "block-group.h"
11+
#include "btrfs_inode.h"
1112

1213
/*
1314
* Block groups with more than this value (percents) of unusable space will be
@@ -354,4 +355,20 @@ static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
354355
spin_unlock(&fs_info->treelog_bg_lock);
355356
}
356357

358+
static inline void btrfs_zoned_data_reloc_lock(struct btrfs_inode *inode)
359+
{
360+
struct btrfs_root *root = inode->root;
361+
362+
if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
363+
btrfs_inode_lock(&inode->vfs_inode, 0);
364+
}
365+
366+
static inline void btrfs_zoned_data_reloc_unlock(struct btrfs_inode *inode)
367+
{
368+
struct btrfs_root *root = inode->root;
369+
370+
if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
371+
btrfs_inode_unlock(&inode->vfs_inode, 0);
372+
}
373+
357374
#endif

0 commit comments

Comments
 (0)