Whamcloud - gitweb
LU-9727 lustre: add uid/gid to Changelogs entries
[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 #define LLOG_CHANGELOG_HDR_SZ (sizeof(struct llog_changelog_rec) - \
65                                sizeof(struct changelog_rec))
66
67 struct mdd_changelog {
68         spinlock_t              mc_lock;        /* for index */
69         int                     mc_flags;
70         int                     mc_mask;
71         __u64                   mc_index;
72         ktime_t                 mc_starttime;
73         spinlock_t              mc_user_lock;
74         int                     mc_lastuser;
75 };
76
77 static inline __u64 cl_time(void)
78 {
79         struct timespec64 time;
80
81         ktime_get_real_ts64(&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         ORPHAN_OBJ = 1 << 1,
123         VOLATILE_OBJ = 1 << 4,
124 };
125
126 struct mdd_object {
127         struct md_object        mod_obj;
128         /* open count */
129         u32                     mod_count;
130         u32                     mod_valid;
131         ktime_t                 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 lu_buf             mti_xattr_buf;
157         struct obdo               mti_oa;
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_req_local    mti_lrl;
164         struct lu_seq_range       mti_range;
165 };
166
167 extern const char orph_index_name[];
168
169 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
170                struct lu_attr *la);
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_create_object_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_write(const struct lu_env *env, struct mdd_object *mdd_obj,
223                     struct linkea_data *ldata, struct thandle *handle);
224 struct lu_buf *mdd_links_get(const struct lu_env *env,
225                              struct mdd_object *mdd_obj);
226 int mdd_links_rename(const struct lu_env *env,
227                      struct mdd_object *mdd_obj,
228                      const struct lu_fid *oldpfid,
229                      const struct lu_name *oldlname,
230                      const struct lu_fid *newpfid,
231                      const struct lu_name *newlname,
232                      struct thandle *handle,
233                      struct linkea_data *ldata,
234                      int first, int check);
235
236 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
237
238 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
239
240 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
241 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
242                                        const void *area, ssize_t len);
243
244 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
245 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
246                      struct thandle *);
247 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
248                      struct thandle *);
249 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
250 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
251 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
252                               umode_t mode, struct thandle *);
253 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
254                               struct thandle *);
255
256 /* mdd_lproc.c */
257 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
258 void mdd_procfs_fini(struct mdd_device *mdd);
259
260 /* mdd_object.c */
261 extern struct kmem_cache *mdd_object_kmem;
262 extern const struct md_dir_operations    mdd_dir_ops;
263 extern const struct md_object_operations mdd_obj_ops;
264 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
265                  struct lu_buf *buf);
266 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
267 extern struct lu_context_key mdd_thread_key;
268 extern const struct lu_device_operations mdd_lu_ops;
269
270 struct mdd_object *mdd_object_find(const struct lu_env *env,
271                                    struct mdd_device *d,
272                                    const struct lu_fid *f);
273 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
274                  const struct lu_rdpg *rdpg);
275 int mdd_declare_changelog_store(const struct lu_env *env,
276                                        struct mdd_device *mdd,
277                                        const struct lu_name *tname,
278                                        const struct lu_name *sname,
279                                        struct thandle *handle);
280 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
281 void mdd_changelog_rec_ext_extra_flags(struct changelog_rec *rec, __u64 eflags);
282 void mdd_changelog_rec_extra_uidgid(struct changelog_rec *rec,
283                                     __u64 uid, __u64 gid);
284 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
285                         struct llog_changelog_rec *rec, struct thandle *th);
286 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
287                              enum changelog_rec_type type, int flags,
288                              struct mdd_object *mdd_obj,
289                              struct thandle *handle);
290 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
291                            enum changelog_rec_type type,
292                            enum changelog_rec_flags crf,
293                            struct mdd_object *target,
294                            const struct lu_fid *tpfid,
295                            const struct lu_fid *sfid,
296                            const struct lu_fid *spfid,
297                            const struct lu_name *tname,
298                            const struct lu_name *sname,
299                            struct thandle *handle);
300 int mdd_invalidate(const struct lu_env *env, struct md_object *obj);
301 int mdd_declare_create_object_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_generic_thread_start(struct mdd_generic_thread *thread,
355                              int (*func)(void *), void *data, char *name);
356 void mdd_generic_thread_stop(struct mdd_generic_thread *thread);
357
358 /* mdd_prepare.c */
359 int mdd_compat_fixes(const struct lu_env *env, struct mdd_device *mdd);
360
361 /* inline functions */
362 static inline int lu_device_is_mdd(struct lu_device *d)
363 {
364         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
365 }
366
367 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
368 {
369         LASSERT(lu_device_is_mdd(d));
370         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
371 }
372
373 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
374 {
375         return (&d->mdd_md_dev.md_lu_dev);
376 }
377
378 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
379 {
380         LASSERT(ergo(o != NULL, lu_device_is_mdd(o->lo_dev)));
381         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
382 }
383
384 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
385 {
386         return lu2mdd_dev(mdo->mo_lu.lo_dev);
387 }
388
389 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
390 {
391         return container_of0(mdo, struct mdd_object, mod_obj);
392 }
393
394 static inline const struct dt_device_operations *
395 mdd_child_ops(struct mdd_device *d)
396 {
397         return d->mdd_child->dd_ops;
398 }
399
400 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
401 {
402         return &obj->mod_obj.mo_lu;
403 }
404
405 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
406 {
407         return container_of0(lu_object_next(mdd2lu_obj(o)),
408                              struct dt_object, do_lu);
409 }
410
411 static inline struct obd_device *mdd2obd_dev(struct mdd_device *mdd)
412 {
413         return (mdd->mdd_md_dev.md_lu_dev.ld_obd);
414 }
415
416 static inline struct mdd_device *mdd_obj2mdd_dev(struct mdd_object *obj)
417 {
418         return mdo2mdd(&obj->mod_obj);
419 }
420
421 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
422 {
423         return lu_object_fid(&obj->mod_obj.mo_lu);
424 }
425
426 static inline umode_t mdd_object_type(const struct mdd_object *obj)
427 {
428         return lu_object_attr(&obj->mod_obj.mo_lu);
429 }
430
431 static inline int mdd_is_dead_obj(struct mdd_object *obj)
432 {
433         return obj && obj->mod_flags & DEAD_OBJ;
434 }
435
436 static inline bool mdd_is_volatile_obj(struct mdd_object *obj)
437 {
438         return obj->mod_flags & VOLATILE_OBJ;
439 }
440
441 static inline int mdd_object_exists(struct mdd_object *obj)
442 {
443         return lu_object_exists(mdd2lu_obj(obj));
444 }
445
446 static inline int mdd_object_remote(struct mdd_object *obj)
447 {
448         return lu_object_remote(mdd2lu_obj(obj));
449 }
450
451 static inline const struct lu_fid *mdd_object_fid(struct mdd_object *obj)
452 {
453         return lu_object_fid(mdd2lu_obj(obj));
454 }
455
456 static inline struct seq_server_site *mdd_seq_site(struct mdd_device *mdd)
457 {
458         return mdd2lu_dev(mdd)->ld_site->ld_seq_site;
459 }
460
461 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
462 {
463         return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
464 }
465
466 #define MAX_ATIME_DIFF 60
467
468 static inline int mdd_permission_internal(const struct lu_env *env,
469                                           struct mdd_object *obj,
470                                           const struct lu_attr *la, int mask)
471 {
472         return __mdd_permission_internal(env, obj, la, mask, -1);
473 }
474
475 static inline int mdd_permission_internal_locked(const struct lu_env *env,
476                                                 struct mdd_object *obj,
477                                                 const struct lu_attr *la,
478                                                 int mask,
479                                                 enum mdd_object_role role)
480 {
481         return __mdd_permission_internal(env, obj, la, mask, role);
482 }
483
484 /* mdd inline func for calling osd_dt_object ops */
485 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
486                                struct lu_attr *la)
487 {
488         struct dt_object *next = mdd_object_child(obj);
489         return dt_attr_get(env, next, la);
490 }
491
492 static inline int mdo_declare_attr_set(const struct lu_env *env,
493                                        struct mdd_object *obj,
494                                        const struct lu_attr *la,
495                                        struct thandle *handle)
496 {
497         struct dt_object *next = mdd_object_child(obj);
498         return dt_declare_attr_set(env, next, la, handle);
499 }
500
501 static inline int mdo_attr_set(const struct lu_env *env,
502                                struct mdd_object *obj,
503                                const struct lu_attr *la,
504                                struct thandle *handle)
505 {
506         struct dt_object *next = mdd_object_child(obj);
507
508         if (!mdd_object_exists(obj))
509                 return -ENOENT;
510
511         return dt_attr_set(env, next, la, handle);
512 }
513
514 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
515                                 struct lu_buf *buf, const char *name)
516 {
517         struct dt_object *next = mdd_object_child(obj);
518         return dt_xattr_get(env, next, buf, name);
519 }
520
521 static inline int mdo_declare_xattr_set(const struct lu_env *env,
522                                         struct mdd_object *obj,
523                                         const struct lu_buf *buf,
524                                         const char *name,
525                                         int fl, struct thandle *handle)
526 {
527         struct dt_object *next = mdd_object_child(obj);
528         return dt_declare_xattr_set(env, next, buf, name, fl, handle);
529 }
530
531 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
532                                 const struct lu_buf *buf, const char *name,
533                                 int fl, struct thandle *handle)
534 {
535         struct dt_object *next = mdd_object_child(obj);
536
537         if (!mdd_object_exists(obj))
538                 return -ENOENT;
539
540         return dt_xattr_set(env, next, buf, name, fl, handle);
541 }
542
543 static inline int mdo_declare_xattr_del(const struct lu_env *env,
544                                         struct mdd_object *obj,
545                                         const char *name,
546                                         struct thandle *handle)
547 {
548         struct dt_object *next = mdd_object_child(obj);
549         return dt_declare_xattr_del(env, next, name, handle);
550 }
551
552 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
553                                 const char *name, struct thandle *handle)
554 {
555         struct dt_object *next = mdd_object_child(obj);
556
557         if (!mdd_object_exists(obj))
558                 return -ENOENT;
559
560         return dt_xattr_del(env, next, name, handle);
561 }
562
563 static inline int
564 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
565                struct lu_buf *buf)
566 {
567         struct dt_object *next = mdd_object_child(obj);
568
569         if (!mdd_object_exists(obj))
570                 return -ENOENT;
571
572         return dt_xattr_list(env, next, buf);
573 }
574
575 static inline int
576 mdo_invalidate(const struct lu_env *env, struct mdd_object *obj)
577 {
578         return dt_invalidate(env, mdd_object_child(obj));
579 }
580
581 static inline int
582 mdo_declare_layout_change(const struct lu_env *env, struct mdd_object *obj,
583                           struct md_layout_change *mlc, struct thandle *handle)
584 {
585         return dt_declare_layout_change(env, mdd_object_child(obj),
586                                         mlc, handle);
587 }
588
589 static inline int
590 mdo_layout_change(const struct lu_env *env, struct mdd_object *obj,
591                   struct md_layout_change *mlc, struct thandle *handle)
592 {
593         return dt_layout_change(env, mdd_object_child(obj), mlc, handle);
594 }
595
596 static inline
597 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
598                              const struct lu_fid *fid, __u32 type,
599                              const char *name, struct thandle *handle)
600 {
601         struct dt_object *next  = mdd_object_child(obj);
602         int               rc;
603
604         /*
605          * if the object doesn't exist yet, then it's supposed to be created
606          * and declaration of the creation should be enough to insert ./..
607          */
608
609         rc = -ENOTDIR;
610         if (dt_try_as_dir(env, next)) {
611                 struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
612
613                 rec->rec_fid = fid;
614                 rec->rec_type = type;
615                 rc = dt_declare_insert(env, next, (const struct dt_rec *)rec,
616                                        (const struct dt_key *)name, handle);
617         }
618
619          return rc;
620 }
621
622 static inline
623 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
624                              const char *name, struct thandle *handle)
625 {
626         struct dt_object *next = mdd_object_child(obj);
627
628         if (!dt_try_as_dir(env, next))
629                 return -ENOTDIR;
630
631         return dt_declare_delete(env, next, (const struct dt_key *)name,
632                                  handle);
633 }
634
635 static inline int mdo_declare_ref_add(const struct lu_env *env,
636                                       struct mdd_object *obj,
637                                       struct thandle *handle)
638 {
639         struct dt_object *next = mdd_object_child(obj);
640         return dt_declare_ref_add(env, next, handle);
641 }
642
643 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
644                               struct thandle *handle)
645 {
646         struct dt_object *next = mdd_object_child(obj);
647
648         if (!mdd_object_exists(obj))
649                 return -ENOENT;
650
651         return dt_ref_add(env, next, handle);
652 }
653
654 static inline int mdo_declare_ref_del(const struct lu_env *env,
655                                       struct mdd_object *obj,
656                                       struct thandle *handle)
657 {
658         struct dt_object *next = mdd_object_child(obj);
659         return dt_declare_ref_del(env, next, handle);
660 }
661
662 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
663                               struct thandle *handle)
664 {
665         struct dt_object *next = mdd_object_child(obj);
666
667         if (!mdd_object_exists(obj))
668                 return -ENOENT;
669
670         return dt_ref_del(env, next, handle);
671 }
672
673 static inline int
674 mdo_declare_create_object(const struct lu_env *env, struct mdd_object *obj,
675                           struct lu_attr *attr, struct dt_allocation_hint *hint,
676                           struct dt_object_format *dof, struct thandle *handle)
677 {
678         struct dt_object *next = mdd_object_child(obj);
679         return dt_declare_create(env, next, attr, hint, dof, handle);
680 }
681
682 static inline int
683 mdo_create_object(const struct lu_env *env, struct mdd_object *obj,
684                   struct lu_attr *attr, struct dt_allocation_hint *hint,
685                   struct dt_object_format *dof, struct thandle *handle)
686 {
687         struct dt_object *next = mdd_object_child(obj);
688         return dt_create(env, next, attr, hint, dof, handle);
689 }
690
691 static inline
692 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
693                         struct thandle *handle)
694 {
695         struct dt_object *next = mdd_object_child(o);
696         return dt_declare_destroy(env, next, handle);
697 }
698
699 static inline
700 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
701                 struct thandle *handle)
702 {
703         struct dt_object *next = mdd_object_child(o);
704         return dt_destroy(env, next, handle);
705 }
706
707 #endif