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