4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #ifndef _LMV_INTERNAL_H_
38 #define _LMV_INTERNAL_H_
40 #include <lustre/lustre_idl.h>
43 #define LMV_MAX_TGT_COUNT 128
45 #define lmv_init_lock(lmv) mutex_lock(&lmv->init_mutex);
46 #define lmv_init_unlock(lmv) mutex_unlock(&lmv->init_mutex);
48 #define LL_IT2STR(it) \
49 ((it) ? ldlm_it2str((it)->it_op) : "0")
57 * Cached home mds number for \a li_fid.
63 unsigned long ls_size;
70 #define O_FREEING (1 << 0)
74 * Link to global objects list.
78 * Sema for protecting fields.
80 struct mutex lo_guard;
82 * Object state like O_FREEING.
88 cfs_atomic_t lo_count;
94 * Object hash type to find stripe by name.
104 struct lmv_stripe *lo_stripes;
106 * Pointer to LMV obd.
108 struct obd_device *lo_obd;
111 int lmv_object_setup(struct obd_device *obd);
112 void lmv_object_cleanup(struct obd_device *obd);
115 lmv_object_lock(struct lmv_object *obj)
118 mutex_lock(&obj->lo_guard);
122 lmv_object_unlock(struct lmv_object *obj)
125 mutex_unlock(&obj->lo_guard);
128 void lmv_object_add(struct lmv_object *obj);
129 void lmv_object_del(struct lmv_object *obj);
131 void lmv_object_put(struct lmv_object *obj);
132 void lmv_object_put_unlock(struct lmv_object *obj);
133 void lmv_object_free(struct lmv_object *obj);
135 struct lmv_object *lmv_object_get(struct lmv_object *obj);
137 struct lmv_object *lmv_object_find(struct obd_device *obd,
138 const struct lu_fid *fid);
140 struct lmv_object *lmv_object_find_lock(struct obd_device *obd,
141 const struct lu_fid *fid);
143 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
144 const struct lu_fid *fid,
145 struct lmv_stripe_md *mea);
147 struct lmv_object *lmv_object_create(struct obd_export *exp,
148 const struct lu_fid *fid,
149 struct lmv_stripe_md *mea);
151 int lmv_object_delete(struct obd_export *exp,
152 const struct lu_fid *fid);
154 int lmv_check_connect(struct obd_device *obd);
156 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
157 void *lmm, int lmmsize, struct lookup_intent *it,
158 int flags, struct ptlrpc_request **reqp,
159 ldlm_blocking_callback cb_blocking,
160 __u64 extra_lock_flags);
162 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
163 void *lmm, int lmmsize, struct lookup_intent *it,
164 int flags, struct ptlrpc_request **reqp,
165 ldlm_blocking_callback cb_blocking,
166 __u64 extra_lock_flags);
168 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
169 void *lmm, int lmmsize, struct lookup_intent *it,
170 int flags, struct ptlrpc_request **reqp,
171 ldlm_blocking_callback cb_blocking,
172 __u64 extra_lock_flags);
174 int lmv_allocate_slaves(struct obd_device *obd, struct lu_fid *pid,
175 struct md_op_data *op, struct lu_fid *fid);
177 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
178 const struct lu_fid *, struct lookup_intent *, int,
179 ldlm_blocking_callback cb_blocking,
180 __u64 extra_lock_flags);
182 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
183 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
185 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
187 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
189 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
190 struct md_op_data *op_data);
192 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
194 struct mdt_body *body;
195 struct lmv_stripe_md *mea;
197 LASSERT(req != NULL);
199 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
201 if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
204 mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
206 LASSERT(mea != NULL);
208 if (mea->mea_count == 0)
210 if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
211 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
212 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
218 static inline int lmv_get_easize(struct lmv_obd *lmv)
220 return sizeof(struct lmv_stripe_md) +
221 lmv->desc.ld_tgt_count *
222 sizeof(struct lu_fid);
225 static inline struct lmv_tgt_desc *
226 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
228 return &lmv->tgts[mds];
231 static inline struct lmv_tgt_desc *
232 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
237 if (lmv->desc.ld_tgt_count > 1) {
238 rc = lmv_fld_lookup(lmv, fid, &mds);
243 return lmv_get_target(lmv, mds);
248 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
250 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
252 memset(lvars, 0, sizeof(*lvars));
255 extern struct file_operations lmv_proc_target_fops;