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