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