Whamcloud - gitweb
LU-1198 idl: move FID VER to DLM resource name[1]
[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  * Copyright (c) 2011, 2012, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  *
38  * lustre/include/md_object.h
39  *
40  * Extention of lu_object.h for metadata objects
41  */
42
43 #ifndef _LUSTRE_MD_OBJECT_H
44 #define _LUSTRE_MD_OBJECT_H
45
46 /** \defgroup md md
47  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
48  * stack.
49  *
50  * Meta-data objects implement namespace operations: you can link, unlink
51  * them, and treat them as directories.
52  *
53  * Examples: mdt, cmm, and mdt are implementations of md interface.
54  * @{
55  */
56
57
58 /*
59  * super-class definitions.
60  */
61 #include <dt_object.h>
62 #include <lvfs.h>
63
64 /* LU-1051, temperary solution to reduce llog credits */
65 #define DECLARE_LLOG_REWRITE  0
66 #define DECLARE_LLOG_WRITE    INT_MAX
67
68 struct md_device;
69 struct md_device_operations;
70 struct md_object;
71 struct obd_export;
72
73 enum {
74         UCRED_INVALID   = -1,
75         UCRED_INIT      = 0,
76         UCRED_OLD       = 1,
77         UCRED_NEW       = 2
78 };
79
80 struct md_ucred {
81         __u32               mu_valid;
82         __u32               mu_o_uid;
83         __u32               mu_o_gid;
84         __u32               mu_o_fsuid;
85         __u32               mu_o_fsgid;
86         __u32               mu_uid;
87         __u32               mu_gid;
88         __u32               mu_fsuid;
89         __u32               mu_fsgid;
90         __u32               mu_suppgids[2];
91         cfs_cap_t           mu_cap;
92         __u32               mu_umask;
93         cfs_group_info_t   *mu_ginfo;
94         struct md_identity *mu_identity;
95 };
96
97 enum {
98         MD_CAPAINFO_MAX = 5
99 };
100
101 /** there are at most 5 fids in one operation, see rename, NOTE the last one
102  * is a temporary one used for is_subdir() */
103 struct md_capainfo {
104         __u32                   mc_auth;
105         __u32                   mc_padding;
106         struct lu_fid           mc_fid[MD_CAPAINFO_MAX];
107         struct lustre_capa     *mc_capa[MD_CAPAINFO_MAX];
108 };
109
110 struct md_quota {
111         struct obd_export       *mq_exp;
112 };
113
114 /**
115  * Implemented in mdd/mdd_handler.c.
116  *
117  * XXX should be moved into separate .h/.c together with all md security
118  * related definitions.
119  */
120 struct md_ucred *md_ucred(const struct lu_env *env);
121 struct md_capainfo *md_capainfo(const struct lu_env *env);
122 struct md_quota *md_quota(const struct lu_env *env);
123
124 /** metadata attributes */
125 enum ma_valid {
126         MA_INODE     = (1 << 0),
127         MA_LOV       = (1 << 1),
128         MA_COOKIE    = (1 << 2),
129         MA_FLAGS     = (1 << 3),
130         MA_LMV       = (1 << 4),
131         MA_ACL_DEF   = (1 << 5),
132         MA_LOV_DEF   = (1 << 6),
133         MA_LAY_GEN   = (1 << 7),
134         MA_HSM       = (1 << 8),
135         MA_SOM       = (1 << 9),
136         MA_PFID      = (1 << 10)
137 };
138
139 typedef enum {
140         MDL_MINMODE  = 0,
141         MDL_EX       = 1,
142         MDL_PW       = 2,
143         MDL_PR       = 4,
144         MDL_CW       = 8,
145         MDL_CR       = 16,
146         MDL_NL       = 32,
147         MDL_GROUP    = 64,
148         MDL_MAXMODE
149 } mdl_mode_t;
150
151 typedef enum {
152         MDT_NUL_LOCK = 0,
153         MDT_REG_LOCK = (1 << 0),
154         MDT_PDO_LOCK = (1 << 1)
155 } mdl_type_t;
156
157 struct md_hsm {
158         __u32  mh_flags;
159         __u32  mh_archive_number;
160 };
161
162 #define IOEPOCH_INVAL 0
163
164 struct md_som_data {
165         __u64 msd_ioepoch;
166         __u64 msd_size;
167         __u64 msd_blocks;
168         __u64 msd_mountid;
169 };
170
171 struct md_attr {
172         __u64                   ma_valid;
173         __u64                   ma_need;
174         __u64                   ma_attr_flags;
175         struct lu_attr          ma_attr;
176         struct lu_fid           ma_pfid;
177         struct md_hsm           ma_hsm;
178         struct lov_mds_md      *ma_lmm;
179         struct lmv_stripe_md   *ma_lmv;
180         void                   *ma_acl;
181         struct llog_cookie     *ma_cookie;
182         struct lustre_capa     *ma_capa;
183         struct md_som_data     *ma_som;
184         int                     ma_lmm_size;
185         int                     ma_lmv_size;
186         int                     ma_acl_size;
187         int                     ma_cookie_size;
188         __u16                   ma_layout_gen;
189 };
190
191 /** Additional parameters for create */
192 struct md_op_spec {
193         union {
194                 /** symlink target */
195                 const char               *sp_symname;
196                 /** parent FID for cross-ref mkdir */
197                 const struct lu_fid      *sp_pfid;
198                 /** eadata for regular files */
199                 struct md_spec_reg {
200                         /** lov objs exist already */
201                         const struct lu_fid   *fid;
202                         const void *eadata;
203                         int  eadatalen;
204                 } sp_ea;
205         } u;
206         /** don't create lov objects or llog cookie - this replay */
207         int no_create;
208
209         /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
210         __u64      sp_cr_flags;
211
212         /** Should mdd do lookup sanity check or not. */
213         int        sp_cr_lookup;
214
215         /** Current lock mode for parent dir where create is performing. */
216         mdl_mode_t sp_cr_mode;
217
218         /** Check for split */
219         int        sp_ck_split;
220
221         /** to create directory */
222         const struct dt_index_features *sp_feat;
223 };
224
225 /**
226  * Operations implemented for each md object (both directory and leaf).
227  */
228 struct md_object_operations {
229         int (*moo_permission)(const struct lu_env *env,
230                               struct md_object *pobj, struct md_object *cobj,
231                               struct md_attr *attr, int mask);
232
233         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
234                             struct md_attr *attr);
235
236         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
237                             const struct md_attr *attr);
238
239         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
240                              struct lu_buf *buf, const char *name);
241
242         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
243                               struct lu_buf *buf);
244
245         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
246                              const struct lu_buf *buf, const char *name,
247                              int fl);
248
249         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
250                              const char *name);
251
252         /** \retval number of bytes actually read upon success */
253         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
254                             const struct lu_rdpg *rdpg);
255
256         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
257                             struct lu_buf *buf);
258         int (*moo_changelog)(const struct lu_env *env,
259                              enum changelog_rec_type type, int flags,
260                              struct md_object *obj);
261         /** part of cross-ref operation */
262         int (*moo_object_create)(const struct lu_env *env,
263                                  struct md_object *obj,
264                                  const struct md_op_spec *spec,
265                                  struct md_attr *ma);
266
267         int (*moo_ref_add)(const struct lu_env *env,
268                            struct md_object *obj,
269                            const struct md_attr *ma);
270
271         int (*moo_ref_del)(const struct lu_env *env,
272                            struct md_object *obj,
273                            struct md_attr *ma);
274
275         int (*moo_open)(const struct lu_env *env,
276                         struct md_object *obj, int flag);
277
278         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
279                          struct md_attr *ma, int mode);
280
281         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
282                             struct lustre_capa *, int renewal);
283
284         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
285         int (*moo_path)(const struct lu_env *env, struct md_object *obj,
286                         char *path, int pathlen, __u64 *recno, int *linkno);
287         int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
288                              struct lov_mds_md *lmm, struct ldlm_extent *extent,
289                              struct lustre_handle *lockh);
290         int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
291                                struct lov_mds_md *lmm,
292                                struct lustre_handle *lockh);
293 };
294
295 /**
296  * Operations implemented for each directory object.
297  */
298 struct md_dir_operations {
299         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
300                               const struct lu_fid *fid, struct lu_fid *sfid);
301
302         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
303                           const struct lu_name *lname, struct lu_fid *fid,
304                           struct md_op_spec *spec);
305
306         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
307                                     struct md_object *obj,
308                                     mdl_mode_t mode);
309
310         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
311                           const struct lu_name *lname, struct md_object *child,
312                           struct md_op_spec *spec,
313                           struct md_attr *ma);
314
315         /** This method is used for creating data object for this meta object*/
316         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
317                                struct md_object *o,
318                                const struct md_op_spec *spec,
319                                struct md_attr *ma);
320
321         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
322                           struct md_object *tpobj, const struct lu_fid *lf,
323                           const struct lu_name *lsname, struct md_object *tobj,
324                           const struct lu_name *ltname, struct md_attr *ma);
325
326         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
327                         struct md_object *src_obj, const struct lu_name *lname,
328                         struct md_attr *ma);
329
330         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
331                           struct md_object *cobj, const struct lu_name *lname,
332                           struct md_attr *ma);
333
334         /** This method is used to compare a requested layout to an existing
335          * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
336         int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
337                                struct md_object *cobj,
338                                const struct md_op_spec *spec,
339                                struct md_attr *ma);
340
341         /** partial ops for cross-ref case */
342         int (*mdo_name_insert)(const struct lu_env *env,
343                                struct md_object *obj,
344                                const struct lu_name *lname,
345                                const struct lu_fid *fid,
346                                const struct md_attr *ma);
347
348         int (*mdo_name_remove)(const struct lu_env *env,
349                                struct md_object *obj,
350                                const struct lu_name *lname,
351                                const struct md_attr *ma);
352
353         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
354                               struct md_object *tobj, const struct lu_fid *fid,
355                               const struct lu_name *lname, struct md_attr *ma);
356 };
357
358 struct md_device_operations {
359         /** meta-data device related handlers. */
360         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
361                             struct lu_fid *f);
362
363         int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
364                                int *md_size, int *cookie_size);
365
366         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
367                           cfs_kstatfs_t *sfs);
368
369         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
370                                   int mode, unsigned long timeout, __u32 alg,
371                                   struct lustre_capa_key *keys);
372
373         int (*mdo_update_capa_key)(const struct lu_env *env,
374                                    struct md_device *m,
375                                    struct lustre_capa_key *key);
376
377         int (*mdo_llog_ctxt_get)(const struct lu_env *env,
378                                  struct md_device *m, int idx, void **h);
379
380         int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
381                              unsigned int cmd, int len, void *data);
382
383 #ifdef HAVE_QUOTA_SUPPORT
384         struct md_quota_operations {
385                 int (*mqo_notify)(const struct lu_env *env,
386                                   struct md_device *m);
387
388                 int (*mqo_setup)(const struct lu_env *env,
389                                  struct md_device *m,
390                                  void *data);
391
392                 int (*mqo_cleanup)(const struct lu_env *env,
393                                    struct md_device *m);
394
395                 int (*mqo_recovery)(const struct lu_env *env,
396                                     struct md_device *m);
397
398                 int (*mqo_check)(const struct lu_env *env,
399                                  struct md_device *m,
400                                  __u32 type);
401
402                 int (*mqo_on)(const struct lu_env *env,
403                               struct md_device *m,
404                               __u32 type);
405
406                 int (*mqo_off)(const struct lu_env *env,
407                                struct md_device *m,
408                                __u32 type);
409
410                 int (*mqo_setinfo)(const struct lu_env *env,
411                                    struct md_device *m,
412                                    __u32 type,
413                                    __u32 id,
414                                    struct obd_dqinfo *dqinfo);
415
416                 int (*mqo_getinfo)(const struct lu_env *env,
417                                    const struct md_device *m,
418                                    __u32 type,
419                                    __u32 id,
420                                    struct obd_dqinfo *dqinfo);
421
422                 int (*mqo_setquota)(const struct lu_env *env,
423                                     struct md_device *m,
424                                     __u32 type,
425                                     __u32 id,
426                                     struct obd_dqblk *dqblk);
427
428                 int (*mqo_getquota)(const struct lu_env *env,
429                                     const struct md_device *m,
430                                     __u32 type,
431                                     __u32 id,
432                                     struct obd_dqblk *dqblk);
433
434                 int (*mqo_getoinfo)(const struct lu_env *env,
435                                     const struct md_device *m,
436                                     __u32 type,
437                                     __u32 id,
438                                     struct obd_dqinfo *dqinfo);
439
440                 int (*mqo_getoquota)(const struct lu_env *env,
441                                      const struct md_device *m,
442                                      __u32 type,
443                                      __u32 id,
444                                      struct obd_dqblk *dqblk);
445
446                 int (*mqo_invalidate)(const struct lu_env *env,
447                                       struct md_device *m,
448                                       __u32 type);
449
450                 int (*mqo_finvalidate)(const struct lu_env *env,
451                                        struct md_device *m,
452                                        __u32 type);
453         } mdo_quota;
454 #endif
455 };
456
457 enum md_upcall_event {
458         /** Sync the md layer*/
459         MD_LOV_SYNC = (1 << 0),
460         /** Just for split, no need trans, for replay */
461         MD_NO_TRANS = (1 << 1),
462         MD_LOV_CONFIG = (1 << 2),
463         /** Trigger quota recovery */
464         MD_LOV_QUOTA = (1 << 3)
465 };
466
467 struct md_upcall {
468         /** this lock protects upcall using against its removal
469          * read lock is for usage the upcall, write - for init/fini */
470         cfs_rw_semaphore_t      mu_upcall_sem;
471         /** device to call, upper layer normally */
472         struct md_device       *mu_upcall_dev;
473         /** upcall function */
474         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
475                          enum md_upcall_event ev, void *data);
476 };
477
478 struct md_device {
479         struct lu_device                   md_lu_dev;
480         const struct md_device_operations *md_ops;
481         struct md_upcall                   md_upcall;
482 };
483
484 static inline void md_upcall_init(struct md_device *m, void *upcl)
485 {
486         cfs_init_rwsem(&m->md_upcall.mu_upcall_sem);
487         m->md_upcall.mu_upcall_dev = NULL;
488         m->md_upcall.mu_upcall = upcl;
489 }
490
491 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
492 {
493         cfs_down_write(&m->md_upcall.mu_upcall_sem);
494         m->md_upcall.mu_upcall_dev = up;
495         cfs_up_write(&m->md_upcall.mu_upcall_sem);
496 }
497
498 static inline void md_upcall_fini(struct md_device *m)
499 {
500         cfs_down_write(&m->md_upcall.mu_upcall_sem);
501         m->md_upcall.mu_upcall_dev = NULL;
502         m->md_upcall.mu_upcall = NULL;
503         cfs_up_write(&m->md_upcall.mu_upcall_sem);
504 }
505
506 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
507                                enum md_upcall_event ev, void *data)
508 {
509         int rc = 0;
510         cfs_down_read(&m->md_upcall.mu_upcall_sem);
511         if (m->md_upcall.mu_upcall_dev != NULL &&
512             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
513                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
514                                               m->md_upcall.mu_upcall_dev,
515                                               ev, data);
516         }
517         cfs_up_read(&m->md_upcall.mu_upcall_sem);
518         return rc;
519 }
520
521 struct md_object {
522         struct lu_object                   mo_lu;
523         const struct md_object_operations *mo_ops;
524         const struct md_dir_operations    *mo_dir_ops;
525 };
526
527 /**
528  * md-server site.
529  */
530 struct md_site {
531         struct lu_site ms_lu;
532         /**
533          * mds number of this site.
534          */
535         mdsno_t               ms_node_id;
536         /**
537          * Fid location database
538          */
539         struct lu_server_fld *ms_server_fld;
540         struct lu_client_fld *ms_client_fld;
541
542         /**
543          * Server Seq Manager
544          */
545         struct lu_server_seq *ms_server_seq;
546
547         /**
548          * Controller Seq Manager
549          */
550         struct lu_server_seq *ms_control_seq;
551         struct obd_export    *ms_control_exp;
552
553         /**
554          * Client Seq Manager
555          */
556         struct lu_client_seq *ms_client_seq;
557 };
558
559 static inline int lu_device_is_md(const struct lu_device *d)
560 {
561         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
562 }
563
564 static inline struct md_device *lu2md_dev(const struct lu_device *d)
565 {
566         LASSERT(IS_ERR(d) || lu_device_is_md(d));
567         return container_of0(d, struct md_device, md_lu_dev);
568 }
569
570 static inline struct lu_device *md2lu_dev(struct md_device *d)
571 {
572         return &d->md_lu_dev;
573 }
574
575 static inline struct md_object *lu2md(const struct lu_object *o)
576 {
577         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
578         return container_of0(o, struct md_object, mo_lu);
579 }
580
581 static inline struct md_object *md_object_next(const struct md_object *obj)
582 {
583         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
584 }
585
586 static inline struct md_device *md_obj2dev(const struct md_object *o)
587 {
588         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
589         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
590 }
591
592 static inline struct md_site *lu_site2md(const struct lu_site *s)
593 {
594         return container_of0(s, struct md_site, ms_lu);
595 }
596
597 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
598 {
599         return lu_device_init(&md->md_lu_dev, t);
600 }
601
602 static inline void md_device_fini(struct md_device *md)
603 {
604         lu_device_fini(&md->md_lu_dev);
605 }
606
607 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
608                                                      struct md_device *md,
609                                                      const struct lu_fid *f)
610 {
611         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
612 }
613
614
615 /** md operations */
616 static inline int mo_permission(const struct lu_env *env,
617                                 struct md_object *p,
618                                 struct md_object *c,
619                                 struct md_attr *at,
620                                 int mask)
621 {
622         LASSERT(c->mo_ops->moo_permission);
623         return c->mo_ops->moo_permission(env, p, c, at, mask);
624 }
625
626 static inline int mo_attr_get(const struct lu_env *env,
627                               struct md_object *m,
628                               struct md_attr *at)
629 {
630         LASSERT(m->mo_ops->moo_attr_get);
631         return m->mo_ops->moo_attr_get(env, m, at);
632 }
633
634 static inline int mo_readlink(const struct lu_env *env,
635                               struct md_object *m,
636                               struct lu_buf *buf)
637 {
638         LASSERT(m->mo_ops->moo_readlink);
639         return m->mo_ops->moo_readlink(env, m, buf);
640 }
641
642 static inline int mo_changelog(const struct lu_env *env,
643                                enum changelog_rec_type type,
644                                int flags, struct md_object *m)
645 {
646         LASSERT(m->mo_ops->moo_changelog);
647         return m->mo_ops->moo_changelog(env, type, flags, m);
648 }
649
650 static inline int mo_attr_set(const struct lu_env *env,
651                               struct md_object *m,
652                               const struct md_attr *at)
653 {
654         LASSERT(m->mo_ops->moo_attr_set);
655         return m->mo_ops->moo_attr_set(env, m, at);
656 }
657
658 static inline int mo_xattr_get(const struct lu_env *env,
659                                struct md_object *m,
660                                struct lu_buf *buf,
661                                const char *name)
662 {
663         LASSERT(m->mo_ops->moo_xattr_get);
664         return m->mo_ops->moo_xattr_get(env, m, buf, name);
665 }
666
667 static inline int mo_xattr_del(const struct lu_env *env,
668                                struct md_object *m,
669                                const char *name)
670 {
671         LASSERT(m->mo_ops->moo_xattr_del);
672         return m->mo_ops->moo_xattr_del(env, m, name);
673 }
674
675 static inline int mo_xattr_set(const struct lu_env *env,
676                                struct md_object *m,
677                                const struct lu_buf *buf,
678                                const char *name,
679                                int flags)
680 {
681         LASSERT(m->mo_ops->moo_xattr_set);
682         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
683 }
684
685 static inline int mo_xattr_list(const struct lu_env *env,
686                                 struct md_object *m,
687                                 struct lu_buf *buf)
688 {
689         LASSERT(m->mo_ops->moo_xattr_list);
690         return m->mo_ops->moo_xattr_list(env, m, buf);
691 }
692
693 static inline int mo_open(const struct lu_env *env,
694                           struct md_object *m,
695                           int flags)
696 {
697         LASSERT(m->mo_ops->moo_open);
698         return m->mo_ops->moo_open(env, m, flags);
699 }
700
701 static inline int mo_close(const struct lu_env *env,
702                            struct md_object *m,
703                            struct md_attr *ma,
704                            int mode)
705 {
706         LASSERT(m->mo_ops->moo_close);
707         return m->mo_ops->moo_close(env, m, ma, mode);
708 }
709
710 static inline int mo_readpage(const struct lu_env *env,
711                               struct md_object *m,
712                               const struct lu_rdpg *rdpg)
713 {
714         LASSERT(m->mo_ops->moo_readpage);
715         return m->mo_ops->moo_readpage(env, m, rdpg);
716 }
717
718 static inline int mo_object_create(const struct lu_env *env,
719                                    struct md_object *m,
720                                    const struct md_op_spec *spc,
721                                    struct md_attr *at)
722 {
723         LASSERT(m->mo_ops->moo_object_create);
724         return m->mo_ops->moo_object_create(env, m, spc, at);
725 }
726
727 static inline int mo_ref_add(const struct lu_env *env,
728                              struct md_object *m,
729                              const struct md_attr *ma)
730 {
731         LASSERT(m->mo_ops->moo_ref_add);
732         return m->mo_ops->moo_ref_add(env, m, ma);
733 }
734
735 static inline int mo_ref_del(const struct lu_env *env,
736                              struct md_object *m,
737                              struct md_attr *ma)
738 {
739         LASSERT(m->mo_ops->moo_ref_del);
740         return m->mo_ops->moo_ref_del(env, m, ma);
741 }
742
743 static inline int mo_capa_get(const struct lu_env *env,
744                               struct md_object *m,
745                               struct lustre_capa *c,
746                               int renewal)
747 {
748         LASSERT(m->mo_ops->moo_capa_get);
749         return m->mo_ops->moo_capa_get(env, m, c, renewal);
750 }
751
752 static inline int mo_path(const struct lu_env *env, struct md_object *m,
753                           char *path, int pathlen, __u64 *recno, int *linkno)
754 {
755         if (m->mo_ops->moo_path == NULL)
756                 return -ENOSYS;
757         return m->mo_ops->moo_path(env, m, path, pathlen, recno, linkno);
758 }
759
760 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
761 {
762         LASSERT(m->mo_ops->moo_object_sync);
763         return m->mo_ops->moo_object_sync(env, m);
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_lum_lmm_cmp(const struct lu_env *env,
867                                   struct md_object *c,
868                                   const struct md_op_spec *spec,
869                                   struct md_attr *ma)
870 {
871         LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
872         return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
873 }
874
875 static inline int mdo_name_insert(const struct lu_env *env,
876                                   struct md_object *p,
877                                   const struct lu_name *lname,
878                                   const struct lu_fid *f,
879                                   const struct md_attr *ma)
880 {
881         LASSERT(p->mo_dir_ops->mdo_name_insert);
882         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
883 }
884
885 static inline int mdo_name_remove(const struct lu_env *env,
886                                   struct md_object *p,
887                                   const struct lu_name *lname,
888                                   const struct md_attr *ma)
889 {
890         LASSERT(p->mo_dir_ops->mdo_name_remove);
891         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
892 }
893
894 static inline int mdo_rename_tgt(const struct lu_env *env,
895                                  struct md_object *p,
896                                  struct md_object *t,
897                                  const struct lu_fid *lf,
898                                  const struct lu_name *lname,
899                                  struct md_attr *ma)
900 {
901         if (t) {
902                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
903                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
904         } else {
905                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
906                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
907         }
908 }
909
910 struct dt_device;
911 /**
912  * Structure to hold object information. This is used to create object
913  * \pre llod_dir exist
914  */
915 struct lu_local_obj_desc {
916         const char                      *llod_dir;
917         const char                      *llod_name;
918         __u32                            llod_oid;
919         int                              llod_is_index;
920         const struct dt_index_features  *llod_feat;
921         cfs_list_t                       llod_linkage;
922 };
923
924 struct md_object *llo_store_resolve(const struct lu_env *env,
925                                     struct md_device *md,
926                                     struct dt_device *dt,
927                                     const char *path,
928                                     struct lu_fid *fid);
929
930 struct md_object *llo_store_open(const struct lu_env *env,
931                                  struct md_device *md,
932                                  struct dt_device *dt,
933                                  const char *dirname,
934                                  const char *objname,
935                                  struct lu_fid *fid);
936
937 struct md_object *llo_store_create_index(const struct lu_env *env,
938                                          struct md_device *md,
939                                          struct dt_device *dt,
940                                          const char *dirname,
941                                          const char *objname,
942                                          const struct lu_fid *fid,
943                                          const struct dt_index_features *feat);
944
945 struct md_object *llo_store_create(const struct lu_env *env,
946                                    struct md_device *md,
947                                    struct dt_device *dt,
948                                    const char *dirname,
949                                    const char *objname,
950                                    const struct lu_fid *fid);
951
952 void llo_local_obj_register(struct lu_local_obj_desc *);
953 void llo_local_obj_unregister(struct lu_local_obj_desc *);
954
955 int llo_local_objects_setup(const struct lu_env *env,
956                              struct md_device * md,
957                              struct dt_device * dt);
958
959 /** @} md */
960 #endif /* _LINUX_MD_OBJECT_H */