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