Whamcloud - gitweb
7a9844b7281d9ae11af7fbe49cea612610b7b781
[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_lov_info {
36         struct obd_device               *mdd_lov_obd;
37         struct obd_uuid                  mdd_lov_uuid;
38         struct lov_desc                  mdd_lov_desc;
39         obd_id                          *mdd_lov_objids;
40         int                              mdd_lov_objids_size;
41         __u32                            mdd_lov_objids_in_file;
42         int                              mdd_lov_nextid_set;
43         struct lu_fid                    mdd_lov_objid_fid;
44         struct dt_object                *mdd_lov_objid_obj;
45         unsigned int                     mdd_lov_objids_dirty:1;
46 };
47
48 struct mdd_device {
49         struct md_device                 mdd_md_dev;
50         struct dt_device                *mdd_child;
51         struct mdd_lov_info              mdd_lov_info;
52         struct dt_device                 mdd_lov_dev;
53         int                              mdd_max_mdsize;
54         int                              mdd_max_cookiesize;
55         struct lu_fid                    mdd_root_fid;
56 };
57
58 struct mdd_object {
59         struct md_object  mod_obj;
60 };
61
62 struct mdd_thread_info {
63         struct txn_param mti_param;
64         struct lu_fid    mti_fid;
65         struct lu_attr   mti_attr;
66         struct lov_desc  mti_ld;
67         struct lov_mds_md mti_lmm;
68 };
69
70 int mdd_lov_init(const struct lu_context *ctxt, struct mdd_device *mdd,
71                  struct lustre_cfg *cfg);
72 int mdd_lov_fini(const struct lu_context *ctxt, struct mdd_device *mdd);
73 int mdd_notify(const struct lu_context *ctxt, struct lu_device *ld,
74                struct obd_device *watched, enum obd_notify_event ev,
75                void *data);
76
77 int mdd_xattr_set(const struct lu_context *ctxt, struct md_object *obj,
78                   const void *buf, int buf_len, const char *name);
79 int mdd_lov_set_md(const struct lu_context *ctxt, struct md_object *pobj,
80                    struct md_object *child);
81 int mdd_lov_create(const struct lu_context *ctxt, struct mdd_device *mdd,
82                    struct mdd_object *child);
83 struct mdd_thread_info *mdd_ctx_info(const struct lu_context *ctx);
84 extern struct lu_device_operations mdd_lu_ops;
85 static inline int lu_device_is_mdd(struct lu_device *d)
86 {
87         /*
88          * XXX for now. Tags in lu_device_type->ldt_something are needed.
89          */
90         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &mdd_lu_ops);
91 }
92
93 static inline struct mdd_device* lu2mdd_dev(struct lu_device *d)
94 {
95         LASSERT(lu_device_is_mdd(d));
96         return container_of0(d, struct mdd_device, mdd_md_dev.md_lu_dev);
97 }
98
99 static inline struct lu_device *mdd2lu_dev(struct mdd_device *d)
100 {
101         return (&d->mdd_md_dev.md_lu_dev);
102 }
103
104 static inline struct mdd_object *lu2mdd_obj(struct lu_object *o)
105 {
106         LASSERT(lu_device_is_mdd(o->lo_dev));
107         return container_of0(o, struct mdd_object, mod_obj.mo_lu);
108 }
109
110 static inline struct mdd_device* mdo2mdd(struct md_object *mdo)
111 {
112         return lu2mdd_dev(mdo->mo_lu.lo_dev);
113 }
114
115 static inline struct mdd_object* md2mdd_obj(struct md_object *mdo)
116 {
117         return container_of0(mdo, struct mdd_object, mod_obj);
118 }
119
120 static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
121 {
122         return d->mdd_child->dd_ops;
123 }
124
125 static inline struct dt_object* mdd_object_child(struct mdd_object *o)
126 {
127         return container_of0(lu_object_next(&o->mod_obj.mo_lu),
128                              struct dt_object, do_lu);
129 }
130
131 #endif