Whamcloud - gitweb
LU-14487 modules: remove references to Sun Trademark.
[fs/lustre-release.git] / lustre / lmv / lmv_internal.h
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
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
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  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #ifndef _LMV_INTERNAL_H_
33 #define _LMV_INTERNAL_H_
34
35 #include <obd.h>
36 #include <lustre_lmv.h>
37
38 #define LMV_MAX_TGT_COUNT 128
39
40 #define LL_IT2STR(it)                                   \
41         ((it) ? ldlm_it2str((it)->it_op) : "0")
42
43 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
44                     struct lookup_intent *it, struct ptlrpc_request **reqp,
45                     ldlm_blocking_callback cb_blocking,
46                     __u64 extra_lock_flags);
47
48 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
49                      void *, int);
50 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds);
51 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
52                   struct lu_fid *fid, struct md_op_data *op_data);
53
54 int lmv_revalidate_slaves(struct obd_export *exp,
55                           const struct lmv_stripe_md *lsm,
56                           ldlm_blocking_callback cb_blocking,
57                           int extra_lock_flags);
58
59 int lmv_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
60                      struct ptlrpc_request **preq);
61 void lmv_activate_target(struct lmv_obd *lmv, struct lmv_tgt_desc *tgt,
62                          int activate);
63
64 int lmv_statfs_check_update(struct obd_device *obd, struct lmv_tgt_desc *tgt);
65
66 static inline struct obd_device *lmv2obd_dev(struct lmv_obd *lmv)
67 {
68         return container_of_safe(lmv, struct obd_device, u.lmv);
69 }
70
71 static inline struct lu_tgt_desc *
72 lmv_tgt(struct lmv_obd *lmv, __u32 index)
73 {
74         return index < lmv->lmv_mdt_descs.ltd_tgts_size ?
75                 LTD_TGT(&lmv->lmv_mdt_descs, index) : NULL;
76 }
77
78 static inline bool
79 lmv_mdt0_inited(struct lmv_obd *lmv)
80 {
81         return lmv->lmv_mdt_descs.ltd_tgts_size > 0 &&
82                test_bit(0, lmv->lmv_mdt_descs.ltd_tgt_bitmap);
83 }
84
85 #define lmv_foreach_tgt(lmv, tgt) ltd_foreach_tgt(&(lmv)->lmv_mdt_descs, tgt)
86
87 #define lmv_foreach_tgt_safe(lmv, tgt, tmp) \
88         ltd_foreach_tgt_safe(&(lmv)->lmv_mdt_descs, tgt, tmp)
89
90 static inline
91 struct lu_tgt_desc *lmv_first_connected_tgt(struct lmv_obd *lmv)
92 {
93         struct lu_tgt_desc *tgt;
94
95         tgt = ltd_first_tgt(&lmv->lmv_mdt_descs);
96         while (tgt && !tgt->ltd_exp)
97                 tgt = ltd_next_tgt(&lmv->lmv_mdt_descs, tgt);
98
99         return tgt;
100 }
101
102 static inline
103 struct lu_tgt_desc *lmv_next_connected_tgt(struct lmv_obd *lmv,
104                                            struct lu_tgt_desc *tgt)
105 {
106         do {
107                 tgt = ltd_next_tgt(&lmv->lmv_mdt_descs, tgt);
108         } while (tgt && !tgt->ltd_exp);
109
110         return tgt;
111 }
112
113 #define lmv_foreach_connected_tgt(lmv, tgt) \
114         for (tgt = lmv_first_connected_tgt(lmv); tgt; \
115              tgt = lmv_next_connected_tgt(lmv, tgt))
116
117 static inline int
118 lmv_fid2tgt_index(struct lmv_obd *lmv, const struct lu_fid *fid)
119 {
120         u32 mdt_idx;
121         int rc;
122
123         if (lmv->lmv_mdt_count < 2)
124                 return 0;
125
126         rc = lmv_fld_lookup(lmv, fid, &mdt_idx);
127         if (rc < 0)
128                 return rc;
129
130         return mdt_idx;
131 }
132
133 static inline struct lmv_tgt_desc *
134 lmv_fid2tgt(struct lmv_obd *lmv, const struct lu_fid *fid)
135 {
136         struct lu_tgt_desc *tgt;
137         int index;
138
139         index = lmv_fid2tgt_index(lmv, fid);
140         if (index < 0)
141                 return ERR_PTR(index);
142
143         tgt = lmv_tgt(lmv, index);
144
145         return tgt ? tgt : ERR_PTR(-ENODEV);
146 }
147
148 static inline int lmv_stripe_md_size(int stripe_count)
149 {
150         struct lmv_stripe_md *lsm;
151
152         return sizeof(*lsm) + stripe_count * sizeof(lsm->lsm_md_oinfo[0]);
153 }
154
155 /* for file under migrating directory, return the target stripe info */
156 static inline const struct lmv_oinfo *
157 lsm_name_to_stripe_info(const struct lmv_stripe_md *lsm, const char *name,
158                         int namelen, bool new_layout)
159 {
160         int stripe_index;
161
162         LASSERT(lmv_dir_striped(lsm));
163
164         stripe_index = __lmv_name_to_stripe_index(lsm->lsm_md_hash_type,
165                                                   lsm->lsm_md_stripe_count,
166                                                   lsm->lsm_md_migrate_hash,
167                                                   lsm->lsm_md_migrate_offset,
168                                                   name, namelen, new_layout);
169         if (stripe_index < 0)
170                 return ERR_PTR(stripe_index);
171
172         return &lsm->lsm_md_oinfo[stripe_index];
173 }
174
175 static inline bool lmv_dir_retry_check_update(struct md_op_data *op_data)
176 {
177         const struct lmv_stripe_md *lsm = op_data->op_mea1;
178
179         if (!lsm)
180                 return false;
181
182         if (lmv_dir_layout_changing(lsm) && !op_data->op_new_layout) {
183                 op_data->op_new_layout = true;
184                 return true;
185         }
186
187         if (lmv_dir_bad_hash(lsm) &&
188             op_data->op_stripe_index < lsm->lsm_md_stripe_count - 1) {
189                 op_data->op_stripe_index++;
190                 return true;
191         }
192
193         return false;
194 }
195
196 struct lmv_tgt_desc *lmv_locate_tgt(struct lmv_obd *lmv,
197                                     struct md_op_data *op_data);
198 int lmv_old_layout_lookup(struct lmv_obd *lmv, struct md_op_data *op_data);
199
200 /* lproc_lmv.c */
201 int lmv_tunables_init(struct obd_device *obd);
202 #endif