Commit c48138c2 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Jan Kara

reiserfs: cleanup, make hash detection saner

The hash detection code uses long ugly macros multiple times to get the same
value. This patch cleans it up to be easier to read.

[JK: Fixed up path leak in find_hash_out()]
Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent a228bf8f
......@@ -1668,13 +1668,12 @@ static __u32 find_hash_out(struct super_block *s)
struct cpu_key key;
INITIALIZE_PATH(path);
struct reiserfs_dir_entry de;
struct reiserfs_de_head *deh;
__u32 hash = DEFAULT_HASH;
__u32 deh_hashval, teahash, r5hash, yurahash;
inode = s->s_root->d_inode;
do { /* Some serious "goto"-hater was there ;) */
u32 teahash, r5hash, yurahash;
make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
retval = search_by_entry_key(s, &key, &path, &de);
if (retval == IO_ERROR) {
......@@ -1683,56 +1682,46 @@ static __u32 find_hash_out(struct super_block *s)
}
if (retval == NAME_NOT_FOUND)
de.de_entry_num--;
set_de_name_and_namelen(&de);
if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
deh = de.de_deh + de.de_entry_num;
if (deh_offset(deh) == DOT_DOT_OFFSET) {
/* allow override in this case */
if (reiserfs_rupasov_hash(s)) {
if (reiserfs_rupasov_hash(s))
hash = YURA_HASH;
reiserfs_info(s, "FS seems to be empty, autodetect is using the default hash\n");
goto out;
}
reiserfs_info(s, "FS seems to be empty, autodetect "
"is using the default hash\n");
break;
}
deh_hashval = GET_HASH_VALUE(deh_offset(deh));
r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
if (((teahash == r5hash)
&&
(GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
== r5hash)) || ((teahash == yurahash)
&& (yurahash ==
GET_HASH_VALUE(deh_offset
(&
(de.
de_deh[de.
de_entry_num])))))
|| ((r5hash == yurahash)
&& (yurahash ==
GET_HASH_VALUE(deh_offset
(&(de.de_deh[de.de_entry_num])))))) {
reiserfs_warning(s, "reiserfs-2506", "Unable to "
"automatically detect hash function. "
"Please mount with -o "
if ((teahash == r5hash && deh_hashval == r5hash) ||
(teahash == yurahash && deh_hashval == yurahash) ||
(r5hash == yurahash && deh_hashval == yurahash)) {
reiserfs_warning(s, "reiserfs-2506",
"Unable to automatically detect hash "
"function. Please mount with -o "
"hash={tea,rupasov,r5}");
hash = UNSET_HASH;
break;
goto out;
}
if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
yurahash)
if (deh_hashval == yurahash)
hash = YURA_HASH;
else if (GET_HASH_VALUE
(deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
else if (deh_hashval == teahash)
hash = TEA_HASH;
else if (GET_HASH_VALUE
(deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
else if (deh_hashval == r5hash)
hash = R5_HASH;
else {
reiserfs_warning(s, "reiserfs-2506",
"Unrecognised hash function");
hash = UNSET_HASH;
}
} while (0);
out:
pathrelse(&path);
return hash;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment