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