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