1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef _LUSTRE_LMV_H
34#define _LUSTRE_LMV_H
35#include "lustre/lustre_idl.h"
36
37struct lmv_oinfo {
38 struct lu_fid lmo_fid;
39 u32 lmo_mds;
40 struct inode *lmo_root;
41};
42
43struct lmv_stripe_md {
44 __u32 lsm_md_magic;
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_default_count;
50 __u32 lsm_md_default_index;
51 char lsm_md_pool_name[LOV_MAXPOOLNAME + 1];
52 struct lmv_oinfo lsm_md_oinfo[0];
53};
54
55static inline bool
56lsm_md_eq(const struct lmv_stripe_md *lsm1, const struct lmv_stripe_md *lsm2)
57{
58 __u32 idx;
59
60 if (lsm1->lsm_md_magic != lsm2->lsm_md_magic ||
61 lsm1->lsm_md_stripe_count != lsm2->lsm_md_stripe_count ||
62 lsm1->lsm_md_master_mdt_index != lsm2->lsm_md_master_mdt_index ||
63 lsm1->lsm_md_hash_type != lsm2->lsm_md_hash_type ||
64 lsm1->lsm_md_layout_version != lsm2->lsm_md_layout_version ||
65 !strcmp(lsm1->lsm_md_pool_name, lsm2->lsm_md_pool_name))
66 return false;
67
68 for (idx = 0; idx < lsm1->lsm_md_stripe_count; idx++) {
69 if (!lu_fid_eq(&lsm1->lsm_md_oinfo[idx].lmo_fid,
70 &lsm2->lsm_md_oinfo[idx].lmo_fid))
71 return false;
72 }
73
74 return true;
75}
76
77union lmv_mds_md;
78
79void lmv_free_memmd(struct lmv_stripe_md *lsm);
80
81static inline void lmv1_le_to_cpu(struct lmv_mds_md_v1 *lmv_dst,
82 const struct lmv_mds_md_v1 *lmv_src)
83{
84 __u32 i;
85
86 lmv_dst->lmv_magic = le32_to_cpu(lmv_src->lmv_magic);
87 lmv_dst->lmv_stripe_count = le32_to_cpu(lmv_src->lmv_stripe_count);
88 lmv_dst->lmv_master_mdt_index =
89 le32_to_cpu(lmv_src->lmv_master_mdt_index);
90 lmv_dst->lmv_hash_type = le32_to_cpu(lmv_src->lmv_hash_type);
91 lmv_dst->lmv_layout_version = le32_to_cpu(lmv_src->lmv_layout_version);
92
93 for (i = 0; i < lmv_src->lmv_stripe_count; i++)
94 fid_le_to_cpu(&lmv_dst->lmv_stripe_fids[i],
95 &lmv_src->lmv_stripe_fids[i]);
96}
97
98static inline void lmv_le_to_cpu(union lmv_mds_md *lmv_dst,
99 const union lmv_mds_md *lmv_src)
100{
101 switch (le32_to_cpu(lmv_src->lmv_magic)) {
102 case LMV_MAGIC_V1:
103 lmv1_le_to_cpu(&lmv_dst->lmv_md_v1, &lmv_src->lmv_md_v1);
104 break;
105 default:
106 break;
107 }
108}
109
110
111static inline unsigned int
112lmv_hash_all_chars(unsigned int count, const char *name, int namelen)
113{
114 const unsigned char *p = (const unsigned char *)name;
115 unsigned int c = 0;
116
117 while (--namelen >= 0)
118 c += p[namelen];
119
120 c = c % count;
121
122 return c;
123}
124
125static inline unsigned int
126lmv_hash_fnv1a(unsigned int count, const char *name, int namelen)
127{
128 __u64 hash;
129
130 hash = lustre_hash_fnv_1a_64(name, namelen);
131
132 return do_div(hash, count);
133}
134
135static inline int lmv_name_to_stripe_index(__u32 lmv_hash_type,
136 unsigned int stripe_count,
137 const char *name, int namelen)
138{
139 __u32 hash_type = lmv_hash_type & LMV_HASH_TYPE_MASK;
140 int idx;
141
142 LASSERT(namelen > 0);
143 if (stripe_count <= 1)
144 return 0;
145
146
147 if (lmv_hash_type & LMV_HASH_FLAG_MIGRATION)
148 return 0;
149
150 switch (hash_type) {
151 case LMV_HASH_TYPE_ALL_CHARS:
152 idx = lmv_hash_all_chars(stripe_count, name, namelen);
153 break;
154 case LMV_HASH_TYPE_FNV_1A_64:
155 idx = lmv_hash_fnv1a(stripe_count, name, namelen);
156 break;
157 default:
158 idx = -EBADFD;
159 break;
160 }
161 CDEBUG(D_INFO, "name %.*s hash_type %d idx %d\n", namelen, name,
162 hash_type, idx);
163
164 return idx;
165}
166
167static inline bool lmv_is_known_hash_type(__u32 type)
168{
169 return (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_FNV_1A_64 ||
170 (type & LMV_HASH_TYPE_MASK) == LMV_HASH_TYPE_ALL_CHARS;
171}
172
173#endif
174