1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
40 #ifndef _LMV_INTERNAL_H_
41 #define _LMV_INTERNAL_H_
43 #include <lustre/lustre_idl.h>
46 #define LMV_MAX_TGT_COUNT 128
48 #define lmv_init_lock(lmv) cfs_down(&lmv->init_sem);
49 #define lmv_init_unlock(lmv) cfs_up(&lmv->init_sem);
51 #define LL_IT2STR(it) \
52 ((it) ? ldlm_it2str((it)->it_op) : "0")
60 * Cached home mds number for \a li_fid.
66 unsigned long ls_size;
73 #define O_FREEING (1 << 0)
77 * Link to global objects list.
81 * Sema for protecting fields.
83 cfs_semaphore_t lo_guard;
85 * Object state like O_FREEING.
91 cfs_atomic_t lo_count;
97 * Object hash type to find stripe by name.
107 struct lmv_stripe *lo_stripes;
109 * Pointer to LMV obd.
111 struct obd_device *lo_obd;
114 int lmv_object_setup(struct obd_device *obd);
115 void lmv_object_cleanup(struct obd_device *obd);
118 lmv_object_lock(struct lmv_object *obj)
121 cfs_down(&obj->lo_guard);
125 lmv_object_unlock(struct lmv_object *obj)
128 cfs_up(&obj->lo_guard);
131 void lmv_object_add(struct lmv_object *obj);
132 void lmv_object_del(struct lmv_object *obj);
134 void lmv_object_put(struct lmv_object *obj);
135 void lmv_object_put_unlock(struct lmv_object *obj);
136 void lmv_object_free(struct lmv_object *obj);
138 struct lmv_object *lmv_object_get(struct lmv_object *obj);
140 struct lmv_object *lmv_object_find(struct obd_device *obd,
141 const struct lu_fid *fid);
143 struct lmv_object *lmv_object_find_lock(struct obd_device *obd,
144 const struct lu_fid *fid);
146 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
147 const struct lu_fid *fid,
148 struct lmv_stripe_md *mea);
150 struct lmv_object *lmv_object_create(struct obd_export *exp,
151 const struct lu_fid *fid,
152 struct lmv_stripe_md *mea);
154 int lmv_object_delete(struct obd_export *exp,
155 const struct lu_fid *fid);
157 int lmv_check_connect(struct obd_device *obd);
159 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
160 void *lmm, int lmmsize, struct lookup_intent *it,
161 int flags, struct ptlrpc_request **reqp,
162 ldlm_blocking_callback cb_blocking,
163 int extra_lock_flags);
165 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
166 void *lmm, int lmmsize, struct lookup_intent *it,
167 int flags, struct ptlrpc_request **reqp,
168 ldlm_blocking_callback cb_blocking,
169 int extra_lock_flags);
171 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
172 void *lmm, int lmmsize, struct lookup_intent *it,
173 int flags, struct ptlrpc_request **reqp,
174 ldlm_blocking_callback cb_blocking,
175 int extra_lock_flags);
177 int lmv_allocate_slaves(struct obd_device *obd, struct lu_fid *pid,
178 struct md_op_data *op, struct lu_fid *fid);
180 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
181 const struct lu_fid *, struct lookup_intent *, int,
182 ldlm_blocking_callback cb_blocking,
183 int extra_lock_flags);
185 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
186 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
188 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
190 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
192 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
193 struct md_op_data *op_data);
195 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
197 struct mdt_body *body;
198 struct lmv_stripe_md *mea;
200 LASSERT(req != NULL);
202 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
204 if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
207 mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
209 LASSERT(mea != NULL);
211 if (mea->mea_count == 0)
213 if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
214 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
215 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
221 static inline int lmv_get_easize(struct lmv_obd *lmv)
223 return sizeof(struct lmv_stripe_md) +
224 lmv->desc.ld_tgt_count *
225 sizeof(struct lu_fid);
228 static inline struct lmv_tgt_desc *
229 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
231 return &lmv->tgts[mds];
234 static inline struct lmv_tgt_desc *
235 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
240 if (lmv->desc.ld_tgt_count > 1) {
241 rc = lmv_fld_lookup(lmv, fid, &mds);
246 return lmv_get_target(lmv, mds);
251 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
253 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
255 memset(lvars, 0, sizeof(*lvars));
258 extern struct file_operations lmv_proc_target_fops;