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