Whamcloud - gitweb
3afea42d787a8dea65c5a1c698f08bcaf2bf60ab
[fs/lustre-release.git] / lustre / mdd / mdd_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *  mdd/mdd_internel.c
4  *
5  *  Copyright (C) 2006 Cluster File Systems, Inc.
6  *   Author: Wang Di <wangdi@clusterfs.com>
7  *
8  *   This file is part of the Lustre file system, http://www.lustre.org
9  *   Lustre is a trademark of Cluster File Systems, Inc.
10  *
11  *   You may have signed or agreed to another license before downloading
12  *   this software.  If so, you are bound by the terms and conditions
13  *   of that agreement, and the following does not apply to you.  See the
14  *   LICENSE file included with this distribution for more information.
15  *
16  *   If you did not agree to a different license, then this copy of Lustre
17  *   is open source software; you can redistribute it and/or modify it
18  *   under the terms of version 2 of the GNU General Public License as
19  *   published by the Free Software Foundation.
20  *
21  *   In either case, Lustre is distributed in the hope that it will be
22  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  *   license text for more details.
25  */
26
27 #ifndef _MDD_INTERNAL_H
28 #define _MDD_INTERNAL_H
29
30 #include <asm/semaphore.h>
31 #include <md_object.h>
32
33 struct dt_device;
34
35 struct mdd_device {
36         struct md_device                 mdd_md_dev;
37         struct dt_device                *mdd_child;
38         struct md_lov_info               mdd_lov_info;
39         struct dt_device                 mdd_lov_dev;
40         struct lu_fid                    mdd_root_fid;
41         struct dt_device_param           mdd_dt_conf;
42 };
43
44 struct mdd_object {
45         struct md_object  mod_obj;
46 };
47
48 struct mdd_thread_info {
49         struct txn_param mti_param;
50         struct lu_fid    mti_fid;
51         struct lu_attr   mti_attr;
52         struct lov_desc  mti_ld;
53         struct lov_mds_md mti_lmm;
54 };
55
56 int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd, 
57                  char *dev);
58 int mdd_xattr_set(const struct lu_context *ctxt, struct md_object *obj,
59                   const void *buf, int buf_len, const char *name, int fl);
60 int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj,
61                    struct md_object *child, struct lov_mds_md *lmm,
62                    int lmm_size, int mode);
63 int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd,
64                    struct mdd_object *parent, struct mdd_object *child, 
65                    struct lov_mds_md **lmm, int *lmm_size, const void *eadata,
66                    int eadatasize, struct lu_attr *la);
67 int mdd_get_md(const struct lu_context *ctxt, struct md_object *obj,
68                void *md, int *md_size);
69 int mdd_unlink_log(const struct lu_context *ctxt, struct mdd_device *mdd, 
70                    struct mdd_object *mdd_cobj, struct md_attr *ma);
71 struct mdd_thread_info *mdd_ctx_info(const struct lu_context *ctx);
72
73 extern struct lu_device_operations mdd_lu_ops;
74 static inline int lu_device_is_mdd(struct lu_device *d)
75 {
76         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
77 }
78
79 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
80 {
81         LASSERT(lu_device_is_mdd(d));
82         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
83 }
84
85 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
86 {
87         return (&d->mdd_md_dev.md_lu_dev);
88 }
89
90 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
91 {
92         LASSERT(lu_device_is_mdd(o->lo_dev));
93         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
94 }
95
96 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
97 {
98         return lu2mdd_dev(mdo->mo_lu.lo_dev);
99 }
100
101 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
102 {
103         return container_of0(mdo, struct mdd_object, mod_obj);
104 }
105
106 static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
107 {
108         return d->mdd_child->dd_ops;
109 }
110
111 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
112 {
113         return &obj->mod_obj.mo_lu;
114 }
115
116 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
117 {
118         return container_of0(lu_object_next(mdd2lu_obj(o)),
119                              struct dt_object, do_lu);
120 }
121 static inline struct obd_device *mdd2_obd(struct mdd_device *mdd)
122 {
123         return mdd->mdd_md_dev.md_lu_dev.ld_obd; 
124 }
125 #endif