Skip to content

Commit

Permalink
ext4: factor out htree rep invariant check
Browse files Browse the repository at this point in the history
This patch moves some debugging code which is used to validate the
hash tree node when doing a binary search of an htree node into a
separate function, which is disabled by default (since it is only used
by developers when they are modifying the htree code paths).

In addition to cleaning up the code to make it more maintainable, it
silences a Clang compiler warning when -Wunreachable-code-aggressive
is enabled.  (There is no plan to enable this warning by default, since
there it has far too many false positives; nevertheless, this commit
reduces one of the many false positives by one.)

Signed-off-by: Vinicius Tinti <viniciustinti@gmail.com>
Link: https://lore.kernel.org/r/20210202162837.129631-1-viniciustinti@gmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Vinicius Tinti authored and Theodore Ts'o committed Feb 3, 2021
1 parent 96e7c02 commit c6c818e
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,29 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
(space/bcount)*100/blocksize);
return (struct stats) { names, space, bcount};
}

/*
* Linear search cross check
*/
static inline void htree_rep_invariant_check(struct dx_entry *at,
struct dx_entry *target,
u32 hash, unsigned int n)
{
while (n--) {
dxtrace(printk(KERN_CONT ","));
if (dx_get_hash(++at) > hash) {
at--;
break;
}
}
ASSERT(at == target - 1);
}
#else /* DX_DEBUG */
static inline void htree_rep_invariant_check(struct dx_entry *at,
struct dx_entry *target,
u32 hash, unsigned int n)
{
}
#endif /* DX_DEBUG */

/*
Expand Down Expand Up @@ -827,20 +850,7 @@ dx_probe(struct ext4_filename *fname, struct inode *dir,
p = m + 1;
}

if (0) { // linear search cross check
unsigned n = count - 1;
at = entries;
while (n--)
{
dxtrace(printk(KERN_CONT ","));
if (dx_get_hash(++at) > hash)
{
at--;
break;
}
}
ASSERT(at == p - 1);
}
htree_rep_invariant_check(entries, p, hash, count - 1);

at = p - 1;
dxtrace(printk(KERN_CONT " %x->%u\n",
Expand Down

0 comments on commit c6c818e

Please sign in to comment.