diff --git a/kmod/src/Makefile b/kmod/src/Makefile index 62aacf23..f6c32636 100644 --- a/kmod/src/Makefile +++ b/kmod/src/Makefile @@ -11,7 +11,7 @@ CFLAGS_scoutfs_trace.o = -I$(src) # define_trace.h double include scoutfs-y += first.o scoutfs-y += block.o btree.o buddy.o counters.o crc.o dir.o filerw.o \ - inode.o ioctl.o msg.o scoutfs_trace.o super.o trace.o trans.o \ - treap.o + inode.o ioctl.o msg.o name.o scoutfs_trace.o super.o trace.o \ + trans.o treap.o scoutfs-y += last.o diff --git a/kmod/src/dir.c b/kmod/src/dir.c index 39745fb7..db741f62 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -23,6 +23,7 @@ #include "super.h" #include "btree.h" #include "trans.h" +#include "name.h" /* * Directory entries are stored in entries with offsets calculated from @@ -84,11 +85,6 @@ static unsigned int dentry_type(unsigned int type) return DT_UNKNOWN; } -static int names_equal(const char *name_a, int len_a, const char *name_b, - int len_b) -{ - return (len_a == len_b) && !memcmp(name_a, name_b, len_a); -} /* * XXX This crc nonsense is a quick hack. We'll want something a @@ -209,8 +205,8 @@ static struct dentry *scoutfs_lookup(struct inode *dir, struct dentry *dentry, dent = curs.val; name_len = item_name_len(&curs); - if (names_equal(dentry->d_name.name, dentry->d_name.len, - dent->name, name_len)) { + if (scoutfs_names_equal(dentry->d_name.name, dentry->d_name.len, + dent->name, name_len)) { ino = le64_to_cpu(dent->ino); di->hash = scoutfs_key_offset(curs.key); break; diff --git a/kmod/src/name.c b/kmod/src/name.c new file mode 100644 index 00000000..e14f52bd --- /dev/null +++ b/kmod/src/name.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 Versity Software, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ +#include +#include +#include + +#include "name.h" + +/* + * XXX This crc nonsense is a quick hack. We'll want something a + * lot stronger like siphash. + */ +u64 scoutfs_name_hash(const char *name, unsigned int len) +{ + unsigned int half = (len + 1) / 2; + + return crc32c(~0, name, half) | + ((u64)crc32c(~0, name + len - half, half) << 32); +} + +int scoutfs_names_equal(const char *name_a, int len_a, + const char *name_b, int len_b) +{ + return (len_a == len_b) && !memcmp(name_a, name_b, len_a); +} diff --git a/kmod/src/name.h b/kmod/src/name.h new file mode 100644 index 00000000..020ecb0f --- /dev/null +++ b/kmod/src/name.h @@ -0,0 +1,8 @@ +#ifndef _SCOUTFS_NAME_H_ +#define _SCOUTFS_NAME_H_ + +u64 scoutfs_name_hash(const char *data, unsigned int len); +int scoutfs_names_equal(const char *name_a, int len_a, + const char *name_b, int len_b); + +#endif