Whamcloud - gitweb
LU-5557 mdt: track reint operations in MDS service stats
[fs/lustre-release.git] / lustre / include / md_object.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/include/md_object.h
37  *
38  * Extention of lu_object.h for metadata objects
39  */
40
41 #ifndef _LUSTRE_MD_OBJECT_H
42 #define _LUSTRE_MD_OBJECT_H
43
44 #ifndef HAVE_SERVER_SUPPORT
45 # error "client code should not depend on md_object.h"
46 #endif /* !HAVE_SERVER_SUPPORT */
47
48 /** \defgroup md md
49  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
50  * stack.
51  *
52  * Meta-data objects implement namespace operations: you can link, unlink
53  * them, and treat them as directories.
54  *
55  * Examples: mdt, cmm, and mdt are implementations of md interface.
56  * @{
57  */
58
59
60 /*
61  * super-class definitions.
62  */
63 #include <dt_object.h>
64
65 struct md_device;
66 struct md_device_operations;
67 struct md_object;
68 struct obd_export;
69
70 struct md_quota {
71         struct obd_export       *mq_exp;
72 };
73
74 struct md_quota *md_quota(const struct lu_env *env);
75
76 /** metadata attributes */
77 enum ma_valid {
78         MA_INODE     = (1 << 0),
79         MA_LOV       = (1 << 1),
80         MA_COOKIE    = (1 << 2),
81         MA_FLAGS     = (1 << 3),
82         MA_LMV       = (1 << 4),
83         MA_ACL_DEF   = (1 << 5),
84         MA_LOV_DEF   = (1 << 6),
85         MA_LAY_GEN   = (1 << 7),
86         MA_HSM       = (1 << 8),
87         MA_SOM       = (1 << 9),
88         MA_PFID      = (1 << 10),
89         MA_LMV_DEF   = (1 << 11)
90 };
91
92 typedef enum {
93         MDL_MINMODE  = 0,
94         MDL_EX       = 1,
95         MDL_PW       = 2,
96         MDL_PR       = 4,
97         MDL_CW       = 8,
98         MDL_CR       = 16,
99         MDL_NL       = 32,
100         MDL_GROUP    = 64,
101         MDL_MAXMODE
102 } mdl_mode_t;
103
104 typedef enum {
105         MDT_NUL_LOCK = 0,
106         MDT_REG_LOCK = (1 << 0),
107         MDT_PDO_LOCK = (1 << 1)
108 } mdl_type_t;
109
110 /* memory structure for hsm attributes
111  * for fields description see the on disk structure hsm_attrs
112  * which is defined in lustre_idl.h
113  */
114 struct md_hsm {
115         __u32   mh_compat;
116         __u32   mh_flags;
117         __u64   mh_arch_id;
118         __u64   mh_arch_ver;
119 };
120
121 #define IOEPOCH_INVAL 0
122
123 /* memory structure for som attributes
124  * for fields description see the on disk structure som_attrs
125  * which is defined in lustre_idl.h
126  */
127 struct md_som_data {
128         __u32   msd_compat;
129         __u32   msd_incompat;
130         __u64   msd_ioepoch;
131         __u64   msd_size;
132         __u64   msd_blocks;
133         __u64   msd_mountid;
134 };
135
136 struct md_attr {
137         __u64                   ma_valid;
138         __u64                   ma_need;
139         __u64                   ma_attr_flags;
140         struct lu_attr          ma_attr;
141         struct lu_fid           ma_pfid;
142         struct md_hsm           ma_hsm;
143         struct lov_mds_md      *ma_lmm;
144         union lmv_mds_md       *ma_lmv;
145         void                   *ma_acl;
146         struct lustre_capa     *ma_capa;
147         struct md_som_data     *ma_som;
148         int                     ma_lmm_size;
149         int                     ma_lmv_size;
150         int                     ma_acl_size;
151         __u16                   ma_layout_gen;
152 };
153
154 /** Additional parameters for create */
155 struct md_op_spec {
156         union {
157                 /** symlink target */
158                 const char               *sp_symname;
159                 /** parent FID for cross-ref mkdir */
160                 const struct lu_fid      *sp_pfid;
161                 /** eadata for regular files */
162                 struct md_spec_reg {
163                         /** lov objs exist already */
164                         const struct lu_fid   *fid;
165                         const void *eadata;
166                         int  eadatalen;
167                 } sp_ea;
168         } u;
169
170         /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
171         __u64      sp_cr_flags;
172
173         /** don't create lov objects or llog cookie - this replay */
174         unsigned int no_create:1,
175                      sp_cr_lookup:1, /* do lookup sanity check or not. */
176                      sp_rm_entry:1;  /* only remove name entry */
177
178         /** Current lock mode for parent dir where create is performing. */
179         mdl_mode_t sp_cr_mode;
180
181         /** to create directory */
182         const struct dt_index_features *sp_feat;
183 };
184
185 union ldlm_policy_data;
186 /**
187  * Operations implemented for each md object (both directory and leaf).
188  */
189 struct md_object_operations {
190         int (*moo_permission)(const struct lu_env *env,
191                               struct md_object *pobj, struct md_object *cobj,
192                               struct md_attr *attr, int mask);
193
194         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
195                             struct md_attr *attr);
196
197         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
198                             const struct md_attr *attr);
199
200         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
201                              struct lu_buf *buf, const char *name);
202
203         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
204                               struct lu_buf *buf);
205
206         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
207                              const struct lu_buf *buf, const char *name,
208                              int fl);
209
210         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
211                              const char *name);
212
213         /** This method is used to swap the layouts between 2 objects */
214         int (*moo_swap_layouts)(const struct lu_env *env,
215                                struct md_object *obj1, struct md_object *obj2,
216                                __u64 flags);
217
218         /** \retval number of bytes actually read upon success */
219         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
220                             const struct lu_rdpg *rdpg);
221
222         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
223                             struct lu_buf *buf);
224         int (*moo_changelog)(const struct lu_env *env,
225                              enum changelog_rec_type type, int flags,
226                              struct md_object *obj);
227         /** part of cross-ref operation */
228         int (*moo_object_create)(const struct lu_env *env,
229                                  struct md_object *obj,
230                                  const struct md_op_spec *spec,
231                                  struct md_attr *ma);
232
233         int (*moo_ref_add)(const struct lu_env *env,
234                            struct md_object *obj,
235                            const struct md_attr *ma);
236
237         int (*moo_ref_del)(const struct lu_env *env,
238                            struct md_object *obj,
239                            struct md_attr *ma);
240
241         int (*moo_open)(const struct lu_env *env,
242                         struct md_object *obj, int flag);
243
244         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
245                          struct md_attr *ma, int mode);
246
247         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
248                             struct lustre_capa *, int renewal);
249
250         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
251
252         int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
253                              struct lov_mds_md *lmm, struct ldlm_extent *extent,
254                              struct lustre_handle *lockh);
255         int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
256                                struct lov_mds_md *lmm,
257                                struct lustre_handle *lockh);
258         int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
259                                struct lustre_handle *lh,
260                                struct ldlm_enqueue_info *einfo,
261                                union ldlm_policy_data *policy);
262         int (*moo_object_unlock)(const struct lu_env *env,
263                                  struct md_object *obj,
264                                  struct ldlm_enqueue_info *einfo,
265                                  union ldlm_policy_data *policy);
266 };
267
268 /**
269  * Operations implemented for each directory object.
270  */
271 struct md_dir_operations {
272         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
273                               const struct lu_fid *fid, struct lu_fid *sfid);
274
275         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
276                           const struct lu_name *lname, struct lu_fid *fid,
277                           struct md_op_spec *spec);
278
279         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
280                                     struct md_object *obj,
281                                     mdl_mode_t mode);
282
283         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
284                           const struct lu_name *lname, struct md_object *child,
285                           struct md_op_spec *spec,
286                           struct md_attr *ma);
287
288         /** This method is used for creating data object for this meta object*/
289         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
290                                struct md_object *o,
291                                const struct md_op_spec *spec,
292                                struct md_attr *ma);
293
294         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
295                           struct md_object *tpobj, const struct lu_fid *lf,
296                           const struct lu_name *lsname, struct md_object *tobj,
297                           const struct lu_name *ltname, struct md_attr *ma);
298
299         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
300                         struct md_object *src_obj, const struct lu_name *lname,
301                         struct md_attr *ma);
302
303         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
304                           struct md_object *cobj, const struct lu_name *lname,
305                           struct md_attr *ma, int no_name);
306
307         int (*mdo_migrate)(const struct lu_env *env, struct md_object *pobj,
308                            struct md_object *sobj, const struct lu_name *lname,
309                            struct md_object *tobj, struct md_attr *ma);
310         /** This method is used to compare a requested layout to an existing
311          * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
312         int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
313                                struct md_object *cobj,
314                                const struct md_op_spec *spec,
315                                struct md_attr *ma);
316
317         /** partial ops for cross-ref case */
318         int (*mdo_name_insert)(const struct lu_env *env,
319                                struct md_object *obj,
320                                const struct lu_name *lname,
321                                const struct lu_fid *fid,
322                                const struct md_attr *ma);
323
324         int (*mdo_name_remove)(const struct lu_env *env,
325                                struct md_object *obj,
326                                const struct lu_name *lname,
327                                const struct md_attr *ma);
328
329         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
330                               struct md_object *tobj, const struct lu_fid *fid,
331                               const struct lu_name *lname, struct md_attr *ma);
332 };
333
334 struct md_device_operations {
335         /** meta-data device related handlers. */
336         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
337                             struct lu_fid *f);
338
339         int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
340                                 int *easize);
341
342         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
343                           struct obd_statfs *sfs);
344
345         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
346                                   int mode, unsigned long timeout, __u32 alg,
347                                   struct lustre_capa_key *keys);
348
349         int (*mdo_update_capa_key)(const struct lu_env *env,
350                                    struct md_device *m,
351                                    struct lustre_capa_key *key);
352
353         int (*mdo_llog_ctxt_get)(const struct lu_env *env,
354                                  struct md_device *m, int idx, void **h);
355
356         int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
357                              unsigned int cmd, int len, void *data);
358 };
359
360 enum md_upcall_event {
361         /** Sync the md layer*/
362         MD_LOV_SYNC = (1 << 0),
363         /** Just for split, no need trans, for replay */
364         MD_NO_TRANS = (1 << 1),
365         MD_LOV_CONFIG = (1 << 2),
366         /** Trigger quota recovery */
367         MD_LOV_QUOTA = (1 << 3)
368 };
369
370 struct md_upcall {
371         /** this lock protects upcall using against its removal
372          * read lock is for usage the upcall, write - for init/fini */
373         struct rw_semaphore     mu_upcall_sem;
374         /** device to call, upper layer normally */
375         struct md_device       *mu_upcall_dev;
376         /** upcall function */
377         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
378                          enum md_upcall_event ev, void *data);
379 };
380
381 struct md_device {
382         struct lu_device                   md_lu_dev;
383         const struct md_device_operations *md_ops;
384         struct md_upcall                   md_upcall;
385 };
386
387 static inline void md_upcall_init(struct md_device *m, void *upcl)
388 {
389         init_rwsem(&m->md_upcall.mu_upcall_sem);
390         m->md_upcall.mu_upcall_dev = NULL;
391         m->md_upcall.mu_upcall = upcl;
392 }
393
394 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
395 {
396         down_write(&m->md_upcall.mu_upcall_sem);
397         m->md_upcall.mu_upcall_dev = up;
398         up_write(&m->md_upcall.mu_upcall_sem);
399 }
400
401 static inline void md_upcall_fini(struct md_device *m)
402 {
403         down_write(&m->md_upcall.mu_upcall_sem);
404         m->md_upcall.mu_upcall_dev = NULL;
405         m->md_upcall.mu_upcall = NULL;
406         up_write(&m->md_upcall.mu_upcall_sem);
407 }
408
409 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
410                                 enum md_upcall_event ev, void *data)
411 {
412         int rc = 0;
413         down_read(&m->md_upcall.mu_upcall_sem);
414         if (m->md_upcall.mu_upcall_dev != NULL &&
415             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
416                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
417                                               m->md_upcall.mu_upcall_dev,
418                                               ev, data);
419         }
420         up_read(&m->md_upcall.mu_upcall_sem);
421         return rc;
422 }
423
424 struct md_object {
425         struct lu_object                   mo_lu;
426         const struct md_object_operations *mo_ops;
427         const struct md_dir_operations    *mo_dir_ops;
428 };
429
430 /* Mark the object to be dead, and can not be accessed anymore.
431  * XXX, right now, it will only be used for striped directory to
432  * mark the slave stripes dead, when deleting master object. It will be
433  * stored in slave LMV EA (see lod_mark_dead_object), which is only
434  * temporary, and will be removed later when we have proper way to mark
435  * the dead object. */
436 #define LUSTRE_SLAVE_DEAD_FL            0x80000000
437
438 static inline struct md_device *lu2md_dev(const struct lu_device *d)
439 {
440         LASSERT(IS_ERR(d) || lu_device_is_md(d));
441         return container_of0(d, struct md_device, md_lu_dev);
442 }
443
444 static inline struct lu_device *md2lu_dev(struct md_device *d)
445 {
446         return &d->md_lu_dev;
447 }
448
449 static inline struct md_object *lu2md(const struct lu_object *o)
450 {
451         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
452         return container_of0(o, struct md_object, mo_lu);
453 }
454
455 static inline struct md_object *md_object_next(const struct md_object *obj)
456 {
457         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
458 }
459
460 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
461 {
462         return lu_device_init(&md->md_lu_dev, t);
463 }
464
465 static inline void md_device_fini(struct md_device *md)
466 {
467         lu_device_fini(&md->md_lu_dev);
468 }
469
470 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
471                                                      struct md_device *md,
472                                                      const struct lu_fid *f)
473 {
474         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
475 }
476
477
478 /** md operations */
479 static inline int mo_permission(const struct lu_env *env,
480                                 struct md_object *p,
481                                 struct md_object *c,
482                                 struct md_attr *at,
483                                 int mask)
484 {
485         LASSERT(c->mo_ops->moo_permission);
486         return c->mo_ops->moo_permission(env, p, c, at, mask);
487 }
488
489 static inline int mo_attr_get(const struct lu_env *env,
490                               struct md_object *m,
491                               struct md_attr *at)
492 {
493         LASSERT(m->mo_ops->moo_attr_get);
494         return m->mo_ops->moo_attr_get(env, m, at);
495 }
496
497 static inline int mo_readlink(const struct lu_env *env,
498                               struct md_object *m,
499                               struct lu_buf *buf)
500 {
501         LASSERT(m->mo_ops->moo_readlink);
502         return m->mo_ops->moo_readlink(env, m, buf);
503 }
504
505 static inline int mo_changelog(const struct lu_env *env,
506                                enum changelog_rec_type type,
507                                int flags, struct md_object *m)
508 {
509         LASSERT(m->mo_ops->moo_changelog);
510         return m->mo_ops->moo_changelog(env, type, flags, m);
511 }
512
513 static inline int mo_attr_set(const struct lu_env *env,
514                               struct md_object *m,
515                               const struct md_attr *at)
516 {
517         LASSERT(m->mo_ops->moo_attr_set);
518         return m->mo_ops->moo_attr_set(env, m, at);
519 }
520
521 static inline int mo_xattr_get(const struct lu_env *env,
522                                struct md_object *m,
523                                struct lu_buf *buf,
524                                const char *name)
525 {
526         LASSERT(m->mo_ops->moo_xattr_get);
527         return m->mo_ops->moo_xattr_get(env, m, buf, name);
528 }
529
530 static inline int mo_xattr_del(const struct lu_env *env,
531                                struct md_object *m,
532                                const char *name)
533 {
534         LASSERT(m->mo_ops->moo_xattr_del);
535         return m->mo_ops->moo_xattr_del(env, m, name);
536 }
537
538 static inline int mo_xattr_set(const struct lu_env *env,
539                                struct md_object *m,
540                                const struct lu_buf *buf,
541                                const char *name,
542                                int flags)
543 {
544         LASSERT(m->mo_ops->moo_xattr_set);
545         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
546 }
547
548 static inline int mo_xattr_list(const struct lu_env *env,
549                                 struct md_object *m,
550                                 struct lu_buf *buf)
551 {
552         LASSERT(m->mo_ops->moo_xattr_list);
553         return m->mo_ops->moo_xattr_list(env, m, buf);
554 }
555
556 static inline int mo_swap_layouts(const struct lu_env *env,
557                                   struct md_object *o1,
558                                   struct md_object *o2, __u64 flags)
559 {
560         LASSERT(o1->mo_ops->moo_swap_layouts);
561         LASSERT(o2->mo_ops->moo_swap_layouts);
562         if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
563                 return -EPERM;
564         return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
565 }
566
567 static inline int mo_open(const struct lu_env *env,
568                           struct md_object *m,
569                           int flags)
570 {
571         LASSERT(m->mo_ops->moo_open);
572         return m->mo_ops->moo_open(env, m, flags);
573 }
574
575 static inline int mo_close(const struct lu_env *env,
576                            struct md_object *m,
577                            struct md_attr *ma,
578                            int mode)
579 {
580         LASSERT(m->mo_ops->moo_close);
581         return m->mo_ops->moo_close(env, m, ma, mode);
582 }
583
584 static inline int mo_readpage(const struct lu_env *env,
585                               struct md_object *m,
586                               const struct lu_rdpg *rdpg)
587 {
588         LASSERT(m->mo_ops->moo_readpage);
589         return m->mo_ops->moo_readpage(env, m, rdpg);
590 }
591
592 static inline int mo_object_create(const struct lu_env *env,
593                                    struct md_object *m,
594                                    const struct md_op_spec *spc,
595                                    struct md_attr *at)
596 {
597         LASSERT(m->mo_ops->moo_object_create);
598         return m->mo_ops->moo_object_create(env, m, spc, at);
599 }
600
601 static inline int mo_ref_add(const struct lu_env *env,
602                              struct md_object *m,
603                              const struct md_attr *ma)
604 {
605         LASSERT(m->mo_ops->moo_ref_add);
606         return m->mo_ops->moo_ref_add(env, m, ma);
607 }
608
609 static inline int mo_ref_del(const struct lu_env *env,
610                              struct md_object *m,
611                              struct md_attr *ma)
612 {
613         LASSERT(m->mo_ops->moo_ref_del);
614         return m->mo_ops->moo_ref_del(env, m, ma);
615 }
616
617 static inline int mo_capa_get(const struct lu_env *env,
618                               struct md_object *m,
619                               struct lustre_capa *c,
620                               int renewal)
621 {
622         LASSERT(m->mo_ops->moo_capa_get);
623         return m->mo_ops->moo_capa_get(env, m, c, renewal);
624 }
625
626 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
627 {
628         LASSERT(m->mo_ops->moo_object_sync);
629         return m->mo_ops->moo_object_sync(env, m);
630 }
631
632 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
633                                struct lov_mds_md *lmm,
634                                struct ldlm_extent *extent,
635                                struct lustre_handle *lockh)
636 {
637         LASSERT(m->mo_ops->moo_file_lock);
638         return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
639 }
640
641 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
642                                  struct lov_mds_md *lmm,
643                                  struct lustre_handle *lockh)
644 {
645         LASSERT(m->mo_ops->moo_file_unlock);
646         return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
647 }
648
649 static inline int mo_object_lock(const struct lu_env *env,
650                                  struct md_object *m,
651                                  struct lustre_handle *lh,
652                                  struct ldlm_enqueue_info *einfo,
653                                  union ldlm_policy_data *policy)
654 {
655         LASSERT(m->mo_ops->moo_object_lock);
656         return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
657 }
658
659 static inline int mo_object_unlock(const struct lu_env *env,
660                                    struct md_object *m,
661                                    struct ldlm_enqueue_info *einfo,
662                                    union ldlm_policy_data *policy)
663 {
664         LASSERT(m->mo_ops->moo_object_unlock);
665         return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
666 }
667
668 static inline int mdo_lookup(const struct lu_env *env,
669                              struct md_object *p,
670                              const struct lu_name *lname,
671                              struct lu_fid *f,
672                              struct md_op_spec *spec)
673 {
674         LASSERT(p->mo_dir_ops->mdo_lookup);
675         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
676 }
677
678 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
679                                        struct md_object *mo,
680                                        mdl_mode_t lm)
681 {
682         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
683                 return MDL_MINMODE;
684         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
685 }
686
687 static inline int mdo_create(const struct lu_env *env,
688                              struct md_object *p,
689                              const struct lu_name *lchild_name,
690                              struct md_object *c,
691                              struct md_op_spec *spc,
692                              struct md_attr *at)
693 {
694         LASSERT(p->mo_dir_ops->mdo_create);
695         return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
696 }
697
698 static inline int mdo_create_data(const struct lu_env *env,
699                                   struct md_object *p,
700                                   struct md_object *c,
701                                   const struct md_op_spec *spec,
702                                   struct md_attr *ma)
703 {
704         LASSERT(c->mo_dir_ops->mdo_create_data);
705         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
706 }
707
708 static inline int mdo_rename(const struct lu_env *env,
709                              struct md_object *sp,
710                              struct md_object *tp,
711                              const struct lu_fid *lf,
712                              const struct lu_name *lsname,
713                              struct md_object *t,
714                              const struct lu_name *ltname,
715                              struct md_attr *ma)
716 {
717         LASSERT(tp->mo_dir_ops->mdo_rename);
718         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
719                                           ma);
720 }
721
722 static inline int mdo_migrate(const struct lu_env *env,
723                              struct md_object *pobj,
724                              struct md_object *sobj,
725                              const struct lu_name *lname,
726                              struct md_object *tobj,
727                              struct md_attr *ma)
728 {
729         LASSERT(pobj->mo_dir_ops->mdo_migrate);
730         return pobj->mo_dir_ops->mdo_migrate(env, pobj, sobj, lname, tobj, ma);
731 }
732
733 static inline int mdo_is_subdir(const struct lu_env *env,
734                                 struct md_object *mo,
735                                 const struct lu_fid *fid,
736                                 struct lu_fid *sfid)
737 {
738         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
739         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
740 }
741
742 static inline int mdo_link(const struct lu_env *env,
743                            struct md_object *p,
744                            struct md_object *s,
745                            const struct lu_name *lname,
746                            struct md_attr *ma)
747 {
748         LASSERT(s->mo_dir_ops->mdo_link);
749         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
750 }
751
752 static inline int mdo_unlink(const struct lu_env *env,
753                              struct md_object *p,
754                              struct md_object *c,
755                              const struct lu_name *lname,
756                              struct md_attr *ma, int no_name)
757 {
758         LASSERT(p->mo_dir_ops->mdo_unlink);
759         return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
760 }
761
762 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
763                                   struct md_object *c,
764                                   const struct md_op_spec *spec,
765                                   struct md_attr *ma)
766 {
767         LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
768         return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
769 }
770
771 static inline int mdo_name_insert(const struct lu_env *env,
772                                   struct md_object *p,
773                                   const struct lu_name *lname,
774                                   const struct lu_fid *f,
775                                   const struct md_attr *ma)
776 {
777         LASSERT(p->mo_dir_ops->mdo_name_insert);
778         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
779 }
780
781 static inline int mdo_name_remove(const struct lu_env *env,
782                                   struct md_object *p,
783                                   const struct lu_name *lname,
784                                   const struct md_attr *ma)
785 {
786         LASSERT(p->mo_dir_ops->mdo_name_remove);
787         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
788 }
789
790 static inline int mdo_rename_tgt(const struct lu_env *env,
791                                  struct md_object *p,
792                                  struct md_object *t,
793                                  const struct lu_fid *lf,
794                                  const struct lu_name *lname,
795                                  struct md_attr *ma)
796 {
797         if (t) {
798                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
799                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
800         } else {
801                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
802                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
803         }
804 }
805
806 /**
807  * Used in MDD/OUT layer for object lock rule
808  **/
809 enum mdd_object_role {
810         MOR_SRC_PARENT,
811         MOR_SRC_CHILD,
812         MOR_TGT_PARENT,
813         MOR_TGT_CHILD,
814         MOR_TGT_ORPHAN
815 };
816
817 struct dt_device;
818 /**
819  * Structure to hold object information. This is used to create object
820  * \pre llod_dir exist
821  */
822 struct lu_local_obj_desc {
823         const char                      *llod_dir;
824         const char                      *llod_name;
825         __u32                            llod_oid;
826         int                              llod_is_index;
827         const struct dt_index_features  *llod_feat;
828         struct list_head                 llod_linkage;
829 };
830
831 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
832 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
833 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
834
835 enum {
836         UCRED_INVALID   = -1,
837         UCRED_INIT      = 0,
838         UCRED_OLD       = 1,
839         UCRED_NEW       = 2,
840 };
841
842 struct lu_ucred {
843         __u32               uc_valid;
844         __u32               uc_o_uid;
845         __u32               uc_o_gid;
846         __u32               uc_o_fsuid;
847         __u32               uc_o_fsgid;
848         __u32               uc_uid;
849         __u32               uc_gid;
850         __u32               uc_fsuid;
851         __u32               uc_fsgid;
852         __u32               uc_suppgids[2];
853         cfs_cap_t           uc_cap;
854         __u32               uc_umask;
855         struct group_info   *uc_ginfo;
856         struct md_identity *uc_identity;
857 };
858
859 struct lu_ucred *lu_ucred(const struct lu_env *env);
860
861 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
862
863 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
864
865 int lu_ucred_global_init(void);
866
867 void lu_ucred_global_fini(void);
868
869 #define md_cap_t(x) (x)
870
871 #define MD_CAP_TO_MASK(x) (1 << (x))
872
873 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
874
875 /* capable() is copied from linux kernel! */
876 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
877 {
878         if (md_cap_raised(uc->uc_cap, cap))
879                 return 1;
880         return 0;
881 }
882
883 /** @} md */
884 #endif /* _LINUX_MD_OBJECT_H */