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