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: WangDi <wangdi@clusterfs.com>
8 * Yury Umanets <umka@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
29 # define EXPORT_SYMTAB
31 #define DEBUG_SUBSYSTEM S_FLD
34 # include <libcfs/libcfs.h>
35 # include <linux/module.h>
36 # include <linux/jbd.h>
37 #else /* __KERNEL__ */
38 # include <liblustre.h>
42 #include <obd_class.h>
43 #include <lustre_ver.h>
44 #include <obd_support.h>
45 #include <lprocfs_status.h>
47 #include <dt_object.h>
48 #include <md_object.h>
49 #include <lustre_mdc.h>
50 #include <lustre_fld.h>
51 #include "fld_internal.h"
53 const char fld_index_name[] = "fld";
55 static const struct dt_index_features fld_index_features = {
56 .dif_flags = DT_IND_UPDATE,
57 .dif_keysize_min = sizeof(seqno_t),
58 .dif_keysize_max = sizeof(seqno_t),
59 .dif_recsize_min = sizeof(mdsno_t),
60 .dif_recsize_max = sizeof(mdsno_t)
64 * number of blocks to reserve for particular operations. Should be function of
65 * ... something. Stub for now.
68 FLD_TXN_INDEX_INSERT_CREDITS = 20,
69 FLD_TXN_INDEX_DELETE_CREDITS = 20,
72 extern struct lu_context_key fld_thread_key;
74 static struct dt_key *fld_key(const struct lu_env *env,
77 struct fld_thread_info *info;
80 info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
81 LASSERT(info != NULL);
83 info->fti_key = cpu_to_be64(seq);
84 RETURN((void *)&info->fti_key);
87 static struct dt_rec *fld_rec(const struct lu_env *env,
90 struct fld_thread_info *info;
93 info = lu_context_key_get(&env->le_ctx, &fld_thread_key);
94 LASSERT(info != NULL);
96 info->fti_rec = cpu_to_be64(mds);
97 RETURN((void *)&info->fti_rec);
100 int fld_index_create(struct lu_server_fld *fld,
101 const struct lu_env *env,
102 seqno_t seq, mdsno_t mds)
104 struct dt_object *dt_obj = fld->lsf_obj;
105 struct dt_device *dt_dev;
106 struct txn_param txn;
111 dt_dev = lu2dt_dev(fld->lsf_obj->do_lu.lo_dev);
113 /* stub here, will fix it later */
114 txn_param_init(&txn, FLD_TXN_INDEX_INSERT_CREDITS);
116 th = dt_dev->dd_ops->dt_trans_start(env, dt_dev, &txn);
118 rc = dt_obj->do_index_ops->dio_insert(env, dt_obj,
122 dt_dev->dd_ops->dt_trans_stop(env, th);
128 int fld_index_delete(struct lu_server_fld *fld,
129 const struct lu_env *env,
132 struct dt_object *dt_obj = fld->lsf_obj;
133 struct dt_device *dt_dev;
134 struct txn_param txn;
139 dt_dev = lu2dt_dev(fld->lsf_obj->do_lu.lo_dev);
140 txn_param_init(&txn, FLD_TXN_INDEX_DELETE_CREDITS);
141 th = dt_dev->dd_ops->dt_trans_start(env, dt_dev, &txn);
143 rc = dt_obj->do_index_ops->dio_delete(env, dt_obj,
144 fld_key(env, seq), th,
146 dt_dev->dd_ops->dt_trans_stop(env, th);
152 int fld_index_lookup(struct lu_server_fld *fld,
153 const struct lu_env *env,
154 seqno_t seq, mdsno_t *mds)
156 struct dt_object *dt_obj = fld->lsf_obj;
157 struct dt_rec *rec = fld_rec(env, 0);
161 rc = dt_obj->do_index_ops->dio_lookup(env, dt_obj, rec,
162 fld_key(env, seq), BYPASS_CAPA);
164 *mds = be64_to_cpu(*(__u64 *)rec);
168 int fld_index_init(struct lu_server_fld *fld,
169 const struct lu_env *env,
170 struct dt_device *dt)
172 struct dt_object *dt_obj;
177 dt_obj = dt_store_open(env, dt, fld_index_name, &fid);
178 if (!IS_ERR(dt_obj)) {
179 fld->lsf_obj = dt_obj;
180 rc = dt_obj->do_ops->do_index_try(env, dt_obj,
181 &fld_index_features);
183 LASSERT(dt_obj->do_index_ops != NULL);
185 CERROR("%s: File \"%s\" is not an index!\n",
186 fld->lsf_name, fld_index_name);
188 CERROR("%s: Can't find \"%s\" obj %d\n",
189 fld->lsf_name, fld_index_name, (int)PTR_ERR(dt_obj));
190 rc = PTR_ERR(dt_obj);
196 void fld_index_fini(struct lu_server_fld *fld,
197 const struct lu_env *env)
200 if (fld->lsf_obj != NULL) {
201 if (!IS_ERR(fld->lsf_obj))
202 lu_object_put(env, &fld->lsf_obj->do_lu);