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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
39 #ifndef _LMV_INTERNAL_H_
40 #define _LMV_INTERNAL_H_
42 #include <lustre/lustre_idl.h>
45 #define LMV_MAX_TGT_COUNT 128
47 #define lmv_init_lock(lmv) cfs_mutex_lock(&lmv->init_mutex);
48 #define lmv_init_unlock(lmv) cfs_mutex_unlock(&lmv->init_mutex);
50 #define LL_IT2STR(it) \
51 ((it) ? ldlm_it2str((it)->it_op) : "0")
59 * Cached home mds number for \a li_fid.
65 unsigned long ls_size;
72 #define O_FREEING (1 << 0)
76 * Link to global objects list.
80 * Sema for protecting fields.
84 * Object state like O_FREEING.
90 cfs_atomic_t lo_count;
96 * Object hash type to find stripe by name.
106 struct lmv_stripe *lo_stripes;
108 * Pointer to LMV obd.
110 struct obd_device *lo_obd;
113 int lmv_object_setup(struct obd_device *obd);
114 void lmv_object_cleanup(struct obd_device *obd);
117 lmv_object_lock(struct lmv_object *obj)
120 cfs_mutex_lock(&obj->lo_guard);
124 lmv_object_unlock(struct lmv_object *obj)
127 cfs_mutex_unlock(&obj->lo_guard);
130 void lmv_object_add(struct lmv_object *obj);
131 void lmv_object_del(struct lmv_object *obj);
133 void lmv_object_put(struct lmv_object *obj);
134 void lmv_object_put_unlock(struct lmv_object *obj);
135 void lmv_object_free(struct lmv_object *obj);
137 struct lmv_object *lmv_object_get(struct lmv_object *obj);
139 struct lmv_object *lmv_object_find(struct obd_device *obd,
140 const struct lu_fid *fid);
142 struct lmv_object *lmv_object_find_lock(struct obd_device *obd,
143 const struct lu_fid *fid);
145 struct lmv_object *lmv_object_alloc(struct obd_device *obd,
146 const struct lu_fid *fid,
147 struct lmv_stripe_md *mea);
149 struct lmv_object *lmv_object_create(struct obd_export *exp,
150 const struct lu_fid *fid,
151 struct lmv_stripe_md *mea);
153 int lmv_object_delete(struct obd_export *exp,
154 const struct lu_fid *fid);
156 int lmv_check_connect(struct obd_device *obd);
158 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
159 void *lmm, int lmmsize, struct lookup_intent *it,
160 int flags, struct ptlrpc_request **reqp,
161 ldlm_blocking_callback cb_blocking,
162 int extra_lock_flags);
164 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
165 void *lmm, int lmmsize, struct lookup_intent *it,
166 int flags, struct ptlrpc_request **reqp,
167 ldlm_blocking_callback cb_blocking,
168 int extra_lock_flags);
170 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
171 void *lmm, int lmmsize, struct lookup_intent *it,
172 int flags, struct ptlrpc_request **reqp,
173 ldlm_blocking_callback cb_blocking,
174 int extra_lock_flags);
176 int lmv_allocate_slaves(struct obd_device *obd, struct lu_fid *pid,
177 struct md_op_data *op, struct lu_fid *fid);
179 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
180 const struct lu_fid *, struct lookup_intent *, int,
181 ldlm_blocking_callback cb_blocking,
182 int extra_lock_flags);
184 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
185 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
187 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
189 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
191 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
192 struct md_op_data *op_data);
194 static inline struct lmv_stripe_md *lmv_get_mea(struct ptlrpc_request *req)
196 struct mdt_body *body;
197 struct lmv_stripe_md *mea;
199 LASSERT(req != NULL);
201 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
203 if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
206 mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
208 LASSERT(mea != NULL);
210 if (mea->mea_count == 0)
212 if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
213 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
214 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
220 static inline int lmv_get_easize(struct lmv_obd *lmv)
222 return sizeof(struct lmv_stripe_md) +
223 lmv->desc.ld_tgt_count *
224 sizeof(struct lu_fid);
227 static inline struct lmv_tgt_desc *
228 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
230 return &lmv->tgts[mds];
233 static inline struct lmv_tgt_desc *
234 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
239 if (lmv->desc.ld_tgt_count > 1) {
240 rc = lmv_fld_lookup(lmv, fid, &mds);
245 return lmv_get_target(lmv, mds);
250 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
252 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
254 memset(lvars, 0, sizeof(*lvars));
257 extern struct file_operations lmv_proc_target_fops;