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 <lustre_eacl.h>
35 #include <md_object.h>
36 #include <dt_object.h>
37 #include <linux/sched.h>
38 #include <linux/capability.h>
39 #include <linux/dynlocks.h>
42 MDD_TXN_OBJECT_DESTROY_OP = 0,
43 MDD_TXN_OBJECT_CREATE_OP,
46 MDD_TXN_INDEX_INSERT_OP,
47 MDD_TXN_INDEX_DELETE_OP,
51 MDD_TXN_RENAME_TGT_OP,
52 MDD_TXN_CREATE_DATA_OP,
57 struct mdd_txn_op_descr {
58 enum mdd_txn_op mod_op;
59 unsigned int mod_credits;
63 struct md_device mdd_md_dev;
64 struct dt_device *mdd_child;
65 struct obd_device *mdd_obd_dev;
66 struct lu_fid mdd_root_fid;
67 struct dt_device_param mdd_dt_conf;
68 struct dt_object *mdd_orphans;
69 struct dt_txn_callback mdd_txn_cb;
70 cfs_proc_dir_entry_t *mdd_proc_entry;
71 struct lprocfs_stats *mdd_stats;
72 struct mdd_txn_op_descr mdd_tod[MDD_TXN_LAST_OP];
73 unsigned long mdd_atime_diff;
77 /* The dir object has been unlinked */
84 #define LUSTRE_APPEND_FL LDISKFS_APPEND_FL
85 #define LUSTRE_IMMUTABLE_FL LDISKFS_IMMUTABLE_FL
86 #define LUSTRE_DIRSYNC_FL LDISKFS_DIRSYNC_FL
89 struct md_object mod_obj;
93 unsigned long mod_flags;
94 struct dynlock mod_pdlock;
98 /* fid of the object*/
100 /* type of operation: unlink, truncate */
102 } __attribute__((packed));
104 struct mdd_thread_info {
105 struct txn_param mti_param;
106 struct lu_fid mti_fid;
107 struct lu_attr mti_la;
108 struct md_attr mti_ma;
109 struct lu_attr mti_la_for_fix;
110 struct obd_info mti_oi;
111 struct orph_key mti_orph_key;
112 struct obd_trans_info mti_oti;
113 struct lu_buf mti_buf;
115 char mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
116 struct lu_fid mti_fid2; /* used for be & cpu converting */
117 struct lu_fid_pack mti_pack;
118 struct dt_allocation_hint mti_hint;
119 struct lov_mds_md *mti_max_lmm;
120 int mti_max_lmm_size;
121 struct llog_cookie *mti_max_cookie;
122 int mti_max_cookie_size;
125 struct lov_mds_md *mdd_max_lmm_get(const struct lu_env *env,
126 struct mdd_device *mdd);
128 struct llog_cookie *mdd_max_cookie_get(const struct lu_env *env,
129 struct mdd_device *mdd);
131 int mdd_init_obd(const struct lu_env *env, struct mdd_device *mdd,
132 struct lustre_cfg *cfg);
133 int mdd_fini_obd(const struct lu_env *env, struct mdd_device *mdd,
134 struct lustre_cfg *lcfg);
135 int mdd_xattr_set_txn(const struct lu_env *env, struct mdd_object *obj,
136 const struct lu_buf *buf, const char *name, int fl,
137 struct thandle *txn);
138 int mdd_lsm_sanity_check(const struct lu_env *env, struct mdd_object *obj);
139 int mdd_lov_set_md(const struct lu_env *env, struct mdd_object *pobj,
140 struct mdd_object *child, struct lov_mds_md *lmm,
141 int lmm_size, struct thandle *handle, int set_stripe);
142 int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
143 struct mdd_object *parent, struct mdd_object *child,
144 struct lov_mds_md **lmm, int *lmm_size,
145 const struct md_op_spec *spec, struct lu_attr *la);
146 void mdd_lov_objid_update(struct mdd_device *mdd, struct lov_mds_md *lmm);
147 void mdd_lov_create_finish(const struct lu_env *env, struct mdd_device *mdd,
148 struct lov_mds_md *lmm, int lmm_size,
149 const struct md_op_spec *spec);
150 int mdd_get_md(const struct lu_env *env, struct mdd_object *obj,
151 void *md, int *md_size, const char *name);
152 int mdd_get_md_locked(const struct lu_env *env, struct mdd_object *obj,
153 void *md, int *md_size, const char *name);
154 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
155 struct lu_attr *la, struct lustre_capa *capa);
156 int mdd_attr_set_internal(const struct lu_env *env, struct mdd_object *o,
157 const struct lu_attr *attr, struct thandle *handle,
159 int mdd_object_kill(const struct lu_env *env, struct mdd_object *obj,
161 int mdd_iattr_get(const struct lu_env *env, struct mdd_object *mdd_obj,
163 int mdd_attr_get_internal_locked(const struct lu_env *env,
164 struct mdd_object *mdd_obj,
166 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
167 struct mdd_object *c, struct md_attr *ma,
168 struct thandle *handle);
169 int mdd_attr_set_internal_locked(const struct lu_env *env,
170 struct mdd_object *o,
171 const struct lu_attr *attr,
172 struct thandle *handle, const int needacl);
173 int mdd_lmm_get_locked(const struct lu_env *env, struct mdd_object *mdd_obj,
176 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj);
177 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj);
178 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
179 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
181 void mdd_pdlock_init(struct mdd_object *obj);
182 unsigned long mdd_name2hash(const char *name);
183 struct dynlock_handle *mdd_pdo_write_lock(const struct lu_env *env,
184 struct mdd_object *obj,
186 struct dynlock_handle *mdd_pdo_read_lock(const struct lu_env *env,
187 struct mdd_object *obj,
189 void mdd_pdo_write_unlock(const struct lu_env *env, struct mdd_object *obj,
190 struct dynlock_handle *dlh);
191 void mdd_pdo_read_unlock(const struct lu_env *env, struct mdd_object *obj,
192 struct dynlock_handle *dlh);
194 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
195 struct mdd_object *cobj, int check_perm, int check_nlink);
196 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
197 const struct md_attr *ma);
198 int mdd_may_delete(const struct lu_env *env, struct mdd_object *pobj,
199 struct mdd_object *cobj, struct md_attr *ma,
200 int check_perm, int check_empty);
201 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
202 struct mdd_object *cobj, struct md_attr *ma);
203 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
204 struct md_attr *ma, struct thandle *th);
205 int mdd_object_initialize(const struct lu_env *env, const struct lu_fid *pfid,
206 struct mdd_object *child, struct md_attr *ma,
207 struct thandle *handle);
208 int mdd_link_sanity_check(const struct lu_env *env, struct mdd_object *tgt_obj,
209 const struct lu_name *lname, struct mdd_object *src_obj);
211 int mdd_unlink_log(const struct lu_env *env, struct mdd_device *mdd,
212 struct mdd_object *mdd_cobj, struct md_attr *ma);
214 int mdd_setattr_log(const struct lu_env *env, struct mdd_device *mdd,
215 const struct md_attr *ma,
216 struct lov_mds_md *lmm, int lmm_size,
217 struct llog_cookie *logcookies, int cookies_size);
219 int mdd_get_cookie_size(const struct lu_env *env, struct mdd_device *mdd,
220 struct lov_mds_md *lmm);
222 int mdd_lov_setattr_async(const struct lu_env *env, struct mdd_object *obj,
223 struct lov_mds_md *lmm, int lmm_size,
224 struct llog_cookie *logcookies);
226 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
228 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
229 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
230 const void *area, ssize_t len);
232 int __mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
233 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
235 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
237 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
238 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
239 int mdd_txn_init_credits(const struct lu_env *env, struct mdd_device *mdd);
242 void lprocfs_mdd_init_vars(struct lprocfs_static_vars *lvars);
243 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
244 int mdd_procfs_fini(struct mdd_device *mdd);
245 void mdd_lprocfs_time_start(const struct lu_env *env);
246 void mdd_lprocfs_time_end(const struct lu_env *env,
247 struct mdd_device *mdd, int op);
249 int mdd_get_flags(const struct lu_env *env, struct mdd_object *obj);
251 extern struct md_dir_operations mdd_dir_ops;
252 extern struct md_object_operations mdd_obj_ops;
255 void mdd_txn_param_build(const struct lu_env *env, struct mdd_device *mdd,
257 int mdd_log_txn_param_build(const struct lu_env *env, struct md_object *obj,
258 struct md_attr *ma, enum mdd_txn_op);
260 static inline void mdd_object_put(const struct lu_env *env,
261 struct mdd_object *o)
263 lu_object_put(env, &o->mod_obj.mo_lu);
266 struct thandle* mdd_trans_start(const struct lu_env *env,
267 struct mdd_device *);
269 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
270 int rc, struct thandle *handle);
272 int mdd_txn_start_cb(const struct lu_env *env, struct txn_param *param,
275 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
278 int mdd_txn_commit_cb(const struct lu_env *env, struct thandle *txn,
281 struct lu_object *mdd_object_alloc(const struct lu_env *env,
282 const struct lu_object_header *hdr,
283 struct lu_device *d);
286 int accmode(const struct lu_env *env, struct lu_attr *la, int flags);
287 extern struct lu_context_key mdd_thread_key;
288 extern struct lu_device_operations mdd_lu_ops;
290 struct mdd_object *mdd_object_find(const struct lu_env *env,
291 struct mdd_device *d,
292 const struct lu_fid *f);
294 /* mdd_permission.c */
295 #define mdd_cap_t(x) (x)
297 #define MDD_CAP_TO_MASK(x) (1 << (x))
299 #define mdd_cap_raised(c, flag) (mdd_cap_t(c) & MDD_CAP_TO_MASK(flag))
301 /* capable() is copied from linux kernel! */
302 static inline int mdd_capable(struct md_ucred *uc, int cap)
304 if (mdd_cap_raised(uc->mu_cap, cap))
309 int mdd_acl_def_get(const struct lu_env *env, struct mdd_object *mdd_obj,
311 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
312 struct thandle *handle);
313 int __mdd_acl_init(const struct lu_env *env, struct mdd_object *obj,
314 struct lu_buf *buf, __u32 *mode, struct thandle *handle);
315 int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
316 struct mdd_object *cobj, __u32 *mode, struct thandle *handle);
317 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
318 struct lu_attr *la, int mask, int needlock);
319 int mdd_permission(const struct lu_env *env,
320 struct md_object *pobj, struct md_object *cobj,
321 struct md_attr *ma, int mask);
322 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
323 struct lustre_capa *capa, int renewal);
325 static inline int lu_device_is_mdd(struct lu_device *d)
327 return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
330 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
332 LASSERT(lu_device_is_mdd(d));
333 return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
336 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
338 return (&d->mdd_md_dev.md_lu_dev);
341 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
343 LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
344 return container_of0(o, struct mdd_object, mod_obj.mo_lu);
347 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
349 return lu2mdd_dev(mdo->mo_lu.lo_dev);
352 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
354 return container_of0(mdo, struct mdd_object, mod_obj);
357 static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
359 return d->mdd_child->dd_ops;
362 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
364 return &obj->mod_obj.mo_lu;
367 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
369 return container_of0(lu_object_next(mdd2lu_obj(o)),
370 struct dt_object, do_lu);
373 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
375 return mdd->mdd_obd_dev;
378 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
380 return mdo2mdd(&obj->mod_obj);
383 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
385 return lu_object_fid(&obj->mod_obj.mo_lu);
388 static inline umode_t mdd_object_type(const struct mdd_object *obj)
390 return lu_object_attr(&obj->mod_obj.mo_lu);
393 static inline int mdd_lov_mdsize(const struct lu_env *env,
394 struct mdd_device *mdd)
396 struct obd_device *obd = mdd2obd_dev(mdd);
397 return obd->u.mds.mds_max_mdsize;
400 static inline int mdd_lov_cookiesize(const struct lu_env *env,
401 struct mdd_device *mdd)
403 struct obd_device *obd = mdd2obd_dev(mdd);
404 return obd->u.mds.mds_max_cookiesize;
407 static inline int mdd_is_immutable(struct mdd_object *obj)
409 return obj->mod_flags & IMMUTE_OBJ;
412 static inline int mdd_is_dead_obj(struct mdd_object *obj)
414 return obj && obj->mod_flags & DEAD_OBJ;
417 static inline int mdd_is_append(struct mdd_object *obj)
419 return obj->mod_flags & APPEND_OBJ;
422 static inline int mdd_object_exists(struct mdd_object *obj)
424 return lu_object_exists(mdd2lu_obj(obj));
427 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
429 return lu_object_fid(mdd2lu_obj(obj));
432 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
433 const struct mdd_object *obj)
435 struct md_capainfo *ci = md_capainfo(env);
436 const struct lu_fid *fid = mdo2fid(obj);
439 /* NB: in mdt_init0 */
442 for (i = 0; i < MD_CAPAINFO_MAX; i++)
443 if (ci->mc_fid[i] && lu_fid_eq(ci->mc_fid[i], fid))
444 return ci->mc_capa[i];
448 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
449 const struct mdd_object *obj,
450 struct lustre_capa *capa)
452 struct md_capainfo *ci = md_capainfo(env);
453 const struct lu_fid *fid = mdo2fid(obj);
455 LASSERT(offset >= 0 && offset <= MD_CAPAINFO_MAX);
456 /* NB: in mdt_init0 */
459 ci->mc_fid[offset] = fid;
460 ci->mc_capa[offset] = capa;
463 #define MAX_ATIME_DIFF 60
469 static inline int mdd_permission_internal(const struct lu_env *env,
470 struct mdd_object *obj,
471 struct lu_attr *la, int mask)
473 return __mdd_permission_internal(env, obj, la, mask, 0);
476 static inline int mdd_permission_internal_locked(const struct lu_env *env,
477 struct mdd_object *obj,
478 struct lu_attr *la, int mask)
480 return __mdd_permission_internal(env, obj, la, mask, 1);
483 /* mdd inline func for calling osd_dt_object ops */
484 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
485 struct lu_attr *la, struct lustre_capa *capa)
487 struct dt_object *next = mdd_object_child(obj);
488 return next->do_ops->do_attr_get(env, next, la, capa);
491 static inline int mdo_attr_set(const struct lu_env *env, struct mdd_object *obj,
492 const struct lu_attr *la, struct thandle *handle,
493 struct lustre_capa *capa)
495 struct dt_object *next = mdd_object_child(obj);
496 LASSERT(mdd_object_exists(obj));
497 return next->do_ops->do_attr_set(env, next, la, handle, capa);
500 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
501 struct lu_buf *buf, const char *name,
502 struct lustre_capa *capa)
504 struct dt_object *next = mdd_object_child(obj);
505 return next->do_ops->do_xattr_get(env, next, buf, name, capa);
508 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
509 const struct lu_buf *buf, const char *name,
510 int fl, struct thandle *handle,
511 struct lustre_capa *capa)
513 struct dt_object *next = mdd_object_child(obj);
514 LASSERT(mdd_object_exists(obj));
515 return next->do_ops->do_xattr_set(env, next, buf, name, fl, handle,
519 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
520 const char *name, struct thandle *handle,
521 struct lustre_capa *capa)
523 struct dt_object *next = mdd_object_child(obj);
524 LASSERT(mdd_object_exists(obj));
525 return next->do_ops->do_xattr_del(env, next, name, handle, capa);
529 int mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
530 struct lu_buf *buf, struct lustre_capa *capa)
532 struct dt_object *next = mdd_object_child(obj);
533 LASSERT(mdd_object_exists(obj));
534 return next->do_ops->do_xattr_list(env, next, buf, capa);
538 int mdo_index_try(const struct lu_env *env, struct mdd_object *obj,
539 const struct dt_index_features *feat)
541 struct dt_object *next = mdd_object_child(obj);
542 return next->do_ops->do_index_try(env, next, feat);
545 static inline void mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
546 struct thandle *handle)
548 struct dt_object *next = mdd_object_child(obj);
549 LASSERT(mdd_object_exists(obj));
550 return next->do_ops->do_ref_add(env, next, handle);
553 static inline void mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
554 struct thandle *handle)
556 struct dt_object *next = mdd_object_child(obj);
557 LASSERT(mdd_object_exists(obj));
558 return next->do_ops->do_ref_del(env, next, handle);
562 int mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
563 struct lu_attr *attr,
564 struct dt_allocation_hint *hint,
565 struct thandle *handle)
567 struct dt_object *next = mdd_object_child(o);
568 return next->do_ops->do_create(env, next, attr, hint, handle);
571 static inline struct obd_capa *mdo_capa_get(const struct lu_env *env,
572 struct mdd_object *obj,
573 struct lustre_capa *old,
576 struct dt_object *next = mdd_object_child(obj);
577 LASSERT(mdd_object_exists(obj));
578 return next->do_ops->do_capa_get(env, next, old, opc);