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
1 changed files with 47 additions and 58 deletions
|
@ -1668,13 +1668,12 @@ 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 ;) */
|
|
||||||
u32 teahash, r5hash, yurahash;
|
|
||||||
|
|
||||||
make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
|
make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
|
||||||
retval = search_by_entry_key(s, &key, &path, &de);
|
retval = search_by_entry_key(s, &key, &path, &de);
|
||||||
if (retval == IO_ERROR) {
|
if (retval == IO_ERROR) {
|
||||||
|
@ -1683,56 +1682,46 @@ static __u32 find_hash_out(struct super_block *s)
|
||||||
}
|
}
|
||||||
if (retval == NAME_NOT_FOUND)
|
if (retval == NAME_NOT_FOUND)
|
||||||
de.de_entry_num--;
|
de.de_entry_num--;
|
||||||
|
|
||||||
set_de_name_and_namelen(&de);
|
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 */
|
/* allow override in this case */
|
||||||
if (reiserfs_rupasov_hash(s)) {
|
if (reiserfs_rupasov_hash(s))
|
||||||
hash = YURA_HASH;
|
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");
|
deh_hashval = GET_HASH_VALUE(deh_offset(deh));
|
||||||
break;
|
|
||||||
}
|
|
||||||
r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
|
r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
|
||||||
teahash = GET_HASH_VALUE(keyed_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));
|
yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
|
||||||
if (((teahash == r5hash)
|
|
||||||
&&
|
if ((teahash == r5hash && deh_hashval == r5hash) ||
|
||||||
(GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
|
(teahash == yurahash && deh_hashval == yurahash) ||
|
||||||
== r5hash)) || ((teahash == yurahash)
|
(r5hash == yurahash && deh_hashval == yurahash)) {
|
||||||
&& (yurahash ==
|
reiserfs_warning(s, "reiserfs-2506",
|
||||||
GET_HASH_VALUE(deh_offset
|
"Unable to automatically detect hash "
|
||||||
(&
|
"function. Please mount with -o "
|
||||||
(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={tea,rupasov,r5}");
|
||||||
hash = UNSET_HASH;
|
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;
|
hash = YURA_HASH;
|
||||||
else if (GET_HASH_VALUE
|
else if (deh_hashval == teahash)
|
||||||
(deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
|
|
||||||
hash = TEA_HASH;
|
hash = TEA_HASH;
|
||||||
else if (GET_HASH_VALUE
|
else if (deh_hashval == r5hash)
|
||||||
(deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
|
|
||||||
hash = R5_HASH;
|
hash = R5_HASH;
|
||||||
else {
|
else {
|
||||||
reiserfs_warning(s, "reiserfs-2506",
|
reiserfs_warning(s, "reiserfs-2506",
|
||||||
"Unrecognised hash function");
|
"Unrecognised hash function");
|
||||||
hash = UNSET_HASH;
|
hash = UNSET_HASH;
|
||||||
}
|
}
|
||||||
} while (0);
|
out:
|
||||||
|
|
||||||
pathrelse(&path);
|
pathrelse(&path);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue