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