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: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
a228bf8f0a
commit
c48138c227
|
@ -1668,71 +1668,60 @@ static __u32 find_hash_out(struct super_block *s)
|
||||||
struct cpu_key key;
|
struct cpu_key key;
|
||||||
INITIALIZE_PATH(path);
|
INITIALIZE_PATH(path);
|
||||||
struct reiserfs_dir_entry de;
|
struct reiserfs_dir_entry de;
|
||||||
|
struct reiserfs_de_head *deh;
|
||||||
__u32 hash = DEFAULT_HASH;
|
__u32 hash = DEFAULT_HASH;
|
||||||
|
__u32 deh_hashval, teahash, r5hash, yurahash;
|
||||||
|
|
||||||
inode = s->s_root->d_inode;
|
inode = s->s_root->d_inode;
|
||||||
|
|
||||||
do { /* Some serious "goto"-hater was there ;) */
|
make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
|
||||||
u32 teahash, r5hash, yurahash;
|
retval = search_by_entry_key(s, &key, &path, &de);
|
||||||
|
if (retval == IO_ERROR) {
|
||||||
|
pathrelse(&path);
|
||||||
|
return UNSET_HASH;
|
||||||
|
}
|
||||||
|
if (retval == NAME_NOT_FOUND)
|
||||||
|
de.de_entry_num--;
|
||||||
|
|
||||||
make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
|
set_de_name_and_namelen(&de);
|
||||||
retval = search_by_entry_key(s, &key, &path, &de);
|
deh = de.de_deh + de.de_entry_num;
|
||||||
if (retval == IO_ERROR) {
|
|
||||||
pathrelse(&path);
|
if (deh_offset(deh) == DOT_DOT_OFFSET) {
|
||||||
return UNSET_HASH;
|
/* allow override in this case */
|
||||||
}
|
if (reiserfs_rupasov_hash(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) {
|
|
||||||
/* allow override in this case */
|
|
||||||
if (reiserfs_rupasov_hash(s)) {
|
|
||||||
hash = YURA_HASH;
|
|
||||||
}
|
|
||||||
reiserfs_info(s, "FS seems to be empty, autodetect "
|
|
||||||
"is using the default hash\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
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 "
|
|
||||||
"hash={tea,rupasov,r5}");
|
|
||||||
hash = UNSET_HASH;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
|
|
||||||
yurahash)
|
|
||||||
hash = YURA_HASH;
|
hash = YURA_HASH;
|
||||||
else if (GET_HASH_VALUE
|
reiserfs_info(s, "FS seems to be empty, autodetect is using the default hash\n");
|
||||||
(deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
|
goto out;
|
||||||
hash = TEA_HASH;
|
}
|
||||||
else if (GET_HASH_VALUE
|
|
||||||
(deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
|
|
||||||
hash = R5_HASH;
|
|
||||||
else {
|
|
||||||
reiserfs_warning(s, "reiserfs-2506",
|
|
||||||
"Unrecognised hash function");
|
|
||||||
hash = UNSET_HASH;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
|
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 && 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;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deh_hashval == yurahash)
|
||||||
|
hash = YURA_HASH;
|
||||||
|
else if (deh_hashval == teahash)
|
||||||
|
hash = TEA_HASH;
|
||||||
|
else if (deh_hashval == r5hash)
|
||||||
|
hash = R5_HASH;
|
||||||
|
else {
|
||||||
|
reiserfs_warning(s, "reiserfs-2506",
|
||||||
|
"Unrecognised hash function");
|
||||||
|
hash = UNSET_HASH;
|
||||||
|
}
|
||||||
|
out:
|
||||||
pathrelse(&path);
|
pathrelse(&path);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue