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