Whamcloud - gitweb
LU-1996 lustre: Flexible changelog format.
[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 };
165
166 extern const char orph_index_name[];
167
168 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
169                struct lu_attr *la, struct lustre_capa *capa);
170 void mdd_flags_xlate(struct mdd_object *obj, __u32 flags);
171 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
172                  struct md_attr *ma);
173 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
174                  const struct md_attr *ma);
175 int mdd_attr_set_internal(const struct lu_env *env,
176                           struct mdd_object *obj,
177                           const struct lu_attr *attr,
178                           struct thandle *handle,
179                           int needacl);
180 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
181                     const struct lu_attr *oattr, struct lu_attr *attr,
182                     struct thandle *handle);
183 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
184                                struct mdd_object *c, struct lu_attr *attr,
185                                struct thandle *handle,
186                                const struct md_op_spec *spec,
187                                struct dt_allocation_hint *hint);
188
189 /* mdd_lock.c */
190 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
191                     enum mdd_object_role role);
192 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
193                    enum mdd_object_role role);
194 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
195 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
196 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
197
198 /* mdd_dir.c */
199 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
200                   const struct lu_fid *fid, struct lu_fid *sfid);
201 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
202                    const struct lu_attr *pattr, struct mdd_object *cobj,
203                    bool check_perm);
204 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
205                    const struct lu_attr *pattr, const struct lu_attr *attr);
206 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
207                    const struct lu_attr *tpattr, struct mdd_object *tobj,
208                    const struct lu_attr *tattr, const struct lu_attr *cattr,
209                    int check_perm, int check_empty);
210 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
211                             const struct lu_attr *pattr,
212                             struct mdd_object *cobj,
213                             const struct lu_attr *cattr);
214 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
215                       struct md_attr *ma, const struct mdd_object *pobj,
216                       const struct lu_name *lname, struct thandle *th);
217
218 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
219 int mdd_lookup(const struct lu_env *env,
220                struct md_object *pobj, const struct lu_name *lname,
221                struct lu_fid* fid, struct md_op_spec *spec);
222 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
223                    struct linkea_data *ldata);
224 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
225                           struct thandle *handle, struct linkea_data *ldata);
226 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
227                     struct linkea_data *ldata, struct thandle *handle);
228 struct lu_buf *mdd_links_get(const struct lu_env *env,
229                              struct mdd_object *mdd_obj);
230 int mdd_links_rename(const struct lu_env *env,
231                      struct mdd_object *mdd_obj,
232                      const struct lu_fid *oldpfid,
233                      const struct lu_name *oldlname,
234                      const struct lu_fid *newpfid,
235                      const struct lu_name *newlname,
236                      struct thandle *handle,
237                      struct linkea_data *ldata,
238                      int first, int check);
239
240 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
241
242 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
243
244 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
245 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
246                                        const void *area, ssize_t len);
247
248 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
249 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
250                      struct thandle *);
251 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
252                      struct thandle *);
253 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
254 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
255 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
256                               umode_t mode, struct thandle *);
257 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
258                               struct thandle *);
259
260 /* mdd_lproc.c */
261 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
262 void mdd_procfs_fini(struct mdd_device *mdd);
263
264 /* mdd_object.c */
265 extern struct kmem_cache *mdd_object_kmem;
266 extern const struct md_dir_operations    mdd_dir_ops;
267 extern const struct md_object_operations mdd_obj_ops;
268 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
269                  struct lu_buf *buf);
270 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
271 extern struct lu_context_key mdd_thread_key;
272 extern const struct lu_device_operations mdd_lu_ops;
273
274 struct mdd_object *mdd_object_find(const struct lu_env *env,
275                                    struct mdd_device *d,
276                                    const struct lu_fid *f);
277 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
278                  const struct lu_rdpg *rdpg);
279 int mdd_declare_changelog_store(const struct lu_env *env,
280                                        struct mdd_device *mdd,
281                                        const struct lu_name *tname,
282                                        const struct lu_name *sname,
283                                        struct thandle *handle);
284 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
285 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
286                         struct llog_changelog_rec *rec, struct thandle *th);
287 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
288                              enum changelog_rec_type type, int flags,
289                              struct mdd_object *mdd_obj,
290                              struct thandle *handle);
291 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
292                            enum changelog_rec_type type,
293                            enum changelog_rec_flags crf,
294                            struct mdd_object *target,
295                            const struct lu_fid *tpfid,
296                            const struct lu_fid *sfid,
297                            const struct lu_fid *spfid,
298                            const struct lu_name *tname,
299                            const struct lu_name *sname,
300                            struct thandle *handle);
301 int mdd_declare_object_create_internal(const struct lu_env *env,
302                                        struct mdd_object *p,
303                                        struct mdd_object *c,
304                                        struct lu_attr *attr,
305                                        struct thandle *handle,
306                                        const struct md_op_spec *spec,
307                                        struct dt_allocation_hint *hint);
308 int mdd_get_lov_ea(const struct lu_env *env, struct mdd_object *obj,
309                    struct lu_buf *lmm_buf);
310
311 /* mdd_trans.c */
312 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
313                           struct mdd_object *child, const struct lu_attr *attr,
314                           const struct md_op_spec *spec,
315                           struct dt_allocation_hint *hint);
316
317 static inline void mdd_object_get(struct mdd_object *o)
318 {
319         lu_object_get(&o->mod_obj.mo_lu);
320 }
321
322 static inline void mdd_object_put(const struct lu_env *env,
323                                   struct mdd_object *o)
324 {
325         lu_object_put(env, &o->mod_obj.mo_lu);
326 }
327
328 struct thandle *mdd_trans_create(const struct lu_env *env,
329                                  struct mdd_device *mdd);
330 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
331                     struct thandle *th);
332 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
333                    int rc, struct thandle *handle);
334
335 /* mdd_device.c */
336 struct lu_object *mdd_object_alloc(const struct lu_env *env,
337                                    const struct lu_object_header *hdr,
338                                    struct lu_device *d);
339 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
340                           const struct lu_fid *pfid, const char *name,
341                           __u32 mode, struct lu_fid *fid);
342
343 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
344                   struct thandle *handle);
345 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
346                 struct lu_attr *attr, const struct lu_buf *buf, int fl);
347 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
348                        __u32 *mode);
349 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
350                               const struct lu_attr *la, int mask, int role);
351 int mdd_permission(const struct lu_env *env,
352                    struct md_object *pobj, struct md_object *cobj,
353                    struct md_attr *ma, int mask);
354 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
355                  struct lustre_capa *capa, int renewal);
356 int mdd_generic_thread_start(struct mdd_generic_thread *thread,
357                              int (*func)(void *), void *data, char *name);
358 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
359
360 /* mdd_prepare.c */
361 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
362
363 /* inline functions */
364 static inline int lu_device_is_mdd(struct lu_device *d)
365 {
366         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
367 }
368
369 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
370 {
371         LASSERT(lu_device_is_mdd(d));
372         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
373 }
374
375 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
376 {
377         return (&d->mdd_md_dev.md_lu_dev);
378 }
379
380 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
381 {
382         LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
383         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
384 }
385
386 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
387 {
388         return lu2mdd_dev(mdo->mo_lu.lo_dev);
389 }
390
391 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
392 {
393         return container_of0(mdo, struct mdd_object, mod_obj);
394 }
395
396 static inline const struct dt_device_operations *
397 mdd_child_ops(struct mdd_device *d)
398 {
399         return d->mdd_child->dd_ops;
400 }
401
402 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
403 {
404         return &obj->mod_obj.mo_lu;
405 }
406
407 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
408 {
409         return container_of0(lu_object_next(mdd2lu_obj(o)),
410                              struct dt_object, do_lu);
411 }
412
413 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
414 {
415         return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
416 }
417
418 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
419 {
420         return mdo2mdd(&obj->mod_obj);
421 }
422
423 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
424 {
425         return lu_object_fid(&obj->mod_obj.mo_lu);
426 }
427
428 static inline umode_t mdd_object_type(const struct mdd_object *obj)
429 {
430         return lu_object_attr(&obj->mod_obj.mo_lu);
431 }
432
433 static inline int mdd_is_immutable(struct mdd_object *obj)
434 {
435         return obj->mod_flags & IMMUTE_OBJ;
436 }
437
438 static inline int mdd_is_dead_obj(struct mdd_object *obj)
439 {
440         return obj && obj->mod_flags & DEAD_OBJ;
441 }
442
443 static inline int mdd_is_append(struct mdd_object *obj)
444 {
445         return obj->mod_flags & APPEND_OBJ;
446 }
447
448 static inline int mdd_object_exists(struct mdd_object *obj)
449 {
450         return lu_object_exists(mdd2lu_obj(obj));
451 }
452
453 static inline int mdd_object_remote(struct mdd_object *obj)
454 {
455         return lu_object_remote(mdd2lu_obj(obj));
456 }
457
458 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
459 {
460         return lu_object_fid(mdd2lu_obj(obj));
461 }
462
463 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
464 {
465         return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
466 }
467
468 static inline struct lustre_capa *mdd_object_capa(const struct lu_env *env,
469                                                   const struct mdd_object *obj)
470 {
471         struct lu_capainfo *lci = lu_capainfo_get(env);
472         const struct lu_fid *fid = mdo2fid(obj);
473         int i;
474
475         /* NB: in mdt_init0 */
476         if (lci == NULL)
477                 return BYPASS_CAPA;
478
479         for (i = 0; i < LU_CAPAINFO_MAX; i++)
480                 if (lu_fid_eq(&lci->lci_fid[i], fid))
481                         return lci->lci_capa[i];
482         return NULL;
483 }
484
485 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
486                                     const struct mdd_object *obj,
487                                     struct lustre_capa *capa)
488 {
489         struct lu_capainfo *lci = lu_capainfo_get(env);
490         const struct lu_fid *fid = mdo2fid(obj);
491
492         LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
493         /* NB: in mdt_init0 */
494         if (lci == NULL)
495                 return;
496
497         lci->lci_fid[offset]  = *fid;
498         lci->lci_capa[offset] = capa;
499 }
500
501 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
502 {
503         return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
504 }
505
506 #define MAX_ATIME_DIFF 60
507
508 static inline int mdd_permission_internal(const struct lu_env *env,
509                                           struct mdd_object *obj,
510                                           const struct lu_attr *la, int mask)
511 {
512         return __mdd_permission_internal(env, obj, la, mask, -1);
513 }
514
515 static inline int mdd_permission_internal_locked(const struct lu_env *env,
516                                                 struct mdd_object *obj,
517                                                 const struct lu_attr *la,
518                                                 int mask,
519                                                 enum mdd_object_role role)
520 {
521         return __mdd_permission_internal(env, obj, la, mask, role);
522 }
523
524 /* mdd inline func for calling osd_dt_object ops */
525 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
526                                struct lu_attr *la, struct lustre_capa *capa)
527 {
528         struct dt_object *next = mdd_object_child(obj);
529         return dt_attr_get(env, next, la, capa);
530 }
531
532 static inline int mdo_declare_attr_set(const struct lu_env *env,
533                                        struct mdd_object *obj,
534                                        const struct lu_attr *la,
535                                        struct thandle *handle)
536 {
537         struct dt_object *next = mdd_object_child(obj);
538         return dt_declare_attr_set(env, next, la, handle);
539 }
540
541 static inline int mdo_attr_set(const struct lu_env *env,
542                                struct mdd_object *obj,
543                                const struct lu_attr *la,
544                                struct thandle *handle,
545                                struct lustre_capa *capa)
546 {
547         struct dt_object *next = mdd_object_child(obj);
548
549         if (!mdd_object_exists(obj))
550                 return -ENOENT;
551
552         return dt_attr_set(env, next, la, handle, capa);
553 }
554
555 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
556                                 struct lu_buf *buf, const char *name,
557                                 struct lustre_capa *capa)
558 {
559         struct dt_object *next = mdd_object_child(obj);
560         return dt_xattr_get(env, next, buf, name, capa);
561 }
562
563 static inline int mdo_declare_xattr_set(const struct lu_env *env,
564                                         struct mdd_object *obj,
565                                         const struct lu_buf *buf,
566                                         const char *name,
567                                         int fl, struct thandle *handle)
568 {
569         struct dt_object *next = mdd_object_child(obj);
570         return dt_declare_xattr_set(env, next, buf, name, fl, handle);
571 }
572
573 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
574                                 const struct lu_buf *buf, const char *name,
575                                 int fl, struct thandle *handle,
576                                 struct lustre_capa *capa)
577 {
578         struct dt_object *next = mdd_object_child(obj);
579
580         if (!mdd_object_exists(obj))
581                 return -ENOENT;
582
583         return dt_xattr_set(env, next, buf, name, fl, handle, capa);
584 }
585
586 static inline int mdo_declare_xattr_del(const struct lu_env *env,
587                                         struct mdd_object *obj,
588                                         const char *name,
589                                         struct thandle *handle)
590 {
591         struct dt_object *next = mdd_object_child(obj);
592         return dt_declare_xattr_del(env, next, name, handle);
593 }
594
595 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
596                                 const char *name, struct thandle *handle,
597                                 struct lustre_capa *capa)
598 {
599         struct dt_object *next = mdd_object_child(obj);
600
601         if (!mdd_object_exists(obj))
602                 return -ENOENT;
603
604         return dt_xattr_del(env, next, name, handle, capa);
605 }
606
607 static inline int
608 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
609                struct lu_buf *buf, struct lustre_capa *capa)
610 {
611         struct dt_object *next = mdd_object_child(obj);
612
613         if (!mdd_object_exists(obj))
614                 return -ENOENT;
615
616         return dt_xattr_list(env, next, buf, capa);
617 }
618
619 static inline
620 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
621                              const struct lu_fid *fid, __u32 type,
622                              const char *name, struct thandle *handle)
623 {
624         struct dt_object *next  = mdd_object_child(obj);
625         int               rc    = 0;
626
627         /*
628          * if the object doesn't exist yet, then it's supposed to be created
629          * and declaration of the creation should be enough to insert ./..
630          */
631
632          /* FIXME: remote object should not be awared by MDD layer, but local
633           * creation does not declare insert ./.. (comments above), which
634           * is required by remote directory creation.
635           * This remote check should be removed when mdd_object_exists check is
636           * removed.
637           */
638         if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
639                 rc = -ENOTDIR;
640                 if (dt_try_as_dir(env, next)) {
641                         struct dt_insert_rec *rec =
642                                         &mdd_env_info(env)->mti_dt_rec;
643
644                         rec->rec_fid = fid;
645                         rec->rec_type = type;
646                         rc = dt_declare_insert(env, next,
647                                                (const struct dt_rec *)rec,
648                                                (const struct dt_key *)name,
649                                                handle);
650                 }
651          }
652
653          return rc;
654 }
655
656 static inline
657 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
658                              const char *name, struct thandle *handle)
659 {
660         struct dt_object *next = mdd_object_child(obj);
661
662         if (!dt_try_as_dir(env, next))
663                 return -ENOTDIR;
664
665         return dt_declare_delete(env, next, (const struct dt_key *)name,
666                                  handle);
667 }
668
669 static inline int mdo_declare_ref_add(const struct lu_env *env,
670                                       struct mdd_object *obj,
671                                       struct thandle *handle)
672 {
673         struct dt_object *next = mdd_object_child(obj);
674         return dt_declare_ref_add(env, next, handle);
675 }
676
677 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
678                               struct thandle *handle)
679 {
680         struct dt_object *next = mdd_object_child(obj);
681
682         if (!mdd_object_exists(obj))
683                 return -ENOENT;
684
685         return dt_ref_add(env, next, handle);
686 }
687
688 static inline int mdo_declare_ref_del(const struct lu_env *env,
689                                       struct mdd_object *obj,
690                                       struct thandle *handle)
691 {
692         struct dt_object *next = mdd_object_child(obj);
693         return dt_declare_ref_del(env, next, handle);
694 }
695
696 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
697                               struct thandle *handle)
698 {
699         struct dt_object *next = mdd_object_child(obj);
700
701         if (!mdd_object_exists(obj))
702                 return -ENOENT;
703
704         return dt_ref_del(env, next, handle);
705 }
706
707 static inline int
708 mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
709                        struct lu_attr *attr,
710                        struct dt_allocation_hint *hint,
711                        struct dt_object_format *dof,
712                        struct thandle *handle)
713 {
714         struct dt_object *next = mdd_object_child(o);
715         return dt_declare_create(env, next, attr, hint, dof, handle);
716 }
717
718 static inline int
719 mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
720                struct lu_attr *attr,
721                struct dt_allocation_hint *hint,
722                struct dt_object_format *dof,
723                struct thandle *handle)
724 {
725         struct dt_object *next = mdd_object_child(o);
726         return dt_create(env, next, attr, hint, dof, handle);
727 }
728
729 static inline
730 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
731                         struct thandle *handle)
732 {
733         struct dt_object *next = mdd_object_child(o);
734         return dt_declare_destroy(env, next, handle);
735 }
736
737 static inline
738 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
739                 struct thandle *handle)
740 {
741         struct dt_object *next = mdd_object_child(o);
742         return dt_destroy(env, next, handle);
743 }
744
745 static inline struct obd_capa *
746 mdo_capa_get(const struct lu_env *env, struct mdd_object *obj,
747              struct lustre_capa *old, __u64 opc)
748 {
749         struct dt_object *next = mdd_object_child(obj);
750
751         if (!mdd_object_exists(obj))
752                 return ERR_PTR(-ENOENT);
753
754         return dt_capa_get(env, next, old, opc);
755 }
756
757 #endif