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 #include <lustre_fid.h>
41 /* no lock is necessary to protect the list, because call-backs
42 * are added during system startup. Please refer to "struct dt_device".
44 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb)
46 list_add(&cb->dtc_linkage, &dev->dd_txn_callbacks);
48 EXPORT_SYMBOL(dt_txn_callback_add);
50 void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb)
52 list_del_init(&cb->dtc_linkage);
54 EXPORT_SYMBOL(dt_txn_callback_del);
56 int dt_txn_hook_start(const struct lu_env *env,
57 struct dt_device *dev, struct txn_param *param)
60 struct dt_txn_callback *cb;
63 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
64 if (cb->dtc_txn_start == NULL)
66 result = cb->dtc_txn_start(env, param, cb->dtc_cookie);
72 EXPORT_SYMBOL(dt_txn_hook_start);
74 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn)
76 struct dt_device *dev = txn->th_dev;
77 struct dt_txn_callback *cb;
81 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
82 if (cb->dtc_txn_stop == NULL)
84 result = cb->dtc_txn_stop(env, txn, cb->dtc_cookie);
90 EXPORT_SYMBOL(dt_txn_hook_stop);
92 int dt_txn_hook_commit(const struct lu_env *env, struct thandle *txn)
94 struct dt_device *dev = txn->th_dev;
95 struct dt_txn_callback *cb;
99 list_for_each_entry(cb, &dev->dd_txn_callbacks, dtc_linkage) {
100 if (cb->dtc_txn_commit == NULL)
102 result = cb->dtc_txn_commit(env, txn, cb->dtc_cookie);
108 EXPORT_SYMBOL(dt_txn_hook_commit);
110 int dt_device_init(struct dt_device *dev, struct lu_device_type *t)
113 CFS_INIT_LIST_HEAD(&dev->dd_txn_callbacks);
114 return lu_device_init(&dev->dd_lu_dev, t);
116 EXPORT_SYMBOL(dt_device_init);
118 void dt_device_fini(struct dt_device *dev)
120 lu_device_fini(&dev->dd_lu_dev);
122 EXPORT_SYMBOL(dt_device_fini);
124 int dt_object_init(struct dt_object *obj,
125 struct lu_object_header *h, struct lu_device *d)
128 return lu_object_init(&obj->do_lu, h, d);
130 EXPORT_SYMBOL(dt_object_init);
132 void dt_object_fini(struct dt_object *obj)
134 lu_object_fini(&obj->do_lu);
136 EXPORT_SYMBOL(dt_object_fini);
138 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj)
140 if (obj->do_index_ops == NULL)
141 obj->do_ops->do_index_try(env, obj, &dt_directory_features);
142 return obj->do_index_ops != NULL;
144 EXPORT_SYMBOL(dt_try_as_dir);
146 extern struct lu_context_key lu_global_key;
148 static int dt_lookup(const struct lu_env *env, struct dt_object *dir,
149 const char *name, struct lu_fid *fid)
151 struct lu_fid_pack *pack = lu_context_key_get(&env->le_ctx,
153 struct dt_rec *rec = (struct dt_rec *)pack;
154 const struct dt_key *key = (const struct dt_key *)name;
157 if (dt_try_as_dir(env, dir)) {
158 result = dir->do_index_ops->dio_lookup(env, dir, rec, key,
161 result = fid_unpack(pack, fid);
167 static struct dt_object *dt_locate(const struct lu_env *env,
168 struct dt_device *dev,
169 const struct lu_fid *fid)
171 struct lu_object *obj;
172 struct dt_object *dt;
174 obj = lu_object_find(env, dev->dd_lu_dev.ld_site, fid);
176 obj = lu_object_locate(obj->lo_header, dev->dd_lu_dev.ld_type);
177 LASSERT(obj != NULL);
178 dt = container_of(obj, struct dt_object, do_lu);
184 struct dt_object *dt_store_open(const struct lu_env *env,
185 struct dt_device *dt, const char *name,
190 struct dt_object *root;
191 struct dt_object *child;
193 result = dt->dd_ops->dt_root_get(env, dt, fid);
195 root = dt_locate(env, dt, fid);
197 result = dt_lookup(env, root, name, fid);
199 child = dt_locate(env, dt, fid);
201 child = ERR_PTR(result);
202 lu_object_put(env, &root->do_lu);
205 child = (void *)root;
208 child = ERR_PTR(result);
211 EXPORT_SYMBOL(dt_store_open);
213 const struct dt_index_features dt_directory_features;
214 EXPORT_SYMBOL(dt_directory_features);