2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License v.2.
10 #include <linux/sched.h>
11 #include <linux/slab.h>
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/buffer_head.h>
15 #include <linux/gfs2_ondisk.h>
16 #include <asm/semaphore.h>
19 #include "lm_interface.h"
28 int gfs2_trans_begin_i(struct gfs2_sbd *sdp, unsigned int blocks,
29 unsigned int revokes, char *file, unsigned int line)
31 struct gfs2_trans *tr;
34 if (gfs2_assert_warn(sdp, !current->journal_info) ||
35 gfs2_assert_warn(sdp, blocks || revokes)) {
36 fs_warn(sdp, "(%s, %u)\n", file, line);
40 tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS);
46 tr->tr_blocks = blocks;
47 tr->tr_revokes = revokes;
50 tr->tr_reserved += 1 + blocks;
52 tr->tr_reserved += gfs2_struct2blk(sdp, revokes,
54 INIT_LIST_HEAD(&tr->tr_list_buf);
57 tr->tr_t_gh = gfs2_holder_get(sdp->sd_trans_gl, LM_ST_SHARED,
58 GL_NEVER_RECURSE, GFP_NOFS);
62 error = gfs2_glock_nq(tr->tr_t_gh);
66 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
67 tr->tr_t_gh->gh_flags |= GL_NOCACHE;
72 error = gfs2_log_reserve(sdp, tr->tr_reserved);
76 current->journal_info = tr;
81 gfs2_glock_dq(tr->tr_t_gh);
84 gfs2_holder_put(tr->tr_t_gh);
92 void gfs2_trans_end(struct gfs2_sbd *sdp)
94 struct gfs2_trans *tr;
95 struct gfs2_holder *t_gh;
97 tr = current->journal_info;
98 current->journal_info = NULL;
100 if (gfs2_assert_warn(sdp, tr))
106 if (!tr->tr_touched) {
107 gfs2_log_release(sdp, tr->tr_reserved);
111 gfs2_holder_put(t_gh);
116 if (gfs2_assert_withdraw(sdp, tr->tr_num_buf <= tr->tr_blocks))
117 fs_err(sdp, "tr_num_buf = %u, tr_blocks = %u "
118 "tr_file = %s, tr_line = %u\n",
119 tr->tr_num_buf, tr->tr_blocks,
120 tr->tr_file, tr->tr_line);
121 if (gfs2_assert_withdraw(sdp, tr->tr_num_revoke <= tr->tr_revokes))
122 fs_err(sdp, "tr_num_revoke = %u, tr_revokes = %u "
123 "tr_file = %s, tr_line = %u\n",
124 tr->tr_num_revoke, tr->tr_revokes,
125 tr->tr_file, tr->tr_line);
127 gfs2_log_commit(sdp, tr);
130 gfs2_holder_put(t_gh);
132 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
136 void gfs2_trans_add_gl(struct gfs2_glock *gl)
138 lops_add(gl->gl_sbd, &gl->gl_le);
142 * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction
143 * @gl: the glock the buffer belongs to
144 * @bh: The buffer to add
145 * @meta: True in the case of adding metadata
149 void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta)
151 struct gfs2_sbd *sdp = gl->gl_sbd;
152 struct gfs2_bufdata *bd;
156 gfs2_assert(sdp, bd->bd_gl == gl);
158 gfs2_attach_bufdata(gl, bh, meta);
161 lops_add(sdp, &bd->bd_le);
164 void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, uint64_t blkno)
166 struct gfs2_revoke *rv = kmalloc(sizeof(struct gfs2_revoke),
167 GFP_NOFS | __GFP_NOFAIL);
168 lops_init_le(&rv->rv_le, &gfs2_revoke_lops);
169 rv->rv_blkno = blkno;
170 lops_add(sdp, &rv->rv_le);
173 void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, uint64_t blkno)
175 struct gfs2_revoke *rv;
180 list_for_each_entry(rv, &sdp->sd_log_le_revoke, rv_le.le_list) {
181 if (rv->rv_blkno == blkno) {
182 list_del(&rv->rv_le.le_list);
183 gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
184 sdp->sd_log_num_revoke--;
190 gfs2_log_unlock(sdp);
193 struct gfs2_trans *tr = current->journal_info;
195 tr->tr_num_revoke_rm++;
199 void gfs2_trans_add_rg(struct gfs2_rgrpd *rgd)
201 lops_add(rgd->rd_sbd, &rgd->rd_le);