hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/gfs2/trans.c
....@@ -1,10 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
34 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4
- *
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 version 2.
85 */
96
107 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -28,19 +25,34 @@
2825 #include "util.h"
2926 #include "trace_gfs2.h"
3027
28
+static void gfs2_print_trans(struct gfs2_sbd *sdp, const struct gfs2_trans *tr)
29
+{
30
+ fs_warn(sdp, "Transaction created at: %pSR\n", (void *)tr->tr_ip);
31
+ fs_warn(sdp, "blocks=%u revokes=%u reserved=%u touched=%u\n",
32
+ tr->tr_blocks, tr->tr_revokes, tr->tr_reserved,
33
+ test_bit(TR_TOUCHED, &tr->tr_flags));
34
+ fs_warn(sdp, "Buf %u/%u Databuf %u/%u Revoke %u/%u\n",
35
+ tr->tr_num_buf_new, tr->tr_num_buf_rm,
36
+ tr->tr_num_databuf_new, tr->tr_num_databuf_rm,
37
+ tr->tr_num_revoke, tr->tr_num_revoke_rm);
38
+}
39
+
3140 int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
3241 unsigned int revokes)
3342 {
3443 struct gfs2_trans *tr;
3544 int error;
3645
37
- BUG_ON(current->journal_info);
46
+ if (current->journal_info) {
47
+ gfs2_print_trans(sdp, current->journal_info);
48
+ BUG();
49
+ }
3850 BUG_ON(blocks == 0 && revokes == 0);
3951
4052 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
4153 return -EROFS;
4254
43
- tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS);
55
+ tr = kmem_cache_zalloc(gfs2_trans_cachep, GFP_NOFS);
4456 if (!tr)
4557 return -ENOMEM;
4658
....@@ -52,10 +64,10 @@
5264 if (blocks)
5365 tr->tr_reserved += 6 + blocks;
5466 if (revokes)
55
- tr->tr_reserved += gfs2_struct2blk(sdp, revokes,
56
- sizeof(u64));
67
+ tr->tr_reserved += gfs2_struct2blk(sdp, revokes);
5768 INIT_LIST_HEAD(&tr->tr_databuf);
5869 INIT_LIST_HEAD(&tr->tr_buf);
70
+ INIT_LIST_HEAD(&tr->tr_list);
5971 INIT_LIST_HEAD(&tr->tr_ail1_list);
6072 INIT_LIST_HEAD(&tr->tr_ail2_list);
6173
....@@ -71,21 +83,9 @@
7183
7284 fail:
7385 sb_end_intwrite(sdp->sd_vfs);
74
- kfree(tr);
86
+ kmem_cache_free(gfs2_trans_cachep, tr);
7587
7688 return error;
77
-}
78
-
79
-static void gfs2_print_trans(const struct gfs2_trans *tr)
80
-{
81
- pr_warn("Transaction created at: %pSR\n", (void *)tr->tr_ip);
82
- pr_warn("blocks=%u revokes=%u reserved=%u touched=%u\n",
83
- tr->tr_blocks, tr->tr_revokes, tr->tr_reserved,
84
- test_bit(TR_TOUCHED, &tr->tr_flags));
85
- pr_warn("Buf %u/%u Databuf %u/%u Revoke %u/%u\n",
86
- tr->tr_num_buf_new, tr->tr_num_buf_rm,
87
- tr->tr_num_databuf_new, tr->tr_num_databuf_rm,
88
- tr->tr_num_revoke, tr->tr_num_revoke_rm);
8989 }
9090
9191 void gfs2_trans_end(struct gfs2_sbd *sdp)
....@@ -99,7 +99,7 @@
9999 if (!test_bit(TR_TOUCHED, &tr->tr_flags)) {
100100 gfs2_log_release(sdp, tr->tr_reserved);
101101 if (alloced) {
102
- kfree(tr);
102
+ gfs2_trans_free(sdp, tr);
103103 sb_end_intwrite(sdp->sd_vfs);
104104 }
105105 return;
....@@ -111,11 +111,11 @@
111111
112112 if (gfs2_assert_withdraw(sdp, (nbuf <= tr->tr_blocks) &&
113113 (tr->tr_num_revoke <= tr->tr_revokes)))
114
- gfs2_print_trans(tr);
114
+ gfs2_print_trans(sdp, tr);
115115
116116 gfs2_log_commit(sdp, tr);
117117 if (alloced && !test_bit(TR_ATTACHED, &tr->tr_flags))
118
- kfree(tr);
118
+ gfs2_trans_free(sdp, tr);
119119 up_read(&sdp->sd_log_flush_lock);
120120
121121 if (sdp->sd_vfs->s_flags & SB_SYNCHRONOUS)
....@@ -126,16 +126,16 @@
126126 }
127127
128128 static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
129
- struct buffer_head *bh,
130
- const struct gfs2_log_operations *lops)
129
+ struct buffer_head *bh)
131130 {
132131 struct gfs2_bufdata *bd;
133132
134133 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
135134 bd->bd_bh = bh;
136135 bd->bd_gl = gl;
137
- bd->bd_ops = lops;
138136 INIT_LIST_HEAD(&bd->bd_list);
137
+ INIT_LIST_HEAD(&bd->bd_ail_st_list);
138
+ INIT_LIST_HEAD(&bd->bd_ail_gl_list);
139139 bh->b_private = bd;
140140 return bd;
141141 }
....@@ -171,7 +171,7 @@
171171 gfs2_log_unlock(sdp);
172172 unlock_buffer(bh);
173173 if (bh->b_private == NULL)
174
- bd = gfs2_alloc_bufdata(gl, bh, &gfs2_databuf_lops);
174
+ bd = gfs2_alloc_bufdata(gl, bh);
175175 else
176176 bd = bh->b_private;
177177 lock_buffer(bh);
....@@ -212,7 +212,7 @@
212212 unlock_buffer(bh);
213213 lock_page(bh->b_page);
214214 if (bh->b_private == NULL)
215
- bd = gfs2_alloc_bufdata(gl, bh, &gfs2_buf_lops);
215
+ bd = gfs2_alloc_bufdata(gl, bh);
216216 else
217217 bd = bh->b_private;
218218 unlock_page(bh->b_page);
....@@ -227,13 +227,18 @@
227227 set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
228228 mh = (struct gfs2_meta_header *)bd->bd_bh->b_data;
229229 if (unlikely(mh->mh_magic != cpu_to_be32(GFS2_MAGIC))) {
230
- pr_err("Attempting to add uninitialised block to journal (inplace block=%lld)\n",
230
+ fs_err(sdp, "Attempting to add uninitialised block to "
231
+ "journal (inplace block=%lld)\n",
231232 (unsigned long long)bd->bd_bh->b_blocknr);
232233 BUG();
233234 }
234235 if (unlikely(state == SFS_FROZEN)) {
235
- printk(KERN_INFO "GFS2:adding buf while frozen\n");
236
+ fs_info(sdp, "GFS2:adding buf while frozen\n");
236237 gfs2_assert_withdraw(sdp, 0);
238
+ }
239
+ if (unlikely(gfs2_withdrawn(sdp))) {
240
+ fs_info(sdp, "GFS2:adding buf while withdrawn! 0x%llx\n",
241
+ (unsigned long long)bd->bd_bh->b_blocknr);
237242 }
238243 gfs2_pin(sdp, bd->bd_bh);
239244 mh->__pad0 = cpu_to_be64(0);
....@@ -256,14 +261,14 @@
256261 tr->tr_num_revoke++;
257262 }
258263
259
-void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
264
+void gfs2_trans_remove_revoke(struct gfs2_sbd *sdp, u64 blkno, unsigned int len)
260265 {
261266 struct gfs2_bufdata *bd, *tmp;
262267 struct gfs2_trans *tr = current->journal_info;
263268 unsigned int n = len;
264269
265270 gfs2_log_lock(sdp);
266
- list_for_each_entry_safe(bd, tmp, &sdp->sd_log_le_revoke, bd_list) {
271
+ list_for_each_entry_safe(bd, tmp, &sdp->sd_log_revokes, bd_list) {
267272 if ((bd->bd_blkno >= blkno) && (bd->bd_blkno < (blkno + len))) {
268273 list_del_init(&bd->bd_list);
269274 gfs2_assert_withdraw(sdp, sdp->sd_log_num_revoke);
....@@ -279,3 +284,14 @@
279284 gfs2_log_unlock(sdp);
280285 }
281286
287
+void gfs2_trans_free(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
288
+{
289
+ if (tr == NULL)
290
+ return;
291
+
292
+ gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list));
293
+ gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list));
294
+ gfs2_assert_warn(sdp, list_empty(&tr->tr_databuf));
295
+ gfs2_assert_warn(sdp, list_empty(&tr->tr_buf));
296
+ kmem_cache_free(gfs2_trans_cachep, tr);
297
+}