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