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