1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Copyright (C) 2006 Cluster File Systems, Inc.
6 * Author: Wang Di <wangdi@clusterfs.com>
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
27 #ifndef _MDD_INTERNAL_H
28 #define _MDD_INTERNAL_H
30 #include <asm/semaphore.h>
32 #include <linux/lustre_acl.h>
33 #include <md_object.h>
34 #include <dt_object.h>
35 #include <linux/sched.h>
36 #include <linux/capability.h>
39 MDD_TXN_OBJECT_DESTROY_OP = 0,
40 MDD_TXN_OBJECT_CREATE_OP,
43 MDD_TXN_INDEX_INSERT_OP,
44 MDD_TXN_INDEX_DELETE_OP,
48 MDD_TXN_RENAME_TGT_OP,
49 MDD_TXN_CREATE_DATA_OP,
54 struct mdd_txn_op_descr {
55 enum mdd_txn_op mod_op;
56 unsigned int mod_credits;
60 struct md_device mdd_md_dev;
61 struct dt_device *mdd_child;
62 struct obd_device *mdd_obd_dev;
63 struct lu_fid mdd_root_fid;
64 struct dt_device_param mdd_dt_conf;
65 struct dt_object *mdd_orphans;
66 struct dt_txn_callback mdd_txn_cb;
67 cfs_proc_dir_entry_t *mdd_proc_entry;
68 struct lprocfs_stats *mdd_stats;
69 struct mdd_txn_op_descr mdd_tod[MDD_TXN_LAST_OP];
73 /*The dir object has been unlinked*/
79 #define LUSTRE_APPEND_FL LDISKFS_APPEND_FL
80 #define LUSTRE_IMMUTABLE_FL LDISKFS_IMMUTABLE_FL
83 struct md_object mod_obj;
87 unsigned long mod_flags;
91 /* fid of the object*/
93 /* type of operation: unlink, truncate */
97 struct mdd_thread_info {
98 struct txn_param mti_param;
99 struct lu_fid mti_fid;
100 struct lu_attr mti_la;
101 struct md_attr mti_ma;
102 struct lu_attr mti_la_for_fix;
103 struct lov_mds_md mti_lmm;
104 struct obd_info mti_oi;
105 struct orph_key mti_orph_key;
106 struct obd_trans_info mti_oti;
107 struct lu_buf mti_buf;
108 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
111 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
112 struct lustre_cfg *cfg);
113 int mdd_fini_obd(const struct lu_env *, struct mdd_device *);
114 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
115 const struct lu_buf *buf, const char *name, int fl,
116 struct thandle *txn);
117 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
118 struct mdd_object *child, struct lov_mds_md *lmm,
119 int lmm_size, struct thandle *handle, int set_stripe);
120 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
121 struct mdd_object *parent, struct mdd_object *child,
122 struct lov_mds_md **lmm, int *lmm_size,
123 const struct md_create_spec *spec, struct lu_attr *la);
124 void mdd_lov_create_finish(const struct lu_env *env,
125 struct mdd_device *mdd, int rc);
126 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
127 void *md, int *md_size, const char *name);
128 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
129 void *md, int *md_size, const char *name);
130 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
131 struct lu_attr *la, struct lustre_capa *capa);
132 int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *o,
133 const struct lu_attr *attr, struct thandle *handle,
135 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
137 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
139 int mdd_attr_get_internal_locked(const struct lu_env *env,
140 struct mdd_object *mdd_obj,
142 int mdd_object_create_internal(const struct lu_env *env,
143 struct mdd_object *obj, struct md_attr *ma,
144 struct thandle *handle);
145 int mdd_attr_set_internal_locked(const struct lu_env *env,
146 struct mdd_object *o,
147 const struct lu_attr *attr,
148 struct thandle *handle);
149 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
152 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
153 struct mdd_object *cobj, struct md_attr *ma);
154 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
155 struct md_attr *ma, struct thandle *th);
156 int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
157 struct mdd_object *child, struct md_attr *ma,
158 struct thandle *handle);
159 int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
160 struct mdd_object *src_obj);
161 void mdd_ref_add_internal(const struct lu_env *env, struct mdd_object *obj,
162 struct thandle *handle);
163 void mdd_ref_del_internal(const struct lu_env *env, struct mdd_object *obj,
164 struct thandle *handle);
166 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
167 struct mdd_object *mdd_cobj, struct md_attr *ma);
169 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
170 struct lov_mds_md *lmm);
172 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
173 struct lov_mds_md *lmm, int lmm_size);
175 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
177 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
178 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
179 const void *area, ssize_t len);
181 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj);
182 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
183 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj);
184 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
186 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
187 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
189 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
191 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
192 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
193 int mdd_txn_init_credits(const struct lu_env *env, struct mdd_device *mdd);
195 int mdd_procfs_init(struct mdd_device *mdd);
196 int mdd_procfs_fini(struct mdd_device *mdd);
197 void mdd_lproc_time_start(struct mdd_device *mdd, struct timeval *start,
199 void mdd_lproc_time_end(struct mdd_device *mdd, struct timeval *start, int op);
201 int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj);
203 extern struct md_dir_operations mdd_dir_ops;
204 extern struct md_object_operations mdd_obj_ops;
207 void mdd_txn_param_build(const struct lu_env *env, struct mdd_device *mdd,
209 int mdd_log_txn_param_build(const struct lu_env *env, struct mdd_object *obj,
210 struct md_attr *ma, enum mdd_txn_op);
212 static inline void mdd_object_put(const struct lu_env *env,
213 struct mdd_object *o)
215 lu_object_put(env, &o->mod_obj.mo_lu);
218 struct thandle* mdd_trans_start(const struct lu_env *env,
219 struct mdd_device *);
221 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
222 int rc, struct thandle *handle);
224 int mdd_txn_start_cb(const struct lu_env *env, struct txn_param *param,
227 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
230 int mdd_txn_commit_cb(const struct lu_env *env, struct thandle *txn,
233 struct lu_object *mdd_object_alloc(const struct lu_env *env,
234 const struct lu_object_header *hdr,
235 struct lu_device *d);
238 extern struct lu_context_key mdd_thread_key;
239 extern struct lu_device_operations mdd_lu_ops;
241 struct mdd_object *mdd_object_find(const struct lu_env *env,
242 struct mdd_device *d,
243 const struct lu_fid *f);
244 /* mdd_permission.c */
245 #define mdd_cap_t(x) (x)
247 #define MDD_CAP_TO_MASK(x) (1 << (x))
249 #define mdd_cap_raised(c, flag) (mdd_cap_t(c) & MDD_CAP_TO_MASK(flag))
251 /* capable() is copied from linux kernel! */
252 static inline int mdd_capable(struct md_ucred *uc, int cap)
254 if (mdd_cap_raised(uc->mu_cap, cap))
259 int mdd_in_group_p(struct md_ucred *uc, gid_t grp);
260 int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj,
262 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
263 struct thandle *handle);
264 int __mdd_acl_init(const struct lu_env *env, struct mdd_object *obj,
265 struct lu_buf *buf, __u32 *mode, struct thandle *handle);
266 int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
267 struct mdd_object *cobj, __u32 *mode, struct thandle *handle);
268 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
269 int mask, int getattr);
270 int mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
272 int mdd_permission(const struct lu_env *env, struct md_object *obj, int mask);
273 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
274 struct lustre_capa *capa, int renewal);
276 static inline int lu_device_is_mdd(struct lu_device *d)
278 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
281 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
283 LASSERT(lu_device_is_mdd(d));
284 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
287 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
289 return (&d->mdd_md_dev.md_lu_dev);
292 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
294 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
295 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
298 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
300 return lu2mdd_dev(mdo->mo_lu.lo_dev);
303 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
305 return container_of0(mdo, struct mdd_object, mod_obj);
308 static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
310 return d->mdd_child->dd_ops;
313 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
315 return &obj->mod_obj.mo_lu;
318 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
320 return container_of0(lu_object_next(mdd2lu_obj(o)),
321 struct dt_object, do_lu);
323 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
325 return mdd->mdd_obd_dev;
328 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
330 return lu_object_fid(&obj->mod_obj.mo_lu);
333 static inline umode_t mdd_object_type(const struct mdd_object *obj)
335 return lu_object_attr(&obj->mod_obj.mo_lu);
338 static inline int mdd_lov_mdsize(const struct lu_env *env,
339 struct mdd_device *mdd)
341 struct obd_device *obd = mdd2obd_dev(mdd);
342 return obd->u.mds.mds_max_mdsize;
345 static inline int mdd_lov_cookiesize(const struct lu_env *env,
346 struct mdd_device *mdd)
348 struct obd_device *obd = mdd2obd_dev(mdd);
349 return obd->u.mds.mds_max_cookiesize;
352 static inline int mdd_is_immutable(struct mdd_object *obj)
354 return obj->mod_flags & IMMUTE_OBJ;
357 static inline int mdd_is_dead_obj(struct mdd_object *obj)
359 return obj && obj->mod_flags & DEAD_OBJ;
362 static inline int mdd_is_append(struct mdd_object *obj)
364 return obj->mod_flags & APPEND_OBJ;
367 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
368 const struct mdd_object *obj)
370 struct md_capainfo *ci = md_capainfo(env);
371 const struct lu_fid *fid = mdo2fid(obj);
374 /* NB: in mdt_init0 */
377 for (i = 0; i < 4; i++)
378 if (ci->mc_fid[i] && lu_fid_eq(ci->mc_fid[i], fid))
379 return ci->mc_capa[i];