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