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