1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (C) 2006 Cluster File Systems, Inc.
7 * Author: Nikita Danilov <nikita@clusterfs.com>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
12 * You may have signed or agreed to another license before downloading
13 * this software. If so, you are bound by the terms and conditions
14 * of that agreement, and the following does not apply to you. See the
15 * LICENSE file included with this distribution for more information.
17 * If you did not agree to a different license, then this copy of Lustre
18 * is open source software; you can redistribute it and/or modify it
19 * under the terms of version 2 of the GNU General Public License as
20 * published by the Free Software Foundation.
22 * In either case, Lustre is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * license text for more details.
27 * Generic functions from dt_object.h
30 #define DEBUG_SUBSYSTEM S_CLASS
32 # define EXPORT_SYMTAB
36 #include <dt_object.h>
37 #include <libcfs/list.h>
39 /* no lock is necessary to protect the list, because call-backs
40 * are added during system startup. Please refer to "struct dt_device".
42 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
44 list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
46 EXPORT_SYMBOL(dt_txn_callback_add);
48 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
50 list_del_init(&cb->dtc_linkage);
52 EXPORT_SYMBOL(dt_txn_callback_del);
54 int dt_txn_hook_start(const struct lu_env *env,
55 struct dt_device *dev, struct txn_param *param)
58 struct dt_txn_callback *cb;
61 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
62 if (cb->dtc_txn_start == NULL)
64 result = cb->dtc_txn_start(env, param, cb->dtc_cookie);
70 EXPORT_SYMBOL(dt_txn_hook_start);
72 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
74 struct dt_device *dev = txn->th_dev;
75 struct dt_txn_callback *cb;
79 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
80 if (cb->dtc_txn_stop == NULL)
82 result = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
88 EXPORT_SYMBOL(dt_txn_hook_stop);
90 int dt_txn_hook_commit(const struct lu_env *env, struct thandle *txn)
92 struct dt_device *dev = txn->th_dev;
93 struct dt_txn_callback *cb;
97 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
98 if (cb->dtc_txn_commit == NULL)
100 result = cb->dtc_txn_commit(env, txn, cb->dtc_cookie);
106 EXPORT_SYMBOL(dt_txn_hook_commit);
108 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
111 CFS_INIT_LIST_HEAD(&dev->dd_txn_callbacks);
112 return lu_device_init(&dev->dd_lu_dev, t);
114 EXPORT_SYMBOL(dt_device_init);
116 void dt_device_fini(struct dt_device *dev)
118 lu_device_fini(&dev->dd_lu_dev);
120 EXPORT_SYMBOL(dt_device_fini);
122 int dt_object_init(struct dt_object *obj,
123 struct lu_object_header *h, struct lu_device *d)
126 return lu_object_init(&obj->do_lu, h, d);
128 EXPORT_SYMBOL(dt_object_init);
130 void dt_object_fini(struct dt_object *obj)
132 lu_object_fini(&obj->do_lu);
134 EXPORT_SYMBOL(dt_object_fini);
136 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
138 if (obj->do_index_ops == NULL)
139 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
140 return obj->do_index_ops != NULL;
142 EXPORT_SYMBOL(dt_try_as_dir);
144 static int dt_lookup(const struct lu_env *env, struct dt_object *dir,
145 const char *name, struct lu_fid *fid)
147 struct dt_rec *rec = (struct dt_rec *)fid;
148 const struct dt_key *key = (const struct dt_key *)name;
151 if (dt_try_as_dir(env, dir))
152 result = dir->do_index_ops->dio_lookup(env, dir, rec, key,
159 static struct dt_object *dt_locate(const struct lu_env *env,
160 struct dt_device *dev,
161 const struct lu_fid *fid)
163 struct lu_object *obj;
164 struct dt_object *dt;
166 obj = lu_object_find(env, dev->dd_lu_dev.ld_site, fid);
168 obj = lu_object_locate(obj->lo_header, dev->dd_lu_dev.ld_type);
169 LASSERT(obj != NULL);
170 dt = container_of(obj, struct dt_object, do_lu);
176 struct dt_object *dt_store_open(const struct lu_env *env,
177 struct dt_device *dt, const char *name,
182 struct dt_object *root;
183 struct dt_object *child;
185 result = dt->dd_ops->dt_root_get(env, dt, fid);
187 root = dt_locate(env, dt, fid);
189 result = dt_lookup(env, root, name, fid);
191 child = dt_locate(env, dt, fid);
193 child = ERR_PTR(result);
194 lu_object_put(env, &root->do_lu);
197 child = (void *)root;
200 child = ERR_PTR(result);
203 EXPORT_SYMBOL(dt_store_open);
205 const struct dt_index_features dt_directory_features;
206 EXPORT_SYMBOL(dt_directory_features);