1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see [sun.com URL with a
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdd/mdd_trans.c
38 * Lustre Metadata Server (mdd) routines
40 * Author: Wang Di <wangdi@clusterfs.com>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_MDS
48 #include <linux/module.h>
49 #include <linux/jbd.h>
51 #include <obd_class.h>
52 #include <lustre_ver.h>
53 #include <obd_support.h>
54 #include <lprocfs_status.h>
56 #include <linux/ldiskfs_fs.h>
57 #include <lustre_mds.h>
58 #include <lustre/lustre_idl.h>
60 #include "mdd_internal.h"
62 static int dto_txn_credits[DTO_NR];
64 int mdd_txn_start_cb(const struct lu_env *env, struct txn_param *param,
67 struct mdd_device *mdd = cookie;
68 struct obd_device *obd = mdd2obd_dev(mdd);
69 /* Each transaction updates lov objids, the credits should be added for
71 int blk, shift = mdd->mdd_dt_conf.ddp_block_shift;
72 blk = ((obd->u.mds.mds_lov_desc.ld_tgt_count * sizeof(obd_id) +
73 (1 << shift) - 1) >> shift) + 1;
75 /* add lov objids credits */
76 param->tp_credits += blk * dto_txn_credits[DTO_WRITE_BLOCK] +
77 dto_txn_credits[DTO_WRITE_BASE];
82 int mdd_txn_stop_cb(const struct lu_env *env, struct thandle *txn,
85 struct mdd_device *mdd = cookie;
86 struct obd_device *obd = mdd2obd_dev(mdd);
89 return mds_lov_write_objids(obd);
92 int mdd_txn_commit_cb(const struct lu_env *env, struct thandle *txn,
98 void mdd_txn_param_build(const struct lu_env *env, struct mdd_device *mdd,
101 LASSERT(0 <= op && op < MDD_TXN_LAST_OP);
103 txn_param_init(&mdd_env_info(env)->mti_param,
104 mdd->mdd_tod[op].mod_credits);
107 int mdd_log_txn_param_build(const struct lu_env *env, struct md_object *obj,
108 struct md_attr *ma, enum mdd_txn_op op)
110 struct mdd_device *mdd = mdo2mdd(&md2mdd_obj(obj)->mod_obj);
111 int rc, log_credits, stripe;
114 mdd_txn_param_build(env, mdd, op);
116 if (S_ISDIR(lu_object_attr(&obj->mo_lu)))
119 LASSERT(op == MDD_TXN_UNLINK_OP || op == MDD_TXN_RENAME_OP);
120 rc = mdd_lmm_get_locked(env, md2mdd_obj(obj), ma);
121 if (rc || !(ma->ma_valid & MA_LOV))
124 LASSERT(le32_to_cpu(ma->ma_lmm->lmm_magic) == LOV_MAGIC);
125 if ((int)le32_to_cpu(ma->ma_lmm->lmm_stripe_count) < 0)
126 stripe = mdd2obd_dev(mdd)->u.mds.mds_lov_desc.ld_tgt_count;
128 stripe = le32_to_cpu(ma->ma_lmm->lmm_stripe_count);
130 log_credits = stripe * dto_txn_credits[DTO_LOG_REC];
131 mdd_env_info(env)->mti_param.tp_credits += log_credits;
135 static void mdd_txn_init_dto_credits(const struct lu_env *env,
136 struct mdd_device *mdd, int *dto_credits)
139 for (op = 0; op < DTO_NR; op++) {
140 credits = mdd_child_ops(mdd)->dt_credit_get(env, mdd->mdd_child,
142 LASSERT(credits > 0);
143 dto_txn_credits[op] = credits;
147 int mdd_txn_init_credits(const struct lu_env *env, struct mdd_device *mdd)
151 /* Init credits for each ops. */
152 mdd_txn_init_dto_credits(env, mdd, dto_txn_credits);
154 /* Calculate the mdd credits. */
155 for (op = MDD_TXN_OBJECT_DESTROY_OP; op < MDD_TXN_LAST_OP; op++) {
156 int *c = &mdd->mdd_tod[op].mod_credits;
157 int *dt = dto_txn_credits;
158 mdd->mdd_tod[op].mod_op = op;
160 case MDD_TXN_OBJECT_DESTROY_OP:
161 *c = dt[DTO_OBJECT_DELETE];
163 case MDD_TXN_OBJECT_CREATE_OP:
164 /* OI_INSERT + CREATE OBJECT */
165 *c = dt[DTO_INDEX_INSERT] +
166 dt[DTO_OBJECT_CREATE];
168 case MDD_TXN_ATTR_SET_OP:
169 /* ATTR set + XATTR(lsm, lmv) set */
170 *c = dt[DTO_ATTR_SET] + dt[DTO_XATTR_SET];
172 case MDD_TXN_XATTR_SET_OP:
173 *c = dt[DTO_XATTR_SET];
175 case MDD_TXN_INDEX_INSERT_OP:
176 *c = dt[DTO_INDEX_INSERT];
178 case MDD_TXN_INDEX_DELETE_OP:
179 *c = dt[DTO_INDEX_DELETE];
181 case MDD_TXN_LINK_OP:
182 *c = dt[DTO_INDEX_INSERT];
184 case MDD_TXN_UNLINK_OP:
185 /* delete index + Unlink log */
186 *c = dt[DTO_INDEX_DELETE];
188 case MDD_TXN_RENAME_OP:
189 /* 2 delete index + 1 insert + Unlink log */
190 *c = 2 * dt[DTO_INDEX_DELETE] +
191 dt[DTO_INDEX_INSERT];
193 case MDD_TXN_RENAME_TGT_OP:
194 /* index insert + index delete */
195 *c = dt[DTO_INDEX_DELETE] +
196 dt[DTO_INDEX_INSERT];
198 case MDD_TXN_CREATE_DATA_OP:
199 /* same as set xattr(lsm) */
200 *c = dt[DTO_XATTR_SET];
202 case MDD_TXN_MKDIR_OP:
203 /* INDEX INSERT + OI INSERT +
204 * CREATE_OBJECT_CREDITS
205 * SET_MD CREDITS is already counted in
206 * CREATE_OBJECT CREDITS
208 *c = 2 * dt[DTO_INDEX_INSERT] +
209 dt[DTO_OBJECT_CREATE];
212 CERROR("Invalid op %d init its credit\n", op);
219 struct thandle* mdd_trans_start(const struct lu_env *env,
220 struct mdd_device *mdd)
222 struct txn_param *p = &mdd_env_info(env)->mti_param;
225 th = mdd_child_ops(mdd)->dt_trans_start(env, mdd->mdd_child, p);
229 void mdd_trans_stop(const struct lu_env *env, struct mdd_device *mdd,
230 int result, struct thandle *handle)
232 handle->th_result = result;
233 mdd_child_ops(mdd)->dt_trans_stop(env, handle);