Whamcloud - gitweb
304646ced06d2f2ec4e3e62f580bce27c090a3bf
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/md_object.h
37  *
38  * Extention of lu_object.h for metadata objects
39  */
40
41 #ifndef _LUSTRE_MD_OBJECT_H
42 #define _LUSTRE_MD_OBJECT_H
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 enum {
67         MD_CAPAINFO_MAX = 5
68 };
69
70 /** there are at most 5 fids in one operation, see rename, NOTE the last one
71  * is a temporary one used for is_subdir() */
72 struct md_capainfo {
73         __u32                   mc_auth;
74         __u32                   mc_padding;
75         struct lu_fid           mc_fid[MD_CAPAINFO_MAX];
76         struct lustre_capa     *mc_capa[MD_CAPAINFO_MAX];
77 };
78
79 struct md_quota {
80         struct obd_export       *mq_exp;
81 };
82
83 /**
84  * Implemented in mdd/mdd_handler.c.
85  *
86  * XXX should be moved into separate .h/.c together with all md security
87  * related definitions.
88  */
89 struct md_capainfo *md_capainfo(const struct lu_env *env);
90 struct md_quota *md_quota(const struct lu_env *env);
91
92 /** metadata attributes */
93 enum ma_valid {
94         MA_INODE     = (1 << 0),
95         MA_LOV       = (1 << 1),
96         MA_COOKIE    = (1 << 2),
97         MA_FLAGS     = (1 << 3),
98         MA_LMV       = (1 << 4),
99         MA_ACL_DEF   = (1 << 5),
100         MA_LOV_DEF   = (1 << 6),
101         MA_LAY_GEN   = (1 << 7),
102         MA_HSM       = (1 << 8),
103         MA_SOM       = (1 << 9),
104         MA_PFID      = (1 << 10)
105 };
106
107 typedef enum {
108         MDL_MINMODE  = 0,
109         MDL_EX       = 1,
110         MDL_PW       = 2,
111         MDL_PR       = 4,
112         MDL_CW       = 8,
113         MDL_CR       = 16,
114         MDL_NL       = 32,
115         MDL_GROUP    = 64,
116         MDL_MAXMODE
117 } mdl_mode_t;
118
119 typedef enum {
120         MDT_NUL_LOCK = 0,
121         MDT_REG_LOCK = (1 << 0),
122         MDT_PDO_LOCK = (1 << 1)
123 } mdl_type_t;
124
125 /* memory structure for hsm attributes
126  * for fields description see the on disk structure hsm_attrs
127  * which is defined in lustre_idl.h
128  */
129 struct md_hsm {
130         __u32   mh_compat;
131         __u32   mh_flags;
132         __u64   mh_arch_id;
133         __u64   mh_arch_ver;
134 };
135
136 #define IOEPOCH_INVAL 0
137
138 /* memory structure for som attributes
139  * for fields description see the on disk structure som_attrs
140  * which is defined in lustre_idl.h
141  */
142 struct md_som_data {
143         __u32   msd_compat;
144         __u32   msd_incompat;
145         __u64   msd_ioepoch;
146         __u64   msd_size;
147         __u64   msd_blocks;
148         __u64   msd_mountid;
149 };
150
151 struct md_attr {
152         __u64                   ma_valid;
153         __u64                   ma_need;
154         __u64                   ma_attr_flags;
155         struct lu_attr          ma_attr;
156         struct lu_fid           ma_pfid;
157         struct md_hsm           ma_hsm;
158         struct lov_mds_md      *ma_lmm;
159         struct lmv_stripe_md   *ma_lmv;
160         void                   *ma_acl;
161         struct llog_cookie     *ma_cookie;
162         struct lustre_capa     *ma_capa;
163         struct md_som_data     *ma_som;
164         int                     ma_lmm_size;
165         int                     ma_lmv_size;
166         int                     ma_acl_size;
167         int                     ma_cookie_size;
168         __u16                   ma_layout_gen;
169 };
170
171 /** Additional parameters for create */
172 struct md_op_spec {
173         union {
174                 /** symlink target */
175                 const char               *sp_symname;
176                 /** parent FID for cross-ref mkdir */
177                 const struct lu_fid      *sp_pfid;
178                 /** eadata for regular files */
179                 struct md_spec_reg {
180                         /** lov objs exist already */
181                         const struct lu_fid   *fid;
182                         const void *eadata;
183                         int  eadatalen;
184                 } sp_ea;
185         } u;
186
187         /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
188         __u64      sp_cr_flags;
189
190         /** don't create lov objects or llog cookie - this replay */
191         unsigned int no_create:1,
192                      sp_cr_lookup:1, /* do lookup sanity check or not. */
193                      sp_rm_entry:1;  /* only remove name entry */
194
195         /** Current lock mode for parent dir where create is performing. */
196         mdl_mode_t sp_cr_mode;
197
198         /** to create directory */
199         const struct dt_index_features *sp_feat;
200 };
201
202 /**
203  * Operations implemented for each md object (both directory and leaf).
204  */
205 struct md_object_operations {
206         int (*moo_permission)(const struct lu_env *env,
207                               struct md_object *pobj, struct md_object *cobj,
208                               struct md_attr *attr, int mask);
209
210         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
211                             struct md_attr *attr);
212
213         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
214                             const struct md_attr *attr);
215
216         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
217                              struct lu_buf *buf, const char *name);
218
219         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
220                               struct lu_buf *buf);
221
222         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
223                              const struct lu_buf *buf, const char *name,
224                              int fl);
225
226         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
227                              const char *name);
228
229         /** This method is used to swap the layouts between 2 objects */
230         int (*moo_swap_layouts)(const struct lu_env *env,
231                                struct md_object *obj1, struct md_object *obj2,
232                                __u64 flags);
233
234         /** \retval number of bytes actually read upon success */
235         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
236                             const struct lu_rdpg *rdpg);
237
238         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
239                             struct lu_buf *buf);
240         int (*moo_changelog)(const struct lu_env *env,
241                              enum changelog_rec_type type, int flags,
242                              struct md_object *obj);
243         /** part of cross-ref operation */
244         int (*moo_object_create)(const struct lu_env *env,
245                                  struct md_object *obj,
246                                  const struct md_op_spec *spec,
247                                  struct md_attr *ma);
248
249         int (*moo_ref_add)(const struct lu_env *env,
250                            struct md_object *obj,
251                            const struct md_attr *ma);
252
253         int (*moo_ref_del)(const struct lu_env *env,
254                            struct md_object *obj,
255                            struct md_attr *ma);
256
257         int (*moo_open)(const struct lu_env *env,
258                         struct md_object *obj, int flag);
259
260         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
261                          struct md_attr *ma, int mode);
262
263         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
264                             struct lustre_capa *, int renewal);
265
266         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
267
268         int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
269                              struct lov_mds_md *lmm, struct ldlm_extent *extent,
270                              struct lustre_handle *lockh);
271         int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
272                                struct lov_mds_md *lmm,
273                                struct lustre_handle *lockh);
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                                void *policy);
278 };
279
280 /**
281  * Operations implemented for each directory object.
282  */
283 struct md_dir_operations {
284         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
285                               const struct lu_fid *fid, struct lu_fid *sfid);
286
287         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
288                           const struct lu_name *lname, struct lu_fid *fid,
289                           struct md_op_spec *spec);
290
291         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
292                                     struct md_object *obj,
293                                     mdl_mode_t mode);
294
295         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
296                           const struct lu_name *lname, struct md_object *child,
297                           struct md_op_spec *spec,
298                           struct md_attr *ma);
299
300         /** This method is used for creating data object for this meta object*/
301         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
302                                struct md_object *o,
303                                const struct md_op_spec *spec,
304                                struct md_attr *ma);
305
306         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
307                           struct md_object *tpobj, const struct lu_fid *lf,
308                           const struct lu_name *lsname, struct md_object *tobj,
309                           const struct lu_name *ltname, struct md_attr *ma);
310
311         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
312                         struct md_object *src_obj, const struct lu_name *lname,
313                         struct md_attr *ma);
314
315         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
316                           struct md_object *cobj, const struct lu_name *lname,
317                           struct md_attr *ma, int no_name);
318
319         /** This method is used to compare a requested layout to an existing
320          * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
321         int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
322                                struct md_object *cobj,
323                                const struct md_op_spec *spec,
324                                struct md_attr *ma);
325
326         /** partial ops for cross-ref case */
327         int (*mdo_name_insert)(const struct lu_env *env,
328                                struct md_object *obj,
329                                const struct lu_name *lname,
330                                const struct lu_fid *fid,
331                                const struct md_attr *ma);
332
333         int (*mdo_name_remove)(const struct lu_env *env,
334                                struct md_object *obj,
335                                const struct lu_name *lname,
336                                const struct md_attr *ma);
337
338         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
339                               struct md_object *tobj, const struct lu_fid *fid,
340                               const struct lu_name *lname, struct md_attr *ma);
341 };
342
343 struct md_device_operations {
344         /** meta-data device related handlers. */
345         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
346                             struct lu_fid *f);
347
348         int (*mdo_maxeasize_get)(const struct lu_env *env, struct md_device *m,
349                                 int *easize);
350
351         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
352                           struct obd_statfs *sfs);
353
354         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
355                                   int mode, unsigned long timeout, __u32 alg,
356                                   struct lustre_capa_key *keys);
357
358         int (*mdo_update_capa_key)(const struct lu_env *env,
359                                    struct md_device *m,
360                                    struct lustre_capa_key *key);
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 enum md_upcall_event {
370         /** Sync the md layer*/
371         MD_LOV_SYNC = (1 << 0),
372         /** Just for split, no need trans, for replay */
373         MD_NO_TRANS = (1 << 1),
374         MD_LOV_CONFIG = (1 << 2),
375         /** Trigger quota recovery */
376         MD_LOV_QUOTA = (1 << 3)
377 };
378
379 struct md_upcall {
380         /** this lock protects upcall using against its removal
381          * read lock is for usage the upcall, write - for init/fini */
382         struct rw_semaphore     mu_upcall_sem;
383         /** device to call, upper layer normally */
384         struct md_device       *mu_upcall_dev;
385         /** upcall function */
386         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
387                          enum md_upcall_event ev, void *data);
388 };
389
390 struct md_device {
391         struct lu_device                   md_lu_dev;
392         const struct md_device_operations *md_ops;
393         struct md_upcall                   md_upcall;
394 };
395
396 static inline void md_upcall_init(struct md_device *m, void *upcl)
397 {
398         init_rwsem(&m->md_upcall.mu_upcall_sem);
399         m->md_upcall.mu_upcall_dev = NULL;
400         m->md_upcall.mu_upcall = upcl;
401 }
402
403 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
404 {
405         down_write(&m->md_upcall.mu_upcall_sem);
406         m->md_upcall.mu_upcall_dev = up;
407         up_write(&m->md_upcall.mu_upcall_sem);
408 }
409
410 static inline void md_upcall_fini(struct md_device *m)
411 {
412         down_write(&m->md_upcall.mu_upcall_sem);
413         m->md_upcall.mu_upcall_dev = NULL;
414         m->md_upcall.mu_upcall = NULL;
415         up_write(&m->md_upcall.mu_upcall_sem);
416 }
417
418 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
419                                 enum md_upcall_event ev, void *data)
420 {
421         int rc = 0;
422         down_read(&m->md_upcall.mu_upcall_sem);
423         if (m->md_upcall.mu_upcall_dev != NULL &&
424             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
425                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
426                                               m->md_upcall.mu_upcall_dev,
427                                               ev, data);
428         }
429         up_read(&m->md_upcall.mu_upcall_sem);
430         return rc;
431 }
432
433 struct md_object {
434         struct lu_object                   mo_lu;
435         const struct md_object_operations *mo_ops;
436         const struct md_dir_operations    *mo_dir_ops;
437 };
438
439 /**
440  * seq-server site.
441  */
442 struct seq_server_site {
443         struct lu_site       *ss_lu;
444         /**
445          * mds number of this site.
446          */
447         mdsno_t               ss_node_id;
448         /**
449          * Fid location database
450          */
451         struct lu_server_fld *ss_server_fld;
452         struct lu_client_fld *ss_client_fld;
453
454         /**
455          * Server Seq Manager
456          */
457         struct lu_server_seq *ss_server_seq;
458
459         /**
460          * Controller Seq Manager
461          */
462         struct lu_server_seq *ss_control_seq;
463         struct obd_export    *ss_control_exp;
464
465         /**
466          * Client Seq Manager
467          */
468         struct lu_client_seq *ss_client_seq;
469 };
470
471 static inline struct md_device *lu2md_dev(const struct lu_device *d)
472 {
473         LASSERT(IS_ERR(d) || lu_device_is_md(d));
474         return container_of0(d, struct md_device, md_lu_dev);
475 }
476
477 static inline struct lu_device *md2lu_dev(struct md_device *d)
478 {
479         return &d->md_lu_dev;
480 }
481
482 static inline struct md_object *lu2md(const struct lu_object *o)
483 {
484         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
485         return container_of0(o, struct md_object, mo_lu);
486 }
487
488 static inline struct md_object *md_object_next(const struct md_object *obj)
489 {
490         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
491 }
492
493 static inline struct md_device *md_obj2dev(const struct md_object *o)
494 {
495         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
496         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
497 }
498
499 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
500 {
501         return lu_device_init(&md->md_lu_dev, t);
502 }
503
504 static inline void md_device_fini(struct md_device *md)
505 {
506         lu_device_fini(&md->md_lu_dev);
507 }
508
509 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
510                                                      struct md_device *md,
511                                                      const struct lu_fid *f)
512 {
513         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
514 }
515
516
517 /** md operations */
518 static inline int mo_permission(const struct lu_env *env,
519                                 struct md_object *p,
520                                 struct md_object *c,
521                                 struct md_attr *at,
522                                 int mask)
523 {
524         LASSERT(c->mo_ops->moo_permission);
525         return c->mo_ops->moo_permission(env, p, c, at, mask);
526 }
527
528 static inline int mo_attr_get(const struct lu_env *env,
529                               struct md_object *m,
530                               struct md_attr *at)
531 {
532         LASSERT(m->mo_ops->moo_attr_get);
533         return m->mo_ops->moo_attr_get(env, m, at);
534 }
535
536 static inline int mo_readlink(const struct lu_env *env,
537                               struct md_object *m,
538                               struct lu_buf *buf)
539 {
540         LASSERT(m->mo_ops->moo_readlink);
541         return m->mo_ops->moo_readlink(env, m, buf);
542 }
543
544 static inline int mo_changelog(const struct lu_env *env,
545                                enum changelog_rec_type type,
546                                int flags, struct md_object *m)
547 {
548         LASSERT(m->mo_ops->moo_changelog);
549         return m->mo_ops->moo_changelog(env, type, flags, m);
550 }
551
552 static inline int mo_attr_set(const struct lu_env *env,
553                               struct md_object *m,
554                               const struct md_attr *at)
555 {
556         LASSERT(m->mo_ops->moo_attr_set);
557         return m->mo_ops->moo_attr_set(env, m, at);
558 }
559
560 static inline int mo_xattr_get(const struct lu_env *env,
561                                struct md_object *m,
562                                struct lu_buf *buf,
563                                const char *name)
564 {
565         LASSERT(m->mo_ops->moo_xattr_get);
566         return m->mo_ops->moo_xattr_get(env, m, buf, name);
567 }
568
569 static inline int mo_xattr_del(const struct lu_env *env,
570                                struct md_object *m,
571                                const char *name)
572 {
573         LASSERT(m->mo_ops->moo_xattr_del);
574         return m->mo_ops->moo_xattr_del(env, m, name);
575 }
576
577 static inline int mo_xattr_set(const struct lu_env *env,
578                                struct md_object *m,
579                                const struct lu_buf *buf,
580                                const char *name,
581                                int flags)
582 {
583         LASSERT(m->mo_ops->moo_xattr_set);
584         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
585 }
586
587 static inline int mo_xattr_list(const struct lu_env *env,
588                                 struct md_object *m,
589                                 struct lu_buf *buf)
590 {
591         LASSERT(m->mo_ops->moo_xattr_list);
592         return m->mo_ops->moo_xattr_list(env, m, buf);
593 }
594
595 static inline int mo_swap_layouts(const struct lu_env *env,
596                                   struct md_object *o1,
597                                   struct md_object *o2, __u64 flags)
598 {
599         LASSERT(o1->mo_ops->moo_swap_layouts);
600         LASSERT(o2->mo_ops->moo_swap_layouts);
601         if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
602                 return -EPERM;
603         return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
604 }
605
606 static inline int mo_open(const struct lu_env *env,
607                           struct md_object *m,
608                           int flags)
609 {
610         LASSERT(m->mo_ops->moo_open);
611         return m->mo_ops->moo_open(env, m, flags);
612 }
613
614 static inline int mo_close(const struct lu_env *env,
615                            struct md_object *m,
616                            struct md_attr *ma,
617                            int mode)
618 {
619         LASSERT(m->mo_ops->moo_close);
620         return m->mo_ops->moo_close(env, m, ma, mode);
621 }
622
623 static inline int mo_readpage(const struct lu_env *env,
624                               struct md_object *m,
625                               const struct lu_rdpg *rdpg)
626 {
627         LASSERT(m->mo_ops->moo_readpage);
628         return m->mo_ops->moo_readpage(env, m, rdpg);
629 }
630
631 static inline int mo_object_create(const struct lu_env *env,
632                                    struct md_object *m,
633                                    const struct md_op_spec *spc,
634                                    struct md_attr *at)
635 {
636         LASSERT(m->mo_ops->moo_object_create);
637         return m->mo_ops->moo_object_create(env, m, spc, at);
638 }
639
640 static inline int mo_ref_add(const struct lu_env *env,
641                              struct md_object *m,
642                              const struct md_attr *ma)
643 {
644         LASSERT(m->mo_ops->moo_ref_add);
645         return m->mo_ops->moo_ref_add(env, m, ma);
646 }
647
648 static inline int mo_ref_del(const struct lu_env *env,
649                              struct md_object *m,
650                              struct md_attr *ma)
651 {
652         LASSERT(m->mo_ops->moo_ref_del);
653         return m->mo_ops->moo_ref_del(env, m, ma);
654 }
655
656 static inline int mo_capa_get(const struct lu_env *env,
657                               struct md_object *m,
658                               struct lustre_capa *c,
659                               int renewal)
660 {
661         LASSERT(m->mo_ops->moo_capa_get);
662         return m->mo_ops->moo_capa_get(env, m, c, renewal);
663 }
664
665 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
666 {
667         LASSERT(m->mo_ops->moo_object_sync);
668         return m->mo_ops->moo_object_sync(env, m);
669 }
670
671 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
672                                struct lov_mds_md *lmm,
673                                struct ldlm_extent *extent,
674                                struct lustre_handle *lockh)
675 {
676         LASSERT(m->mo_ops->moo_file_lock);
677         return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
678 }
679
680 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
681                                  struct lov_mds_md *lmm,
682                                  struct lustre_handle *lockh)
683 {
684         LASSERT(m->mo_ops->moo_file_unlock);
685         return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
686 }
687
688 static inline int mo_object_lock(const struct lu_env *env,
689                                  struct md_object *m,
690                                  struct lustre_handle *lh,
691                                  struct ldlm_enqueue_info *einfo,
692                                  void *policy)
693 {
694         LASSERT(m->mo_ops->moo_object_lock);
695         return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
696 }
697
698 static inline int mdo_lookup(const struct lu_env *env,
699                              struct md_object *p,
700                              const struct lu_name *lname,
701                              struct lu_fid *f,
702                              struct md_op_spec *spec)
703 {
704         LASSERT(p->mo_dir_ops->mdo_lookup);
705         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
706 }
707
708 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
709                                        struct md_object *mo,
710                                        mdl_mode_t lm)
711 {
712         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
713                 return MDL_MINMODE;
714         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
715 }
716
717 static inline int mdo_create(const struct lu_env *env,
718                              struct md_object *p,
719                              const struct lu_name *lchild_name,
720                              struct md_object *c,
721                              struct md_op_spec *spc,
722                              struct md_attr *at)
723 {
724         LASSERT(p->mo_dir_ops->mdo_create);
725         return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
726 }
727
728 static inline int mdo_create_data(const struct lu_env *env,
729                                   struct md_object *p,
730                                   struct md_object *c,
731                                   const struct md_op_spec *spec,
732                                   struct md_attr *ma)
733 {
734         LASSERT(c->mo_dir_ops->mdo_create_data);
735         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
736 }
737
738 static inline int mdo_rename(const struct lu_env *env,
739                              struct md_object *sp,
740                              struct md_object *tp,
741                              const struct lu_fid *lf,
742                              const struct lu_name *lsname,
743                              struct md_object *t,
744                              const struct lu_name *ltname,
745                              struct md_attr *ma)
746 {
747         LASSERT(tp->mo_dir_ops->mdo_rename);
748         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
749                                           ma);
750 }
751
752 static inline int mdo_is_subdir(const struct lu_env *env,
753                                 struct md_object *mo,
754                                 const struct lu_fid *fid,
755                                 struct lu_fid *sfid)
756 {
757         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
758         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
759 }
760
761 static inline int mdo_link(const struct lu_env *env,
762                            struct md_object *p,
763                            struct md_object *s,
764                            const struct lu_name *lname,
765                            struct md_attr *ma)
766 {
767         LASSERT(s->mo_dir_ops->mdo_link);
768         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
769 }
770
771 static inline int mdo_unlink(const struct lu_env *env,
772                              struct md_object *p,
773                              struct md_object *c,
774                              const struct lu_name *lname,
775                              struct md_attr *ma, int no_name)
776 {
777         LASSERT(p->mo_dir_ops->mdo_unlink);
778         return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
779 }
780
781 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
782                                   struct md_object *c,
783                                   const struct md_op_spec *spec,
784                                   struct md_attr *ma)
785 {
786         LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
787         return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
788 }
789
790 static inline int mdo_name_insert(const struct lu_env *env,
791                                   struct md_object *p,
792                                   const struct lu_name *lname,
793                                   const struct lu_fid *f,
794                                   const struct md_attr *ma)
795 {
796         LASSERT(p->mo_dir_ops->mdo_name_insert);
797         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
798 }
799
800 static inline int mdo_name_remove(const struct lu_env *env,
801                                   struct md_object *p,
802                                   const struct lu_name *lname,
803                                   const struct md_attr *ma)
804 {
805         LASSERT(p->mo_dir_ops->mdo_name_remove);
806         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
807 }
808
809 static inline int mdo_rename_tgt(const struct lu_env *env,
810                                  struct md_object *p,
811                                  struct md_object *t,
812                                  const struct lu_fid *lf,
813                                  const struct lu_name *lname,
814                                  struct md_attr *ma)
815 {
816         if (t) {
817                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
818                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
819         } else {
820                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
821                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
822         }
823 }
824
825 /**
826  * Used in MDD/OUT layer for object lock rule
827  **/
828 enum mdd_object_role {
829         MOR_SRC_PARENT,
830         MOR_SRC_CHILD,
831         MOR_TGT_PARENT,
832         MOR_TGT_CHILD,
833         MOR_TGT_ORPHAN
834 };
835
836 struct dt_device;
837 /**
838  * Structure to hold object information. This is used to create object
839  * \pre llod_dir exist
840  */
841 struct lu_local_obj_desc {
842         const char                      *llod_dir;
843         const char                      *llod_name;
844         __u32                            llod_oid;
845         int                              llod_is_index;
846         const struct dt_index_features  *llod_feat;
847         cfs_list_t                       llod_linkage;
848 };
849
850 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
851 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
852 void lustre_hsm2buf(void *buf, const struct md_hsm *mh);
853
854 enum {
855         UCRED_INVALID   = -1,
856         UCRED_INIT      = 0,
857         UCRED_OLD       = 1,
858         UCRED_NEW       = 2,
859 };
860
861 struct lu_ucred {
862         __u32               uc_valid;
863         __u32               uc_o_uid;
864         __u32               uc_o_gid;
865         __u32               uc_o_fsuid;
866         __u32               uc_o_fsgid;
867         __u32               uc_uid;
868         __u32               uc_gid;
869         __u32               uc_fsuid;
870         __u32               uc_fsgid;
871         __u32               uc_suppgids[2];
872         cfs_cap_t           uc_cap;
873         __u32               uc_umask;
874         cfs_group_info_t   *uc_ginfo;
875         struct md_identity *uc_identity;
876 };
877
878 struct lu_ucred *lu_ucred(const struct lu_env *env);
879
880 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
881
882 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
883
884 int lu_ucred_global_init(void);
885
886 void lu_ucred_global_fini(void);
887
888 #define md_cap_t(x) (x)
889
890 #define MD_CAP_TO_MASK(x) (1 << (x))
891
892 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
893
894 /* capable() is copied from linux kernel! */
895 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
896 {
897         if (md_cap_raised(uc->uc_cap, cap))
898                 return 1;
899         return 0;
900 }
901
902 /** @} md */
903 #endif /* _LINUX_MD_OBJECT_H */