mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-30 19:51:31 -04:00
vfs: make the string hashes salt the hash
We always mixed in the parent pointer into the dentry name hash, but we did it late at lookup time. It turns out that we can simplify that lookup-time action by salting the hash with the parent pointer early instead of late. A few other users of our string hashes also wanted to mix in their own pointers into the hash, and those are updated to use the same mechanism. Hash users that don't have any particular initial salt can just use the NULL pointer as a no-salt. Cc: Vegard Nossum <[email protected]> Cc: George Spelvin <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
147d9e7bca
commit
8387ff2577
38 changed files with 99 additions and 89 deletions
|
|
@ -81,6 +81,7 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
|
|||
struct jffs2_full_dirent *fd = NULL, *fd_list;
|
||||
uint32_t ino = 0;
|
||||
struct inode *inode = NULL;
|
||||
unsigned int nhash;
|
||||
|
||||
jffs2_dbg(1, "jffs2_lookup()\n");
|
||||
|
||||
|
|
@ -89,11 +90,14 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
|
|||
|
||||
dir_f = JFFS2_INODE_INFO(dir_i);
|
||||
|
||||
/* The 'nhash' on the fd_list is not the same as the dentry hash */
|
||||
nhash = full_name_hash(NULL, target->d_name.name, target->d_name.len);
|
||||
|
||||
mutex_lock(&dir_f->sem);
|
||||
|
||||
/* NB: The 2.2 backport will need to explicitly check for '.' and '..' here */
|
||||
for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= target->d_name.hash; fd_list = fd_list->next) {
|
||||
if (fd_list->nhash == target->d_name.hash &&
|
||||
for (fd_list = dir_f->dents; fd_list && fd_list->nhash <= nhash; fd_list = fd_list->next) {
|
||||
if (fd_list->nhash == nhash &&
|
||||
(!fd || fd_list->version > fd->version) &&
|
||||
strlen(fd_list->name) == target->d_name.len &&
|
||||
!strncmp(fd_list->name, target->d_name.name, target->d_name.len)) {
|
||||
|
|
|
|||
|
|
@ -674,7 +674,7 @@ static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_r
|
|||
}
|
||||
}
|
||||
|
||||
fd->nhash = full_name_hash(fd->name, rd->nsize);
|
||||
fd->nhash = full_name_hash(NULL, fd->name, rd->nsize);
|
||||
fd->next = NULL;
|
||||
fd->name[rd->nsize] = '\0';
|
||||
|
||||
|
|
|
|||
|
|
@ -1100,7 +1100,7 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
|
|||
fd->next = NULL;
|
||||
fd->version = je32_to_cpu(rd->version);
|
||||
fd->ino = je32_to_cpu(rd->ino);
|
||||
fd->nhash = full_name_hash(fd->name, checkedlen);
|
||||
fd->nhash = full_name_hash(NULL, fd->name, checkedlen);
|
||||
fd->type = rd->type;
|
||||
jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
|
||||
|
||||
|
|
|
|||
|
|
@ -476,7 +476,7 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
|
|||
fd->next = NULL;
|
||||
fd->version = je32_to_cpu(spd->version);
|
||||
fd->ino = je32_to_cpu(spd->ino);
|
||||
fd->nhash = full_name_hash(fd->name, checkedlen);
|
||||
fd->nhash = full_name_hash(NULL, fd->name, checkedlen);
|
||||
fd->type = spd->type;
|
||||
|
||||
jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jff
|
|||
|
||||
fd->version = je32_to_cpu(rd->version);
|
||||
fd->ino = je32_to_cpu(rd->ino);
|
||||
fd->nhash = full_name_hash(name, namelen);
|
||||
fd->nhash = full_name_hash(NULL, name, namelen);
|
||||
fd->type = rd->type;
|
||||
memcpy(fd->name, name, namelen);
|
||||
fd->name[namelen]=0;
|
||||
|
|
@ -598,7 +598,7 @@ int jffs2_do_unlink(struct jffs2_sb_info *c, struct jffs2_inode_info *dir_f,
|
|||
jffs2_add_fd_to_list(c, fd, &dir_f->dents);
|
||||
mutex_unlock(&dir_f->sem);
|
||||
} else {
|
||||
uint32_t nhash = full_name_hash(name, namelen);
|
||||
uint32_t nhash = full_name_hash(NULL, name, namelen);
|
||||
|
||||
fd = dir_f->dents;
|
||||
/* We don't actually want to reserve any space, but we do
|
||||
|
|
|
|||
Loading…
Reference in a new issue