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