4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2014, 2016, Intel Corporation.
26 * lustre/include/lustre_lmv.h
28 * Lustre LMV structures and functions.
30 * Author: Di Wang <di.wang@intel.com>
35 #include <uapi/linux/lustre/lustre_idl.h>
38 struct lu_fid lmo_fid;
40 struct inode *lmo_root;
43 struct lmv_stripe_md {
45 __u32 lsm_md_stripe_count;
46 __u32 lsm_md_master_mdt_index;
47 __u32 lsm_md_hash_type;
48 __u32 lsm_md_layout_version;
49 __u32 lsm_md_migrate_offset;
50 __u32 lsm_md_migrate_hash;
51 __u32 lsm_md_default_count;
52 __u32 lsm_md_default_index;
53 char lsm_md_pool_name[LOV_MAXPOOLNAME + 1];
54 struct lmv_oinfo lsm_md_oinfo[0];
58 lsm_md_eq(const struct lmv_stripe_md *lsm1, const struct lmv_stripe_md *lsm2)
62 if (lsm1->lsm_md_magic != lsm2->lsm_md_magic ||
63 lsm1->lsm_md_stripe_count != lsm2->lsm_md_stripe_count ||
64 lsm1->lsm_md_master_mdt_index !=
65 lsm2->lsm_md_master_mdt_index ||
66 lsm1->lsm_md_hash_type != lsm2->lsm_md_hash_type ||
67 lsm1->lsm_md_layout_version !=
68 lsm2->lsm_md_layout_version ||
69 lsm1->lsm_md_migrate_offset !=
70 lsm2->lsm_md_migrate_offset ||
71 lsm1->lsm_md_migrate_hash !=
72 lsm2->lsm_md_migrate_hash ||
73 strcmp(lsm1->lsm_md_pool_name,
74 lsm2->lsm_md_pool_name) != 0)
77 for (idx = 0; idx < lsm1->lsm_md_stripe_count; idx++) {
78 if (!lu_fid_eq(&lsm1->lsm_md_oinfo[idx].lmo_fid,
79 &lsm2->lsm_md_oinfo[idx].lmo_fid))
87 void lmv_free_memmd(struct lmv_stripe_md *lsm);
89 int lmvea_load_shards(const struct lu_env *env, struct dt_object *obj,
90 struct lu_dirent *ent, struct lu_buf *buf,
93 static inline void lmv1_le_to_cpu(struct lmv_mds_md_v1 *lmv_dst,
94 const struct lmv_mds_md_v1 *lmv_src)
98 lmv_dst->lmv_magic = le32_to_cpu(lmv_src->lmv_magic);
99 lmv_dst->lmv_stripe_count = le32_to_cpu(lmv_src->lmv_stripe_count);
100 lmv_dst->lmv_master_mdt_index =
101 le32_to_cpu(lmv_src->lmv_master_mdt_index);
102 lmv_dst->lmv_hash_type = le32_to_cpu(lmv_src->lmv_hash_type);
103 lmv_dst->lmv_layout_version = le32_to_cpu(lmv_src->lmv_layout_version);
104 for (i = 0; i < lmv_src->lmv_stripe_count; i++)
105 fid_le_to_cpu(&lmv_dst->lmv_stripe_fids[i],
106 &lmv_src->lmv_stripe_fids[i]);
109 static inline void lmv_le_to_cpu(union lmv_mds_md *lmv_dst,
110 const union lmv_mds_md *lmv_src)
112 switch (le32_to_cpu(lmv_src->lmv_magic)) {
114 lmv1_le_to_cpu(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
121 /* This hash is only for testing purpose */
122 static inline unsigned int
123 lmv_hash_all_chars(unsigned int count, const char *name, int namelen)
126 const unsigned char *p = (const unsigned char *)name;
128 while (--namelen >= 0)
136 static inline unsigned int
137 lmv_hash_fnv1a(unsigned int count, const char *name, int namelen)
141 hash = lustre_hash_fnv_1a_64(name, namelen);
143 return do_div(hash, count);
146 static inline int lmv_name_to_stripe_index(__u32 lmv_hash_type,
147 unsigned int stripe_count,
148 const char *name, int namelen)
152 LASSERT(namelen > 0);
154 if (stripe_count <= 1)
157 switch (lmv_hash_type & LMV_HASH_TYPE_MASK) {
158 case LMV_HASH_TYPE_ALL_CHARS:
159 idx = lmv_hash_all_chars(stripe_count, name, namelen);
161 case LMV_HASH_TYPE_FNV_1A_64:
162 idx = lmv_hash_fnv1a(stripe_count, name, namelen);
169 CDEBUG(D_INFO, "name %.*s hash_type %#x idx %d/%u\n", namelen, name,
170 lmv_hash_type, idx, stripe_count);
175 static inline bool lmv_is_known_hash_type(__u32 type)
177 return (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_FNV_1A_64 ||
178 (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_ALL_CHARS;