Whamcloud - gitweb
- add two methods for lu_device - init/fini. Aftef all lu_device are allocateed,
[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 #include <linux/lu_object.h>
29
30 struct md_device;
31 struct md_device_operations;
32 struct md_object;
33
34 /*the context of the mdd ops*/
35 struct context {
36         __u32           mode;
37         int             flags;
38 };
39
40 struct md_device_operations {
41         int (*mdo_root_get)(struct md_device *m, struct lu_fid *f);
42         int (*mdo_statfs)(struct md_device *m, struct kstatfs *sfs);
43         int (*mdo_mkdir)(struct md_object *obj, const char *name,
44                          struct md_object *child);
45
46         int (*mdo_rename)(struct md_object *spobj, struct md_object *tpobj,
47                           struct md_object *sobj, const char *sname,
48                           struct md_object *tobj, const char *tname,
49                           struct context *uctxt);
50         int (*mdo_link)(struct md_object *tobj, struct md_object *sobj,
51                         const char *name, struct context *uctxt);
52         int (*mdo_attr_get)(struct md_object *obj, void *buf, int buf_len,
53                             const char *name, struct context *uctxt);
54         int (*mdo_attr_set)(struct md_object *obj, void *buf, int buf_len,
55                             const char *name, struct context *uctxt);
56         int (*mdo_index_insert)(struct md_object *pobj, struct md_object *obj,
57                                 const char *name, struct context *uctxt);
58         int (*mdo_index_delete)(struct md_object *pobj, struct md_object *obj,
59                                 const char *name, struct context *uctxt);
60         int (*mdo_object_create)(struct md_object *pobj, struct md_object *child,
61                                  struct context *uctxt);
62 };
63
64 struct md_device {
65         struct lu_device             md_lu_dev;
66         struct md_device_operations *md_ops;
67 };
68
69 struct md_object {
70         struct lu_object mo_lu;
71 };
72
73 static inline int lu_device_is_md(struct lu_device *d)
74 {
75         return d->ld_type->ldt_tags & LU_DEVICE_MD;
76 }
77
78 static inline struct md_device *lu2md_dev(struct lu_device *d)
79 {
80         LASSERT(lu_device_is_md(d));
81         return container_of(d, struct md_device, md_lu_dev);
82 }
83
84 static inline struct lu_device *md2lu_dev(struct md_device *d)
85 {
86         return &d->md_lu_dev;
87 }
88
89 static inline struct md_object *lu2md(struct lu_object *o)
90 {
91         LASSERT(lu_device_is_md(o->lo_dev));
92         return container_of(o, struct md_object, mo_lu);
93 }
94
95 static inline struct md_device *md_device_get(struct md_object *o)
96 {
97         LASSERT(lu_device_is_md(o->mo_lu.lo_dev));
98         return container_of(o->mo_lu.lo_dev, struct md_device, md_lu_dev);
99 }
100
101 static inline int md_device_init(struct md_device *md, struct lu_device_type *t)
102 {
103         return lu_device_init(&md->md_lu_dev, t);
104 }
105
106 static inline void md_device_fini(struct md_device *md)
107 {
108         lu_device_fini(&md->md_lu_dev);
109 }
110 #endif /* _LINUX_MD_OBJECT_H */