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