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