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