Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8387ff25 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

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 <vegard.nossum@oracle.com>
Cc: George Spelvin <linux@sciencehorizons.net>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 147d9e7b
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -174,7 +174,8 @@ static inline int is_omitted_entry(struct ll_statahead_info *sai, __u64 index)
 * Insert it into sai_entries tail when init.
 */
static struct ll_sa_entry *
ll_sa_entry_alloc(struct ll_statahead_info *sai, __u64 index,
ll_sa_entry_alloc(struct dentry *parent,
		  struct ll_statahead_info *sai, __u64 index,
		  const char *name, int len)
{
	struct ll_inode_info *lli;
@@ -221,7 +222,8 @@ ll_sa_entry_alloc(struct ll_statahead_info *sai, __u64 index,
	dname = (char *)entry + sizeof(struct ll_sa_entry);
	memcpy(dname, name, len);
	dname[len] = 0;
	entry->se_qstr.hash = full_name_hash(name, len);

	entry->se_qstr.hash = full_name_hash(parent, name, len);
	entry->se_qstr.len = len;
	entry->se_qstr.name = dname;

@@ -902,7 +904,7 @@ static void ll_statahead_one(struct dentry *parent, const char *entry_name,
	int		       rc;
	int		       rc1;

	entry = ll_sa_entry_alloc(sai, sai->sai_index, entry_name,
	entry = ll_sa_entry_alloc(parent, sai, sai->sai_index, entry_name,
				  entry_name_len);
	if (IS_ERR(entry))
		return;
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ adfs_hash(const struct dentry *parent, struct qstr *qstr)
	 */
	qstr->len = i = name_len;
	name = qstr->name;
	hash = init_name_hash();
	hash = init_name_hash(parent);
	while (i--) {
		char c;

+4 −4
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ affs_get_toupper(struct super_block *sb)
 * Note: the dentry argument is the parent dentry.
 */
static inline int
__affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
__affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr, toupper_t toupper, bool notruncate)
{
	const u8 *name = qstr->name;
	unsigned long hash;
@@ -72,7 +72,7 @@ __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
	if (retval)
		return retval;

	hash = init_name_hash();
	hash = init_name_hash(dentry);
	len = min(qstr->len, AFFSNAMEMAX);
	for (; len > 0; name++, len--)
		hash = partial_name_hash(toupper(*name), hash);
@@ -84,7 +84,7 @@ __affs_hash_dentry(struct qstr *qstr, toupper_t toupper, bool notruncate)
static int
affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr)
{
	return __affs_hash_dentry(qstr, affs_toupper,
	return __affs_hash_dentry(dentry, qstr, affs_toupper,
				  affs_nofilenametruncate(dentry));

}
@@ -92,7 +92,7 @@ affs_hash_dentry(const struct dentry *dentry, struct qstr *qstr)
static int
affs_intl_hash_dentry(const struct dentry *dentry, struct qstr *qstr)
{
	return __affs_hash_dentry(qstr, affs_intl_toupper,
	return __affs_hash_dentry(dentry, qstr, affs_intl_toupper,
				  affs_nofilenametruncate(dentry));

}
+1 −1
Original line number Diff line number Diff line
@@ -397,7 +397,7 @@ int autofs4_wait(struct autofs_sb_info *sbi,
		}
	}
	qstr.name = name;
	qstr.hash = full_name_hash(name, qstr.len);
	qstr.hash = full_name_hash(dentry, name, qstr.len);

	if (mutex_lock_interruptible(&sbi->wq_mutex)) {
		kfree(qstr.name);
+2 −2
Original line number Diff line number Diff line
@@ -1164,7 +1164,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req,

			dname.name = rinfo->dname;
			dname.len = rinfo->dname_len;
			dname.hash = full_name_hash(dname.name, dname.len);
			dname.hash = full_name_hash(parent, dname.name, dname.len);
			vino.ino = le64_to_cpu(rinfo->targeti.in->ino);
			vino.snap = le64_to_cpu(rinfo->targeti.in->snapid);
retry_lookup:
@@ -1508,7 +1508,7 @@ int ceph_readdir_prepopulate(struct ceph_mds_request *req,

		dname.name = rde->name;
		dname.len = rde->name_len;
		dname.hash = full_name_hash(dname.name, dname.len);
		dname.hash = full_name_hash(parent, dname.name, dname.len);

		vino.ino = le64_to_cpu(rde->inode.in->ino);
		vino.snap = le64_to_cpu(rde->inode.in->snapid);
Loading