Whamcloud - gitweb
update CMM device
[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 struct cmm_object *cmm_object_find(struct cmm_device *d, struct lu_fid *f)
38 {
39         struct lu_object *o;
40
41         o = lu_object_find(d->cmm_md_dev.md_lu_dev.ld_site, f);
42         if (IS_ERR(o))
43                 return (struct cmm_object *)o;
44         else
45                 return container_of(o, struct cmm_object, cmo_obj.mo_lu);
46 }
47
48 void cmm_object_put(struct cmm_object *o)
49 {
50         lu_object_put(&o->cmo_obj.mo_lu);
51 }
52
53 struct lu_object *cmm_object_alloc(struct lu_device *d)
54 {
55         struct cmm_object *mo;
56
57         OBD_ALLOC_PTR(mo);
58         if (mo != NULL) {
59                 struct lu_object *o;
60                 o = &mo->cmo_obj.mo_lu;
61                 return o;
62         } else
63                 return NULL;
64 }
65
66 int cmm_object_init(struct lu_object *o)
67 {
68         struct cmm_device *d = lu2cmm_dev(o->lo_dev);
69         struct lu_device  *under;
70         struct lu_object  *below;
71
72         under = &d->cmm_child->md_lu_dev;
73         below = under->ld_ops->ldo_object_alloc(under);
74         if (below != NULL) {
75                 lu_object_add(o, below);
76                 return 0;
77         } else
78                 return -ENOMEM;
79 }
80
81 void cmm_object_free(struct lu_object *o)
82 {
83         lu_object_fini(o);
84 }
85
86 void cmm_object_release(struct lu_object *o)
87 {
88         return;
89 }
90
91 int cmm_object_print(struct seq_file *f, const struct lu_object *o)
92 {
93         return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", o);
94 }
95
96 /* Locking API */
97 #if 0
98 static void cmm_lock(struct md_object *obj, __u32 mode)
99 {
100         struct cmm_object *cmm_obj = md2cmm_obj(obj);
101         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
102         
103         CMM_DO_CHILD(cmm_dev)->ldo_lock_obj(cmm2child_obj(cmm_obj), mode);
104         return;
105 }
106
107 static void cmm_unlock(struct md_object *obj, __u32 mode)
108 {
109         struct cmm_object *cmm_obj = md2cmm_obj(obj);
110         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
111         
112         CMM_DO_CHILD(cmm_dev)->ldo_unlock_obj(cmm2child_obj(cmm_obj), mode);
113         return;
114 }
115 #endif
116 /* Llog API */
117 /* Object API */
118 /* Metadata API */
119 int cmm_root_get(struct md_device *md, struct lu_fid *fid) {
120         return 0;
121 }
122
123 int cmm_mkdir(struct md_object *md_parent, const char *name, 
124               struct md_object *md_child)
125 {
126         struct cmm_object *cmm_parent = md2cmm_obj(md_parent);
127         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_parent);
128         int result = -EOPNOTSUPP;
129
130         if (CMM_CHILD_OPS(cmm_dev) && CMM_CHILD_OPS(cmm_dev)->mdo_mkdir) {
131                 result = CMM_CHILD_OPS(cmm_dev)->mdo_mkdir(
132                                                   cmm2child_obj(cmm_parent),
133                                                   name, md_child);
134         }       
135         
136         return result;
137 }
138
139