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