Whamcloud - gitweb
split part of md_operations into md_dir_operations. Cannot test as fld does not work
[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 };
63
64 /*
65  * Operations implemented for each directory object.
66  */
67 struct md_dir_operations {
68         int (*mdo_mkdir)(struct lu_context *ctxt, struct lu_attr *attr,
69                          struct md_object *obj,
70                          const char *name, struct md_object *child);
71
72         int (*mdo_rename)(struct lu_context *ctxt, struct md_object *spobj,
73                           struct md_object *tpobj, struct md_object *sobj,
74                           const char *sname, struct md_object *tobj,
75                           const char *tname);
76
77         int (*mdo_link)(struct lu_context *ctxt, struct md_object *tobj,
78                         struct md_object *sobj, const char *name);
79
80 };
81
82 struct md_device_operations {
83         /* method for getting/setting device wide back stored config data, like
84          * last used meta-sequence, etc. */
85         int (*mdo_config) (struct lu_context *ctx,
86                            struct md_device *m, const char *name,
87                            void *buf, int size, int mode);
88
89         /* meta-data device related handlers. */
90         int (*mdo_root_get)(struct lu_context *ctx,
91                             struct md_device *m, struct lu_fid *f);
92         int (*mdo_statfs)(struct lu_context *ctx,
93                           struct md_device *m, struct kstatfs *sfs);
94 };
95
96 struct md_device {
97         struct lu_device             md_lu_dev;
98         struct md_device_operations *md_ops;
99 };
100
101 struct md_object {
102         struct lu_object             mo_lu;
103         struct md_object_operations *mo_ops;
104         struct md_dir_operations    *mo_dir_ops;
105 };
106
107 static inline int lu_device_is_md(const struct lu_device *d)
108 {
109         return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_MD);
110 }
111
112 static inline struct md_device *lu2md_dev(const struct lu_device *d)
113 {
114         LASSERT(lu_device_is_md(d));
115         return container_of0(d, struct md_device, md_lu_dev);
116 }
117
118 static inline struct lu_device *md2lu_dev(struct md_device *d)
119 {
120         return &d->md_lu_dev;
121 }
122
123 static inline struct md_object *lu2md(const struct lu_object *o)
124 {
125         LASSERT(lu_device_is_md(o->lo_dev));
126         return container_of0(o, struct md_object, mo_lu);
127 }
128
129 static inline struct md_object *md_object_next(const struct md_object *obj)
130 {
131         return lu2md(lu_object_next(&obj->mo_lu));
132 }
133
134 static inline struct md_device *md_device_get(const struct md_object *o)
135 {
136         LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
137         return container_of0(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
138 }
139
140 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
141 {
142         return lu_device_init(&md->md_lu_dev, t);
143 }
144
145 static inline void md_device_fini(struct md_device *md)
146 {
147         lu_device_fini(&md->md_lu_dev);
148 }
149
150 #endif /* _LINUX_MD_OBJECT_H */