Whamcloud - gitweb
LU-5478 style: get rid of seqno_t and mdsno_t typedefs
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _LMV_INTERNAL_H_
38 #define _LMV_INTERNAL_H_
39
40 #include <lustre/lustre_idl.h>
41 #include <obd.h>
42 #include <lustre_lmv.h>
43
44 #define LMV_MAX_TGT_COUNT 128
45
46 #define lmv_init_lock(lmv)   mutex_lock(&lmv->init_mutex);
47 #define lmv_init_unlock(lmv) mutex_unlock(&lmv->init_mutex);
48
49 #define LL_IT2STR(it)                                   \
50         ((it) ? ldlm_it2str((it)->it_op) : "0")
51
52 int lmv_check_connect(struct obd_device *obd);
53
54 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
55                     struct lookup_intent *it, struct ptlrpc_request **reqp,
56                     ldlm_blocking_callback cb_blocking,
57                     __u64 extra_lock_flags);
58
59 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
60                      void *, int);
61 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds);
62 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds);
63 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
64                   struct lu_fid *fid, struct md_op_data *op_data);
65
66 int lmv_unpack_md(struct obd_export *exp, struct lmv_stripe_md **lsmp,
67                   const union lmv_mds_md *lmm, int stripe_count);
68
69 int lmv_revalidate_slaves(struct obd_export *exp, struct mdt_body *mbody,
70                           struct lmv_stripe_md *lsm,
71                           ldlm_blocking_callback cb_blocking,
72                           int extra_lock_flags);
73
74 static inline struct obd_device *lmv2obd_dev(struct lmv_obd *lmv)
75 {
76         return container_of0(lmv, struct obd_device, u.lmv);
77 }
78
79 static inline struct lmv_tgt_desc *
80 lmv_get_target(struct lmv_obd *lmv, u32 mdt_idx, int *index)
81 {
82         int i;
83
84         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
85                 if (lmv->tgts[i] == NULL)
86                         continue;
87
88                 if (lmv->tgts[i]->ltd_idx == mdt_idx) {
89                         if (index != NULL)
90                                 *index = i;
91                         return lmv->tgts[i];
92                 }
93         }
94
95         return ERR_PTR(-ENODEV);
96 }
97
98 static inline int
99 lmv_find_target_index(struct lmv_obd *lmv, const struct lu_fid *fid)
100 {
101         struct lmv_tgt_desc     *ltd;
102         u32                     mdt_idx = 0;
103         int                     index = 0;
104
105         if (lmv->desc.ld_tgt_count > 1) {
106                 int rc;
107                 rc = lmv_fld_lookup(lmv, fid, &mdt_idx);
108                 if (rc < 0)
109                         return rc;
110         }
111
112         ltd = lmv_get_target(lmv, mdt_idx, &index);
113         if (IS_ERR(ltd))
114                 return PTR_ERR(ltd);
115
116         return index;
117 }
118
119 static inline struct lmv_tgt_desc *
120 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
121 {
122         int index;
123
124         index = lmv_find_target_index(lmv, fid);
125         if (index < 0)
126                 return ERR_PTR(index);
127
128         return lmv->tgts[index];
129 }
130
131 static inline int lmv_stripe_md_size(int stripe_count)
132 {
133         struct lmv_stripe_md *lsm;
134
135         return sizeof(*lsm) + stripe_count * sizeof(lsm->lsm_md_oinfo[0]);
136 }
137
138 int lmv_name_to_stripe_index(enum lmv_hash_type hashtype,
139                              unsigned int max_mdt_index,
140                              const char *name, int namelen);
141
142 static inline const struct lmv_oinfo *
143 lsm_name_to_stripe_info(const struct lmv_stripe_md *lsm, const char *name,
144                         int namelen)
145 {
146         int stripe_index;
147
148         stripe_index = lmv_name_to_stripe_index(lsm->lsm_md_hash_type,
149                                                 lsm->lsm_md_stripe_count,
150                                                 name, namelen);
151         if (stripe_index < 0)
152                 return ERR_PTR(stripe_index);
153
154         LASSERTF(stripe_index < lsm->lsm_md_stripe_count,
155                  "stripe_index = %d, stripe_count = %d hash_type = %x"
156                  "name = %.*s\n", stripe_index, lsm->lsm_md_stripe_count,
157                  lsm->lsm_md_hash_type, namelen, name);
158
159         return &lsm->lsm_md_oinfo[stripe_index];
160 }
161
162 static inline bool lmv_is_known_hash_type(const struct lmv_stripe_md *lsm)
163 {
164         return lsm->lsm_md_hash_type == LMV_HASH_TYPE_FNV_1A_64 ||
165                lsm->lsm_md_hash_type == LMV_HASH_TYPE_ALL_CHARS;
166 }
167
168 static inline bool lmv_need_try_all_stripes(const struct lmv_stripe_md *lsm)
169 {
170         return !lmv_is_known_hash_type(lsm) ||
171                lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION;
172 }
173
174 struct lmv_tgt_desc
175 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
176                 struct lu_fid *fid);
177 /* lproc_lmv.c */
178 #ifdef LPROCFS
179 extern struct lprocfs_seq_vars lprocfs_lmv_obd_vars[];
180 #endif
181 extern struct file_operations lmv_proc_target_fops;
182
183 #endif