Whamcloud - gitweb
add lu_context everywhere. Mountability preserved.
[fs/lustre-release.git] / lustre / cmm / cmm_object.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/cmm/cmm_object.c
5  *  Lustre Cluster Metadata Manager (cmm)
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Mike Pershin <tappro@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32
33 #define DEBUG_SUBSYSTEM S_MDS
34
35 #include "cmm_internal.h"
36
37 static struct md_object_operations cmm_mo_ops;
38
39 struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *d)
40 {
41         struct cmm_object *mo;
42         ENTRY;
43
44         OBD_ALLOC_PTR(mo);
45         if (mo != NULL) {
46                 struct lu_object *o;
47
48                 o = &mo->cmo_obj.mo_lu;
49                 lu_object_init(o, NULL, d);
50                 mo->cmo_obj.mo_ops = &cmm_mo_ops;
51                 RETURN(o);
52         } else
53                 RETURN(NULL);
54 }
55
56 int cmm_object_init(struct lu_context *ctxt, struct lu_object *o)
57 {
58         struct cmm_device *d = lu2cmm_dev(o->lo_dev);
59         struct lu_device  *under;
60         struct lu_object  *below;
61         ENTRY;
62
63         under = &d->cmm_child->md_lu_dev;
64         below = under->ld_ops->ldo_object_alloc(ctxt, under);
65         if (below != NULL) {
66                 lu_object_add(o, below);
67                 RETURN(0);
68         } else
69                 RETURN(-ENOMEM);
70 }
71
72 void cmm_object_free(struct lu_context *ctx, struct lu_object *o)
73 {
74         lu_object_fini(o);
75 }
76
77 void cmm_object_release(struct lu_context *ctxt, struct lu_object *o)
78 {
79         return;
80 }
81
82 int cmm_object_print(struct lu_context *ctx,
83                      struct seq_file *f, const struct lu_object *o)
84 {
85         return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", o);
86 }
87
88 /* Locking API */
89 #if 0
90 static void cmm_lock(struct lu_context *ctxt, struct md_object *obj, __u32 mode)
91 {
92         struct cmm_object *cmm_obj = md2cmm_obj(obj);
93         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
94         struct md_object  *next    = cmm2child_obj(cmm_obj);
95
96         next->mo_ops->moo_object_lock(ctxt, next, mode);
97 }
98
99 static void cmm_unlock(struct lu_context *ctxt,
100                        struct md_object *obj, __u32 mode)
101 {
102         struct cmm_object *cmm_obj = md2cmm_obj(obj);
103         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
104         struct md_object  *next    = cmm2child_obj(cmm_obj);
105
106         next->mo_ops->moo_object_unlock(ctxt, next, mode);
107 }
108 #endif
109 /* Llog API */
110 /* Object API */
111 /* Metadata API */
112 int cmm_root_get(struct lu_context *ctx,
113                  struct md_device *md, struct lu_fid *fid)
114 {
115         struct cmm_device *cmm_dev = md2cmm_dev(md);
116
117         return cmm_child_ops(cmm_dev)->mdo_root_get(ctx,
118                                                     cmm_dev->cmm_child, fid);
119 }
120
121 int cmm_config(struct lu_context *ctxt,
122                struct md_device *md, const char *name,
123                void *buf, int size, int mode)
124 {
125         struct cmm_device *cmm_dev = md2cmm_dev(md);
126         int result;
127         ENTRY;
128         result = cmm_child_ops(cmm_dev)->mdo_config(ctxt, cmm_dev->cmm_child,
129                                                     name, buf, size, mode);
130         RETURN(result);
131 }
132
133 int cmm_statfs(struct lu_context *ctxt,
134                struct md_device *md, struct kstatfs *sfs) {
135         struct cmm_device *cmm_dev = md2cmm_dev(md);
136         int result;
137
138         ENTRY;
139         result = cmm_child_ops(cmm_dev)->mdo_statfs(ctxt,
140                                                     cmm_dev->cmm_child, sfs);
141         RETURN (result);
142 }
143
144 int cmm_mkdir(struct lu_context *ctxt, struct md_object *md_parent,
145               const char *name, struct md_object *md_child)
146 {
147         struct cmm_object *cmm_parent = md2cmm_obj(md_parent);
148         struct md_object  *next       = cmm2child_obj(cmm_parent);
149
150         return next->mo_ops->moo_mkdir(ctxt, next, name, md_child);
151 }
152
153 int cmm_attr_get(struct lu_context *ctxt, struct md_object *obj,
154                  void *buf, int size, const char *name, struct md_params *arg)
155 {
156         struct md_object *next = cmm2child_obj(md2cmm_obj(obj));
157
158         return next->mo_ops->moo_attr_get(ctxt, next, buf, size, name, arg);
159 }
160
161 static struct md_object_operations cmm_mo_ops = {
162         .moo_mkdir      = cmm_mkdir,
163         .moo_attr_get   = cmm_attr_get,
164 //        .moo_rename     = cmm_rename,
165 //        .moo_link       = cmm_link,
166 //        .moo_attr_set   = cmm_attr_set,
167 //        .moo_index_insert = cmm_index_insert,
168 //        .moo_index_delete = cmm_index_delete,
169 //        .moo_object_create = cmm_object_create,
170 };
171
172