1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mdd) routines
7 * Copyright (C) 2006 Cluster File Systems, Inc.
8 * Author: Wang Di <wangdi@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_MDS
33 #include <linux/module.h>
34 #include <linux/jbd.h>
36 #include <obd_class.h>
37 #include <lustre_ver.h>
38 #include <obd_support.h>
39 #include <lprocfs_status.h>
41 #include <linux/ldiskfs_fs.h>
42 #include <lustre_mds.h>
43 #include <lustre/lustre_idl.h>
45 #include "mdd_internal.h"
47 static int dto_txn_credits[DTO_NR];
49 int mdd_txn_start_cb(const struct lu_env *env, struct txn_param *param,
52 struct mdd_device *mdd = cookie;
53 struct obd_device *obd = mdd2obd_dev(mdd);
54 /* Each transaction updates lov objids, the credits should be added for
56 int blk, shift = mdd->mdd_dt_conf.ddp_block_shift;
57 blk = ((obd->u.mds.mds_lov_desc.ld_tgt_count * sizeof(obd_id) +
58 (1 << shift) - 1) >> shift) + 1;
60 /* add lov objids credits */
61 param->tp_credits += blk * dto_txn_credits[DTO_WRITE_BLOCK] +
62 dto_txn_credits[DTO_WRITE_BASE];
67 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
70 struct mdd_device *mdd = cookie;
71 struct obd_device *obd = mdd2obd_dev(mdd);
74 return mds_lov_write_objids(obd);
77 int mdd_txn_commit_cb(const struct lu_env *env, struct thandle *txn,
83 void mdd_txn_param_build(const struct lu_env *env, struct mdd_device *mdd,
86 LASSERT(0 <= op && op < MDD_TXN_LAST_OP);
88 txn_param_init(&mdd_env_info(env)->mti_param,
89 mdd->mdd_tod[op].mod_credits);
92 int mdd_log_txn_param_build(const struct lu_env *env, struct md_object *obj,
93 struct md_attr *ma, enum mdd_txn_op op)
95 struct mdd_device *mdd = mdo2mdd(&md2mdd_obj(obj)->mod_obj);
96 int rc, log_credits, stripe;
99 mdd_txn_param_build(env, mdd, op);
101 if (S_ISDIR(lu_object_attr(&obj->mo_lu)))
104 LASSERT(op == MDD_TXN_UNLINK_OP || op == MDD_TXN_RENAME_OP);
105 rc = mdd_lmm_get_locked(env, md2mdd_obj(obj), ma);
106 if (rc || !(ma->ma_valid & MA_LOV))
109 LASSERT(le32_to_cpu(ma->ma_lmm->lmm_magic) == LOV_MAGIC);
110 if ((int)le32_to_cpu(ma->ma_lmm->lmm_stripe_count) < 0)
111 stripe = mdd2obd_dev(mdd)->u.mds.mds_lov_desc.ld_tgt_count;
113 stripe = le32_to_cpu(ma->ma_lmm->lmm_stripe_count);
115 log_credits = stripe * dto_txn_credits[DTO_LOG_REC];
116 mdd_env_info(env)->mti_param.tp_credits += log_credits;
120 static void mdd_txn_init_dto_credits(const struct lu_env *env,
121 struct mdd_device *mdd, int *dto_credits)
124 for (op = 0; op < DTO_NR; op++) {
125 credits = mdd_child_ops(mdd)->dt_credit_get(env, mdd->mdd_child,
127 LASSERT(credits > 0);
128 dto_txn_credits[op] = credits;
132 int mdd_txn_init_credits(const struct lu_env *env, struct mdd_device *mdd)
136 /* Init credits for each ops. */
137 mdd_txn_init_dto_credits(env, mdd, dto_txn_credits);
139 /* Calculate the mdd credits. */
140 for (op = MDD_TXN_OBJECT_DESTROY_OP; op < MDD_TXN_LAST_OP; op++) {
141 int *c = &mdd->mdd_tod[op].mod_credits;
142 int *dt = dto_txn_credits;
143 mdd->mdd_tod[op].mod_op = op;
145 case MDD_TXN_OBJECT_DESTROY_OP:
146 *c = dt[DTO_OBJECT_DELETE];
148 case MDD_TXN_OBJECT_CREATE_OP:
149 /* OI_INSERT + CREATE OBJECT */
150 *c = dt[DTO_INDEX_INSERT] +
151 dt[DTO_OBJECT_CREATE];
153 case MDD_TXN_ATTR_SET_OP:
154 /* ATTR set + XATTR(lsm, lmv) set */
155 *c = dt[DTO_ATTR_SET] + dt[DTO_XATTR_SET];
157 case MDD_TXN_XATTR_SET_OP:
158 *c = dt[DTO_XATTR_SET];
160 case MDD_TXN_INDEX_INSERT_OP:
161 *c = dt[DTO_INDEX_INSERT];
163 case MDD_TXN_INDEX_DELETE_OP:
164 *c = dt[DTO_INDEX_DELETE];
166 case MDD_TXN_LINK_OP:
167 *c = dt[DTO_INDEX_INSERT];
169 case MDD_TXN_UNLINK_OP:
170 /* delete index + Unlink log */
171 *c = dt[DTO_INDEX_DELETE];
173 case MDD_TXN_RENAME_OP:
174 /* 2 delete index + 1 insert + Unlink log */
175 *c = 2 * dt[DTO_INDEX_DELETE] +
176 dt[DTO_INDEX_INSERT];
178 case MDD_TXN_RENAME_TGT_OP:
179 /* index insert + index delete */
180 *c = dt[DTO_INDEX_DELETE] +
181 dt[DTO_INDEX_INSERT];
183 case MDD_TXN_CREATE_DATA_OP:
184 /* same as set xattr(lsm) */
185 *c = dt[DTO_XATTR_SET];
187 case MDD_TXN_MKDIR_OP:
188 /* INDEX INSERT + OI INSERT +
189 * CREATE_OBJECT_CREDITS
190 * SET_MD CREDITS is already counted in
191 * CREATE_OBJECT CREDITS
193 *c = 2 * dt[DTO_INDEX_INSERT] +
194 dt[DTO_OBJECT_CREATE];
197 CERROR("Invalid op %d init its credit\n", op);
204 struct thandle* mdd_trans_start(const struct lu_env *env,
205 struct mdd_device *mdd)
207 struct txn_param *p = &mdd_env_info(env)->mti_param;
210 th = mdd_child_ops(mdd)->dt_trans_start(env, mdd->mdd_child, p);
214 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
215 int result, struct thandle *handle)
217 handle->th_result = result;
218 mdd_child_ops(mdd)->dt_trans_stop(env, handle);