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