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