Whamcloud - gitweb
383831b4dcd52923455acf778dca90e7796bc70e
[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 /* memory structure for hsm attributes
138  * for fields description see the on disk structure hsm_attrs
139  * which is defined in lustre_idl.h
140  */
141 struct md_hsm {
142         __u32   mh_compat;
143         __u32   mh_flags;
144         __u64   mh_arch_id;
145         __u64   mh_arch_ver;
146 };
147
148 #define IOEPOCH_INVAL 0
149
150 /* memory structure for som attributes
151  * for fields description see the on disk structure som_attrs
152  * which is defined in lustre_idl.h
153  */
154 struct md_som_data {
155         __u32   msd_compat;
156         __u32   msd_incompat;
157         __u64   msd_ioepoch;
158         __u64   msd_size;
159         __u64   msd_blocks;
160         __u64   msd_mountid;
161 };
162
163 struct md_attr {
164         __u64                   ma_valid;
165         __u64                   ma_need;
166         __u64                   ma_attr_flags;
167         struct lu_attr          ma_attr;
168         struct lu_fid           ma_pfid;
169         struct md_hsm           ma_hsm;
170         struct lov_mds_md      *ma_lmm;
171         struct lmv_stripe_md   *ma_lmv;
172         void                   *ma_acl;
173         struct llog_cookie     *ma_cookie;
174         struct lustre_capa     *ma_capa;
175         struct md_som_data     *ma_som;
176         int                     ma_lmm_size;
177         int                     ma_lmv_size;
178         int                     ma_acl_size;
179         int                     ma_cookie_size;
180         __u16                   ma_layout_gen;
181 };
182
183 /** Additional parameters for create */
184 struct md_op_spec {
185         union {
186                 /** symlink target */
187                 const char               *sp_symname;
188                 /** parent FID for cross-ref mkdir */
189                 const struct lu_fid      *sp_pfid;
190                 /** eadata for regular files */
191                 struct md_spec_reg {
192                         /** lov objs exist already */
193                         const struct lu_fid   *fid;
194                         const void *eadata;
195                         int  eadatalen;
196                 } sp_ea;
197         } u;
198
199         /** Create flag from client: such as MDS_OPEN_CREAT, and others. */
200         __u64      sp_cr_flags;
201
202         /** don't create lov objects or llog cookie - this replay */
203         unsigned int no_create:1,
204                      sp_cr_lookup:1, /* do lookup sanity check or not. */
205                      sp_rm_entry:1;  /* only remove name entry */
206
207         /** Current lock mode for parent dir where create is performing. */
208         mdl_mode_t sp_cr_mode;
209
210         /** to create directory */
211         const struct dt_index_features *sp_feat;
212 };
213
214 /**
215  * Operations implemented for each md object (both directory and leaf).
216  */
217 struct md_object_operations {
218         int (*moo_permission)(const struct lu_env *env,
219                               struct md_object *pobj, struct md_object *cobj,
220                               struct md_attr *attr, int mask);
221
222         int (*moo_attr_get)(const struct lu_env *env, struct md_object *obj,
223                             struct md_attr *attr);
224
225         int (*moo_attr_set)(const struct lu_env *env, struct md_object *obj,
226                             const struct md_attr *attr);
227
228         int (*moo_xattr_get)(const struct lu_env *env, struct md_object *obj,
229                              struct lu_buf *buf, const char *name);
230
231         int (*moo_xattr_list)(const struct lu_env *env, struct md_object *obj,
232                               struct lu_buf *buf);
233
234         int (*moo_xattr_set)(const struct lu_env *env, struct md_object *obj,
235                              const struct lu_buf *buf, const char *name,
236                              int fl);
237
238         int (*moo_xattr_del)(const struct lu_env *env, struct md_object *obj,
239                              const char *name);
240
241         /** This method is used to swap the layouts between 2 objects */
242         int (*moo_swap_layouts)(const struct lu_env *env,
243                                struct md_object *obj1, struct md_object *obj2,
244                                __u64 flags);
245
246         /** \retval number of bytes actually read upon success */
247         int (*moo_readpage)(const struct lu_env *env, struct md_object *obj,
248                             const struct lu_rdpg *rdpg);
249
250         int (*moo_readlink)(const struct lu_env *env, struct md_object *obj,
251                             struct lu_buf *buf);
252         int (*moo_changelog)(const struct lu_env *env,
253                              enum changelog_rec_type type, int flags,
254                              struct md_object *obj);
255         /** part of cross-ref operation */
256         int (*moo_object_create)(const struct lu_env *env,
257                                  struct md_object *obj,
258                                  const struct md_op_spec *spec,
259                                  struct md_attr *ma);
260
261         int (*moo_ref_add)(const struct lu_env *env,
262                            struct md_object *obj,
263                            const struct md_attr *ma);
264
265         int (*moo_ref_del)(const struct lu_env *env,
266                            struct md_object *obj,
267                            struct md_attr *ma);
268
269         int (*moo_open)(const struct lu_env *env,
270                         struct md_object *obj, int flag);
271
272         int (*moo_close)(const struct lu_env *env, struct md_object *obj,
273                          struct md_attr *ma, int mode);
274
275         int (*moo_capa_get)(const struct lu_env *, struct md_object *,
276                             struct lustre_capa *, int renewal);
277
278         int (*moo_object_sync)(const struct lu_env *, struct md_object *);
279
280         int (*moo_file_lock)(const struct lu_env *env, struct md_object *obj,
281                              struct lov_mds_md *lmm, struct ldlm_extent *extent,
282                              struct lustre_handle *lockh);
283         int (*moo_file_unlock)(const struct lu_env *env, struct md_object *obj,
284                                struct lov_mds_md *lmm,
285                                struct lustre_handle *lockh);
286         int (*moo_object_lock)(const struct lu_env *env, struct md_object *obj,
287                                struct lustre_handle *lh,
288                                struct ldlm_enqueue_info *einfo,
289                                void *policy);
290 };
291
292 /**
293  * Operations implemented for each directory object.
294  */
295 struct md_dir_operations {
296         int (*mdo_is_subdir) (const struct lu_env *env, struct md_object *obj,
297                               const struct lu_fid *fid, struct lu_fid *sfid);
298
299         int (*mdo_lookup)(const struct lu_env *env, struct md_object *obj,
300                           const struct lu_name *lname, struct lu_fid *fid,
301                           struct md_op_spec *spec);
302
303         mdl_mode_t (*mdo_lock_mode)(const struct lu_env *env,
304                                     struct md_object *obj,
305                                     mdl_mode_t mode);
306
307         int (*mdo_create)(const struct lu_env *env, struct md_object *pobj,
308                           const struct lu_name *lname, struct md_object *child,
309                           struct md_op_spec *spec,
310                           struct md_attr *ma);
311
312         /** This method is used for creating data object for this meta object*/
313         int (*mdo_create_data)(const struct lu_env *env, struct md_object *p,
314                                struct md_object *o,
315                                const struct md_op_spec *spec,
316                                struct md_attr *ma);
317
318         int (*mdo_rename)(const struct lu_env *env, struct md_object *spobj,
319                           struct md_object *tpobj, const struct lu_fid *lf,
320                           const struct lu_name *lsname, struct md_object *tobj,
321                           const struct lu_name *ltname, struct md_attr *ma);
322
323         int (*mdo_link)(const struct lu_env *env, struct md_object *tgt_obj,
324                         struct md_object *src_obj, const struct lu_name *lname,
325                         struct md_attr *ma);
326
327         int (*mdo_unlink)(const struct lu_env *env, struct md_object *pobj,
328                           struct md_object *cobj, const struct lu_name *lname,
329                           struct md_attr *ma, int no_name);
330
331         /** This method is used to compare a requested layout to an existing
332          * layout (struct lov_mds_md_v1/3 vs struct lov_mds_md_v1/3) */
333         int (*mdo_lum_lmm_cmp)(const struct lu_env *env,
334                                struct md_object *cobj,
335                                const struct md_op_spec *spec,
336                                struct md_attr *ma);
337
338         /** partial ops for cross-ref case */
339         int (*mdo_name_insert)(const struct lu_env *env,
340                                struct md_object *obj,
341                                const struct lu_name *lname,
342                                const struct lu_fid *fid,
343                                const struct md_attr *ma);
344
345         int (*mdo_name_remove)(const struct lu_env *env,
346                                struct md_object *obj,
347                                const struct lu_name *lname,
348                                const struct md_attr *ma);
349
350         int (*mdo_rename_tgt)(const struct lu_env *env, struct md_object *pobj,
351                               struct md_object *tobj, const struct lu_fid *fid,
352                               const struct lu_name *lname, struct md_attr *ma);
353 };
354
355 struct md_device_operations {
356         /** meta-data device related handlers. */
357         int (*mdo_root_get)(const struct lu_env *env, struct md_device *m,
358                             struct lu_fid *f);
359
360         int (*mdo_maxsize_get)(const struct lu_env *env, struct md_device *m,
361                                int *md_size, int *cookie_size);
362
363         int (*mdo_statfs)(const struct lu_env *env, struct md_device *m,
364                           struct obd_statfs *sfs);
365
366         int (*mdo_init_capa_ctxt)(const struct lu_env *env, struct md_device *m,
367                                   int mode, unsigned long timeout, __u32 alg,
368                                   struct lustre_capa_key *keys);
369
370         int (*mdo_update_capa_key)(const struct lu_env *env,
371                                    struct md_device *m,
372                                    struct lustre_capa_key *key);
373
374         int (*mdo_llog_ctxt_get)(const struct lu_env *env,
375                                  struct md_device *m, int idx, void **h);
376
377         int (*mdo_iocontrol)(const struct lu_env *env, struct md_device *m,
378                              unsigned int cmd, int len, void *data);
379 };
380
381 enum md_upcall_event {
382         /** Sync the md layer*/
383         MD_LOV_SYNC = (1 << 0),
384         /** Just for split, no need trans, for replay */
385         MD_NO_TRANS = (1 << 1),
386         MD_LOV_CONFIG = (1 << 2),
387         /** Trigger quota recovery */
388         MD_LOV_QUOTA = (1 << 3)
389 };
390
391 struct md_upcall {
392         /** this lock protects upcall using against its removal
393          * read lock is for usage the upcall, write - for init/fini */
394         struct rw_semaphore     mu_upcall_sem;
395         /** device to call, upper layer normally */
396         struct md_device       *mu_upcall_dev;
397         /** upcall function */
398         int (*mu_upcall)(const struct lu_env *env, struct md_device *md,
399                          enum md_upcall_event ev, void *data);
400 };
401
402 struct md_device {
403         struct lu_device                   md_lu_dev;
404         const struct md_device_operations *md_ops;
405         struct md_upcall                   md_upcall;
406 };
407
408 static inline void md_upcall_init(struct md_device *m, void *upcl)
409 {
410         init_rwsem(&m->md_upcall.mu_upcall_sem);
411         m->md_upcall.mu_upcall_dev = NULL;
412         m->md_upcall.mu_upcall = upcl;
413 }
414
415 static inline void md_upcall_dev_set(struct md_device *m, struct md_device *up)
416 {
417         down_write(&m->md_upcall.mu_upcall_sem);
418         m->md_upcall.mu_upcall_dev = up;
419         up_write(&m->md_upcall.mu_upcall_sem);
420 }
421
422 static inline void md_upcall_fini(struct md_device *m)
423 {
424         down_write(&m->md_upcall.mu_upcall_sem);
425         m->md_upcall.mu_upcall_dev = NULL;
426         m->md_upcall.mu_upcall = NULL;
427         up_write(&m->md_upcall.mu_upcall_sem);
428 }
429
430 static inline int md_do_upcall(const struct lu_env *env, struct md_device *m,
431                                 enum md_upcall_event ev, void *data)
432 {
433         int rc = 0;
434         down_read(&m->md_upcall.mu_upcall_sem);
435         if (m->md_upcall.mu_upcall_dev != NULL &&
436             m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall != NULL) {
437                 rc = m->md_upcall.mu_upcall_dev->md_upcall.mu_upcall(env,
438                                               m->md_upcall.mu_upcall_dev,
439                                               ev, data);
440         }
441         up_read(&m->md_upcall.mu_upcall_sem);
442         return rc;
443 }
444
445 struct md_object {
446         struct lu_object                   mo_lu;
447         const struct md_object_operations *mo_ops;
448         const struct md_dir_operations    *mo_dir_ops;
449 };
450
451 /**
452  * seq-server site.
453  */
454 struct seq_server_site {
455         struct lu_site       *ss_lu;
456         /**
457          * mds number of this site.
458          */
459         mdsno_t               ss_node_id;
460         /**
461          * Fid location database
462          */
463         struct lu_server_fld *ss_server_fld;
464         struct lu_client_fld *ss_client_fld;
465
466         /**
467          * Server Seq Manager
468          */
469         struct lu_server_seq *ss_server_seq;
470
471         /**
472          * Controller Seq Manager
473          */
474         struct lu_server_seq *ss_control_seq;
475         struct obd_export    *ss_control_exp;
476
477         /**
478          * Client Seq Manager
479          */
480         struct lu_client_seq *ss_client_seq;
481 };
482
483 static inline struct md_device *lu2md_dev(const struct lu_device *d)
484 {
485         LASSERT(IS_ERR(d) || lu_device_is_md(d));
486         return container_of0(d, struct md_device, md_lu_dev);
487 }
488
489 static inline struct lu_device *md2lu_dev(struct md_device *d)
490 {
491         return &d->md_lu_dev;
492 }
493
494 static inline struct md_object *lu2md(const struct lu_object *o)
495 {
496         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->lo_dev));
497         return container_of0(o, struct md_object, mo_lu);
498 }
499
500 static inline struct md_object *md_object_next(const struct md_object *obj)
501 {
502         return (obj ? lu2md(lu_object_next(&obj->mo_lu)) : NULL);
503 }
504
505 static inline struct md_device *md_obj2dev(const struct md_object *o)
506 {
507         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_md(o->mo_lu.lo_dev));
508         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
509 }
510
511 static inline struct seq_server_site *lu_site2seq(const struct lu_site *s)
512 {
513         return s->ld_seq_site;
514 }
515
516 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
517 {
518         return lu_device_init(&md->md_lu_dev, t);
519 }
520
521 static inline void md_device_fini(struct md_device *md)
522 {
523         lu_device_fini(&md->md_lu_dev);
524 }
525
526 static inline struct md_object *md_object_find_slice(const struct lu_env *env,
527                                                      struct md_device *md,
528                                                      const struct lu_fid *f)
529 {
530         return lu2md(lu_object_find_slice(env, md2lu_dev(md), f, NULL));
531 }
532
533
534 /** md operations */
535 static inline int mo_permission(const struct lu_env *env,
536                                 struct md_object *p,
537                                 struct md_object *c,
538                                 struct md_attr *at,
539                                 int mask)
540 {
541         LASSERT(c->mo_ops->moo_permission);
542         return c->mo_ops->moo_permission(env, p, c, at, mask);
543 }
544
545 static inline int mo_attr_get(const struct lu_env *env,
546                               struct md_object *m,
547                               struct md_attr *at)
548 {
549         LASSERT(m->mo_ops->moo_attr_get);
550         return m->mo_ops->moo_attr_get(env, m, at);
551 }
552
553 static inline int mo_readlink(const struct lu_env *env,
554                               struct md_object *m,
555                               struct lu_buf *buf)
556 {
557         LASSERT(m->mo_ops->moo_readlink);
558         return m->mo_ops->moo_readlink(env, m, buf);
559 }
560
561 static inline int mo_changelog(const struct lu_env *env,
562                                enum changelog_rec_type type,
563                                int flags, struct md_object *m)
564 {
565         LASSERT(m->mo_ops->moo_changelog);
566         return m->mo_ops->moo_changelog(env, type, flags, m);
567 }
568
569 static inline int mo_attr_set(const struct lu_env *env,
570                               struct md_object *m,
571                               const struct md_attr *at)
572 {
573         LASSERT(m->mo_ops->moo_attr_set);
574         return m->mo_ops->moo_attr_set(env, m, at);
575 }
576
577 static inline int mo_xattr_get(const struct lu_env *env,
578                                struct md_object *m,
579                                struct lu_buf *buf,
580                                const char *name)
581 {
582         LASSERT(m->mo_ops->moo_xattr_get);
583         return m->mo_ops->moo_xattr_get(env, m, buf, name);
584 }
585
586 static inline int mo_xattr_del(const struct lu_env *env,
587                                struct md_object *m,
588                                const char *name)
589 {
590         LASSERT(m->mo_ops->moo_xattr_del);
591         return m->mo_ops->moo_xattr_del(env, m, name);
592 }
593
594 static inline int mo_xattr_set(const struct lu_env *env,
595                                struct md_object *m,
596                                const struct lu_buf *buf,
597                                const char *name,
598                                int flags)
599 {
600         LASSERT(m->mo_ops->moo_xattr_set);
601         return m->mo_ops->moo_xattr_set(env, m, buf, name, flags);
602 }
603
604 static inline int mo_xattr_list(const struct lu_env *env,
605                                 struct md_object *m,
606                                 struct lu_buf *buf)
607 {
608         LASSERT(m->mo_ops->moo_xattr_list);
609         return m->mo_ops->moo_xattr_list(env, m, buf);
610 }
611
612 static inline int mo_swap_layouts(const struct lu_env *env,
613                                   struct md_object *o1,
614                                   struct md_object *o2, __u64 flags)
615 {
616         LASSERT(o1->mo_ops->moo_swap_layouts);
617         LASSERT(o2->mo_ops->moo_swap_layouts);
618         if (o1->mo_ops->moo_swap_layouts != o2->mo_ops->moo_swap_layouts)
619                 return -EPERM;
620         return o1->mo_ops->moo_swap_layouts(env, o1, o2, flags);
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                            int mode)
635 {
636         LASSERT(m->mo_ops->moo_close);
637         return m->mo_ops->moo_close(env, m, ma, mode);
638 }
639
640 static inline int mo_readpage(const struct lu_env *env,
641                               struct md_object *m,
642                               const struct lu_rdpg *rdpg)
643 {
644         LASSERT(m->mo_ops->moo_readpage);
645         return m->mo_ops->moo_readpage(env, m, rdpg);
646 }
647
648 static inline int mo_object_create(const struct lu_env *env,
649                                    struct md_object *m,
650                                    const struct md_op_spec *spc,
651                                    struct md_attr *at)
652 {
653         LASSERT(m->mo_ops->moo_object_create);
654         return m->mo_ops->moo_object_create(env, m, spc, at);
655 }
656
657 static inline int mo_ref_add(const struct lu_env *env,
658                              struct md_object *m,
659                              const struct md_attr *ma)
660 {
661         LASSERT(m->mo_ops->moo_ref_add);
662         return m->mo_ops->moo_ref_add(env, m, ma);
663 }
664
665 static inline int mo_ref_del(const struct lu_env *env,
666                              struct md_object *m,
667                              struct md_attr *ma)
668 {
669         LASSERT(m->mo_ops->moo_ref_del);
670         return m->mo_ops->moo_ref_del(env, m, ma);
671 }
672
673 static inline int mo_capa_get(const struct lu_env *env,
674                               struct md_object *m,
675                               struct lustre_capa *c,
676                               int renewal)
677 {
678         LASSERT(m->mo_ops->moo_capa_get);
679         return m->mo_ops->moo_capa_get(env, m, c, renewal);
680 }
681
682 static inline int mo_object_sync(const struct lu_env *env, struct md_object *m)
683 {
684         LASSERT(m->mo_ops->moo_object_sync);
685         return m->mo_ops->moo_object_sync(env, m);
686 }
687
688 static inline int mo_file_lock(const struct lu_env *env, struct md_object *m,
689                                struct lov_mds_md *lmm,
690                                struct ldlm_extent *extent,
691                                struct lustre_handle *lockh)
692 {
693         LASSERT(m->mo_ops->moo_file_lock);
694         return m->mo_ops->moo_file_lock(env, m, lmm, extent, lockh);
695 }
696
697 static inline int mo_file_unlock(const struct lu_env *env, struct md_object *m,
698                                  struct lov_mds_md *lmm,
699                                  struct lustre_handle *lockh)
700 {
701         LASSERT(m->mo_ops->moo_file_unlock);
702         return m->mo_ops->moo_file_unlock(env, m, lmm, lockh);
703 }
704
705 static inline int mo_object_lock(const struct lu_env *env,
706                                  struct md_object *m,
707                                  struct lustre_handle *lh,
708                                  struct ldlm_enqueue_info *einfo,
709                                  void *policy)
710 {
711         LASSERT(m->mo_ops->moo_object_lock);
712         return m->mo_ops->moo_object_lock(env, m, lh, einfo, policy);
713 }
714
715 static inline int mdo_lookup(const struct lu_env *env,
716                              struct md_object *p,
717                              const struct lu_name *lname,
718                              struct lu_fid *f,
719                              struct md_op_spec *spec)
720 {
721         LASSERT(p->mo_dir_ops->mdo_lookup);
722         return p->mo_dir_ops->mdo_lookup(env, p, lname, f, spec);
723 }
724
725 static inline mdl_mode_t mdo_lock_mode(const struct lu_env *env,
726                                        struct md_object *mo,
727                                        mdl_mode_t lm)
728 {
729         if (mo->mo_dir_ops->mdo_lock_mode == NULL)
730                 return MDL_MINMODE;
731         return mo->mo_dir_ops->mdo_lock_mode(env, mo, lm);
732 }
733
734 static inline int mdo_create(const struct lu_env *env,
735                              struct md_object *p,
736                              const struct lu_name *lchild_name,
737                              struct md_object *c,
738                              struct md_op_spec *spc,
739                              struct md_attr *at)
740 {
741         LASSERT(p->mo_dir_ops->mdo_create);
742         return p->mo_dir_ops->mdo_create(env, p, lchild_name, c, spc, at);
743 }
744
745 static inline int mdo_create_data(const struct lu_env *env,
746                                   struct md_object *p,
747                                   struct md_object *c,
748                                   const struct md_op_spec *spec,
749                                   struct md_attr *ma)
750 {
751         LASSERT(c->mo_dir_ops->mdo_create_data);
752         return c->mo_dir_ops->mdo_create_data(env, p, c, spec, ma);
753 }
754
755 static inline int mdo_rename(const struct lu_env *env,
756                              struct md_object *sp,
757                              struct md_object *tp,
758                              const struct lu_fid *lf,
759                              const struct lu_name *lsname,
760                              struct md_object *t,
761                              const struct lu_name *ltname,
762                              struct md_attr *ma)
763 {
764         LASSERT(tp->mo_dir_ops->mdo_rename);
765         return tp->mo_dir_ops->mdo_rename(env, sp, tp, lf, lsname, t, ltname,
766                                           ma);
767 }
768
769 static inline int mdo_is_subdir(const struct lu_env *env,
770                                 struct md_object *mo,
771                                 const struct lu_fid *fid,
772                                 struct lu_fid *sfid)
773 {
774         LASSERT(mo->mo_dir_ops->mdo_is_subdir);
775         return mo->mo_dir_ops->mdo_is_subdir(env, mo, fid, sfid);
776 }
777
778 static inline int mdo_link(const struct lu_env *env,
779                            struct md_object *p,
780                            struct md_object *s,
781                            const struct lu_name *lname,
782                            struct md_attr *ma)
783 {
784         LASSERT(s->mo_dir_ops->mdo_link);
785         return s->mo_dir_ops->mdo_link(env, p, s, lname, ma);
786 }
787
788 static inline int mdo_unlink(const struct lu_env *env,
789                              struct md_object *p,
790                              struct md_object *c,
791                              const struct lu_name *lname,
792                              struct md_attr *ma, int no_name)
793 {
794         LASSERT(p->mo_dir_ops->mdo_unlink);
795         return p->mo_dir_ops->mdo_unlink(env, p, c, lname, ma, no_name);
796 }
797
798 static inline int mdo_lum_lmm_cmp(const struct lu_env *env,
799                                   struct md_object *c,
800                                   const struct md_op_spec *spec,
801                                   struct md_attr *ma)
802 {
803         LASSERT(c->mo_dir_ops->mdo_lum_lmm_cmp);
804         return c->mo_dir_ops->mdo_lum_lmm_cmp(env, c, spec, ma);
805 }
806
807 static inline int mdo_name_insert(const struct lu_env *env,
808                                   struct md_object *p,
809                                   const struct lu_name *lname,
810                                   const struct lu_fid *f,
811                                   const struct md_attr *ma)
812 {
813         LASSERT(p->mo_dir_ops->mdo_name_insert);
814         return p->mo_dir_ops->mdo_name_insert(env, p, lname, f, ma);
815 }
816
817 static inline int mdo_name_remove(const struct lu_env *env,
818                                   struct md_object *p,
819                                   const struct lu_name *lname,
820                                   const struct md_attr *ma)
821 {
822         LASSERT(p->mo_dir_ops->mdo_name_remove);
823         return p->mo_dir_ops->mdo_name_remove(env, p, lname, ma);
824 }
825
826 static inline int mdo_rename_tgt(const struct lu_env *env,
827                                  struct md_object *p,
828                                  struct md_object *t,
829                                  const struct lu_fid *lf,
830                                  const struct lu_name *lname,
831                                  struct md_attr *ma)
832 {
833         if (t) {
834                 LASSERT(t->mo_dir_ops->mdo_rename_tgt);
835                 return t->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
836         } else {
837                 LASSERT(p->mo_dir_ops->mdo_rename_tgt);
838                 return p->mo_dir_ops->mdo_rename_tgt(env, p, t, lf, lname, ma);
839         }
840 }
841
842 /**
843  * Used in MDD/OUT layer for object lock rule
844  **/
845 enum mdd_object_role {
846         MOR_SRC_PARENT,
847         MOR_SRC_CHILD,
848         MOR_TGT_PARENT,
849         MOR_TGT_CHILD,
850         MOR_TGT_ORPHAN
851 };
852
853 struct dt_device;
854 /**
855  * Structure to hold object information. This is used to create object
856  * \pre llod_dir exist
857  */
858 struct lu_local_obj_desc {
859         const char                      *llod_dir;
860         const char                      *llod_name;
861         __u32                            llod_oid;
862         int                              llod_is_index;
863         const struct dt_index_features  *llod_feat;
864         cfs_list_t                       llod_linkage;
865 };
866
867 struct md_object *llo_store_resolve(const struct lu_env *env,
868                                     struct md_device *md,
869                                     struct dt_device *dt,
870                                     const char *path,
871                                     struct lu_fid *fid);
872
873 struct md_object *llo_store_open(const struct lu_env *env,
874                                  struct md_device *md,
875                                  struct dt_device *dt,
876                                  const char *dirname,
877                                  const char *objname,
878                                  struct lu_fid *fid);
879
880 struct md_object *llo_store_create_index(const struct lu_env *env,
881                                          struct md_device *md,
882                                          struct dt_device *dt,
883                                          const char *dirname,
884                                          const char *objname,
885                                          const struct lu_fid *fid,
886                                          const struct dt_index_features *feat);
887
888 struct md_object *llo_store_create(const struct lu_env *env,
889                                    struct md_device *md,
890                                    struct dt_device *dt,
891                                    const char *dirname,
892                                    const char *objname,
893                                    const struct lu_fid *fid);
894
895 void llo_local_obj_register(struct lu_local_obj_desc *);
896 void llo_local_obj_unregister(struct lu_local_obj_desc *);
897
898 int llo_local_objects_setup(const struct lu_env *env,
899                              struct md_device * md,
900                              struct dt_device * dt);
901
902 int llo_global_init(void);
903 void llo_global_fini(void);
904
905 int lustre_buf2som(void *buf, int rc, struct md_som_data *msd);
906 int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh);
907 void lustre_hsm2buf(void *buf, struct md_hsm *mh);
908
909 struct lu_ucred {
910         __u32               uc_valid;
911         __u32               uc_o_uid;
912         __u32               uc_o_gid;
913         __u32               uc_o_fsuid;
914         __u32               uc_o_fsgid;
915         __u32               uc_uid;
916         __u32               uc_gid;
917         __u32               uc_fsuid;
918         __u32               uc_fsgid;
919         __u32               uc_suppgids[2];
920         cfs_cap_t           uc_cap;
921         __u32               uc_umask;
922         cfs_group_info_t   *uc_ginfo;
923         struct md_identity *uc_identity;
924 };
925
926 struct lu_ucred *lu_ucred(const struct lu_env *env);
927
928 struct lu_ucred *lu_ucred_check(const struct lu_env *env);
929
930 struct lu_ucred *lu_ucred_assert(const struct lu_env *env);
931
932 int lu_ucred_global_init(void);
933
934 void lu_ucred_global_fini(void);
935
936 #define md_cap_t(x) (x)
937
938 #define MD_CAP_TO_MASK(x) (1 << (x))
939
940 #define md_cap_raised(c, flag) (md_cap_t(c) & MD_CAP_TO_MASK(flag))
941
942 /* capable() is copied from linux kernel! */
943 static inline int md_capable(struct lu_ucred *uc, cfs_cap_t cap)
944 {
945         if (md_cap_raised(uc->uc_cap, cap))
946                 return 1;
947         return 0;
948 }
949
950 /** @} md */
951 #endif /* _LINUX_MD_OBJECT_H */