Whamcloud - gitweb
08fb439ed2a2caaa3380157c29594a5d7e0cf921
[fs/lustre-release.git] / lustre / cmm / cmm_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2006 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #ifndef _CMM_INTERNAL_H
24 #define _CMM_INTERNAL_H
25
26 #if defined(__KERNEL__)
27
28 #include <linux/obd.h>
29 #include <linux/md_object.h>
30
31 struct cmm_device {
32         struct md_device cmm_md_dev;
33         /* underlaying device in MDS stack, usually MDD */
34         struct md_device *cmm_child;
35         /* other MD servers in cluster */
36         __u32            cmm_local_num;
37         __u32            cmm_tgt_count;
38         struct list_head cmm_targets;
39 };
40
41 static inline struct md_device_operations *cmm_child_ops(struct cmm_device *d)
42 {
43         return (d->cmm_child->md_ops);
44 }
45
46 static inline struct cmm_device *md2cmm_dev(struct md_device *m)
47 {
48         return container_of0(m, struct cmm_device, cmm_md_dev);
49 }
50
51 static inline struct cmm_device *lu2cmm_dev(struct lu_device *d)
52 {
53         //LASSERT(lu_device_is_cmm(d));
54         return container_of0(d, struct cmm_device, cmm_md_dev.md_lu_dev);
55 }
56
57 static inline struct lu_device *cmm2lu_dev(struct cmm_device *d)
58 {
59         return (&d->cmm_md_dev.md_lu_dev);
60 }
61
62 struct cmm_object {
63         struct md_object cmo_obj;
64         /* mds number where object is placed */
65         __u32            cmo_num;
66 };
67
68 static inline struct cmm_device *cmm_obj2dev(struct cmm_object *c)
69 {
70         return (md2cmm_dev(md_device_get(&c->cmo_obj)));
71 }
72
73 static inline struct cmm_object *lu2cmm_obj(struct lu_object *o)
74 {
75         //LASSERT(lu_device_is_cmm(o->lo_dev));
76         return container_of0(o, struct cmm_object, cmo_obj.mo_lu);
77 }
78
79 static inline int cmm_is_local_obj(struct cmm_object *c)
80 {
81         return (c->cmo_num == cmm_obj2dev(c)->cmm_local_num);
82 }
83
84 /* get cmm object from md_object */
85 static inline struct cmm_object *md2cmm_obj(struct md_object *o)
86 {
87         return container_of0(o, struct cmm_object, cmo_obj);
88 }
89 /* get lower-layer object */
90 static inline struct md_object *cmm2child_obj(struct cmm_object *o)
91 {
92         return lu2md(lu_object_next(&o->cmo_obj.mo_lu));
93 }
94
95 /* cmm_object.c */
96 struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *);
97 void cmm_object_free(struct lu_context *ctx, struct lu_object *o);
98 //int cmm_getattr(struct lu_object *o, struct lu_attr *a);
99 //int cmm_setattr(struct lu_object *o, struct lu_attr *a);
100
101 /* cmm md operations */
102 int cmm_config(struct lu_context *ctx, struct md_device *md, const char *name,
103                void *buf, int size, int mode);
104 int cmm_root_get(struct lu_context *ctx, struct md_device *m, struct lu_fid *f);
105 int cmm_statfs(struct lu_context *ctx,
106                struct md_device *m, struct kstatfs *sfs);
107 int cmm_mkdir(struct lu_context *ctxt, struct lu_attr*,
108               struct md_object *o, const char *name,
109               struct md_object *child);
110 int cmm_xattr_get(struct lu_context *ctxt,
111                   struct md_object *obj, void *buf, int size,
112                   const char *name);
113
114 #endif /* __KERNEL__ */
115 #endif /* _CMM_INTERNAL_H */