vfs: make it possible to access the dentry hash/len as one 64-bit entry

This allows comparing hash and len in one operation on 64-bit
architectures.  Right now only __d_lookup_rcu() takes advantage of this,
since that is the case we care most about.

The use of anonymous struct/unions hides the alternate 64-bit approach
from most users, the exception being a few cases where we initialize a
'struct qstr' with a static initializer.  This makes the problematic
cases use a new QSTR_INIT() helper function for that (but initializing
just the name pointer with a "{ .name = xyzzy }" initializer remains
valid, as does just copying another qstr structure).

Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Linus Torvalds 2012-05-10 13:14:12 -07:00
commit 26fe575028
18 changed files with 44 additions and 48 deletions

View file

@ -1502,7 +1502,7 @@ struct dentry *d_make_root(struct inode *root_inode)
struct dentry *res = NULL;
if (root_inode) {
static const struct qstr name = { .name = "/", .len = 1 };
static const struct qstr name = QSTR_INIT("/", 1);
res = __d_alloc(root_inode->i_sb, &name);
if (res)
@ -1816,10 +1816,9 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
const struct qstr *name,
unsigned *seqp, struct inode *inode)
{
unsigned int len = name->len;
unsigned int hash = name->hash;
u64 hashlen = name->hash_len;
const unsigned char *str = name->name;
struct hlist_bl_head *b = d_hash(parent, hash);
struct hlist_bl_head *b = d_hash(parent, hashlen_hash(hashlen));
struct hlist_bl_node *node;
struct dentry *dentry;
@ -1846,9 +1845,6 @@ struct dentry *__d_lookup_rcu(const struct dentry *parent,
hlist_bl_for_each_entry_rcu(dentry, node, b, d_hash) {
unsigned seq;
if (dentry->d_name.hash != hash)
continue;
seqretry:
/*
* The dentry sequence count protects us from concurrent
@ -1871,6 +1867,8 @@ seqretry:
*seqp = seq;
if (unlikely(parent->d_flags & DCACHE_OP_COMPARE)) {
if (dentry->d_name.hash != hashlen_hash(hashlen))
continue;
switch (slow_dentry_cmp(parent, inode, dentry, seq, name)) {
case D_COMP_OK:
return dentry;
@ -1881,9 +1879,9 @@ seqretry:
}
}
if (dentry->d_name.len != len)
if (dentry->d_name.hash_len != hashlen)
continue;
if (!dentry_cmp(dentry, str, len))
if (!dentry_cmp(dentry, str, hashlen_len(hashlen)))
return dentry;
}
return NULL;