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