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