1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <obd_class.h>
40 #include <linux/kmod.h> /* for request_module() */
41 #include <linux/module.h>
42 #include <linux/random.h>
43 #include <linux/slab.h>
44 #include <linux/pagemap.h>
46 #include <liblustre.h>
49 #include <lprocfs_status.h>
50 #include <lustre/lustre_idl.h>
54 #ifdef HAVE_EXT4_LDISKFS
55 #include <ldiskfs/ldiskfs_jbd2.h>
57 #include <linux/jbd.h>
60 #ifdef HAVE_SERVER_SUPPORT
63 #ifdef HAVE_EXT4_LDISKFS
64 #include <ldiskfs/ldiskfs.h>
66 #include <linux/ldiskfs_fs.h>
71 static int mea_last_char_hash(int count, char *name, int namelen)
75 c = name[namelen - 1];
77 CWARN("looks like wrong len is passed\n");
82 static int mea_all_chars_hash(int count, char *name, int namelen)
86 while (--namelen >= 0)
93 /* This hash calculate method must be same as the lvar hash method */
95 #define LVAR_HASH_SANDWICH (0)
96 #define LVAR_HASH_PREFIX (0)
98 static __u32 hash_build0(const char *name, int namelen)
104 if (strncmp(name, ".", 1) == 0 && namelen == 1)
106 if (strncmp(name, "..", 2) == 0 && namelen == 2)
109 if (LVAR_HASH_PREFIX) {
111 strncpy((void *)&result,
112 name, min(namelen, (int)sizeof result));
114 struct ldiskfs_dx_hash_info hinfo;
116 hinfo.hash_version = LDISKFS_DX_HASH_TEA;
118 ldiskfsfs_dirhash(name, namelen, &hinfo);
120 if (LVAR_HASH_SANDWICH) {
123 hinfo.hash_version = LDISKFS_DX_HASH_TEA;
125 ldiskfsfs_dirhash(name, namelen, &hinfo);
126 result2 = hinfo.hash;
127 result = (0xfc000000 & result2) | (0x03ffffff & result);
135 HASH_GRAY_AREA = 1024
138 static __u32 hash_build(const char *name, int namelen)
142 hash = (hash_build0(name, namelen) << 1) & MAX_HASH_SIZE_32;
143 if (hash > MAX_HASH_SIZE_32 - HASH_GRAY_AREA)
144 hash &= HASH_GRAY_AREA - 1;
148 static int mea_hash_segment(int count, const char *name, int namelen)
152 LASSERT(IS_PO2(MAX_HASH_SIZE_32 + 1));
154 hash = hash_build(name, namelen) / (MAX_HASH_SIZE_32 / count);
155 LASSERTF(hash < count, "hash %x count %d \n", hash, count);
160 static int mea_hash_segment(int count, char *name, int namelen)
165 int raw_name2idx(int hashtype, int count, const char *name, int namelen)
169 LASSERT(namelen > 0);
174 case MEA_MAGIC_LAST_CHAR:
175 c = mea_last_char_hash(count, (char *)name, namelen);
177 case MEA_MAGIC_ALL_CHARS:
178 c = mea_all_chars_hash(count, (char *)name, namelen);
180 case MEA_MAGIC_HASH_SEGMENT:
181 c = mea_hash_segment(count, (char *)name, namelen);
184 CERROR("Unknown hash type 0x%x\n", hashtype);
191 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen)
195 LASSERT(mea && mea->mea_count);
197 c = raw_name2idx(mea->mea_magic, mea->mea_count, name, namelen);
199 LASSERT(c < mea->mea_count);