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