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