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