Whamcloud - gitweb
Branch: b_new_cmd
[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 enum mod_flags {
45         /*The dir object has been unlinked*/
46         DEAD_OBJ = 1 << 0,        
47 };
48
49 struct mdd_object {
50         struct md_object  mod_obj;
51         unsigned long     mod_flags;
52 };
53
54 struct mdd_thread_info {
55         struct txn_param mti_param;
56         struct lu_fid    mti_fid;
57         struct lu_attr    mti_la;
58         struct lov_desc  mti_ld;
59         struct lov_mds_md mti_lmm;
60 };
61
62 int mdd_init_obd(const struct lu_context *ctxt, struct mdd_device *mdd,
63                  char *dev);
64 int mdd_xattr_set_txn(const struct lu_context *ctxt, struct md_object *obj,
65                       const void *buf, int buf_len, const char *name, int fl,
66                       struct thandle *txn);
67 int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj,
68                    struct md_object *child, struct lov_mds_md *lmm,
69                    int lmm_size, int mode, struct thandle *handle);
70 int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd,
71                    struct mdd_object *parent, struct mdd_object *child,
72                    struct lov_mds_md **lmm, int *lmm_size,
73                    const struct md_create_spec *spec, struct lu_attr *la);
74
75 int mdd_get_md(const struct lu_context *ctxt, struct md_object *obj,
76                void *md, int *md_size);
77 int mdd_unlink_log(const struct lu_context *ctxt, struct mdd_device *mdd,
78                    struct mdd_object *mdd_cobj, struct md_attr *ma);
79 struct mdd_thread_info *mdd_ctx_info(const struct lu_context *ctx);
80
81 extern struct lu_device_operations mdd_lu_ops;
82 static inline int lu_device_is_mdd(struct lu_device *d)
83 {
84         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
85 }
86
87 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
88 {
89         LASSERT(lu_device_is_mdd(d));
90         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
91 }
92
93 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
94 {
95         return (&d->mdd_md_dev.md_lu_dev);
96 }
97
98 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
99 {
100         LASSERT(lu_device_is_mdd(o->lo_dev));
101         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
102 }
103
104 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
105 {
106         return lu2mdd_dev(mdo->mo_lu.lo_dev);
107 }
108
109 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
110 {
111         return container_of0(mdo, struct mdd_object, mod_obj);
112 }
113
114 static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
115 {
116         return d->mdd_child->dd_ops;
117 }
118
119 static inline struct lu_object *mdd2lu_obj(struct mdd_object *obj)
120 {
121         return &obj->mod_obj.mo_lu;
122 }
123
124 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
125 {
126         return container_of0(lu_object_next(mdd2lu_obj(o)),
127                              struct dt_object, do_lu);
128 }
129 static inline struct obd_device *mdd2_obd(struct mdd_device *mdd)
130 {
131         return mdd->mdd_md_dev.md_lu_dev.ld_obd;
132 }
133
134 static inline const struct lu_fid *mdo2fid(const struct mdd_object *obj)
135 {
136         return lu_object_fid(&obj->mod_obj.mo_lu);
137 }
138
139 int mdd_lov_mdsize(const struct lu_context *ctxt, struct mdd_device *mdd,
140                    int *md_size);
141 int mdd_lov_cookiesize(const struct lu_context *ctxt, struct mdd_device *mdd,
142                        int *cookie_size);
143 #endif