Whamcloud - gitweb
f44453af2672756233595439859761bd24176b62
[fs/lustre-release.git] / lustre / include / md_object.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * Copyright (c) 2011 Whamcloud, Inc.
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  *
39  * lustre/include/md_object.h
40  *
41  * Extention of lu_object.h for metadata objects
42  */
43
44 #ifndef _LUSTRE_MD_OBJECT_H
45 #define _LUSTRE_MD_OBJECT_H
46
47 /** \defgroup md md
48  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
49  * stack.
50  *
51  * Meta-data objects implement namespace operations: you can link, unlink
52  * them, and treat them as directories.
53  *
54  * Examples: mdt, cmm, and mdt are implementations of md interface.
55  * @{
56  */
57
58
59 /*
60  * super-class definitions.
61  */
62 #include <dt_object.h>
63 #include <lvfs.h>
64
65 struct md_device;
66 struct md_device_operations;
67 struct md_object;
68 struct obd_export;
69
70 enum {
71         UCRED_INVALID   = -1,
72         UCRED_INIT      = 0,
73         UCRED_OLD       = 1,
74         UCRED_NEW       = 2
75 };
76
77 struct md_ucred {
78         __u32               mu_valid;
79         __u32               mu_o_uid;
80         __u32               mu_o_gid;
81         __u32               mu_o_fsuid;
82         __u32               mu_o_fsgid;
83         __u32               mu_uid;
84         __u32               mu_gid;
85         __u32               mu_fsuid;
86         __u32               mu_fsgid;
87         __u32               mu_suppgids[2];
88         cfs_cap_t           mu_cap;
89         __u32               mu_umask;
90         cfs_group_info_t   *mu_ginfo;
91         struct md_identity *mu_identity;
92 };
93
94 enum {
95         MD_CAPAINFO_MAX = 5
96 };
97
98 /** there are at most 5 fids in one operation, see rename, NOTE the last one
99  * is a temporary one used for is_subdir() */
100 struct md_capainfo {
101         __u32                   mc_auth;
102         __u32                   mc_padding;
103         const struct lu_fid    *mc_fid[MD_CAPAINFO_MAX];
104         struct lustre_capa     *mc_capa[MD_CAPAINFO_MAX];
105 };
106
107 struct md_quota {
108         struct obd_export       *mq_exp;
109 };
110
111 /**
112  * Implemented in mdd/mdd_handler.c.
113  *
114  * XXX should be moved into separate .h/.c together with all md security
115  * related definitions.
116  */
117 struct md_ucred *md_ucred(const struct lu_env *env);
118 struct md_capainfo *md_capainfo(const struct lu_env *env);
119 struct md_quota *md_quota(const struct lu_env *env);
120
121 /** metadata attributes */
122 enum ma_valid {
123         MA_INODE     = (1 << 0),
124         MA_LOV       = (1 << 1),
125         MA_COOKIE    = (1 << 2),
126         MA_FLAGS     = (1 << 3),
127         MA_LMV       = (1 << 4),
128         MA_ACL_DEF   = (1 << 5),
129         MA_LOV_DEF   = (1 << 6),
130         MA_LAY_GEN   = (1 << 7),
131         MA_HSM       = (1 << 8),
132         MA_SOM       = (1 << 9),
133         MA_PFID      = (1 << 10)
134 };
135
136 typedef enum {
137         MDL_MINMODE  = 0,
138         MDL_EX       = 1,
139         MDL_PW       = 2,
140         MDL_PR       = 4,
141         MDL_CW       = 8,
142         MDL_CR       = 16,
143         MDL_NL       = 32,
144         MDL_GROUP    = 64,
145         MDL_MAXMODE
146 } mdl_mode_t;
147
148 typedef enum {
149         MDT_NUL_LOCK = 0,
150         MDT_REG_LOCK = (1 << 0),
151         MDT_PDO_LOCK = (1 << 1)
152 } mdl_type_t;
153
154 struct md_hsm {
155         __u32  mh_flags;
156         __u32  mh_archive_number;
157 };
158
159 #define IOEPOCH_INVAL 0
160
161 struct md_som_data {
162         __u64 msd_ioepoch;
163         __u64 msd_size;
164         __u64 msd_blocks;
165         __u64 msd_mountid;
166 };
167
168 struct md_attr {
169         __u64                   ma_valid;
170         __u64                   ma_need;
171         __u64                   ma_attr_flags;
172         struct lu_attr          ma_attr;
173         struct lu_fid           ma_pfid;
174         struct md_hsm           ma_hsm;
175         struct lov_mds_md      *ma_lmm;
176         struct lmv_stripe_md   *ma_lmv;
177         void                   *ma_acl;
178         struct llog_cookie     *ma_cookie;
179         struct lustre_capa     *ma_capa;
180         struct md_som_data     *ma_som;
181         int                     ma_lmm_size;
182         int                     ma_lmv_size;
183         int                     ma_acl_size;
184         int                     ma_cookie_size;
185         __u16                   ma_layout_gen;
186 };
187
188 /** Additional parameters for create */
189 struct md_op_spec {
190         union {
191                 /** symlink target */
192                 const char               *sp_symname;
193                 /** parent FID for cross-ref mkdir */
194                 const struct lu_fid      *sp_pfid;
195                 /** eadata for regular files */
196                 struct md_spec_reg {
197                         /** lov objs exist already */
198                         const struct lu_fid   *fid;
199                         const void *eadata;
200                         int  eadatalen;
201                 } sp_ea;
202         } u;
203         /** don't create lov objects or llog cookie - this replay */
204         int no_create;
205
206         /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
207         __u64      sp_cr_flags;
208
209         /** Should mdd do lookup sanity check or not. */
210         int        sp_cr_lookup;
211
212         /** Current lock mode for parent dir where create is performing. */
213         mdl_mode_t sp_cr_mode;
214
215         /** Check for split */
216         int        sp_ck_split;
217
218         /** to create directory */
219         const struct dt_index_features *sp_feat;
220 };
221
222 /**
223  * Operations implemented for each md object (both directory and leaf).
224  */
225 struct md_object_operations {
226         int (*moo_permission)(const struct lu_env *env,
227                               struct md_object *pobj, struct md_object *cobj,
228                               struct md_attr *attr, int mask);
229
230         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
231                             struct md_attr *attr);
232
233         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
234                             const struct md_attr *attr);
235
236         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
237                              struct lu_buf *buf, const char *name);
238
239         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
240                               struct lu_buf *buf);
241
242         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
243                              const struct lu_buf *buf, const char *name,
244                              int fl);
245
246         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
247                              const char *name);
248
249         /** \retval number of bytes actually read upon success */
250         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
251                             const struct lu_rdpg *rdpg);
252
253         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
254                             struct lu_buf *buf);
255         int (*moo_changelog)(const struct lu_env *env,
256                              enum changelog_rec_type type, int flags,
257                              struct md_object *obj);
258         /** part of cross-ref operation */
259         int (*moo_object_create)(const struct lu_env *env,
260                                  struct md_object *obj,
261                                  const struct md_op_spec *spec,
262                                  struct md_attr *ma);
263
264         int (*moo_ref_add)(const struct lu_env *env,
265                            struct md_object *obj,
266                            const struct md_attr *ma);
267
268         int (*moo_ref_del)(const struct lu_env *env,
269                            struct md_object *obj,
270                            struct md_attr *ma);
271
272         int (*moo_open)(const struct lu_env *env,
273                         struct md_object *obj, int flag);
274
275         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
276                          struct md_attr *ma, int mode);
277
278         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
279                             struct lustre_capa *, int renewal);
280
281         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
282         int (*moo_path)(const struct lu_env *env, struct md_object *obj,
283                         char *path, int pathlen, __u64 *recno, int *linkno);
284         int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
285                              struct lov_mds_md *lmm, struct ldlm_extent *extent,
286                              struct lustre_handle *lockh);
287         int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
288                                struct lov_mds_md *lmm,
289                                struct lustre_handle *lockh);
290 };
291
292 /**
293  * Operations implemented for each directory object.
294  */
295 struct md_dir_operations {
296         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
297                               const struct lu_fid *fid, struct lu_fid *sfid);
298
299         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
300                           const struct lu_name *lname, struct lu_fid *fid,
301                           struct md_op_spec *spec);
302
303         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
304                                     struct md_object *obj,
305                                     mdl_mode_t mode);
306
307         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
308                           const struct lu_name *lname, struct md_object *child,
309                           struct md_op_spec *spec,
310                           struct md_attr *ma);
311
312         /** This method is used for creating data object for this meta object*/
313         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
314                                struct md_object *o,
315                                const struct md_op_spec *spec,
316                                struct md_attr *ma);
317
318         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
319                           struct md_object *tpobj, const struct lu_fid *lf,
320                           const struct lu_name *lsname, struct md_object *tobj,
321                           const struct lu_name *ltname, struct md_attr *ma);
322
323         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
324                         struct md_object *src_obj, const struct lu_name *lname,
325                         struct md_attr *ma);
326
327         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
328                           struct md_object *cobj, const struct lu_name *lname,
329                           struct md_attr *ma);
330
331         /** This method is used to compare a requested layout to an existing
332          * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
333         int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
334                                struct md_object *cobj,
335                                const struct md_op_spec *spec,
336                                struct md_attr *ma);
337
338         /** partial ops for cross-ref case */
339         int (*mdo_name_insert)(const struct lu_env *env,
340                                struct md_object *obj,
341                                const struct lu_name *lname,
342                                const struct lu_fid *fid,
343                                const struct md_attr *ma);
344
345         int (*mdo_name_remove)(const struct lu_env *env,
346                                struct md_object *obj,
347                                const struct lu_name *lname,
348                                const struct md_attr *ma);
349
350         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
351                               struct md_object *tobj, const struct lu_fid *fid,
352                               const struct lu_name *lname, struct md_attr *ma);
353 };
354
355 struct md_device_operations {
356         /** meta-data device related handlers. */
357         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
358                             struct lu_fid *f);
359
360         int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
361                                int *md_size, int *cookie_size);
362
363         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
364                           cfs_kstatfs_t *sfs);
365
366         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
367                                   int mode, unsigned long timeout, __u32 alg,
368                                   struct lustre_capa_key *keys);
369
370         int (*mdo_update_capa_key)(const struct lu_env *env,
371                                    struct md_device *m,
372                                    struct lustre_capa_key *key);
373
374         int (*mdo_llog_ctxt_get)(const struct lu_env *env,
375                                  struct md_device *m, int idx, void **h);
376
377         int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
378                              unsigned int cmd, int len, void *data);
379
380 #ifdef HAVE_QUOTA_SUPPORT
381         struct md_quota_operations {
382                 int (*mqo_notify)(const struct lu_env *env,
383                                   struct md_device *m);
384
385                 int (*mqo_setup)(const struct lu_env *env,
386                                  struct md_device *m,
387                                  void *data);
388
389                 int (*mqo_cleanup)(const struct lu_env *env,
390                                    struct md_device *m);
391
392                 int (*mqo_recovery)(const struct lu_env *env,
393                                     struct md_device *m);
394
395                 int (*mqo_check)(const struct lu_env *env,
396                                  struct md_device *m,
397                                  __u32 type);
398
399                 int (*mqo_on)(const struct lu_env *env,
400                               struct md_device *m,
401                               __u32 type);
402
403                 int (*mqo_off)(const struct lu_env *env,
404                                struct md_device *m,
405                                __u32 type);
406
407                 int (*mqo_setinfo)(const struct lu_env *env,
408                                    struct md_device *m,
409                                    __u32 type,
410                                    __u32 id,
411                                    struct obd_dqinfo *dqinfo);
412
413                 int (*mqo_getinfo)(const struct lu_env *env,
414                                    const struct md_device *m,
415                                    __u32 type,
416                                    __u32 id,
417                                    struct obd_dqinfo *dqinfo);
418
419                 int (*mqo_setquota)(const struct lu_env *env,
420                                     struct md_device *m,
421                                     __u32 type,
422                                     __u32 id,
423                                     struct obd_dqblk *dqblk);
424
425                 int (*mqo_getquota)(const struct lu_env *env,
426                                     const struct md_device *m,
427                                     __u32 type,
428                                     __u32 id,
429                                     struct obd_dqblk *dqblk);
430
431                 int (*mqo_getoinfo)(const struct lu_env *env,
432                                     const struct md_device *m,
433                                     __u32 type,
434                                     __u32 id,
435                                     struct obd_dqinfo *dqinfo);
436
437                 int (*mqo_getoquota)(const struct lu_env *env,
438                                      const struct md_device *m,
439                                      __u32 type,
440                                      __u32 id,
441                                      struct obd_dqblk *dqblk);
442
443                 int (*mqo_invalidate)(const struct lu_env *env,
444                                       struct md_device *m,
445                                       __u32 type);
446
447                 int (*mqo_finvalidate)(const struct lu_env *env,
448                                        struct md_device *m,
449                                        __u32 type);
450         } mdo_quota;
451 #endif
452 };
453
454 enum md_upcall_event {
455         /** Sync the md layer*/
456         MD_LOV_SYNC = (1 << 0),
457         /** Just for split, no need trans, for replay */
458         MD_NO_TRANS = (1 << 1),
459         MD_LOV_CONFIG = (1 << 2),
460         /** Trigger quota recovery */
461         MD_LOV_QUOTA = (1 << 3)
462 };
463
464 struct md_upcall {
465         /** this lock protects upcall using against its removal
466          * read lock is for usage the upcall, write - for init/fini */
467         cfs_rw_semaphore_t      mu_upcall_sem;
468         /** device to call, upper layer normally */
469         struct md_device       *mu_upcall_dev;
470         /** upcall function */
471         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
472                          enum md_upcall_event ev, void *data);
473 };
474
475 struct md_device {
476         struct lu_device                   md_lu_dev;
477         const struct md_device_operations *md_ops;
478         struct md_upcall                   md_upcall;
479 };
480
481 static inline void md_upcall_init(struct md_device *m, void *upcl)
482 {
483         cfs_init_rwsem(&m->md_upcall.mu_upcall_sem);
484         m->md_upcall.mu_upcall_dev = NULL;
485         m->md_upcall.mu_upcall = upcl;
486 }
487
488 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
489 {
490         cfs_down_write(&m->md_upcall.mu_upcall_sem);
491         m->md_upcall.mu_upcall_dev = up;
492         cfs_up_write(&m->md_upcall.mu_upcall_sem);
493 }
494
495 static inline void md_upcall_fini(struct md_device *m)
496 {
497         cfs_down_write(&m->md_upcall.mu_upcall_sem);
498         m->md_upcall.mu_upcall_dev = NULL;
499         m->md_upcall.mu_upcall = NULL;
500         cfs_up_write(&m->md_upcall.mu_upcall_sem);
501 }
502
503 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
504                                enum md_upcall_event ev, void *data)
505 {
506         int rc = 0;
507         cfs_down_read(&m->md_upcall.mu_upcall_sem);
508         if (m->md_upcall.mu_upcall_dev != NULL &&
509             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
510                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
511                                               m->md_upcall.mu_upcall_dev,
512                                               ev, data);
513         }
514         cfs_up_read(&m->md_upcall.mu_upcall_sem);
515         return rc;
516 }
517
518 struct md_object {
519         struct lu_object                   mo_lu;
520         const struct md_object_operations *mo_ops;
521         const struct md_dir_operations    *mo_dir_ops;
522 };
523
524 /**
525  * md-server site.
526  */
527 struct md_site {
528         struct lu_site ms_lu;
529         /**
530          * mds number of this site.
531          */
532         mdsno_t               ms_node_id;
533         /**
534          * Fid location database
535          */
536         struct lu_server_fld *ms_server_fld;
537         struct lu_client_fld *ms_client_fld;
538
539         /**
540          * Server Seq Manager
541          */
542         struct lu_server_seq *ms_server_seq;
543
544         /**
545          * Controller Seq Manager
546          */
547         struct lu_server_seq *ms_control_seq;
548         struct obd_export    *ms_control_exp;
549
550         /**
551          * Client Seq Manager
552          */
553         struct lu_client_seq *ms_client_seq;
554 };
555
556 static inline int lu_device_is_md(const struct lu_device *d)
557 {
558         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
559 }
560
561 static inline struct md_device *lu2md_dev(const struct lu_device *d)
562 {
563         LASSERT(IS_ERR(d) || lu_device_is_md(d));
564         return container_of0(d, struct md_device, md_lu_dev);
565 }
566
567 static inline struct lu_device *md2lu_dev(struct md_device *d)
568 {
569         return &d->md_lu_dev;
570 }
571
572 static inline struct md_object *lu2md(const struct lu_object *o)
573 {
574         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
575         return container_of0(o, struct md_object, mo_lu);
576 }
577
578 static inline struct md_object *md_object_next(const struct md_object *obj)
579 {
580         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
581 }
582
583 static inline struct md_device *md_obj2dev(const struct md_object *o)
584 {
585         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
586         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
587 }
588
589 static inline struct md_site *lu_site2md(const struct lu_site *s)
590 {
591         return container_of0(s, struct md_site, ms_lu);
592 }
593
594 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
595 {
596         return lu_device_init(&md->md_lu_dev, t);
597 }
598
599 static inline void md_device_fini(struct md_device *md)
600 {
601         lu_device_fini(&md->md_lu_dev);
602 }
603
604 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
605                                                      struct md_device *md,
606                                                      const struct lu_fid *f)
607 {
608         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
609 }
610
611
612 /** md operations */
613 static inline int mo_permission(const struct lu_env *env,
614                                 struct md_object *p,
615                                 struct md_object *c,
616                                 struct md_attr *at,
617                                 int mask)
618 {
619         LASSERT(c->mo_ops->moo_permission);
620         return c->mo_ops->moo_permission(env, p, c, at, mask);
621 }
622
623 static inline int mo_attr_get(const struct lu_env *env,
624                               struct md_object *m,
625                               struct md_attr *at)
626 {
627         LASSERT(m->mo_ops->moo_attr_get);
628         return m->mo_ops->moo_attr_get(env, m, at);
629 }
630
631 static inline int mo_readlink(const struct lu_env *env,
632                               struct md_object *m,
633                               struct lu_buf *buf)
634 {
635         LASSERT(m->mo_ops->moo_readlink);
636         return m->mo_ops->moo_readlink(env, m, buf);
637 }
638
639 static inline int mo_changelog(const struct lu_env *env,
640                                enum changelog_rec_type type,
641                                int flags, struct md_object *m)
642 {
643         LASSERT(m->mo_ops->moo_changelog);
644         return m->mo_ops->moo_changelog(env, type, flags, m);
645 }
646
647 static inline int mo_attr_set(const struct lu_env *env,
648                               struct md_object *m,
649                               const struct md_attr *at)
650 {
651         LASSERT(m->mo_ops->moo_attr_set);
652         return m->mo_ops->moo_attr_set(env, m, at);
653 }
654
655 static inline int mo_xattr_get(const struct lu_env *env,
656                                struct md_object *m,
657                                struct lu_buf *buf,
658                                const char *name)
659 {
660         LASSERT(m->mo_ops->moo_xattr_get);
661         return m->mo_ops->moo_xattr_get(env, m, buf, name);
662 }
663
664 static inline int mo_xattr_del(const struct lu_env *env,
665                                struct md_object *m,
666                                const char *name)
667 {
668         LASSERT(m->mo_ops->moo_xattr_del);
669         return m->mo_ops->moo_xattr_del(env, m, name);
670 }
671
672 static inline int mo_xattr_set(const struct lu_env *env,
673                                struct md_object *m,
674                                const struct lu_buf *buf,
675                                const char *name,
676                                int flags)
677 {
678         LASSERT(m->mo_ops->moo_xattr_set);
679         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
680 }
681
682 static inline int mo_xattr_list(const struct lu_env *env,
683                                 struct md_object *m,
684                                 struct lu_buf *buf)
685 {
686         LASSERT(m->mo_ops->moo_xattr_list);
687         return m->mo_ops->moo_xattr_list(env, m, buf);
688 }
689
690 static inline int mo_open(const struct lu_env *env,
691                           struct md_object *m,
692                           int flags)
693 {
694         LASSERT(m->mo_ops->moo_open);
695         return m->mo_ops->moo_open(env, m, flags);
696 }
697
698 static inline int mo_close(const struct lu_env *env,
699                            struct md_object *m,
700                            struct md_attr *ma,
701                            int mode)
702 {
703         LASSERT(m->mo_ops->moo_close);
704         return m->mo_ops->moo_close(env, m, ma, mode);
705 }
706
707 static inline int mo_readpage(const struct lu_env *env,
708                               struct md_object *m,
709                               const struct lu_rdpg *rdpg)
710 {
711         LASSERT(m->mo_ops->moo_readpage);
712         return m->mo_ops->moo_readpage(env, m, rdpg);
713 }
714
715 static inline int mo_object_create(const struct lu_env *env,
716                                    struct md_object *m,
717                                    const struct md_op_spec *spc,
718                                    struct md_attr *at)
719 {
720         LASSERT(m->mo_ops->moo_object_create);
721         return m->mo_ops->moo_object_create(env, m, spc, at);
722 }
723
724 static inline int mo_ref_add(const struct lu_env *env,
725                              struct md_object *m,
726                              const struct md_attr *ma)
727 {
728         LASSERT(m->mo_ops->moo_ref_add);
729         return m->mo_ops->moo_ref_add(env, m, ma);
730 }
731
732 static inline int mo_ref_del(const struct lu_env *env,
733                              struct md_object *m,
734                              struct md_attr *ma)
735 {
736         LASSERT(m->mo_ops->moo_ref_del);
737         return m->mo_ops->moo_ref_del(env, m, ma);
738 }
739
740 static inline int mo_capa_get(const struct lu_env *env,
741                               struct md_object *m,
742                               struct lustre_capa *c,
743                               int renewal)
744 {
745         LASSERT(m->mo_ops->moo_capa_get);
746         return m->mo_ops->moo_capa_get(env, m, c, renewal);
747 }
748
749 static inline int mo_path(const struct lu_env *env, struct md_object *m,
750                           char *path, int pathlen, __u64 *recno, int *linkno)
751 {
752         if (m->mo_ops->moo_path == NULL)
753                 return -ENOSYS;
754         return m->mo_ops->moo_path(env, m, path, pathlen, recno, linkno);
755 }
756
757 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
758 {
759         LASSERT(m->mo_ops->moo_object_sync);
760         return m->mo_ops->moo_object_sync(env, m);
761 }
762
763 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
764                                struct lov_mds_md *lmm,
765                                struct ldlm_extent *extent,
766                                struct lustre_handle *lockh)
767 {
768         LASSERT(m->mo_ops->moo_file_lock);
769         return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
770 }
771
772 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
773                                  struct lov_mds_md *lmm,
774                                  struct lustre_handle *lockh)
775 {
776         LASSERT(m->mo_ops->moo_file_unlock);
777         return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
778 }
779
780 static inline int mdo_lookup(const struct lu_env *env,
781                              struct md_object *p,
782                              const struct lu_name *lname,
783                              struct lu_fid *f,
784                              struct md_op_spec *spec)
785 {
786         LASSERT(p->mo_dir_ops->mdo_lookup);
787         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
788 }
789
790 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
791                                        struct md_object *mo,
792                                        mdl_mode_t lm)
793 {
794         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
795                 return MDL_MINMODE;
796         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
797 }
798
799 static inline int mdo_create(const struct lu_env *env,
800                              struct md_object *p,
801                              const struct lu_name *lchild_name,
802                              struct md_object *c,
803                              struct md_op_spec *spc,
804                              struct md_attr *at)
805 {
806         LASSERT(c->mo_dir_ops->mdo_create);
807         return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
808 }
809
810 static inline int mdo_create_data(const struct lu_env *env,
811                                   struct md_object *p,
812                                   struct md_object *c,
813                                   const struct md_op_spec *spec,
814                                   struct md_attr *ma)
815 {
816         LASSERT(c->mo_dir_ops->mdo_create_data);
817         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
818 }
819
820 static inline int mdo_rename(const struct lu_env *env,
821                              struct md_object *sp,
822                              struct md_object *tp,
823                              const struct lu_fid *lf,
824                              const struct lu_name *lsname,
825                              struct md_object *t,
826                              const struct lu_name *ltname,
827                              struct md_attr *ma)
828 {
829         LASSERT(tp->mo_dir_ops->mdo_rename);
830         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
831                                           ma);
832 }
833
834 static inline int mdo_is_subdir(const struct lu_env *env,
835                                 struct md_object *mo,
836                                 const struct lu_fid *fid,
837                                 struct lu_fid *sfid)
838 {
839         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
840         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
841 }
842
843 static inline int mdo_link(const struct lu_env *env,
844                            struct md_object *p,
845                            struct md_object *s,
846                            const struct lu_name *lname,
847                            struct md_attr *ma)
848 {
849         LASSERT(s->mo_dir_ops->mdo_link);
850         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
851 }
852
853 static inline int mdo_unlink(const struct lu_env *env,
854                              struct md_object *p,
855                              struct md_object *c,
856                              const struct lu_name *lname,
857                              struct md_attr *ma)
858 {
859         LASSERT(c->mo_dir_ops->mdo_unlink);
860         return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
861 }
862
863 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
864                                   struct md_object *c,
865                                   const struct md_op_spec *spec,
866                                   struct md_attr *ma)
867 {
868         LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
869         return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
870 }
871
872 static inline int mdo_name_insert(const struct lu_env *env,
873                                   struct md_object *p,
874                                   const struct lu_name *lname,
875                                   const struct lu_fid *f,
876                                   const struct md_attr *ma)
877 {
878         LASSERT(p->mo_dir_ops->mdo_name_insert);
879         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
880 }
881
882 static inline int mdo_name_remove(const struct lu_env *env,
883                                   struct md_object *p,
884                                   const struct lu_name *lname,
885                                   const struct md_attr *ma)
886 {
887         LASSERT(p->mo_dir_ops->mdo_name_remove);
888         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
889 }
890
891 static inline int mdo_rename_tgt(const struct lu_env *env,
892                                  struct md_object *p,
893                                  struct md_object *t,
894                                  const struct lu_fid *lf,
895                                  const struct lu_name *lname,
896                                  struct md_attr *ma)
897 {
898         if (t) {
899                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
900                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
901         } else {
902                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
903                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
904         }
905 }
906
907 struct dt_device;
908 /**
909  * Structure to hold object information. This is used to create object
910  * \pre llod_dir exist
911  */
912 struct lu_local_obj_desc {
913         const char                      *llod_dir;
914         const char                      *llod_name;
915         __u32                            llod_oid;
916         int                              llod_is_index;
917         const struct dt_index_features  *llod_feat;
918         cfs_list_t                       llod_linkage;
919 };
920
921 struct md_object *llo_store_resolve(const struct lu_env *env,
922                                     struct md_device *md,
923                                     struct dt_device *dt,
924                                     const char *path,
925                                     struct lu_fid *fid);
926
927 struct md_object *llo_store_open(const struct lu_env *env,
928                                  struct md_device *md,
929                                  struct dt_device *dt,
930                                  const char *dirname,
931                                  const char *objname,
932                                  struct lu_fid *fid);
933
934 struct md_object *llo_store_create_index(const struct lu_env *env,
935                                          struct md_device *md,
936                                          struct dt_device *dt,
937                                          const char *dirname,
938                                          const char *objname,
939                                          const struct lu_fid *fid,
940                                          const struct dt_index_features *feat);
941
942 struct md_object *llo_store_create(const struct lu_env *env,
943                                    struct md_device *md,
944                                    struct dt_device *dt,
945                                    const char *dirname,
946                                    const char *objname,
947                                    const struct lu_fid *fid);
948
949 void llo_local_obj_register(struct lu_local_obj_desc *);
950 void llo_local_obj_unregister(struct lu_local_obj_desc *);
951
952 int llo_local_objects_setup(const struct lu_env *env,
953                              struct md_device * md,
954                              struct dt_device * dt);
955
956 /** @} md */
957 #endif /* _LINUX_MD_OBJECT_H */