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