Whamcloud - gitweb
de07e164114f1b24c83b5babd238fa5797c117b4
[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                     void *lmm, int lmmsize, struct lookup_intent *it,
56                     int flags, struct ptlrpc_request **reqp,
57                     ldlm_blocking_callback cb_blocking,
58                     __u64 extra_lock_flags);
59
60 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
61                       void *lmm, int lmmsize, struct lookup_intent *it,
62                       int flags, struct ptlrpc_request **reqp,
63                       ldlm_blocking_callback cb_blocking,
64                       __u64 extra_lock_flags);
65
66 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
67                     void *lmm, int lmmsize, struct lookup_intent *it,
68                     int flags, struct ptlrpc_request **reqp,
69                     ldlm_blocking_callback cb_blocking,
70                     __u64 extra_lock_flags);
71
72 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
73                      void *, int);
74 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
75                    mdsno_t *mds);
76 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
77                     mdsno_t mds);
78 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
79                   struct md_op_data *op_data);
80
81 static inline struct lmv_tgt_desc *
82 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
83 {
84         int count = lmv->desc.ld_tgt_count;
85         int i;
86
87         for (i = 0; i < count; i++) {
88                 if (lmv->tgts[i] == NULL)
89                         continue;
90
91                 if (lmv->tgts[i]->ltd_idx == mds)
92                         return lmv->tgts[i];
93         }
94
95         return ERR_PTR(-ENODEV);
96 }
97
98 static inline struct lmv_tgt_desc *
99 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
100 {
101         mdsno_t mds = 0;
102         int rc;
103
104         if (lmv->desc.ld_tgt_count > 1) {
105                 rc = lmv_fld_lookup(lmv, fid, &mds);
106                 if (rc)
107                         return ERR_PTR(rc);
108         }
109
110         return lmv_get_target(lmv, mds);
111 }
112
113 static inline unsigned int
114 mea_last_char_hash(unsigned int count, const char *name, int namelen)
115 {
116         unsigned int c;
117
118         c = name[namelen - 1];
119         if (c == 0)
120                 CWARN("invalid name %.*s\n", namelen, name);
121
122         c = c % count;
123
124         return c;
125 }
126
127 static inline unsigned int
128 mea_all_chars_hash(unsigned int count, const char *name, int namelen)
129 {
130         unsigned int c = 0;
131
132         while (--namelen >= 0)
133                 c += name[namelen];
134
135         c = c % count;
136
137         return c;
138 }
139
140 static inline int lmv_stripe_md_size(int stripe_count)
141 {
142         struct lmv_stripe_md *lsm;
143
144         return sizeof(*lsm) + stripe_count * sizeof(lsm->lsm_md_oinfo[0]);
145 }
146
147 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
148
149 struct lmv_tgt_desc
150 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
151                 struct lu_fid *fid);
152 /* lproc_lmv.c */
153 #ifdef LPROCFS
154 extern struct lprocfs_seq_vars lprocfs_lmv_obd_vars[];
155 #endif
156 extern struct file_operations lmv_proc_target_fops;
157
158 #endif