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 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
44 /* XXX: dirty hack, needs to be fixed more clever way. */
52 #define LMV_MAX_TGT_COUNT 128
54 #define lmv_init_lock(lmv) down(&lmv->init_sem);
55 #define lmv_init_unlock(lmv) up(&lmv->init_sem);
57 #define LL_IT2STR(it) \
58 ((it) ? ldlm_it2str((it)->it_op) : "0")
61 struct lu_fid li_fid; /* id of dirobj */
62 mdsno_t li_mds; /* cached mdsno where @li_fid lives */
63 unsigned long li_size; /* slave size value */
67 #define O_FREEING (1 << 0)
70 struct list_head lo_list;
71 struct semaphore lo_guard;
72 int lo_state; /* object state. */
73 atomic_t lo_count; /* ref counter. */
74 struct lu_fid lo_fid; /* master id of dir */
75 void *lo_update; /* bitmap of status (up-to-date) */
77 int lo_objcount; /* number of slaves */
78 struct lmv_inode *lo_inodes; /* array of sub-objs */
79 struct obd_device *lo_obd; /* pointer to LMV itself */
82 int lmv_obj_setup(struct obd_device *obd);
83 void lmv_obj_cleanup(struct obd_device *obd);
86 lmv_obj_lock(struct lmv_obj *obj)
93 lmv_obj_unlock(struct lmv_obj *obj)
99 void lmv_obj_add(struct lmv_obj *obj);
100 void lmv_obj_del(struct lmv_obj *obj);
102 void lmv_obj_put(struct lmv_obj *obj);
103 void lmv_obj_free(struct lmv_obj *obj);
105 struct lmv_obj *lmv_obj_get(struct lmv_obj *obj);
107 struct lmv_obj *lmv_obj_grab(struct obd_device *obd,
108 const struct lu_fid *fid);
110 struct lmv_obj *lmv_obj_alloc(struct obd_device *obd,
111 const struct lu_fid *fid,
112 struct lmv_stripe_md *mea);
114 struct lmv_obj *lmv_obj_create(struct obd_export *exp,
115 const struct lu_fid *fid,
116 struct lmv_stripe_md *mea);
118 int lmv_obj_delete(struct obd_export *exp,
119 const struct lu_fid *fid);
121 int lmv_check_connect(struct obd_device *obd);
123 int lmv_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
124 void *lmm, int lmmsize, struct lookup_intent *it,
125 int flags, struct ptlrpc_request **reqp,
126 ldlm_blocking_callback cb_blocking,
127 int extra_lock_flags);
129 int lmv_intent_lookup(struct obd_export *exp, struct md_op_data *op_data,
130 void *lmm, int lmmsize, struct lookup_intent *it,
131 int flags, struct ptlrpc_request **reqp,
132 ldlm_blocking_callback cb_blocking,
133 int extra_lock_flags);
135 int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
136 void *lmm, int lmmsize, struct lookup_intent *it,
137 int flags, struct ptlrpc_request **reqp,
138 ldlm_blocking_callback cb_blocking,
139 int extra_lock_flags);
141 int lmv_intent_getattr(struct obd_export *exp, struct md_op_data *op_data,
142 void *lmm, int lmmsize, struct lookup_intent *it,
143 int flags, struct ptlrpc_request **reqp,
144 ldlm_blocking_callback cb_blocking,
145 int extra_lock_flags);
147 int lmv_revalidate_slaves(struct obd_export *, struct ptlrpc_request **,
148 const struct lu_fid *, struct lookup_intent *, int,
149 ldlm_blocking_callback cb_blocking,
150 int extra_lock_flags);
152 int lmv_handle_split(struct obd_export *, const struct lu_fid *);
153 int lmv_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
155 int lmv_fld_lookup(struct lmv_obd *lmv, const struct lu_fid *fid,
157 int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid,
159 int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
160 struct md_op_data *op_data);
161 int lmv_alloc_slave_fids(struct obd_device *obd, struct lu_fid *pid,
162 struct md_op_data *op, struct lu_fid *fid);
164 static inline struct lmv_stripe_md *
165 lmv_get_mea(struct ptlrpc_request *req)
167 struct mdt_body *body;
168 struct lmv_stripe_md *mea;
172 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
174 if (!body || !S_ISDIR(body->mode) || !body->eadatasize)
177 mea = req_capsule_server_sized_get(&req->rq_pill, &RMF_MDT_MD,
179 LASSERT(mea != NULL);
181 if (mea->mea_count == 0)
183 if( mea->mea_magic != MEA_MAGIC_LAST_CHAR &&
184 mea->mea_magic != MEA_MAGIC_ALL_CHARS &&
185 mea->mea_magic != MEA_MAGIC_HASH_SEGMENT)
191 static inline int lmv_get_easize(struct lmv_obd *lmv)
193 return sizeof(struct lmv_stripe_md) +
194 lmv->desc.ld_tgt_count *
195 sizeof(struct lu_fid);
198 static inline struct lmv_tgt_desc *
199 lmv_get_target(struct lmv_obd *lmv, mdsno_t mds)
201 return &lmv->tgts[mds];
204 static inline struct obd_export *
205 lmv_get_export(struct lmv_obd *lmv, mdsno_t mds)
207 return lmv_get_target(lmv, mds)->ltd_exp;
210 static inline struct lmv_tgt_desc *
211 lmv_find_target(struct lmv_obd *lmv, const struct lu_fid *fid)
216 rc = lmv_fld_lookup(lmv, fid, &mds);
220 return lmv_get_target(lmv, mds);
223 static inline struct obd_export *
224 lmv_find_export(struct lmv_obd *lmv, const struct lu_fid *fid)
226 struct lmv_tgt_desc *tgt = lmv_find_target(lmv, fid);
228 return (struct obd_export *)tgt;
232 static inline void lmv_update_body(struct mdt_body *body,
233 struct lmv_inode *lino)
235 /* update object size */
236 body->size += lino->li_size;
241 void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars);
243 static inline void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars)
245 memset(lvars, 0, sizeof(*lvars));
248 extern struct file_operations lmv_proc_target_fops;