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