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