Whamcloud - gitweb
LU-6245 libcfs: remove cfs_fs_time handling
[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, 2014, 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_compat.h>
46 #include <lustre_eacl.h>
47 #include <md_object.h>
48 #include <dt_object.h>
49 #include <lustre_lfsck.h>
50 #include <lustre_fid.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 {
80         struct timespec64 time;
81
82         ktime_get_real_ts64(&time);
83         return (((__u64)time.tv_sec) << 30) + time.tv_nsec;
84 }
85
86 /** Objects in .lustre dir */
87 struct mdd_dot_lustre_objs {
88         struct mdd_object *mdd_obf;
89         struct mdd_object *mdd_lpf;
90 };
91
92 struct mdd_generic_thread {
93         struct completion       mgt_started;
94         struct completion       mgt_finished;
95         void                   *mgt_data;
96         bool                    mgt_abort;
97         bool                    mgt_init;
98 };
99
100 struct mdd_device {
101         struct md_device                 mdd_md_dev;
102         struct obd_export               *mdd_child_exp;
103         struct dt_device                *mdd_child;
104         struct dt_device                *mdd_bottom;
105         struct lu_fid                    mdd_root_fid; /* /ROOT */
106         struct lu_fid                    mdd_local_root_fid;
107         struct dt_device_param           mdd_dt_conf;
108         struct dt_object                *mdd_orphans; /* PENDING directory */
109         struct proc_dir_entry            *mdd_proc_entry;
110         struct mdd_changelog             mdd_cl;
111         unsigned long                    mdd_atime_diff;
112         struct mdd_object               *mdd_dot_lustre;
113         struct mdd_dot_lustre_objs       mdd_dot_lustre_objs;
114         unsigned int                     mdd_sync_permission;
115         int                              mdd_connects;
116         struct local_oid_storage        *mdd_los;
117         struct mdd_generic_thread        mdd_orph_cleanup_thread;
118 };
119
120 enum mod_flags {
121         /* The dir object has been unlinked */
122         DEAD_OBJ   = 1 << 0,
123         ORPHAN_OBJ = 1 << 1,
124 };
125
126 struct mdd_object {
127         struct md_object   mod_obj;
128         /* open count */
129         __u32             mod_count;
130         __u32             mod_valid;
131         __u64             mod_cltime;
132         unsigned long     mod_flags;
133 };
134
135 struct mdd_thread_info {
136         struct lu_fid             mti_fid;
137         struct lu_fid             mti_fid2; /* used for be & cpu converting */
138         /**
139         * only be used by MDD interfaces, can be passed into local MDD APIs.
140         */
141         struct lu_attr            mti_pattr;
142         struct lu_attr            mti_cattr;
143         struct lu_attr            mti_tpattr;
144         struct lu_attr            mti_tattr;
145         /** used to set c/mtime */
146         struct lu_attr            mti_la_for_fix;
147         /* Only used in mdd_object_start */
148         struct lu_attr            mti_la_for_start;
149         /* mti_ent and mti_key must be conjoint,
150         * then mti_ent::lde_name will be mti_key. */
151         struct lu_dirent          mti_ent;
152         char                      mti_key[NAME_MAX + 16];
153         struct lu_buf             mti_buf[4];
154         struct lu_buf             mti_big_buf; /* biggish persistent buf */
155         struct lu_buf             mti_link_buf; /* buf for link ea */
156         struct obdo               mti_oa;
157         char                      mti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE];
158         struct dt_allocation_hint mti_hint;
159         struct dt_object_format   mti_dof;
160         struct linkea_data        mti_link_data;
161         struct md_op_spec         mti_spec;
162         struct dt_insert_rec      mti_dt_rec;
163         struct lfsck_request      mti_lr;
164         struct lu_seq_range       mti_range;
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);
176 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
177                  struct md_attr *ma);
178 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
179                  const struct md_attr *ma);
180 int mdd_attr_set_internal(const struct lu_env *env,
181                           struct mdd_object *obj,
182                           const struct lu_attr *attr,
183                           struct thandle *handle,
184                           int needacl);
185 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
186                     const struct lu_attr *oattr, struct lu_attr *attr,
187                     struct thandle *handle);
188 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
189                                struct mdd_object *c, struct lu_attr *attr,
190                                struct thandle *handle,
191                                const struct md_op_spec *spec,
192                                struct dt_allocation_hint *hint);
193
194 /* mdd_lock.c */
195 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
196                     enum mdd_object_role role);
197 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
198                    enum mdd_object_role role);
199 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
200 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
201 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
202
203 /* mdd_dir.c */
204 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
205                   const struct lu_fid *fid, struct lu_fid *sfid);
206 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
207                    const struct lu_attr *pattr, struct mdd_object *cobj,
208                    bool check_perm);
209 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
210                    const struct lu_attr *pattr, const struct lu_attr *attr);
211 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
212                    const struct lu_attr *tpattr, struct mdd_object *tobj,
213                    const struct lu_attr *tattr, const struct lu_attr *cattr,
214                    int check_perm, int check_empty);
215 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
216                             const struct lu_attr *pattr,
217                             struct mdd_object *cobj,
218                             const struct lu_attr *cattr);
219 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
220                       struct md_attr *ma, const struct mdd_object *pobj,
221                       const struct lu_name *lname, struct thandle *th);
222
223 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
224 int mdd_lookup(const struct lu_env *env,
225                struct md_object *pobj, const struct lu_name *lname,
226                struct lu_fid* fid, struct md_op_spec *spec);
227 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
228                    struct linkea_data *ldata);
229 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
230                           struct thandle *handle, struct linkea_data *ldata,
231                           enum mdd_links_add_overflow overflow);
232 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
233                     struct linkea_data *ldata, struct thandle *handle);
234 struct lu_buf *mdd_links_get(const struct lu_env *env,
235                              struct mdd_object *mdd_obj);
236 int mdd_links_rename(const struct lu_env *env,
237                      struct mdd_object *mdd_obj,
238                      const struct lu_fid *oldpfid,
239                      const struct lu_name *oldlname,
240                      const struct lu_fid *newpfid,
241                      const struct lu_name *newlname,
242                      struct thandle *handle,
243                      struct linkea_data *ldata,
244                      int first, int check);
245
246 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
247
248 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
249
250 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
251 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
252                                        const void *area, ssize_t len);
253
254 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
255 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
256                      struct thandle *);
257 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
258                      struct thandle *);
259 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
260 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
261 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
262                               umode_t mode, struct thandle *);
263 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
264                               struct thandle *);
265
266 /* mdd_lproc.c */
267 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
268 void mdd_procfs_fini(struct mdd_device *mdd);
269
270 /* mdd_object.c */
271 extern struct kmem_cache *mdd_object_kmem;
272 extern const struct md_dir_operations    mdd_dir_ops;
273 extern const struct md_object_operations mdd_obj_ops;
274 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
275                  struct lu_buf *buf);
276 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
277 extern struct lu_context_key mdd_thread_key;
278 extern const struct lu_device_operations mdd_lu_ops;
279
280 struct mdd_object *mdd_object_find(const struct lu_env *env,
281                                    struct mdd_device *d,
282                                    const struct lu_fid *f);
283 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
284                  const struct lu_rdpg *rdpg);
285 int mdd_declare_changelog_store(const struct lu_env *env,
286                                        struct mdd_device *mdd,
287                                        const struct lu_name *tname,
288                                        const struct lu_name *sname,
289                                        struct thandle *handle);
290 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
291 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
292                         struct llog_changelog_rec *rec, struct thandle *th);
293 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
294                              enum changelog_rec_type type, int flags,
295                              struct mdd_object *mdd_obj,
296                              struct thandle *handle);
297 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
298                            enum changelog_rec_type type,
299                            enum changelog_rec_flags crf,
300                            struct mdd_object *target,
301                            const struct lu_fid *tpfid,
302                            const struct lu_fid *sfid,
303                            const struct lu_fid *spfid,
304                            const struct lu_name *tname,
305                            const struct lu_name *sname,
306                            struct thandle *handle);
307 int mdd_invalidate(const struct lu_env *env, struct md_object *obj);
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_generic_thread_start(struct mdd_generic_thread *thread,
362                              int (*func)(void *), void *data, char *name);
363 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
364
365 /* mdd_prepare.c */
366 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
367
368 /* inline functions */
369 static inline int lu_device_is_mdd(struct lu_device *d)
370 {
371         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
372 }
373
374 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
375 {
376         LASSERT(lu_device_is_mdd(d));
377         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
378 }
379
380 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
381 {
382         return (&d->mdd_md_dev.md_lu_dev);
383 }
384
385 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
386 {
387         LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
388         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
389 }
390
391 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
392 {
393         return lu2mdd_dev(mdo->mo_lu.lo_dev);
394 }
395
396 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
397 {
398         return container_of0(mdo, struct mdd_object, mod_obj);
399 }
400
401 static inline const struct dt_device_operations *
402 mdd_child_ops(struct mdd_device *d)
403 {
404         return d->mdd_child->dd_ops;
405 }
406
407 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
408 {
409         return &obj->mod_obj.mo_lu;
410 }
411
412 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
413 {
414         return container_of0(lu_object_next(mdd2lu_obj(o)),
415                              struct dt_object, do_lu);
416 }
417
418 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
419 {
420         return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
421 }
422
423 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
424 {
425         return mdo2mdd(&obj->mod_obj);
426 }
427
428 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
429 {
430         return lu_object_fid(&obj->mod_obj.mo_lu);
431 }
432
433 static inline umode_t mdd_object_type(const struct mdd_object *obj)
434 {
435         return lu_object_attr(&obj->mod_obj.mo_lu);
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_object_exists(struct mdd_object *obj)
444 {
445         return lu_object_exists(mdd2lu_obj(obj));
446 }
447
448 static inline int mdd_object_remote(struct mdd_object *obj)
449 {
450         return lu_object_remote(mdd2lu_obj(obj));
451 }
452
453 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
454 {
455         return lu_object_fid(mdd2lu_obj(obj));
456 }
457
458 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
459 {
460         return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
461 }
462
463 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
464 {
465         return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
466 }
467
468 #define MAX_ATIME_DIFF 60
469
470 static inline int mdd_permission_internal(const struct lu_env *env,
471                                           struct mdd_object *obj,
472                                           const struct lu_attr *la, int mask)
473 {
474         return __mdd_permission_internal(env, obj, la, mask, -1);
475 }
476
477 static inline int mdd_permission_internal_locked(const struct lu_env *env,
478                                                 struct mdd_object *obj,
479                                                 const struct lu_attr *la,
480                                                 int mask,
481                                                 enum mdd_object_role role)
482 {
483         return __mdd_permission_internal(env, obj, la, mask, role);
484 }
485
486 /* mdd inline func for calling osd_dt_object ops */
487 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
488                                struct lu_attr *la)
489 {
490         struct dt_object *next = mdd_object_child(obj);
491         return dt_attr_get(env, next, la);
492 }
493
494 static inline int mdo_declare_attr_set(const struct lu_env *env,
495                                        struct mdd_object *obj,
496                                        const struct lu_attr *la,
497                                        struct thandle *handle)
498 {
499         struct dt_object *next = mdd_object_child(obj);
500         return dt_declare_attr_set(env, next, la, handle);
501 }
502
503 static inline int mdo_attr_set(const struct lu_env *env,
504                                struct mdd_object *obj,
505                                const struct lu_attr *la,
506                                struct thandle *handle)
507 {
508         struct dt_object *next = mdd_object_child(obj);
509
510         if (!mdd_object_exists(obj))
511                 return -ENOENT;
512
513         return dt_attr_set(env, next, la, handle);
514 }
515
516 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
517                                 struct lu_buf *buf, const char *name)
518 {
519         struct dt_object *next = mdd_object_child(obj);
520         return dt_xattr_get(env, next, buf, name);
521 }
522
523 static inline int mdo_declare_xattr_set(const struct lu_env *env,
524                                         struct mdd_object *obj,
525                                         const struct lu_buf *buf,
526                                         const char *name,
527                                         int fl, struct thandle *handle)
528 {
529         struct dt_object *next = mdd_object_child(obj);
530         return dt_declare_xattr_set(env, next, buf, name, fl, handle);
531 }
532
533 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
534                                 const struct lu_buf *buf, const char *name,
535                                 int fl, struct thandle *handle)
536 {
537         struct dt_object *next = mdd_object_child(obj);
538
539         if (!mdd_object_exists(obj))
540                 return -ENOENT;
541
542         return dt_xattr_set(env, next, buf, name, fl, handle);
543 }
544
545 static inline int mdo_declare_xattr_del(const struct lu_env *env,
546                                         struct mdd_object *obj,
547                                         const char *name,
548                                         struct thandle *handle)
549 {
550         struct dt_object *next = mdd_object_child(obj);
551         return dt_declare_xattr_del(env, next, name, handle);
552 }
553
554 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
555                                 const char *name, struct thandle *handle)
556 {
557         struct dt_object *next = mdd_object_child(obj);
558
559         if (!mdd_object_exists(obj))
560                 return -ENOENT;
561
562         return dt_xattr_del(env, next, name, handle);
563 }
564
565 static inline int
566 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
567                struct lu_buf *buf)
568 {
569         struct dt_object *next = mdd_object_child(obj);
570
571         if (!mdd_object_exists(obj))
572                 return -ENOENT;
573
574         return dt_xattr_list(env, next, buf);
575 }
576
577 static inline int
578 mdo_invalidate(const struct lu_env *env, struct mdd_object *obj)
579 {
580         return dt_invalidate(env, mdd_object_child(obj));
581 }
582
583 static inline
584 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
585                              const struct lu_fid *fid, __u32 type,
586                              const char *name, struct thandle *handle)
587 {
588         struct dt_object *next  = mdd_object_child(obj);
589         int               rc;
590
591         /*
592          * if the object doesn't exist yet, then it's supposed to be created
593          * and declaration of the creation should be enough to insert ./..
594          */
595
596         rc = -ENOTDIR;
597         if (dt_try_as_dir(env, next)) {
598                 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
599
600                 rec->rec_fid = fid;
601                 rec->rec_type = type;
602                 rc = dt_declare_insert(env, next, (const struct dt_rec *)rec,
603                                        (const struct dt_key *)name, handle);
604         }
605
606          return rc;
607 }
608
609 static inline
610 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
611                              const char *name, struct thandle *handle)
612 {
613         struct dt_object *next = mdd_object_child(obj);
614
615         if (!dt_try_as_dir(env, next))
616                 return -ENOTDIR;
617
618         return dt_declare_delete(env, next, (const struct dt_key *)name,
619                                  handle);
620 }
621
622 static inline int mdo_declare_ref_add(const struct lu_env *env,
623                                       struct mdd_object *obj,
624                                       struct thandle *handle)
625 {
626         struct dt_object *next = mdd_object_child(obj);
627         return dt_declare_ref_add(env, next, handle);
628 }
629
630 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
631                               struct thandle *handle)
632 {
633         struct dt_object *next = mdd_object_child(obj);
634
635         if (!mdd_object_exists(obj))
636                 return -ENOENT;
637
638         return dt_ref_add(env, next, handle);
639 }
640
641 static inline int mdo_declare_ref_del(const struct lu_env *env,
642                                       struct mdd_object *obj,
643                                       struct thandle *handle)
644 {
645         struct dt_object *next = mdd_object_child(obj);
646         return dt_declare_ref_del(env, next, handle);
647 }
648
649 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
650                               struct thandle *handle)
651 {
652         struct dt_object *next = mdd_object_child(obj);
653
654         if (!mdd_object_exists(obj))
655                 return -ENOENT;
656
657         return dt_ref_del(env, next, handle);
658 }
659
660 static inline int
661 mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
662                        struct lu_attr *attr,
663                        struct dt_allocation_hint *hint,
664                        struct dt_object_format *dof,
665                        struct thandle *handle)
666 {
667         struct dt_object *next = mdd_object_child(o);
668         return dt_declare_create(env, next, attr, hint, dof, handle);
669 }
670
671 static inline int
672 mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
673                struct lu_attr *attr,
674                struct dt_allocation_hint *hint,
675                struct dt_object_format *dof,
676                struct thandle *handle)
677 {
678         struct dt_object *next = mdd_object_child(o);
679         return dt_create(env, next, attr, hint, dof, handle);
680 }
681
682 static inline
683 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
684                         struct thandle *handle)
685 {
686         struct dt_object *next = mdd_object_child(o);
687         return dt_declare_destroy(env, next, handle);
688 }
689
690 static inline
691 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
692                 struct thandle *handle)
693 {
694         struct dt_object *next = mdd_object_child(o);
695         return dt_destroy(env, next, handle);
696 }
697
698 #endif