Whamcloud - gitweb
c6b76f5dd23fe6c19b11ea0850afad0b19ce9e8e
[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, 2013, 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_eacl.h>
46 #include <md_object.h>
47 #include <dt_object.h>
48 #include <lustre_lfsck.h>
49 #include <lustre_fid.h>
50 #include <lustre_capa.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 };
164
165 enum mdd_links_add_overflow {
166         MLAO_IGNORE     = false,
167         MLAO_CHECK      = true,
168 };
169
170 extern const char orph_index_name[];
171
172 int mdd_la_get(const struct lu_env *env, struct mdd_object *obj,
173                struct lu_attr *la, struct lustre_capa *capa);
174 int mdd_attr_get(const struct lu_env *env, struct md_object *obj,
175                  struct md_attr *ma);
176 int mdd_attr_set(const struct lu_env *env, struct md_object *obj,
177                  const struct md_attr *ma);
178 int mdd_attr_set_internal(const struct lu_env *env,
179                           struct mdd_object *obj,
180                           const struct lu_attr *attr,
181                           struct thandle *handle,
182                           int needacl);
183 int mdd_update_time(const struct lu_env *env, struct mdd_object *obj,
184                     const struct lu_attr *oattr, struct lu_attr *attr,
185                     struct thandle *handle);
186 int mdd_object_create_internal(const struct lu_env *env, struct mdd_object *p,
187                                struct mdd_object *c, struct lu_attr *attr,
188                                struct thandle *handle,
189                                const struct md_op_spec *spec,
190                                struct dt_allocation_hint *hint);
191
192 /* mdd_lock.c */
193 void mdd_write_lock(const struct lu_env *env, struct mdd_object *obj,
194                     enum mdd_object_role role);
195 void mdd_read_lock(const struct lu_env *env, struct mdd_object *obj,
196                    enum mdd_object_role role);
197 void mdd_write_unlock(const struct lu_env *env, struct mdd_object *obj);
198 void mdd_read_unlock(const struct lu_env *env, struct mdd_object *obj);
199 int mdd_write_locked(const struct lu_env *env, struct mdd_object *obj);
200
201 /* mdd_dir.c */
202 int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
203                   const struct lu_fid *fid, struct lu_fid *sfid);
204 int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
205                    const struct lu_attr *pattr, struct mdd_object *cobj,
206                    bool check_perm);
207 int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
208                    const struct lu_attr *pattr, const struct lu_attr *attr);
209 int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
210                    const struct lu_attr *tpattr, struct mdd_object *tobj,
211                    const struct lu_attr *tattr, const struct lu_attr *cattr,
212                    int check_perm, int check_empty);
213 int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
214                             const struct lu_attr *pattr,
215                             struct mdd_object *cobj,
216                             const struct lu_attr *cattr);
217 int mdd_finish_unlink(const struct lu_env *env, struct mdd_object *obj,
218                       struct md_attr *ma, const struct mdd_object *pobj,
219                       const struct lu_name *lname, struct thandle *th);
220
221 int mdd_is_root(struct mdd_device *mdd, const struct lu_fid *fid);
222 int mdd_lookup(const struct lu_env *env,
223                struct md_object *pobj, const struct lu_name *lname,
224                struct lu_fid* fid, struct md_op_spec *spec);
225 int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
226                    struct linkea_data *ldata);
227 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
228                           struct thandle *handle, struct linkea_data *ldata,
229                           enum mdd_links_add_overflow overflow);
230 int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
231                     struct linkea_data *ldata, struct thandle *handle);
232 struct lu_buf *mdd_links_get(const struct lu_env *env,
233                              struct mdd_object *mdd_obj);
234 int mdd_links_rename(const struct lu_env *env,
235                      struct mdd_object *mdd_obj,
236                      const struct lu_fid *oldpfid,
237                      const struct lu_name *oldlname,
238                      const struct lu_fid *newpfid,
239                      const struct lu_name *newlname,
240                      struct thandle *handle,
241                      struct linkea_data *ldata,
242                      int first, int check);
243
244 struct mdd_thread_info *mdd_env_info(const struct lu_env *env);
245
246 #define MDD_ENV_VAR(env, var) (&mdd_env_info(env)->mti_##var)
247
248 struct lu_buf *mdd_buf_get(const struct lu_env *env, void *area, ssize_t len);
249 const struct lu_buf *mdd_buf_get_const(const struct lu_env *env,
250                                        const void *area, ssize_t len);
251
252 int mdd_orphan_cleanup(const struct lu_env *env, struct mdd_device *d);
253 int __mdd_orphan_add(const struct lu_env *, struct mdd_object *,
254                      struct thandle *);
255 int __mdd_orphan_del(const struct lu_env *, struct mdd_object *,
256                      struct thandle *);
257 int orph_index_init(const struct lu_env *env, struct mdd_device *mdd);
258 void orph_index_fini(const struct lu_env *env, struct mdd_device *mdd);
259 int orph_declare_index_insert(const struct lu_env *, struct mdd_object *,
260                               umode_t mode, struct thandle *);
261 int orph_declare_index_delete(const struct lu_env *, struct mdd_object *,
262                               struct thandle *);
263
264 /* mdd_lproc.c */
265 int mdd_procfs_init(struct mdd_device *mdd, const char *name);
266 void mdd_procfs_fini(struct mdd_device *mdd);
267
268 /* mdd_object.c */
269 extern struct kmem_cache *mdd_object_kmem;
270 extern const struct md_dir_operations    mdd_dir_ops;
271 extern const struct md_object_operations mdd_obj_ops;
272 int mdd_readlink(const struct lu_env *env, struct md_object *obj,
273                  struct lu_buf *buf);
274 int accmode(const struct lu_env *env, const struct lu_attr *la, int flags);
275 extern struct lu_context_key mdd_thread_key;
276 extern const struct lu_device_operations mdd_lu_ops;
277
278 struct mdd_object *mdd_object_find(const struct lu_env *env,
279                                    struct mdd_device *d,
280                                    const struct lu_fid *f);
281 int mdd_readpage(const struct lu_env *env, struct md_object *obj,
282                  const struct lu_rdpg *rdpg);
283 int mdd_declare_changelog_store(const struct lu_env *env,
284                                        struct mdd_device *mdd,
285                                        const struct lu_name *tname,
286                                        const struct lu_name *sname,
287                                        struct thandle *handle);
288 void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid);
289 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
290                         struct llog_changelog_rec *rec, struct thandle *th);
291 int mdd_changelog_data_store(const struct lu_env *env, struct mdd_device *mdd,
292                              enum changelog_rec_type type, int flags,
293                              struct mdd_object *mdd_obj,
294                              struct thandle *handle);
295 int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
296                            enum changelog_rec_type type,
297                            enum changelog_rec_flags crf,
298                            struct mdd_object *target,
299                            const struct lu_fid *tpfid,
300                            const struct lu_fid *sfid,
301                            const struct lu_fid *spfid,
302                            const struct lu_name *tname,
303                            const struct lu_name *sname,
304                            struct thandle *handle);
305 int mdd_declare_object_create_internal(const struct lu_env *env,
306                                        struct mdd_object *p,
307                                        struct mdd_object *c,
308                                        struct lu_attr *attr,
309                                        struct thandle *handle,
310                                        const struct md_op_spec *spec,
311                                        struct dt_allocation_hint *hint);
312 int mdd_get_lov_ea(const struct lu_env *env, struct mdd_object *obj,
313                    struct lu_buf *lmm_buf);
314
315 /* mdd_trans.c */
316 void mdd_object_make_hint(const struct lu_env *env, struct mdd_object *parent,
317                           struct mdd_object *child, const struct lu_attr *attr,
318                           const struct md_op_spec *spec,
319                           struct dt_allocation_hint *hint);
320
321 static inline void mdd_object_get(struct mdd_object *o)
322 {
323         lu_object_get(&o->mod_obj.mo_lu);
324 }
325
326 static inline void mdd_object_put(const struct lu_env *env,
327                                   struct mdd_object *o)
328 {
329         lu_object_put(env, &o->mod_obj.mo_lu);
330 }
331
332 struct thandle *mdd_trans_create(const struct lu_env *env,
333                                  struct mdd_device *mdd);
334 int mdd_trans_start(const struct lu_env *env, struct mdd_device *mdd,
335                     struct thandle *th);
336 int mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
337                    int rc, struct thandle *handle);
338
339 /* mdd_device.c */
340 struct lu_object *mdd_object_alloc(const struct lu_env *env,
341                                    const struct lu_object_header *hdr,
342                                    struct lu_device *d);
343 int mdd_local_file_create(const struct lu_env *env, struct mdd_device *mdd,
344                           const struct lu_fid *pfid, const char *name,
345                           __u32 mode, struct lu_fid *fid);
346
347 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
348                   struct thandle *handle);
349 int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
350                 struct lu_attr *attr, const struct lu_buf *buf, int fl);
351 int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
352                        __u32 *mode);
353 int __mdd_permission_internal(const struct lu_env *env, struct mdd_object *obj,
354                               const struct lu_attr *la, int mask, int role);
355 int mdd_permission(const struct lu_env *env,
356                    struct md_object *pobj, struct md_object *cobj,
357                    struct md_attr *ma, int mask);
358 int mdd_capa_get(const struct lu_env *env, struct md_object *obj,
359                  struct lustre_capa *capa, int renewal);
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 struct lustre_capa *mdd_object_capa(const struct lu_env *env,
463                                                   const struct mdd_object *obj)
464 {
465         struct lu_capainfo *lci = lu_capainfo_get(env);
466         const struct lu_fid *fid = mdo2fid(obj);
467         int i;
468
469         /* NB: in mdt_init0 */
470         if (lci == NULL)
471                 return BYPASS_CAPA;
472
473         for (i = 0; i < LU_CAPAINFO_MAX; i++)
474                 if (lu_fid_eq(&lci->lci_fid[i], fid))
475                         return lci->lci_capa[i];
476         return NULL;
477 }
478
479 static inline void mdd_set_capainfo(const struct lu_env *env, int offset,
480                                     const struct mdd_object *obj,
481                                     struct lustre_capa *capa)
482 {
483         struct lu_capainfo *lci = lu_capainfo_get(env);
484         const struct lu_fid *fid = mdo2fid(obj);
485
486         LASSERT(offset >= 0 && offset < LU_CAPAINFO_MAX);
487         /* NB: in mdt_init0 */
488         if (lci == NULL)
489                 return;
490
491         lci->lci_fid[offset]  = *fid;
492         lci->lci_capa[offset] = capa;
493 }
494
495 static inline const char *mdd_obj_dev_name(const struct mdd_object *obj)
496 {
497         return lu_dev_name(obj->mod_obj.mo_lu.lo_dev);
498 }
499
500 #define MAX_ATIME_DIFF 60
501
502 static inline int mdd_permission_internal(const struct lu_env *env,
503                                           struct mdd_object *obj,
504                                           const struct lu_attr *la, int mask)
505 {
506         return __mdd_permission_internal(env, obj, la, mask, -1);
507 }
508
509 static inline int mdd_permission_internal_locked(const struct lu_env *env,
510                                                 struct mdd_object *obj,
511                                                 const struct lu_attr *la,
512                                                 int mask,
513                                                 enum mdd_object_role role)
514 {
515         return __mdd_permission_internal(env, obj, la, mask, role);
516 }
517
518 /* mdd inline func for calling osd_dt_object ops */
519 static inline int mdo_attr_get(const struct lu_env *env, struct mdd_object *obj,
520                                struct lu_attr *la, struct lustre_capa *capa)
521 {
522         struct dt_object *next = mdd_object_child(obj);
523         return dt_attr_get(env, next, la, capa);
524 }
525
526 static inline int mdo_declare_attr_set(const struct lu_env *env,
527                                        struct mdd_object *obj,
528                                        const struct lu_attr *la,
529                                        struct thandle *handle)
530 {
531         struct dt_object *next = mdd_object_child(obj);
532         return dt_declare_attr_set(env, next, la, handle);
533 }
534
535 static inline int mdo_attr_set(const struct lu_env *env,
536                                struct mdd_object *obj,
537                                const struct lu_attr *la,
538                                struct thandle *handle,
539                                struct lustre_capa *capa)
540 {
541         struct dt_object *next = mdd_object_child(obj);
542
543         if (!mdd_object_exists(obj))
544                 return -ENOENT;
545
546         return dt_attr_set(env, next, la, handle, capa);
547 }
548
549 static inline int mdo_xattr_get(const struct lu_env *env,struct mdd_object *obj,
550                                 struct lu_buf *buf, const char *name,
551                                 struct lustre_capa *capa)
552 {
553         struct dt_object *next = mdd_object_child(obj);
554         return dt_xattr_get(env, next, buf, name, capa);
555 }
556
557 static inline int mdo_declare_xattr_set(const struct lu_env *env,
558                                         struct mdd_object *obj,
559                                         const struct lu_buf *buf,
560                                         const char *name,
561                                         int fl, struct thandle *handle)
562 {
563         struct dt_object *next = mdd_object_child(obj);
564         return dt_declare_xattr_set(env, next, buf, name, fl, handle);
565 }
566
567 static inline int mdo_xattr_set(const struct lu_env *env,struct mdd_object *obj,
568                                 const struct lu_buf *buf, const char *name,
569                                 int fl, struct thandle *handle,
570                                 struct lustre_capa *capa)
571 {
572         struct dt_object *next = mdd_object_child(obj);
573
574         if (!mdd_object_exists(obj))
575                 return -ENOENT;
576
577         return dt_xattr_set(env, next, buf, name, fl, handle, capa);
578 }
579
580 static inline int mdo_declare_xattr_del(const struct lu_env *env,
581                                         struct mdd_object *obj,
582                                         const char *name,
583                                         struct thandle *handle)
584 {
585         struct dt_object *next = mdd_object_child(obj);
586         return dt_declare_xattr_del(env, next, name, handle);
587 }
588
589 static inline int mdo_xattr_del(const struct lu_env *env,struct mdd_object *obj,
590                                 const char *name, struct thandle *handle,
591                                 struct lustre_capa *capa)
592 {
593         struct dt_object *next = mdd_object_child(obj);
594
595         if (!mdd_object_exists(obj))
596                 return -ENOENT;
597
598         return dt_xattr_del(env, next, name, handle, capa);
599 }
600
601 static inline int
602 mdo_xattr_list(const struct lu_env *env, struct mdd_object *obj,
603                struct lu_buf *buf, struct lustre_capa *capa)
604 {
605         struct dt_object *next = mdd_object_child(obj);
606
607         if (!mdd_object_exists(obj))
608                 return -ENOENT;
609
610         return dt_xattr_list(env, next, buf, capa);
611 }
612
613 static inline
614 int mdo_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
615                              const struct lu_fid *fid, __u32 type,
616                              const char *name, struct thandle *handle)
617 {
618         struct dt_object *next  = mdd_object_child(obj);
619         int               rc    = 0;
620
621         /*
622          * if the object doesn't exist yet, then it's supposed to be created
623          * and declaration of the creation should be enough to insert ./..
624          */
625
626          /* FIXME: remote object should not be awared by MDD layer, but local
627           * creation does not declare insert ./.. (comments above), which
628           * is required by remote directory creation.
629           * This remote check should be removed when mdd_object_exists check is
630           * removed.
631           */
632         if (mdd_object_exists(obj) || mdd_object_remote(obj)) {
633                 rc = -ENOTDIR;
634                 if (dt_try_as_dir(env, next)) {
635                         struct dt_insert_rec *rec =
636                                         &mdd_env_info(env)->mti_dt_rec;
637
638                         rec->rec_fid = fid;
639                         rec->rec_type = type;
640                         rc = dt_declare_insert(env, next,
641                                                (const struct dt_rec *)rec,
642                                                (const struct dt_key *)name,
643                                                handle);
644                 }
645          }
646
647          return rc;
648 }
649
650 static inline
651 int mdo_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
652                              const char *name, struct thandle *handle)
653 {
654         struct dt_object *next = mdd_object_child(obj);
655
656         if (!dt_try_as_dir(env, next))
657                 return -ENOTDIR;
658
659         return dt_declare_delete(env, next, (const struct dt_key *)name,
660                                  handle);
661 }
662
663 static inline int mdo_declare_ref_add(const struct lu_env *env,
664                                       struct mdd_object *obj,
665                                       struct thandle *handle)
666 {
667         struct dt_object *next = mdd_object_child(obj);
668         return dt_declare_ref_add(env, next, handle);
669 }
670
671 static inline int mdo_ref_add(const struct lu_env *env, struct mdd_object *obj,
672                               struct thandle *handle)
673 {
674         struct dt_object *next = mdd_object_child(obj);
675
676         if (!mdd_object_exists(obj))
677                 return -ENOENT;
678
679         return dt_ref_add(env, next, handle);
680 }
681
682 static inline int mdo_declare_ref_del(const struct lu_env *env,
683                                       struct mdd_object *obj,
684                                       struct thandle *handle)
685 {
686         struct dt_object *next = mdd_object_child(obj);
687         return dt_declare_ref_del(env, next, handle);
688 }
689
690 static inline int mdo_ref_del(const struct lu_env *env, struct mdd_object *obj,
691                               struct thandle *handle)
692 {
693         struct dt_object *next = mdd_object_child(obj);
694
695         if (!mdd_object_exists(obj))
696                 return -ENOENT;
697
698         return dt_ref_del(env, next, handle);
699 }
700
701 static inline int
702 mdo_declare_create_obj(const struct lu_env *env, struct mdd_object *o,
703                        struct lu_attr *attr,
704                        struct dt_allocation_hint *hint,
705                        struct dt_object_format *dof,
706                        struct thandle *handle)
707 {
708         struct dt_object *next = mdd_object_child(o);
709         return dt_declare_create(env, next, attr, hint, dof, handle);
710 }
711
712 static inline int
713 mdo_create_obj(const struct lu_env *env, struct mdd_object *o,
714                struct lu_attr *attr,
715                struct dt_allocation_hint *hint,
716                struct dt_object_format *dof,
717                struct thandle *handle)
718 {
719         struct dt_object *next = mdd_object_child(o);
720         return dt_create(env, next, attr, hint, dof, handle);
721 }
722
723 static inline
724 int mdo_declare_destroy(const struct lu_env *env, struct mdd_object *o,
725                         struct thandle *handle)
726 {
727         struct dt_object *next = mdd_object_child(o);
728         return dt_declare_destroy(env, next, handle);
729 }
730
731 static inline
732 int mdo_destroy(const struct lu_env *env, struct mdd_object *o,
733                 struct thandle *handle)
734 {
735         struct dt_object *next = mdd_object_child(o);
736         return dt_destroy(env, next, handle);
737 }
738
739 static inline struct obd_capa *
740 mdo_capa_get(const struct lu_env *env, struct mdd_object *obj,
741              struct lustre_capa *old, __u64 opc)
742 {
743         struct dt_object *next = mdd_object_child(obj);
744
745         if (!mdd_object_exists(obj))
746                 return ERR_PTR(-ENOENT);
747
748         return dt_capa_get(env, next, old, opc);
749 }
750
751 #endif