Whamcloud - gitweb
LU-7988 hsm: run HSM coordinator once per second at most
[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 <lustre/lustre_idl.h>
37 #include <obd.h>
38 #include <lustre_lmv.h>
39
40 #define LMV_MAX_TGT_COUNT 128
41
42 #define LL_IT2STR(it)                                   \
43         ((it) ? ldlm_it2str((it)->it_op) : "0")
44
45 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
46                     struct lookup_intent *it, struct ptlrpc_request **reqp,
47                     ldlm_blocking_callback cb_blocking,
48                     __u64 extra_lock_flags);
49
50 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
51                      void *, int);
52 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid, u32 *mds);
53 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, u32 mds);
54 int lmv_fid_alloc(const struct lu_env *env, struct obd_export *exp,
55                   struct lu_fid *fid, struct md_op_data *op_data);
56
57 int lmv_revalidate_slaves(struct obd_export *exp,
58                           const struct lmv_stripe_md *lsm,
59                           ldlm_blocking_callback cb_blocking,
60                           int extra_lock_flags);
61
62 static inline struct obd_device *lmv2obd_dev(struct lmv_obd *lmv)
63 {
64         return container_of0(lmv, struct obd_device, u.lmv);
65 }
66
67 static inline struct lmv_tgt_desc *
68 lmv_get_target(struct lmv_obd *lmv, u32 mdt_idx, int *index)
69 {
70         int i;
71
72         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
73                 if (lmv->tgts[i] == NULL)
74                         continue;
75
76                 if (lmv->tgts[i]->ltd_idx == mdt_idx) {
77                         if (index != NULL)
78                                 *index = i;
79                         return lmv->tgts[i];
80                 }
81         }
82
83         return ERR_PTR(-ENODEV);
84 }
85
86 static inline int
87 lmv_find_target_index(struct lmv_obd *lmv, const struct lu_fid *fid)
88 {
89         struct lmv_tgt_desc     *ltd;
90         u32                     mdt_idx = 0;
91         int                     index = 0;
92
93         if (lmv->desc.ld_tgt_count > 1) {
94                 int rc;
95                 rc = lmv_fld_lookup(lmv, fid, &mdt_idx);
96                 if (rc < 0)
97                         return rc;
98         }
99
100         ltd = lmv_get_target(lmv, mdt_idx, &index);
101         if (IS_ERR(ltd))
102                 return PTR_ERR(ltd);
103
104         return index;
105 }
106
107 static inline struct lmv_tgt_desc *
108 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
109 {
110         int index;
111
112         index = lmv_find_target_index(lmv, fid);
113         if (index < 0)
114                 return ERR_PTR(index);
115
116         return lmv->tgts[index];
117 }
118
119 static inline int lmv_stripe_md_size(int stripe_count)
120 {
121         struct lmv_stripe_md *lsm;
122
123         return sizeof(*lsm) + stripe_count * sizeof(lsm->lsm_md_oinfo[0]);
124 }
125
126 static inline const struct lmv_oinfo *
127 lsm_name_to_stripe_info(const struct lmv_stripe_md *lsm, const char *name,
128                         int namelen)
129 {
130         int stripe_index;
131
132         stripe_index = lmv_name_to_stripe_index(lsm->lsm_md_hash_type,
133                                                 lsm->lsm_md_stripe_count,
134                                                 name, namelen);
135         if (stripe_index < 0)
136                 return ERR_PTR(stripe_index);
137
138         LASSERTF(stripe_index < lsm->lsm_md_stripe_count,
139                  "stripe_index = %d, stripe_count = %d hash_type = %x"
140                  "name = %.*s\n", stripe_index, lsm->lsm_md_stripe_count,
141                  lsm->lsm_md_hash_type, namelen, name);
142
143         return &lsm->lsm_md_oinfo[stripe_index];
144 }
145
146 static inline bool lmv_need_try_all_stripes(const struct lmv_stripe_md *lsm)
147 {
148         return !lmv_is_known_hash_type(lsm->lsm_md_hash_type) ||
149                lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION;
150 }
151
152 struct lmv_tgt_desc
153 *lmv_locate_mds(struct lmv_obd *lmv, struct md_op_data *op_data,
154                 struct lu_fid *fid);
155 /* lproc_lmv.c */
156 #ifdef CONFIG_PROC_FS
157 extern struct lprocfs_vars lprocfs_lmv_obd_vars[];
158 #endif
159 extern struct file_operations lmv_proc_target_fops;
160
161 #endif