Commit 200e9ef7 authored by Linus Torvalds's avatar Linus Torvalds

vfs: split up name hashing in link_path_walk() into helper function

The code in link_path_walk() that finds out the length and the hash of
the next path component is some of the hottest code in the kernel.  And
I have a version of it that does things at the full width of the CPU
wordsize at a time, but that means that we *really* want to split it up
into a separate helper function.

So this re-organizes the code a bit and splits the hashing part into a
helper function called "hash_name()".  It returns the length of the
pathname component, while at the same time computing and writing the
hash to the appropriate location.

The code generation is slightly changed by this patch, but generally for
the better - and the added abstraction actually makes the code easier to
read too.  And the new interface is well suited for replacing just the
"hash_name()" function with alternative implementations.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5707c87f
...@@ -1382,6 +1382,25 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len) ...@@ -1382,6 +1382,25 @@ unsigned int full_name_hash(const unsigned char *name, unsigned int len)
return end_name_hash(hash); return end_name_hash(hash);
} }
/*
* We know there's a real path component here of at least
* one character.
*/
static inline unsigned long hash_name(const char *name, unsigned int *hashp)
{
unsigned long hash = init_name_hash();
unsigned long len = 0, c;
c = (unsigned char)*name;
do {
len++;
hash = partial_name_hash(c, hash);
c = (unsigned char)name[len];
} while (c && c != '/');
*hashp = end_name_hash(hash);
return len;
}
/* /*
* Name resolution. * Name resolution.
* This is the basic name resolution function, turning a pathname into * This is the basic name resolution function, turning a pathname into
...@@ -1402,31 +1421,22 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1402,31 +1421,22 @@ static int link_path_walk(const char *name, struct nameidata *nd)
/* At this point we know we have a real path component. */ /* At this point we know we have a real path component. */
for(;;) { for(;;) {
unsigned long hash;
struct qstr this; struct qstr this;
unsigned int c; long len;
int type; int type;
err = may_lookup(nd); err = may_lookup(nd);
if (err) if (err)
break; break;
len = hash_name(name, &this.hash);
this.name = name; this.name = name;
c = *(const unsigned char *)name; this.len = len;
hash = init_name_hash();
do {
name++;
hash = partial_name_hash(c, hash);
c = *(const unsigned char *)name;
} while (c && (c != '/'));
this.len = name - (const char *) this.name;
this.hash = end_name_hash(hash);
type = LAST_NORM; type = LAST_NORM;
if (this.name[0] == '.') switch (this.len) { if (name[0] == '.') switch (len) {
case 2: case 2:
if (this.name[1] == '.') { if (name[1] == '.') {
type = LAST_DOTDOT; type = LAST_DOTDOT;
nd->flags |= LOOKUP_JUMPED; nd->flags |= LOOKUP_JUMPED;
} }
...@@ -1445,12 +1455,18 @@ static int link_path_walk(const char *name, struct nameidata *nd) ...@@ -1445,12 +1455,18 @@ static int link_path_walk(const char *name, struct nameidata *nd)
} }
} }
/* remove trailing slashes? */ if (!name[len])
if (!c)
goto last_component; goto last_component;
while (*++name == '/'); /*
if (!*name) * If it wasn't NUL, we know it was '/'. Skip that
* slash, and continue until no more slashes.
*/
do {
len++;
} while (unlikely(name[len] == '/'));
if (!name[len])
goto last_component; goto last_component;
name += len;
err = walk_component(nd, &next, &this, type, LOOKUP_FOLLOW); err = walk_component(nd, &next, &this, type, LOOKUP_FOLLOW);
if (err < 0) if (err < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment