Skip to content

Commit 3f67e7c

Browse files
jankaratytso
authored andcommitted
ext4: fold ext4_data_block_valid_rcu() into the caller
After the previous patch, ext4_data_block_valid_rcu() has a single caller. Fold it into it. Reviewed-by: Lukas Czerner <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent ce9f24c commit 3f67e7c

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

fs/ext4/block_validity.c

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -144,40 +144,6 @@ static void debug_print_tree(struct ext4_sb_info *sbi)
144144
printk(KERN_CONT "\n");
145145
}
146146

147-
/*
148-
* Returns 1 if the passed-in block region (start_blk,
149-
* start_blk+count) is valid; 0 if some part of the block region
150-
* overlaps with filesystem metadata blocks.
151-
*/
152-
static int ext4_data_block_valid_rcu(struct ext4_sb_info *sbi,
153-
struct ext4_system_blocks *system_blks,
154-
ext4_fsblk_t start_blk,
155-
unsigned int count, ino_t ino)
156-
{
157-
struct ext4_system_zone *entry;
158-
struct rb_node *n;
159-
160-
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
161-
(start_blk + count < start_blk) ||
162-
(start_blk + count > ext4_blocks_count(sbi->s_es)))
163-
return 0;
164-
165-
if (system_blks == NULL)
166-
return 1;
167-
168-
n = system_blks->root.rb_node;
169-
while (n) {
170-
entry = rb_entry(n, struct ext4_system_zone, node);
171-
if (start_blk + count - 1 < entry->start_blk)
172-
n = n->rb_left;
173-
else if (start_blk >= (entry->start_blk + entry->count))
174-
n = n->rb_right;
175-
else
176-
return entry->ino == ino;
177-
}
178-
return 1;
179-
}
180-
181147
static int ext4_protect_reserved_inode(struct super_block *sb,
182148
struct ext4_system_blocks *system_blks,
183149
u32 ino)
@@ -333,21 +299,48 @@ void ext4_release_system_zone(struct super_block *sb)
333299
call_rcu(&system_blks->rcu, ext4_destroy_system_zone);
334300
}
335301

302+
/*
303+
* Returns 1 if the passed-in block region (start_blk,
304+
* start_blk+count) is valid; 0 if some part of the block region
305+
* overlaps with some other filesystem metadata blocks.
306+
*/
336307
int ext4_inode_block_valid(struct inode *inode, ext4_fsblk_t start_blk,
337308
unsigned int count)
338309
{
310+
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
339311
struct ext4_system_blocks *system_blks;
340-
int ret;
312+
struct ext4_system_zone *entry;
313+
struct rb_node *n;
314+
int ret = 1;
315+
316+
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
317+
(start_blk + count < start_blk) ||
318+
(start_blk + count > ext4_blocks_count(sbi->s_es)))
319+
return 0;
341320

342321
/*
343322
* Lock the system zone to prevent it being released concurrently
344323
* when doing a remount which inverse current "[no]block_validity"
345324
* mount option.
346325
*/
347326
rcu_read_lock();
348-
system_blks = rcu_dereference(EXT4_SB(inode->i_sb)->system_blks);
349-
ret = ext4_data_block_valid_rcu(EXT4_SB(inode->i_sb), system_blks,
350-
start_blk, count, inode->i_ino);
327+
system_blks = rcu_dereference(sbi->system_blks);
328+
if (system_blks == NULL)
329+
goto out_rcu;
330+
331+
n = system_blks->root.rb_node;
332+
while (n) {
333+
entry = rb_entry(n, struct ext4_system_zone, node);
334+
if (start_blk + count - 1 < entry->start_blk)
335+
n = n->rb_left;
336+
else if (start_blk >= (entry->start_blk + entry->count))
337+
n = n->rb_right;
338+
else {
339+
ret = (entry->ino == inode->i_ino);
340+
break;
341+
}
342+
}
343+
out_rcu:
351344
rcu_read_unlock();
352345
return ret;
353346
}

0 commit comments

Comments
 (0)