Merge remote-tracking branch 'staging/staging-next'
[deliverable/linux.git] / drivers / staging / lustre / lustre / lmv / lmv_internal.h
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 19 *
d7e09d03
PT
20 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
1dc563a6 26 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
27 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32
33#ifndef _LMV_INTERNAL_H_
34#define _LMV_INTERNAL_H_
35
a8c495ac
GKH
36#include "../include/lustre/lustre_idl.h"
37#include "../include/obd.h"
8e9dfe8a 38#include "../include/lustre_lmv.h"
d7e09d03
PT
39
40#define LMV_MAX_TGT_COUNT 128
41
d7e09d03
PT
42#define LL_IT2STR(it) \
43 ((it) ? ldlm_it2str((it)->it_op) : "0")
44
45int lmv_check_connect(struct obd_device *obd);
46
47int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
70a251f6 48 struct lookup_intent *it, struct ptlrpc_request **reqp,
d7e09d03
PT
49 ldlm_blocking_callback cb_blocking,
50 __u64 extra_lock_flags);
51
114acca8
OD
52int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds);
53int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds);
8f18c8a4 54int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
55 struct lu_fid *fid, struct md_op_data *op_data);
d7e09d03 56
2de35386 57int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
58 const union lmv_mds_md *lmm, int stripe_count);
59
60int lmv_revalidate_slaves(struct obd_export *exp, struct mdt_body *mbody,
61 struct lmv_stripe_md *lsm,
62 ldlm_blocking_callback cb_blocking,
63 int extra_lock_flags);
64
d7e09d03 65static inline struct lmv_tgt_desc *
711942df 66lmv_get_target(struct lmv_obd *lmv, u32 mdt_idx, int *index)
d7e09d03 67{
d7e09d03
PT
68 int i;
69
711942df 70 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2cbdaa45 71 if (!lmv->tgts[i])
d7e09d03
PT
72 continue;
73
711942df 74 if (lmv->tgts[i]->ltd_idx == mdt_idx) {
75 if (index)
76 *index = i;
d7e09d03 77 return lmv->tgts[i];
711942df 78 }
d7e09d03
PT
79 }
80
81 return ERR_PTR(-ENODEV);
82}
83
711942df 84static inline int
85lmv_find_target_index(struct lmv_obd *lmv, const struct lu_fid *fid)
d7e09d03 86{
711942df 87 struct lmv_tgt_desc *ltd;
88 u32 mdt_idx = 0;
89 int index = 0;
d7e09d03
PT
90
91 if (lmv->desc.ld_tgt_count > 1) {
711942df 92 int rc;
93
94 rc = lmv_fld_lookup(lmv, fid, &mdt_idx);
95 if (rc < 0)
96 return rc;
d7e09d03
PT
97 }
98
711942df 99 ltd = lmv_get_target(lmv, mdt_idx, &index);
100 if (IS_ERR(ltd))
101 return PTR_ERR(ltd);
102
103 return index;
104}
105
106static inline struct lmv_tgt_desc *
107lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
108{
109 int index;
110
111 index = lmv_find_target_index(lmv, fid);
112 if (index < 0)
113 return ERR_PTR(index);
114
115 return lmv->tgts[index];
d7e09d03
PT
116}
117
fad3a392 118static inline int lmv_stripe_md_size(int stripe_count)
119{
120 struct lmv_stripe_md *lsm;
121
122 return sizeof(*lsm) + stripe_count * sizeof(lsm->lsm_md_oinfo[0]);
123}
124
2de35386 125int lmv_name_to_stripe_index(enum lmv_hash_type hashtype,
126 unsigned int max_mdt_index,
127 const char *name, int namelen);
128
129static inline const struct lmv_oinfo *
130lsm_name_to_stripe_info(const struct lmv_stripe_md *lsm, const char *name,
131 int namelen)
132{
133 int stripe_index;
134
135 stripe_index = lmv_name_to_stripe_index(lsm->lsm_md_hash_type,
136 lsm->lsm_md_stripe_count,
137 name, namelen);
138 if (stripe_index < 0)
139 return ERR_PTR(stripe_index);
140
141 LASSERTF(stripe_index < lsm->lsm_md_stripe_count,
142 "stripe_index = %d, stripe_count = %d hash_type = %x name = %.*s\n",
143 stripe_index, lsm->lsm_md_stripe_count,
144 lsm->lsm_md_hash_type, namelen, name);
145
146 return &lsm->lsm_md_oinfo[stripe_index];
147}
148
893ab747 149static inline bool lmv_is_known_hash_type(const struct lmv_stripe_md *lsm)
150{
151 return lsm->lsm_md_hash_type == LMV_HASH_TYPE_FNV_1A_64 ||
152 lsm->lsm_md_hash_type == LMV_HASH_TYPE_ALL_CHARS;
153}
154
155static inline bool lmv_need_try_all_stripes(const struct lmv_stripe_md *lsm)
156{
157 return !lmv_is_known_hash_type(lsm) ||
158 lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION;
159}
160
d7e09d03
PT
161struct lmv_tgt_desc
162*lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
163 struct lu_fid *fid);
164/* lproc_lmv.c */
d7e09d03 165void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
e4ba525e 166
d6e7a2fe 167extern const struct file_operations lmv_proc_target_fops;
d7e09d03
PT
168
169#endif
This page took 0.371095 seconds and 5 git commands to generate.