Whamcloud - gitweb
eff209869b0d9f2173390cef88d81e1270c768ed
[fs/lustre-release.git] / lustre / mdd / mdd_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mdd/mdd_internal.h
37  *
38  * Author: Wang Di <wangdi@clusterfs.com>
39  */
40
41 #ifndef _MDD_INTERNAL_H
42 #define _MDD_INTERNAL_H
43
44 #include <lustre_acl.h>
45 #include <lustre_eacl.h>
46 #include <md_object.h>
47 #include <dt_object.h>
48 #include <lustre_lfsck.h>
49 #include <lustre_fid.h>
50 #include <lustre_capa.h>
51 #include <lprocfs_status.h>
52 #include <lustre_log.h>
53 #include <lustre_linkea.h>
54
55 /* Changelog flags */
56 /** changelog is recording */
57 #define CLM_ON    0x00001
58 /** internal error prevented changelogs from starting */
59 #define CLM_ERR   0x00002
60 /* Marker flags */
61 /** changelogs turned on */
62 #define CLM_START 0x10000
63 /** changelogs turned off */
64 #define CLM_FINI  0x20000
65 /** some changelog records purged */
66 #define CLM_PURGE 0x40000
67
68 struct mdd_changelog {
69         spinlock_t              mc_lock;        /* for index */
70         int                     mc_flags;
71         int                     mc_mask;
72         __u64                   mc_index;
73         __u64                   mc_starttime;
74         spinlock_t              mc_user_lock;
75         int                     mc_lastuser;
76 };
77
78 static inline __u64 cl_time(void) {
79         cfs_fs_time_t time;
80
81         cfs_fs_time_current(&time);
82         return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
83 }
84
85 /** Objects in .lustre dir */
86 struct mdd_dot_lustre_objs {
87         struct mdd_object *mdd_obf;
88         struct mdd_object *mdd_lpf;
89 };
90
91 struct mdd_generic_thread {
92         struct completion       mgt_started;
93         struct completion       mgt_finished;
94         void                   *mgt_data;
95         bool                    mgt_abort;
96         bool                    mgt_init;
97 };
98
99 struct mdd_device {
100         struct md_device                 mdd_md_dev;
101         struct obd_export               *mdd_child_exp;
102         struct dt_device                *mdd_child;
103         struct dt_device                *mdd_bottom;
104         struct lu_fid                    mdd_root_fid; /* /ROOT */
105         struct lu_fid                    mdd_local_root_fid;
106         struct dt_device_param           mdd_dt_conf;
107         struct dt_object                *mdd_orphans; /* PENDING directory */
108         struct proc_dir_entry            *mdd_proc_entry;
109         struct mdd_changelog             mdd_cl;
110         unsigned long                    mdd_atime_diff;
111         struct mdd_object               *mdd_dot_lustre;
112         struct mdd_dot_lustre_objs       mdd_dot_lustre_objs;
113         unsigned int                     mdd_sync_permission;
114         int                              mdd_connects;
115         struct local_oid_storage        *mdd_los;
116         struct mdd_generic_thread        mdd_orph_cleanup_thread;
117 };
118
119 enum mod_flags {
120         /* The dir object has been unlinked */
121         DEAD_OBJ   = 1 << 0,
122         APPEND_OBJ = 1 << 1,
123         IMMUTE_OBJ = 1 << 2,
124         ORPHAN_OBJ = 1 << 3,
125 };
126
127 struct mdd_object {
128         struct md_object   mod_obj;
129         /* open count */
130         __u32             mod_count;
131         __u32             mod_valid;
132         __u64             mod_cltime;
133         unsigned long     mod_flags;
134 };
135
136 struct mdd_thread_info {
137         struct lu_fid             mti_fid;
138         struct lu_fid             mti_fid2; /* used for be & cpu converting */
139         /**
140         * only be used by MDD interfaces, can be passed into local MDD APIs.
141         */
142         struct lu_attr            mti_pattr;
143         struct lu_attr            mti_cattr;
144         struct lu_attr            mti_tpattr;
145         struct lu_attr            mti_tattr;
146         /** used to set c/mtime */
147         struct lu_attr            mti_la_for_fix;
148         /* Only used in mdd_object_start */
149         struct lu_attr            mti_la_for_start;
150         /* mti_ent and mti_key must be conjoint,
151         * then mti_ent::lde_name will be mti_key. */
152         struct lu_dirent          mti_ent;
153         char                      mti_key[NAME_MAX + 16];
154         struct lu_buf             mti_buf[4];
155         struct lu_buf             mti_big_buf; /* biggish persistent buf */
156         struct lu_buf             mti_link_buf; /* buf for link ea */
157         struct obdo               mti_oa;
158         char                      mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
159         struct dt_allocation_hint mti_hint;
160         struct dt_object_format   mti_dof;
161         struct linkea_data        mti_link_data;
162         struct md_op_spec         mti_spec;
163         struct dt_insert_rec      mti_dt_rec;
164         struct lfsck_request      mti_lr;
165 };
166
167 enum mdd_links_add_overflow {
168         MLAO_IGNORE     = false,
169         MLAO_CHECK      = true,
170 };
171
172 extern const char orph_index_name[];
173
174 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
175                struct lu_attr *la, struct lustre_capa *capa);
176 void mdd_flags_xlate(struct mdd_object *obj, __u32 flags);
177 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
178                  struct md_attr *ma);
179 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
180                  const struct md_attr *ma);
181 int mdd_attr_set_internal(const struct lu_env *env,
182                           struct mdd_object *obj,
183                           const struct lu_attr *attr,
184                           struct thandle *handle,
185                           int needacl);
186 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
187                     const struct lu_attr *oattr, struct lu_attr *attr,
188                     struct thandle *handle);
189 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
190                                struct mdd_object *c, struct lu_attr *attr,
191                                struct thandle *handle,
192                                const struct md_op_spec *spec,
193                                struct dt_allocation_hint *hint);
194
195 /* mdd_lock.c */
196 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
197                     enum mdd_object_role role);
198 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
199                    enum mdd_object_role role);
200 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
201 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
202 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
203
204 /* mdd_dir.c */
205 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
206                   const struct lu_fid *fid, struct lu_fid *sfid);
207 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
208                    const struct lu_attr *pattr, struct mdd_object *cobj,
209                    bool check_perm);
210 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
211                    const struct lu_attr *pattr, const struct lu_attr *attr);
212 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
213                    const struct lu_attr *tpattr, struct mdd_object *tobj,
214                    const struct lu_attr *tattr, const struct lu_attr *cattr,
215                    int check_perm, int check_empty);
216 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
217                             const struct lu_attr *pattr,
218                             struct mdd_object *cobj,
219                             const struct lu_attr *cattr);
220 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
221                       struct md_attr *ma, const struct mdd_object *pobj,
222                       const struct lu_name *lname, struct thandle *th);
223
224 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
225 int mdd_lookup(const struct lu_env *env,
226                struct md_object *pobj, const struct lu_name *lname,
227                struct lu_fid* fid, struct md_op_spec *spec);
228 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
229                    struct linkea_data *ldata);
230 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
231                           struct thandle *handle, struct linkea_data *ldata,
232                           enum mdd_links_add_overflow overflow);
233 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
234                     struct linkea_data *ldata, struct thandle *handle);
235 struct lu_buf *mdd_links_get(const struct lu_env *env,
236                              struct mdd_object *mdd_obj);
237 int mdd_links_rename(const struct lu_env *env,
238                      struct mdd_object *mdd_obj,
239                      const struct lu_fid *oldpfid,
240                      const struct lu_name *oldlname,
241                      const struct lu_fid *newpfid,
242                      const struct lu_name *newlname,
243                      struct thandle *handle,
244                      struct linkea_data *ldata,
245                      int first, int check);
246
247 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
248
249 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
250
251 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
252 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
253                                        const void *area, ssize_t len);
254
255 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
256 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
257                      struct thandle *);
258 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
259                      struct thandle *);
260 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
261 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
262 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
263                               umode_t mode, struct thandle *);
264 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
265                               struct thandle *);
266
267 /* mdd_lproc.c */
268 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
269 void mdd_procfs_fini(struct mdd_device *mdd);
270
271 /* mdd_object.c */
272 extern struct kmem_cache *mdd_object_kmem;
273 extern const struct md_dir_operations    mdd_dir_ops;
274 extern const struct md_object_operations mdd_obj_ops;
275 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
276                  struct lu_buf *buf);
277 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
278 extern struct lu_context_key mdd_thread_key;
279 extern const struct lu_device_operations mdd_lu_ops;
280
281 struct mdd_object *mdd_object_find(const struct lu_env *env,
282                                    struct mdd_device *d,
283                                    const struct lu_fid *f);
284 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
285                  const struct lu_rdpg *rdpg);
286 int mdd_declare_changelog_store(const struct lu_env *env,
287                                        struct mdd_device *mdd,
288                                        const struct lu_name *tname,
289                                        const struct lu_name *sname,
290                                        struct thandle *handle);
291 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
292 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
293                         struct llog_changelog_rec *rec, struct thandle *th);
294 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
295                              enum changelog_rec_type type, int flags,
296                              struct mdd_object *mdd_obj,
297                              struct thandle *handle);
298 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
299                            enum changelog_rec_type type,
300                            enum changelog_rec_flags crf,
301                            struct mdd_object *target,
302                            const struct lu_fid *tpfid,
303                            const struct lu_fid *sfid,
304                            const struct lu_fid *spfid,
305                            const struct lu_name *tname,
306                            const struct lu_name *sname,
307                            struct thandle *handle);
308 int mdd_declare_object_create_internal(const struct lu_env *env,
309                                        struct mdd_object *p,
310                                        struct mdd_object *c,
311                                        struct lu_attr *attr,
312                                        struct thandle *handle,
313                                        const struct md_op_spec *spec,
314                                        struct dt_allocation_hint *hint);
315 int mdd_get_lov_ea(const struct lu_env *env, struct mdd_object *obj,
316                    struct lu_buf *lmm_buf);
317
318 /* mdd_trans.c */
319 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
320                           struct mdd_object *child, const struct lu_attr *attr,
321                           const struct md_op_spec *spec,
322                           struct dt_allocation_hint *hint);
323
324 static inline void mdd_object_get(struct mdd_object *o)
325 {
326         lu_object_get(&o->mod_obj.mo_lu);
327 }
328
329 static inline void mdd_object_put(const struct lu_env *env,
330                                   struct mdd_object *o)
331 {
332         lu_object_put(env, &o->mod_obj.mo_lu);
333 }
334
335 struct thandle *mdd_trans_create(const struct lu_env *env,
336                                  struct mdd_device *mdd);
337 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
338                     struct thandle *th);
339 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
340                    int rc, struct thandle *handle);
341
342 /* mdd_device.c */
343 struct lu_object *mdd_object_alloc(const struct lu_env *env,
344                                    const struct lu_object_header *hdr,
345                                    struct lu_device *d);
346 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
347                           const struct lu_fid *pfid, const char *name,
348                           __u32 mode, struct lu_fid *fid);
349
350 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
351                   struct thandle *handle);
352 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
353                 struct lu_attr *attr, const struct lu_buf *buf, int fl);
354 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
355                        __u32 *mode);
356 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
357                               const struct lu_attr *la, int mask, int role);
358 int mdd_permission(const struct lu_env *env,
359                    struct md_object *pobj, struct md_object *cobj,
360                    struct md_attr *ma, int mask);
361 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
362                  struct lustre_capa *capa, int renewal);
363 int mdd_generic_thread_start(struct mdd_generic_thread *thread,
364                              int (*func)(void *), void *data, char *name);
365 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
366
367 /* mdd_prepare.c */
368 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
369
370 /* inline functions */
371 static inline int lu_device_is_mdd(struct lu_device *d)
372 {
373         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
374 }
375
376 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
377 {
378         LASSERT(lu_device_is_mdd(d));
379         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
380 }
381
382 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
383 {
384         return (&d->mdd_md_dev.md_lu_dev);
385 }
386
387 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
388 {
389         LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
390         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
391 }
392
393 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
394 {
395         return lu2mdd_dev(mdo->mo_lu.lo_dev);
396 }
397
398 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
399 {
400         return container_of0(mdo, struct mdd_object, mod_obj);
401 }
402
403 static inline const struct dt_device_operations *
404 mdd_child_ops(struct mdd_device *d)
405 {
406         return d->mdd_child->dd_ops;
407 }
408
409 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
410 {
411         return &obj->mod_obj.mo_lu;
412 }
413
414 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
415 {
416         return container_of0(lu_object_next(mdd2lu_obj(o)),
417                              struct dt_object, do_lu);
418 }
419
420 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
421 {
422         return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
423 }
424
425 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
426 {
427         return mdo2mdd(&obj->mod_obj);
428 }
429
430 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
431 {
432         return lu_object_fid(&obj->mod_obj.mo_lu);
433 }
434
435 static inline umode_t mdd_object_type(const struct mdd_object *obj)
436 {
437         return lu_object_attr(&obj->mod_obj.mo_lu);
438 }
439
440 static inline int mdd_is_immutable(struct mdd_object *obj)
441 {
442         return obj->mod_flags & IMMUTE_OBJ;
443 }
444
445 static inline int mdd_is_dead_obj(struct mdd_object *obj)
446 {
447         return obj && obj->mod_flags & DEAD_OBJ;
448 }
449
450 static inline int mdd_is_append(struct mdd_object *obj)
451 {
452         return obj->mod_flags & APPEND_OBJ;
453 }
454
455 static inline int mdd_object_exists(struct mdd_object *obj)
456 {
457         return lu_object_exists(mdd2lu_obj(obj));
458 }
459
460 static inline int mdd_object_remote(struct mdd_object *obj)
461 {
462         return lu_object_remote(mdd2lu_obj(obj));
463 }
464
465 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
466 {
467         return lu_object_fid(mdd2lu_obj(obj));
468 }
469
470 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
471 {
472         return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
473 }
474
475 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
476                                                   const struct mdd_object *obj)
477 {
478         struct lu_capainfo *lci = lu_capainfo_get(env);
479         const struct lu_fid *fid = mdo2fid(obj);
480         int i;
481
482         /* NB: in mdt_init0 */
483         if (lci == NULL)
484                 return BYPASS_CAPA;
485
486         for (i = 0; i < LU_CAPAINFO_MAX; i++)
487                 if (lu_fid_eq(&lci->lci_fid[i], fid))
488                         return lci->lci_capa[i];
489         return NULL;
490 }
491
492 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
493                                     const struct mdd_object *obj,
494                                     struct lustre_capa *capa)
495 {
496         struct lu_capainfo *lci = lu_capainfo_get(env);
497         const struct lu_fid *fid = mdo2fid(obj);
498
499         LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
500         /* NB: in mdt_init0 */
501         if (lci == NULL)
502                 return;
503
504         lci->lci_fid[offset]  = *fid;
505         lci->lci_capa[offset] = capa;
506 }
507
508 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
509 {
510         return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
511 }
512
513 #define MAX_ATIME_DIFF 60
514
515 static inline int mdd_permission_internal(const struct lu_env *env,
516                                           struct mdd_object *obj,
517                                           const struct lu_attr *la, int mask)
518 {
519         return __mdd_permission_internal(env, obj, la, mask, -1);
520 }
521
522 static inline int mdd_permission_internal_locked(const struct lu_env *env,
523                                                 struct mdd_object *obj,
524                                                 const struct lu_attr *la,
525                                                 int mask,
526                                                 enum mdd_object_role role)
527 {
528         return __mdd_permission_internal(env, obj, la, mask, role);
529 }
530
531 /* mdd inline func for calling osd_dt_object ops */
532 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
533                                struct lu_attr *la, struct lustre_capa *capa)
534 {
535         struct dt_object *next = mdd_object_child(obj);
536         return dt_attr_get(env, next, la, capa);
537 }
538
539 static inline int mdo_declare_attr_set(const struct lu_env *env,
540                                        struct mdd_object *obj,
541                                        const struct lu_attr *la,
542                                        struct thandle *handle)
543 {
544         struct dt_object *next = mdd_object_child(obj);
545         return dt_declare_attr_set(env, next, la, handle);
546 }
547
548 static inline int mdo_attr_set(const struct lu_env *env,
549                                struct mdd_object *obj,
550                                const struct lu_attr *la,
551                                struct thandle *handle,
552                                struct lustre_capa *capa)
553 {
554         struct dt_object *next = mdd_object_child(obj);
555
556         if (!mdd_object_exists(obj))
557                 return -ENOENT;
558
559         return dt_attr_set(env, next, la, handle, capa);
560 }
561
562 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
563                                 struct lu_buf *buf, const char *name,
564                                 struct lustre_capa *capa)
565 {
566         struct dt_object *next = mdd_object_child(obj);
567         return dt_xattr_get(env, next, buf, name, capa);
568 }
569
570 static inline int mdo_declare_xattr_set(const struct lu_env *env,
571                                         struct mdd_object *obj,
572                                         const struct lu_buf *buf,
573                                         const char *name,
574                                         int fl, struct thandle *handle)
575 {
576         struct dt_object *next = mdd_object_child(obj);
577         return dt_declare_xattr_set(env, next, buf, name, fl, handle);
578 }
579
580 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
581                                 const struct lu_buf *buf, const char *name,
582                                 int fl, struct thandle *handle,
583                                 struct lustre_capa *capa)
584 {
585         struct dt_object *next = mdd_object_child(obj);
586
587         if (!mdd_object_exists(obj))
588                 return -ENOENT;
589
590         return dt_xattr_set(env, next, buf, name, fl, handle, capa);
591 }
592
593 static inline int mdo_declare_xattr_del(const struct lu_env *env,
594                                         struct mdd_object *obj,
595                                         const char *name,
596                                         struct thandle *handle)
597 {
598         struct dt_object *next = mdd_object_child(obj);
599         return dt_declare_xattr_del(env, next, name, handle);
600 }
601
602 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
603                                 const char *name, struct thandle *handle,
604                                 struct lustre_capa *capa)
605 {
606         struct dt_object *next = mdd_object_child(obj);
607
608         if (!mdd_object_exists(obj))
609                 return -ENOENT;
610
611         return dt_xattr_del(env, next, name, handle, capa);
612 }
613
614 static inline int
615 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
616                struct lu_buf *buf, struct lustre_capa *capa)
617 {
618         struct dt_object *next = mdd_object_child(obj);
619
620         if (!mdd_object_exists(obj))
621                 return -ENOENT;
622
623         return dt_xattr_list(env, next, buf, capa);
624 }
625
626 static inline
627 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
628                              const struct lu_fid *fid, __u32 type,
629                              const char *name, struct thandle *handle)
630 {
631         struct dt_object *next  = mdd_object_child(obj);
632         int               rc    = 0;
633
634         /*
635          * if the object doesn't exist yet, then it's supposed to be created
636          * and declaration of the creation should be enough to insert ./..
637          */
638
639          /* FIXME: remote object should not be awared by MDD layer, but local
640           * creation does not declare insert ./.. (comments above), which
641           * is required by remote directory creation.
642           * This remote check should be removed when mdd_object_exists check is
643           * removed.
644           */
645         if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
646                 rc = -ENOTDIR;
647                 if (dt_try_as_dir(env, next)) {
648                         struct dt_insert_rec *rec =
649                                         &mdd_env_info(env)->mti_dt_rec;
650
651                         rec->rec_fid = fid;
652                         rec->rec_type = type;
653                         rc = dt_declare_insert(env, next,
654                                                (const struct dt_rec *)rec,
655                                                (const struct dt_key *)name,
656                                                handle);
657                 }
658          }
659
660          return rc;
661 }
662
663 static inline
664 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
665                              const char *name, struct thandle *handle)
666 {
667         struct dt_object *next = mdd_object_child(obj);
668
669         if (!dt_try_as_dir(env, next))
670                 return -ENOTDIR;
671
672         return dt_declare_delete(env, next, (const struct dt_key *)name,
673                                  handle);
674 }
675
676 static inline int mdo_declare_ref_add(const struct lu_env *env,
677                                       struct mdd_object *obj,
678                                       struct thandle *handle)
679 {
680         struct dt_object *next = mdd_object_child(obj);
681         return dt_declare_ref_add(env, next, handle);
682 }
683
684 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
685                               struct thandle *handle)
686 {
687         struct dt_object *next = mdd_object_child(obj);
688
689         if (!mdd_object_exists(obj))
690                 return -ENOENT;
691
692         return dt_ref_add(env, next, handle);
693 }
694
695 static inline int mdo_declare_ref_del(const struct lu_env *env,
696                                       struct mdd_object *obj,
697                                       struct thandle *handle)
698 {
699         struct dt_object *next = mdd_object_child(obj);
700         return dt_declare_ref_del(env, next, handle);
701 }
702
703 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
704                               struct thandle *handle)
705 {
706         struct dt_object *next = mdd_object_child(obj);
707
708         if (!mdd_object_exists(obj))
709                 return -ENOENT;
710
711         return dt_ref_del(env, next, handle);
712 }
713
714 static inline int
715 mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
716                        struct lu_attr *attr,
717                        struct dt_allocation_hint *hint,
718                        struct dt_object_format *dof,
719                        struct thandle *handle)
720 {
721         struct dt_object *next = mdd_object_child(o);
722         return dt_declare_create(env, next, attr, hint, dof, handle);
723 }
724
725 static inline int
726 mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
727                struct lu_attr *attr,
728                struct dt_allocation_hint *hint,
729                struct dt_object_format *dof,
730                struct thandle *handle)
731 {
732         struct dt_object *next = mdd_object_child(o);
733         return dt_create(env, next, attr, hint, dof, handle);
734 }
735
736 static inline
737 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
738                         struct thandle *handle)
739 {
740         struct dt_object *next = mdd_object_child(o);
741         return dt_declare_destroy(env, next, handle);
742 }
743
744 static inline
745 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
746                 struct thandle *handle)
747 {
748         struct dt_object *next = mdd_object_child(o);
749         return dt_destroy(env, next, handle);
750 }
751
752 static inline struct obd_capa *
753 mdo_capa_get(const struct lu_env *env, struct mdd_object *obj,
754              struct lustre_capa *old, __u64 opc)
755 {
756         struct dt_object *next = mdd_object_child(obj);
757
758         if (!mdd_object_exists(obj))
759                 return ERR_PTR(-ENOENT);
760
761         return dt_capa_get(env, next, old, opc);
762 }
763
764 #endif