Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  *
31  * lustre/include/md_object.h
32  *
33  * Extention of lu_object.h for metadata objects
34  */
35
36 #ifndef _LUSTRE_MD_OBJECT_H
37 #define _LUSTRE_MD_OBJECT_H
38
39 #ifndef HAVE_SERVER_SUPPORT
40 # error "client code should not depend on md_object.h"
41 #endif /* !HAVE_SERVER_SUPPORT */
42
43 /** \defgroup md md
44  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
45  * stack.
46  *
47  * Meta-data objects implement namespace operations: you can link, unlink
48  * them, and treat them as directories.
49  *
50  * Examples: mdt, cmm, and mdt are implementations of md interface.
51  * @{
52  */
53
54
55 /*
56  * super-class definitions.
57  */
58 #include <dt_object.h>
59
60 struct md_device;
61 struct md_device_operations;
62 struct md_object;
63 struct obd_export;
64
65 /** metadata attributes */
66 enum ma_valid {
67         MA_INODE        = BIT(0),
68         MA_LOV          = BIT(1),
69         MA_FLAGS        = BIT(2),
70         MA_LMV          = BIT(3),
71         MA_ACL_DEF      = BIT(4),
72         MA_LOV_DEF      = BIT(5),
73         MA_HSM          = BIT(6),
74         MA_PFID         = BIT(7),
75         MA_LMV_DEF      = BIT(8),
76         MA_SOM          = BIT(9),
77         MA_FORCE_LOG    = BIT(10), /* forced close logged in mdt_mfd_close */
78         MA_DIRENT_CNT   = BIT(11),
79 };
80
81 typedef enum {
82         MDL_MINMODE  = 0,
83         MDL_EX       = 1,
84         MDL_PW       = 2,
85         MDL_PR       = 4,
86         MDL_CW       = 8,
87         MDL_CR       = 16,
88         MDL_NL       = 32,
89         MDL_GROUP    = 64,
90         MDL_MAXMODE
91 } mdl_mode_t;
92
93 typedef enum {
94         MDT_NUL_LOCK = 0,
95         MDT_REG_LOCK = BIT(0),
96         MDT_PDO_LOCK = BIT(1),
97 } mdl_type_t;
98
99 /* lfs rgetfacl permission check */
100 #define MAY_RGETFACL    BIT(14)
101
102 /* memory structure for hsm attributes
103  * for fields description see the on disk structure hsm_attrs
104  * which is defined in lustre_idl.h
105  */
106 struct md_hsm {
107         __u32   mh_compat;
108         __u32   mh_flags;
109         __u64   mh_arch_id;
110         __u64   mh_arch_ver;
111 };
112
113
114 /* memory structure for SOM attributes
115  * for fields description see the on disk structure som_attrs
116  * which is defined in lustre_idl.h
117  */
118 struct md_som {
119         __u16   ms_valid;
120         __u64   ms_size;
121         __u64   ms_blocks;
122 };
123
124 struct md_attr {
125         __u64                    ma_valid;
126         __u64                    ma_need;
127         __u64                    ma_attr_flags;
128         struct lu_attr           ma_attr;
129         struct lu_fid            ma_pfid;
130         struct md_hsm            ma_hsm;
131         struct md_som            ma_som;
132         struct lov_mds_md       *ma_lmm;
133         union lmv_mds_md        *ma_lmv;
134         struct lmv_user_md      *ma_default_lmv;
135         void                    *ma_acl;
136         int                      ma_lmm_size;
137         int                      ma_lmv_size;
138         int                      ma_default_lmv_size;
139         int                      ma_acl_size;
140         int                      ma_enable_chprojid_gid;
141 };
142
143 /** Additional parameters for create */
144 struct md_op_spec {
145         union {
146                 /** symlink target */
147                 struct lu_name sp_symname;
148                 /** eadata for regular files */
149                 struct md_spec_reg {
150                         void *eadata;
151                         int  eadatalen;
152                 } sp_ea;
153         } u;
154
155         /** Open flags from client: such as MDS_OPEN_CREAT, and others. */
156         __u64      sp_cr_flags;
157
158         /* File security context for creates. */
159         const char      *sp_cr_file_secctx_name; /* (security) xattr name */
160         void            *sp_cr_file_secctx; /* xattr value */
161         size_t           sp_cr_file_secctx_size; /* xattr value size */
162
163         /* File encryption context for creates. */
164         void            *sp_cr_file_encctx; /* enc ctx value */
165         size_t           sp_cr_file_encctx_size; /* enc ctx size */
166
167         /* Archive ID used for auto PCC attach when create newly files. */
168         __u32            sp_archive_id;
169
170         /** don't create lov objects or llog cookie - this replay */
171         unsigned int no_create:1,
172                      sp_cr_lookup:1, /* do lookup sanity check or not. */
173                      sp_rm_entry:1,  /* only remove name entry */
174                      sp_permitted:1, /* do not check permission */
175                      sp_migrate_close:1, /* close the file during migrate */
176                      sp_migrate_nsonly:1, /* migrate dirent only */
177                      sp_dmv_imp_inherit:1, /* implicit default LMV inherit */
178                      sp_replay:1; /* replay, op may be partially executed */
179
180         /** to create directory */
181         const struct dt_index_features *sp_feat;
182
183         /* name of xattr used to store jobid in inode, or empty if disabled */
184         char sp_cr_job_xattr[XATTR_JOB_MAX_LEN];
185 };
186
187 enum md_layout_opc {
188         MD_LAYOUT_NOP   = 0,
189         MD_LAYOUT_WRITE,        /* FLR: write the file */
190         MD_LAYOUT_RESYNC,       /* FLR: resync starts */
191         MD_LAYOUT_RESYNC_DONE,  /* FLR: resync done */
192         MD_LAYOUT_ATTACH,       /* attach stripes */
193         MD_LAYOUT_DETACH,       /* detach stripes */
194         MD_LAYOUT_SHRINK,       /* shrink striped directory (destroy stripes) */
195         MD_LAYOUT_SPLIT,        /* split directory (allocate new stripes) */
196         MD_LAYOUT_MAX,
197 };
198
199 /**
200  * Parameters for layout change API.
201  */
202 struct md_layout_change {
203         enum md_layout_opc                       mlc_opc;
204         struct lu_buf                            mlc_buf;
205         union {
206                 struct {
207                         __u16                    mlc_mirror_id;
208                         struct layout_intent    *mlc_intent;
209                         struct lustre_som_attrs  mlc_som;
210                         size_t                   mlc_resync_count;
211                         __u32                   *mlc_resync_ids;
212                 }; /* file */
213                 struct {
214                         /* parent obj in plain dir split */
215                         struct md_object        *mlc_parent;
216                         /* target obj in plain dir split */
217                         struct md_object        *mlc_target;
218                         /* target attr in plain dir split */
219                         struct lu_attr          *mlc_attr;
220                         /* target name in plain dir split */
221                         const struct lu_name    *mlc_name;
222                         /* dir split spec */
223                         struct md_op_spec       *mlc_spec;
224                 }; /* dir */
225         };
226 };
227
228 union ldlm_policy_data;
229 /**
230  * Operations implemented for each md object (both directory and leaf).
231  */
232 struct md_object_operations {
233         int (*moo_permission)(const struct lu_env *env,
234                               struct md_object *pobj, struct md_object *cobj,
235                               struct md_attr *attr, unsigned int may_mask);
236
237         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
238                             struct md_attr *attr);
239
240         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
241                             const struct md_attr *attr);
242
243         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
244                              struct lu_buf *buf, const char *name);
245
246         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
247                               struct lu_buf *buf);
248
249         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
250                              const struct lu_buf *buf, const char *name,
251                              int fl);
252
253         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
254                              const char *name);
255
256         /** This method is used to swap the layouts between 2 objects */
257         int (*moo_swap_layouts)(const struct lu_env *env,
258                                struct md_object *obj1, struct md_object *obj2,
259                                __u64 dv1, __u64 dv2, __u64 flags);
260
261         /** \retval number of bytes actually read upon success */
262         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
263                             const struct lu_rdpg *rdpg);
264
265         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
266                             struct lu_buf *buf);
267
268         int (*moo_changelog)(const struct lu_env *env,
269                              enum changelog_rec_type type,
270                              enum changelog_rec_flags clf_flags,
271                              struct md_device *m, const struct lu_fid *fid);
272
273         int (*moo_open)(const struct lu_env *env, struct md_object *obj,
274                         u64 open_flags, struct md_op_spec*);
275
276         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
277                          struct md_attr *ma, u64 open_flags);
278
279         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
280
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                                union ldlm_policy_data *policy);
285         int (*moo_object_unlock)(const struct lu_env *env,
286                                  struct md_object *obj,
287                                  struct ldlm_enqueue_info *einfo,
288                                  union ldlm_policy_data *policy);
289
290         int (*moo_invalidate)(const struct lu_env *env, struct md_object *obj);
291         /**
292          * Trying to write to un-instantiated layout component.
293          *
294          * The caller should have held layout lock.
295          *
296          * This API can be extended to support every other layout changing
297          * operations, such as component {add,del,change}, layout swap,
298          * layout merge, etc. One of the benefits by doing this is that the MDT
299          * no longer needs to understand layout.
300          *
301          * However, layout creation, removal, and fetch should still use
302          * xattr_{get,set}() because they don't interpret layout on the
303          * MDT layer.
304          *
305          * \param[in] env       execution environment
306          * \param[in] obj       MD object
307          * \param[in] layout    data structure to describe the changes to
308          *                      the MD object's layout
309          *
310          * \retval 0            success
311          * \retval -ne          error code
312          */
313         int (*moo_layout_change)(const struct lu_env *env,
314                                  struct md_object *obj,
315                                  struct md_layout_change *layout);
316 };
317
318 /**
319  * Operations implemented for each directory object.
320  */
321 struct md_dir_operations {
322         int (*mdo_is_subdir)(const struct lu_env *env, struct md_object *obj,
323                              const struct lu_fid *fid);
324
325         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
326                           const struct lu_name *lname, struct lu_fid *fid,
327                           struct md_op_spec *spec);
328
329         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
330                                     struct md_object *obj,
331                                     mdl_mode_t mode);
332
333         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
334                           const struct lu_name *lname, struct md_object *child,
335                           struct md_op_spec *spec,
336                           struct md_attr *ma);
337
338         /** This method is used for creating data object for this meta object*/
339         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
340                                struct md_object *o,
341                                const struct md_op_spec *spec,
342                                struct md_attr *ma);
343
344         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
345                           struct md_object *tpobj, const struct lu_fid *lf,
346                           const struct lu_name *lsname, struct md_object *tobj,
347                           const struct lu_name *ltname, struct md_attr *ma);
348
349         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
350                         struct md_object *src_obj, const struct lu_name *lname,
351                         struct md_attr *ma);
352
353         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
354                           struct md_object *cobj, const struct lu_name *lname,
355                           struct md_attr *ma, int no_name);
356
357         int (*mdo_migrate)(const struct lu_env *env, struct md_object *spobj,
358                            struct md_object *tpobj, struct md_object *sobj,
359                            struct md_object *tobj, const struct lu_name *lname,
360                            struct md_op_spec *spec, struct md_attr *ma);
361 };
362
363 struct md_device_operations {
364         /** meta-data device related handlers. */
365         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
366                             struct lu_fid *f);
367
368         const struct dt_device_param *(*mdo_dtconf_get)(const struct lu_env *e,
369                                                         struct md_device *m);
370
371         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
372                           struct obd_statfs *sfs);
373
374         int (*mdo_llog_ctxt_get)(const struct lu_env *env,
375                                  struct md_device *m, int idx, void **h);
376
377         int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
378                              unsigned int cmd, int len, void *data);
379 };
380
381 struct md_device {
382         struct lu_device                   md_lu_dev;
383         const struct md_device_operations *md_ops;
384 };
385
386 struct md_object {
387         struct lu_object                   mo_lu;
388         const struct md_object_operations *mo_ops;
389         const struct md_dir_operations    *mo_dir_ops;
390 };
391
392 static inline struct md_device *lu2md_dev(const struct lu_device *d)
393 {
394         LASSERT(IS_ERR(d) || lu_device_is_md(d));
395         return container_of_safe(d, struct md_device, md_lu_dev);
396 }
397
398 static inline struct lu_device *md2lu_dev(struct md_device *d)
399 {
400         return &d->md_lu_dev;
401 }
402
403 static inline struct md_object *lu2md(const struct lu_object *o)
404 {
405         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
406         return container_of_safe(o, struct md_object, mo_lu);
407 }
408
409 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
410 {
411         return lu_device_init(&md->md_lu_dev, t);
412 }
413
414 static inline void md_device_fini(struct md_device *md)
415 {
416         lu_device_fini(&md->md_lu_dev);
417 }
418
419 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
420                                                      struct md_device *md,
421                                                      const struct lu_fid *f)
422 {
423         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
424 }
425
426
427 /** md operations */
428 static inline int mo_permission(const struct lu_env *env, struct md_object *p,
429                                 struct md_object *c, struct md_attr *at,
430                                 unsigned int may_mask)
431 {
432         LASSERT(c->mo_ops->moo_permission);
433         return c->mo_ops->moo_permission(env, p, c, at, may_mask);
434 }
435
436 static inline int mo_attr_get(const struct lu_env *env, struct md_object *m,
437                               struct md_attr *at)
438 {
439         LASSERT(m->mo_ops->moo_attr_get);
440         return m->mo_ops->moo_attr_get(env, m, at);
441 }
442
443 static inline int mo_readlink(const struct lu_env *env,
444                               struct md_object *m,
445                               struct lu_buf *buf)
446 {
447         LASSERT(m->mo_ops->moo_readlink);
448         return m->mo_ops->moo_readlink(env, m, buf);
449 }
450
451 static inline int mo_changelog(const struct lu_env *env,
452                                enum changelog_rec_type type,
453                                enum changelog_rec_flags clf_flags,
454                                struct md_device *m, const struct lu_fid *fid)
455 {
456         struct lu_fid rootfid;
457         struct md_object *root;
458         int rc;
459
460         rc = m->md_ops->mdo_root_get(env, m, &rootfid);
461         if (rc)
462                 return rc;
463
464         root = md_object_find_slice(env, m, &rootfid);
465         if (IS_ERR(root))
466                 RETURN(PTR_ERR(root));
467
468         LASSERT(root->mo_ops->moo_changelog);
469         rc = root->mo_ops->moo_changelog(env, type, clf_flags, m, fid);
470
471         lu_object_put(env, &root->mo_lu);
472
473         return rc;
474 }
475
476 static inline int mo_attr_set(const struct lu_env *env,
477                               struct md_object *m,
478                               const struct md_attr *at)
479 {
480         LASSERT(m->mo_ops->moo_attr_set);
481         return m->mo_ops->moo_attr_set(env, m, at);
482 }
483
484 static inline int mo_xattr_get(const struct lu_env *env,
485                                struct md_object *m,
486                                struct lu_buf *buf,
487                                const char *name)
488 {
489         LASSERT(m->mo_ops->moo_xattr_get);
490         return m->mo_ops->moo_xattr_get(env, m, buf, name);
491 }
492
493 static inline int mo_xattr_del(const struct lu_env *env,
494                                struct md_object *m,
495                                const char *name)
496 {
497         LASSERT(m->mo_ops->moo_xattr_del);
498         return m->mo_ops->moo_xattr_del(env, m, name);
499 }
500
501 static inline int mo_xattr_set(const struct lu_env *env,
502                                struct md_object *m,
503                                const struct lu_buf *buf,
504                                const char *name,
505                                int flags)
506 {
507         LASSERT(m->mo_ops->moo_xattr_set);
508         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
509 }
510
511 static inline int mo_xattr_list(const struct lu_env *env,
512                                 struct md_object *m,
513                                 struct lu_buf *buf)
514 {
515         LASSERT(m->mo_ops->moo_xattr_list);
516         return m->mo_ops->moo_xattr_list(env, m, buf);
517 }
518
519 static inline int mo_invalidate(const struct lu_env *env, struct md_object *m)
520 {
521         LASSERT(m->mo_ops->moo_invalidate);
522         return m->mo_ops->moo_invalidate(env, m);
523 }
524
525 static inline int mo_layout_change(const struct lu_env *env,
526                                    struct md_object *m,
527                                    struct md_layout_change *layout)
528 {
529         /* need instantiate objects which in the access range */
530         LASSERT(m->mo_ops->moo_layout_change);
531         return m->mo_ops->moo_layout_change(env, m, layout);
532 }
533
534 static inline int mo_swap_layouts(const struct lu_env *env,
535                                   struct md_object *o1, struct md_object *o2,
536                                   __u64 dv1, __u64 dv2, __u64 flags)
537 {
538         LASSERT(o1->mo_ops->moo_swap_layouts);
539         LASSERT(o2->mo_ops->moo_swap_layouts);
540         if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
541                 return -EPERM;
542         return o1->mo_ops->moo_swap_layouts(env, o1, o2, dv1, dv2, flags);
543 }
544
545 static inline int mo_open(const struct lu_env *env, struct md_object *m,
546                           u64 open_flags, struct md_op_spec *spec)
547 {
548         LASSERT(m->mo_ops->moo_open);
549         return m->mo_ops->moo_open(env, m, open_flags, spec);
550 }
551
552 static inline int mo_close(const struct lu_env *env, struct md_object *m,
553                            struct md_attr *ma, u64 open_flags)
554 {
555         LASSERT(m->mo_ops->moo_close);
556         return m->mo_ops->moo_close(env, m, ma, open_flags);
557 }
558
559 static inline int mo_readpage(const struct lu_env *env,
560                               struct md_object *m,
561                               const struct lu_rdpg *rdpg)
562 {
563         LASSERT(m->mo_ops->moo_readpage);
564         return m->mo_ops->moo_readpage(env, m, rdpg);
565 }
566
567 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
568 {
569         LASSERT(m->mo_ops->moo_object_sync);
570         return m->mo_ops->moo_object_sync(env, m);
571 }
572
573 static inline int mo_object_lock(const struct lu_env *env,
574                                  struct md_object *m,
575                                  struct lustre_handle *lh,
576                                  struct ldlm_enqueue_info *einfo,
577                                  union ldlm_policy_data *policy)
578 {
579         LASSERT(m->mo_ops->moo_object_lock);
580         return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
581 }
582
583 static inline int mo_object_unlock(const struct lu_env *env,
584                                    struct md_object *m,
585                                    struct ldlm_enqueue_info *einfo,
586                                    union ldlm_policy_data *policy)
587 {
588         LASSERT(m->mo_ops->moo_object_unlock);
589         return m->mo_ops->moo_object_unlock(env, m, einfo, policy);
590 }
591
592 static inline int mdo_lookup(const struct lu_env *env,
593                              struct md_object *p,
594                              const struct lu_name *lname,
595                              struct lu_fid *f,
596                              struct md_op_spec *spec)
597 {
598         LASSERT(p->mo_dir_ops->mdo_lookup);
599         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
600 }
601
602 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
603                                        struct md_object *mo,
604                                        mdl_mode_t lm)
605 {
606         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
607                 return MDL_MINMODE;
608         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
609 }
610
611 static inline int mdo_create(const struct lu_env *env,
612                              struct md_object *p,
613                              const struct lu_name *lchild_name,
614                              struct md_object *c,
615                              struct md_op_spec *spc,
616                              struct md_attr *at)
617 {
618         LASSERT(p->mo_dir_ops->mdo_create);
619         return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
620 }
621
622 static inline int mdo_create_data(const struct lu_env *env,
623                                   struct md_object *p,
624                                   struct md_object *c,
625                                   const struct md_op_spec *spec,
626                                   struct md_attr *ma)
627 {
628         LASSERT(c->mo_dir_ops->mdo_create_data);
629         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
630 }
631
632 static inline int mdo_rename(const struct lu_env *env,
633                              struct md_object *sp,
634                              struct md_object *tp,
635                              const struct lu_fid *lf,
636                              const struct lu_name *lsname,
637                              struct md_object *t,
638                              const struct lu_name *ltname,
639                              struct md_attr *ma)
640 {
641         LASSERT(tp->mo_dir_ops->mdo_rename);
642         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
643                                           ma);
644 }
645
646 static inline int mdo_migrate(const struct lu_env *env,
647                               struct md_object *spobj,
648                               struct md_object *tpobj,
649                               struct md_object *sobj,
650                               struct md_object *tobj,
651                               const struct lu_name *lname,
652                               struct md_op_spec *spec,
653                               struct md_attr *ma)
654 {
655         LASSERT(spobj->mo_dir_ops->mdo_migrate);
656         return spobj->mo_dir_ops->mdo_migrate(env, spobj, tpobj, sobj, tobj,
657                                               lname, spec, ma);
658 }
659
660 static inline int mdo_is_subdir(const struct lu_env *env,
661                                 struct md_object *mo,
662                                 const struct lu_fid *fid)
663 {
664         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
665         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid);
666 }
667
668 static inline int mdo_link(const struct lu_env *env,
669                            struct md_object *p,
670                            struct md_object *s,
671                            const struct lu_name *lname,
672                            struct md_attr *ma)
673 {
674         LASSERT(s->mo_dir_ops->mdo_link);
675         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
676 }
677
678 static inline int mdo_unlink(const struct lu_env *env,
679                              struct md_object *p,
680                              struct md_object *c,
681                              const struct lu_name *lname,
682                              struct md_attr *ma, int no_name)
683 {
684         LASSERT(p->mo_dir_ops->mdo_unlink);
685         return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
686 }
687
688 static inline int mdo_statfs(const struct lu_env *env,
689                              struct md_device *m,
690                              struct obd_statfs *sfs)
691 {
692         LASSERT(m->md_ops->mdo_statfs);
693         return m->md_ops->mdo_statfs(env, m, sfs);
694 }
695
696 struct dt_device;
697
698 void lustre_som_swab(struct lustre_som_attrs *attrs);
699 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
700 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
701
702 enum {
703         UCRED_INVALID   = -1,
704         UCRED_INIT      = 0,
705         UCRED_OLD       = 1,
706         UCRED_NEW       = 2,
707 };
708
709 struct lu_ucred {
710         __u32                    uc_valid;
711         __u32                    uc_o_uid;
712         __u32                    uc_o_gid;
713         __u32                    uc_o_fsuid;
714         __u32                    uc_o_fsgid;
715         __u32                    uc_uid;
716         __u32                    uc_gid;
717         __u32                    uc_fsuid;
718         __u32                    uc_fsgid;
719         __u32                    uc_suppgids[2];
720         kernel_cap_t             uc_cap;
721         __u32                    uc_umask;
722         struct group_info       *uc_ginfo;
723         struct md_identity      *uc_identity;
724         char                     uc_jobid[LUSTRE_JOBID_SIZE];
725         lnet_nid_t               uc_nid;
726         bool                     uc_enable_audit;
727         int                      uc_rbac_file_perms:1;
728         int                      uc_rbac_dne_ops:1;
729         int                      uc_rbac_quota_ops:1;
730         int                      uc_rbac_byfid_ops:1;
731         int                      uc_rbac_chlg_ops:1;
732         int                      uc_rbac_fscrypt_admin:1;
733 };
734
735 struct lu_ucred *lu_ucred(const struct lu_env *env);
736
737 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
738
739 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
740
741 int lu_ucred_global_init(void);
742
743 void lu_ucred_global_fini(void);
744
745 /** @} md */
746 #endif /* _LINUX_MD_OBJECT_H */