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