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