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