Whamcloud - gitweb
modify dt_index_operations to be usable as generic index
[fs/lustre-release.git] / lustre / include / linux / md_object.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Extention of lu_object.h for metadata objects
5  *
6  *  Copyright (C) 2006 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  */
24
25 #ifndef _LINUX_MD_OBJECT_H
26 #define _LINUX_MD_OBJECT_H
27
28 /*
29  * Sub-class of lu_object with methods common for "meta-data" objects in MDT
30  * stack.
31  *
32  * Meta-data objects implement namespace operations: you can link, unlink
33  * them, and treat them as directories.
34  *
35  * Examples: mdt, cmm, and mdt are implementations of md interface.
36  */
37
38
39 /*
40  * super-class definitions.
41  */
42 #include <linux/lu_object.h>
43
44 struct md_device;
45 struct md_device_operations;
46 struct md_object;
47
48 /*
49  * Operations implemented for each md object (both directory and leaf).
50  */
51 struct md_object_operations {
52         int (*moo_attr_get)(struct lu_context *ctxt, struct md_object *dt,
53                             struct lu_attr *attr);
54         int (*moo_attr_set)(struct lu_context *ctxt, struct md_object *dt,
55                             struct lu_attr *attr);
56
57         int (*moo_xattr_get)(struct lu_context *ctxt, struct md_object *obj,
58                              void *buf, int buf_len, const char *name);
59
60         int (*moo_xattr_set)(struct lu_context *ctxt, struct md_object *obj,
61                              void *buf, int buf_len, const char *name);
62         /* part of cross-ref operation */
63         int (*moo_object_create)(struct lu_context *,
64                                  struct md_object *, struct lu_attr *);
65         int (*moo_object_destroy)(struct lu_context *, struct md_object *);
66
67 };
68
69 /*
70  * Operations implemented for each directory object.
71  */
72 struct md_dir_operations {
73         int (*mdo_mkdir)(struct lu_context *ctxt, struct lu_attr *attr,
74                          struct md_object *obj,
75                          const char *name, struct md_object *child);
76
77         int (*mdo_rename)(struct lu_context *ctxt, struct md_object *spobj,
78                           struct md_object *tpobj, struct md_object *sobj,
79                           const char *sname, struct md_object *tobj,
80                           const char *tname);
81
82         int (*mdo_link)(struct lu_context *ctxt, struct md_object *tobj,
83                         struct md_object *sobj, const char *name);
84
85         /* partial ops for cross-ref case */
86         int (*mdo_name_insert)(struct lu_context *, struct md_object *,
87                                const char *name, const struct lu_fid *,
88                                struct lu_attr *);
89         int (*mdo_name_remove)(struct lu_context *, struct md_object *,
90                                const char *name, struct lu_attr *);
91 };
92
93 struct md_device_operations {
94         /* method for getting/setting device wide back stored config data, like
95          * last used meta-sequence, etc. */
96         int (*mdo_config) (struct lu_context *ctx,
97                            struct md_device *m, const char *name,
98                            void *buf, int size, int mode);
99
100         /* meta-data device related handlers. */
101         int (*mdo_root_get)(struct lu_context *ctx,
102                             struct md_device *m, struct lu_fid *f);
103         int (*mdo_statfs)(struct lu_context *ctx,
104                           struct md_device *m, struct kstatfs *sfs);
105
106 };
107
108 struct md_device {
109         struct lu_device             md_lu_dev;
110         struct md_device_operations *md_ops;
111 };
112
113 struct md_object {
114         struct lu_object             mo_lu;
115         struct md_object_operations *mo_ops;
116         struct md_dir_operations    *mo_dir_ops;
117 };
118
119 static inline int lu_device_is_md(const struct lu_device *d)
120 {
121         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
122 }
123
124 static inline struct md_device *lu2md_dev(const struct lu_device *d)
125 {
126         LASSERT(lu_device_is_md(d));
127         return container_of0(d, struct md_device, md_lu_dev);
128 }
129
130 static inline struct lu_device *md2lu_dev(struct md_device *d)
131 {
132         return &d->md_lu_dev;
133 }
134
135 static inline struct md_object *lu2md(const struct lu_object *o)
136 {
137         LASSERT(lu_device_is_md(o->lo_dev));
138         return container_of0(o, struct md_object, mo_lu);
139 }
140
141 static inline struct md_object *md_object_next(const struct md_object *obj)
142 {
143         return lu2md(lu_object_next(&obj->mo_lu));
144 }
145
146 static inline struct md_device *md_device_get(const struct md_object *o)
147 {
148         LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
149         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
150 }
151
152 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
153 {
154         return lu_device_init(&md->md_lu_dev, t);
155 }
156
157 static inline void md_device_fini(struct md_device *md)
158 {
159         lu_device_fini(&md->md_lu_dev);
160 }
161
162 #endif /* _LINUX_MD_OBJECT_H */