Whamcloud - gitweb
b=17785
[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 <lu_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         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
248 };
249
250 /**
251  * Operations implemented for each directory object.
252  */
253 struct md_dir_operations {
254         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
255                               const struct lu_fid *fid, struct lu_fid *sfid);
256
257         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
258                           const struct lu_name *lname, struct lu_fid *fid,
259                           struct md_op_spec *spec);
260
261         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
262                                     struct md_object *obj,
263                                     mdl_mode_t mode);
264
265         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
266                           const struct lu_name *lname, struct md_object *child,
267                           struct md_op_spec *spec,
268                           struct md_attr *ma);
269
270         /** This method is used for creating data object for this meta object*/
271         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
272                                struct md_object *o,
273                                const struct md_op_spec *spec,
274                                struct md_attr *ma);
275
276         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
277                           struct md_object *tpobj, const struct lu_fid *lf,
278                           const struct lu_name *lsname, struct md_object *tobj,
279                           const struct lu_name *ltname, struct md_attr *ma);
280
281         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
282                         struct md_object *src_obj, const struct lu_name *lname,
283                         struct md_attr *ma);
284
285         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
286                           struct md_object *cobj, const struct lu_name *lname,
287                           struct md_attr *ma);
288
289         /** partial ops for cross-ref case */
290         int (*mdo_name_insert)(const struct lu_env *env,
291                                struct md_object *obj,
292                                const struct lu_name *lname,
293                                const struct lu_fid *fid,
294                                const struct md_attr *ma);
295
296         int (*mdo_name_remove)(const struct lu_env *env,
297                                struct md_object *obj,
298                                const struct lu_name *lname,
299                                const struct md_attr *ma);
300
301         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
302                               struct md_object *tobj, const struct lu_fid *fid,
303                               const struct lu_name *lname, struct md_attr *ma);
304 };
305
306 struct md_device_operations {
307         /** meta-data device related handlers. */
308         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
309                             struct lu_fid *f);
310
311         int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
312                                int *md_size, int *cookie_size);
313
314         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
315                           struct kstatfs *sfs);
316
317         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
318                                   int mode, unsigned long timeout, __u32 alg,
319                                   struct lustre_capa_key *keys);
320
321         int (*mdo_update_capa_key)(const struct lu_env *env,
322                                    struct md_device *m,
323                                    struct lustre_capa_key *key);
324
325 #ifdef HAVE_QUOTA_SUPPORT
326         struct md_quota_operations {
327                 int (*mqo_notify)(const struct lu_env *env,
328                                   struct md_device *m);
329
330                 int (*mqo_setup)(const struct lu_env *env,
331                                  struct md_device *m,
332                                  void *data);
333
334                 int (*mqo_cleanup)(const struct lu_env *env,
335                                    struct md_device *m);
336
337                 int (*mqo_recovery)(const struct lu_env *env,
338                                     struct md_device *m);
339
340                 int (*mqo_check)(const struct lu_env *env,
341                                  struct md_device *m,
342                                  struct obd_export *exp,
343                                  __u32 type);
344
345                 int (*mqo_on)(const struct lu_env *env,
346                               struct md_device *m,
347                               __u32 type,
348                               __u32 id);
349
350                 int (*mqo_off)(const struct lu_env *env,
351                                struct md_device *m,
352                                __u32 type,
353                                __u32 id);
354
355                 int (*mqo_setinfo)(const struct lu_env *env,
356                                    struct md_device *m,
357                                    __u32 type,
358                                    __u32 id,
359                                    struct obd_dqinfo *dqinfo);
360
361                 int (*mqo_getinfo)(const struct lu_env *env,
362                                    const struct md_device *m,
363                                    __u32 type,
364                                    __u32 id,
365                                    struct obd_dqinfo *dqinfo);
366
367                 int (*mqo_setquota)(const struct lu_env *env,
368                                     struct md_device *m,
369                                     __u32 type,
370                                     __u32 id,
371                                     struct obd_dqblk *dqblk);
372
373                 int (*mqo_getquota)(const struct lu_env *env,
374                                     const struct md_device *m,
375                                     __u32 type,
376                                     __u32 id,
377                                     struct obd_dqblk *dqblk);
378
379                 int (*mqo_getoinfo)(const struct lu_env *env,
380                                     const struct md_device *m,
381                                     __u32 type,
382                                     __u32 id,
383                                     struct obd_dqinfo *dqinfo);
384
385                 int (*mqo_getoquota)(const struct lu_env *env,
386                                      const struct md_device *m,
387                                      __u32 type,
388                                      __u32 id,
389                                      struct obd_dqblk *dqblk);
390
391                 int (*mqo_invalidate)(const struct lu_env *env,
392                                       struct md_device *m,
393                                       __u32 type);
394
395                 int (*mqo_finvalidate)(const struct lu_env *env,
396                                        struct md_device *m,
397                                        __u32 type);
398         } mdo_quota;
399 #endif
400 };
401
402 enum md_upcall_event {
403         /**sync the md layer*/
404         MD_LOV_SYNC = (1 << 0),
405         /** Just for split, no need trans, for replay */
406         MD_NO_TRANS = (1 << 1),
407         MD_LOV_CONFIG = (1 << 2)
408 };
409
410 struct md_upcall {
411         /** this lock protects upcall using against its removal
412          * read lock is for usage the upcall, write - for init/fini */
413         struct rw_semaphore     mu_upcall_sem;
414         /** device to call, upper layer normally */
415         struct md_device       *mu_upcall_dev;
416         /** upcall function */
417         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
418                          enum md_upcall_event ev);
419 };
420
421 struct md_device {
422         struct lu_device                   md_lu_dev;
423         const struct md_device_operations *md_ops;
424         struct md_upcall                   md_upcall;
425 };
426
427 static inline void md_upcall_init(struct md_device *m, void *upcl)
428 {
429         init_rwsem(&m->md_upcall.mu_upcall_sem);
430         m->md_upcall.mu_upcall_dev = NULL;
431         m->md_upcall.mu_upcall = upcl;
432 }
433
434 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
435 {
436         down_write(&m->md_upcall.mu_upcall_sem);
437         m->md_upcall.mu_upcall_dev = up;
438         up_write(&m->md_upcall.mu_upcall_sem);
439 }
440
441 static inline void md_upcall_fini(struct md_device *m)
442 {
443         down_write(&m->md_upcall.mu_upcall_sem);
444         m->md_upcall.mu_upcall_dev = NULL;
445         m->md_upcall.mu_upcall = NULL;
446         up_write(&m->md_upcall.mu_upcall_sem);
447 }
448
449 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
450                                enum md_upcall_event ev)
451 {
452         int rc = 0;
453         down_read(&m->md_upcall.mu_upcall_sem);
454         if (m->md_upcall.mu_upcall_dev != NULL &&
455             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
456                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
457                                               m->md_upcall.mu_upcall_dev, ev);
458         }
459         up_read(&m->md_upcall.mu_upcall_sem);
460         return rc;
461 }
462
463 struct md_object {
464         struct lu_object                   mo_lu;
465         const struct md_object_operations *mo_ops;
466         const struct md_dir_operations    *mo_dir_ops;
467 };
468
469 /**
470  * md-server site.
471  */
472 struct md_site {
473         struct lu_site ms_lu;
474         /**
475          * mds number of this site.
476          */
477         mdsno_t               ms_node_id;
478         /**
479          * Fid location database
480          */
481         struct lu_server_fld *ms_server_fld;
482         struct lu_client_fld *ms_client_fld;
483
484         /**
485          * Server Seq Manager
486          */
487         struct lu_server_seq *ms_server_seq;
488
489         /**
490          * Controller Seq Manager
491          */
492         struct lu_server_seq *ms_control_seq;
493         struct obd_export    *ms_control_exp;
494
495         /**
496          * Client Seq Manager
497          */
498         struct lu_client_seq *ms_client_seq;
499 };
500
501 static inline int lu_device_is_md(const struct lu_device *d)
502 {
503         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
504 }
505
506 static inline struct md_device *lu2md_dev(const struct lu_device *d)
507 {
508         LASSERT(IS_ERR(d) || lu_device_is_md(d));
509         return container_of0(d, struct md_device, md_lu_dev);
510 }
511
512 static inline struct lu_device *md2lu_dev(struct md_device *d)
513 {
514         return &d->md_lu_dev;
515 }
516
517 static inline struct md_object *lu2md(const struct lu_object *o)
518 {
519         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
520         return container_of0(o, struct md_object, mo_lu);
521 }
522
523 static inline struct md_object *md_object_next(const struct md_object *obj)
524 {
525         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
526 }
527
528 static inline struct md_device *md_obj2dev(const struct md_object *o)
529 {
530         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
531         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
532 }
533
534 static inline struct md_site *lu_site2md(const struct lu_site *s)
535 {
536         return container_of0(s, struct md_site, ms_lu);
537 }
538
539 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
540 {
541         return lu_device_init(&md->md_lu_dev, t);
542 }
543
544 static inline void md_device_fini(struct md_device *md)
545 {
546         lu_device_fini(&md->md_lu_dev);
547 }
548
549 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
550                                                      struct md_device *md,
551                                                      const struct lu_fid *f)
552 {
553         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
554 }
555
556
557 /** md operations */
558 static inline int mo_permission(const struct lu_env *env,
559                                 struct md_object *p,
560                                 struct md_object *c,
561                                 struct md_attr *at,
562                                 int mask)
563 {
564         LASSERT(c->mo_ops->moo_permission);
565         return c->mo_ops->moo_permission(env, p, c, at, mask);
566 }
567
568 static inline int mo_attr_get(const struct lu_env *env,
569                               struct md_object *m,
570                               struct md_attr *at)
571 {
572         LASSERT(m->mo_ops->moo_attr_get);
573         return m->mo_ops->moo_attr_get(env, m, at);
574 }
575
576 static inline int mo_readlink(const struct lu_env *env,
577                               struct md_object *m,
578                               struct lu_buf *buf)
579 {
580         LASSERT(m->mo_ops->moo_readlink);
581         return m->mo_ops->moo_readlink(env, m, buf);
582 }
583
584 static inline int mo_attr_set(const struct lu_env *env,
585                               struct md_object *m,
586                               const struct md_attr *at)
587 {
588         LASSERT(m->mo_ops->moo_attr_set);
589         return m->mo_ops->moo_attr_set(env, m, at);
590 }
591
592 static inline int mo_xattr_get(const struct lu_env *env,
593                                struct md_object *m,
594                                struct lu_buf *buf,
595                                const char *name)
596 {
597         LASSERT(m->mo_ops->moo_xattr_get);
598         return m->mo_ops->moo_xattr_get(env, m, buf, name);
599 }
600
601 static inline int mo_xattr_del(const struct lu_env *env,
602                                struct md_object *m,
603                                const char *name)
604 {
605         LASSERT(m->mo_ops->moo_xattr_del);
606         return m->mo_ops->moo_xattr_del(env, m, name);
607 }
608
609 static inline int mo_xattr_set(const struct lu_env *env,
610                                struct md_object *m,
611                                const struct lu_buf *buf,
612                                const char *name,
613                                int flags)
614 {
615         LASSERT(m->mo_ops->moo_xattr_set);
616         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
617 }
618
619 static inline int mo_xattr_list(const struct lu_env *env,
620                                 struct md_object *m,
621                                 struct lu_buf *buf)
622 {
623         LASSERT(m->mo_ops->moo_xattr_list);
624         return m->mo_ops->moo_xattr_list(env, m, buf);
625 }
626
627 static inline int mo_open(const struct lu_env *env,
628                           struct md_object *m,
629                           int flags)
630 {
631         LASSERT(m->mo_ops->moo_open);
632         return m->mo_ops->moo_open(env, m, flags);
633 }
634
635 static inline int mo_close(const struct lu_env *env,
636                            struct md_object *m,
637                            struct md_attr *ma)
638 {
639         LASSERT(m->mo_ops->moo_close);
640         return m->mo_ops->moo_close(env, m, ma);
641 }
642
643 static inline int mo_readpage(const struct lu_env *env,
644                               struct md_object *m,
645                               const struct lu_rdpg *rdpg)
646 {
647         LASSERT(m->mo_ops->moo_readpage);
648         return m->mo_ops->moo_readpage(env, m, rdpg);
649 }
650
651 static inline int mo_object_create(const struct lu_env *env,
652                                    struct md_object *m,
653                                    const struct md_op_spec *spc,
654                                    struct md_attr *at)
655 {
656         LASSERT(m->mo_ops->moo_object_create);
657         return m->mo_ops->moo_object_create(env, m, spc, at);
658 }
659
660 static inline int mo_ref_add(const struct lu_env *env,
661                              struct md_object *m,
662                              const struct md_attr *ma)
663 {
664         LASSERT(m->mo_ops->moo_ref_add);
665         return m->mo_ops->moo_ref_add(env, m, ma);
666 }
667
668 static inline int mo_ref_del(const struct lu_env *env,
669                              struct md_object *m,
670                              struct md_attr *ma)
671 {
672         LASSERT(m->mo_ops->moo_ref_del);
673         return m->mo_ops->moo_ref_del(env, m, ma);
674 }
675
676 static inline int mo_capa_get(const struct lu_env *env,
677                               struct md_object *m,
678                               struct lustre_capa *c,
679                               int renewal)
680 {
681         LASSERT(m->mo_ops->moo_capa_get);
682         return m->mo_ops->moo_capa_get(env, m, c, renewal);
683 }
684
685 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
686 {
687         LASSERT(m->mo_ops->moo_object_sync);
688         return m->mo_ops->moo_object_sync(env, m);
689 }
690
691 static inline int mdo_lookup(const struct lu_env *env,
692                              struct md_object *p,
693                              const struct lu_name *lname,
694                              struct lu_fid *f,
695                              struct md_op_spec *spec)
696 {
697         LASSERT(p->mo_dir_ops->mdo_lookup);
698         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
699 }
700
701 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
702                                        struct md_object *mo,
703                                        mdl_mode_t lm)
704 {
705         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
706                 return MDL_MINMODE;
707         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
708 }
709
710 static inline int mdo_create(const struct lu_env *env,
711                              struct md_object *p,
712                              const struct lu_name *lchild_name,
713                              struct md_object *c,
714                              struct md_op_spec *spc,
715                              struct md_attr *at)
716 {
717         LASSERT(c->mo_dir_ops->mdo_create);
718         return c->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
719 }
720
721 static inline int mdo_create_data(const struct lu_env *env,
722                                   struct md_object *p,
723                                   struct md_object *c,
724                                   const struct md_op_spec *spec,
725                                   struct md_attr *ma)
726 {
727         LASSERT(c->mo_dir_ops->mdo_create_data);
728         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
729 }
730
731 static inline int mdo_rename(const struct lu_env *env,
732                              struct md_object *sp,
733                              struct md_object *tp,
734                              const struct lu_fid *lf,
735                              const struct lu_name *lsname,
736                              struct md_object *t,
737                              const struct lu_name *ltname,
738                              struct md_attr *ma)
739 {
740         LASSERT(tp->mo_dir_ops->mdo_rename);
741         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
742                                           ma);
743 }
744
745 static inline int mdo_is_subdir(const struct lu_env *env,
746                                 struct md_object *mo,
747                                 const struct lu_fid *fid,
748                                 struct lu_fid *sfid)
749 {
750         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
751         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
752 }
753
754 static inline int mdo_link(const struct lu_env *env,
755                            struct md_object *p,
756                            struct md_object *s,
757                            const struct lu_name *lname,
758                            struct md_attr *ma)
759 {
760         LASSERT(s->mo_dir_ops->mdo_link);
761         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
762 }
763
764 static inline int mdo_unlink(const struct lu_env *env,
765                              struct md_object *p,
766                              struct md_object *c,
767                              const struct lu_name *lname,
768                              struct md_attr *ma)
769 {
770         LASSERT(c->mo_dir_ops->mdo_unlink);
771         return c->mo_dir_ops->mdo_unlink(env, p, c, lname, ma);
772 }
773
774 static inline int mdo_name_insert(const struct lu_env *env,
775                                   struct md_object *p,
776                                   const struct lu_name *lname,
777                                   const struct lu_fid *f,
778                                   const struct md_attr *ma)
779 {
780         LASSERT(p->mo_dir_ops->mdo_name_insert);
781         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
782 }
783
784 static inline int mdo_name_remove(const struct lu_env *env,
785                                   struct md_object *p,
786                                   const struct lu_name *lname,
787                                   const struct md_attr *ma)
788 {
789         LASSERT(p->mo_dir_ops->mdo_name_remove);
790         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
791 }
792
793 static inline int mdo_rename_tgt(const struct lu_env *env,
794                                  struct md_object *p,
795                                  struct md_object *t,
796                                  const struct lu_fid *lf,
797                                  const struct lu_name *lname,
798                                  struct md_attr *ma)
799 {
800         if (t) {
801                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
802                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
803         } else {
804                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
805                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
806         }
807 }
808
809 struct dt_device;
810 /**
811  * Structure to hold object information. This is used to create object
812  * \pre llod_dir exist
813  */
814 struct lu_local_obj_desc {
815         const char                      *llod_dir;
816         const char                      *llod_name;
817         __u32                            llod_oid;
818         int                              llod_is_index;
819         const struct dt_index_features * llod_feat;
820         struct list_head                 llod_linkage;
821 };
822
823 struct md_object *llo_store_resolve(const struct lu_env *env,
824                                     struct md_device *md,
825                                     struct dt_device *dt,
826                                     const char *path,
827                                     struct lu_fid *fid);
828
829 struct md_object *llo_store_open(const struct lu_env *env,
830                                  struct md_device *md,
831                                  struct dt_device *dt,
832                                  const char *dirname,
833                                  const char *objname,
834                                  struct lu_fid *fid);
835
836 struct md_object *llo_store_create_index(const struct lu_env *env,
837                                          struct md_device *md,
838                                          struct dt_device *dt,
839                                          const char *dirname,
840                                          const char *objname,
841                                          const struct lu_fid *fid,
842                                          const struct dt_index_features *feat);
843
844 struct md_object *llo_store_create(const struct lu_env *env,
845                                    struct md_device *md,
846                                    struct dt_device *dt,
847                                    const char *dirname,
848                                    const char *objname,
849                                    const struct lu_fid *fid);
850
851 void llo_local_obj_register(struct lu_local_obj_desc *);
852 void llo_local_obj_unregister(struct lu_local_obj_desc *);
853
854 int llo_local_objects_setup(const struct lu_env *env,
855                              struct md_device * md,
856                              struct dt_device * dt);
857
858 /** @} md */
859 #endif /* _LINUX_MD_OBJECT_H */