aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSteven Whitehouse <swhiteho@redhat.com>2012-12-14 12:54:21 -0500
committerSteven Whitehouse <swhiteho@redhat.com>2013-01-29 05:28:44 -0500
commitc76c4d96bdd89027306cebc80eb3397286d8da66 (patch)
tree6e3de8b09e50d6a9fe1c690125e0a6118724de4c /fs
parent767f433f346959d6a09b85478eb5db133ab25c6f (diff)
GFS2: Merge gfs2_attach_bufdata() into trans.c
The locking in gfs2_attach_bufdata() was type specific (data/meta) which made the function rather confusing. This patch moves the core of gfs2_attach_bufdata() into trans.c renaming it gfs2_alloc_bufdata() and moving the locking into gfs2_trans_add_data()/gfs2_trans_add_meta() As a result all of the locking related to adding data and metadata to the journal is now in these two functions. This should help to clarify what is going on, and give us some opportunities to simplify in some cases. Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/gfs2/lops.h7
-rw-r--r--fs/gfs2/meta_io.c35
-rw-r--r--fs/gfs2/meta_io.h3
-rw-r--r--fs/gfs2/trans.c37
4 files changed, 26 insertions, 56 deletions
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h
index d85b3767ee08..ba77b7da8325 100644
--- a/fs/gfs2/lops.h
+++ b/fs/gfs2/lops.h
@@ -47,13 +47,6 @@ static inline unsigned int databuf_limit(struct gfs2_sbd *sdp)
47 return limit; 47 return limit;
48} 48}
49 49
50static inline void lops_init_le(struct gfs2_bufdata *bd,
51 const struct gfs2_log_operations *lops)
52{
53 INIT_LIST_HEAD(&bd->bd_list);
54 bd->bd_ops = lops;
55}
56
57static inline void lops_before_commit(struct gfs2_sbd *sdp) 50static inline void lops_before_commit(struct gfs2_sbd *sdp)
58{ 51{
59 int x; 52 int x;
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 22255d96b27e..b059bbb5059e 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -271,41 +271,6 @@ int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
271 return 0; 271 return 0;
272} 272}
273 273
274/**
275 * gfs2_attach_bufdata - attach a struct gfs2_bufdata structure to a buffer
276 * @gl: the glock the buffer belongs to
277 * @bh: The buffer to be attached to
278 * @meta: Flag to indicate whether its metadata or not
279 */
280
281void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
282 int meta)
283{
284 struct gfs2_bufdata *bd;
285
286 if (meta)
287 lock_page(bh->b_page);
288
289 if (bh->b_private) {
290 if (meta)
291 unlock_page(bh->b_page);
292 return;
293 }
294
295 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
296 bd->bd_bh = bh;
297 bd->bd_gl = gl;
298
299 if (meta)
300 lops_init_le(bd, &gfs2_buf_lops);
301 else
302 lops_init_le(bd, &gfs2_databuf_lops);
303 bh->b_private = bd;
304
305 if (meta)
306 unlock_page(bh->b_page);
307}
308
309void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta) 274void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta)
310{ 275{
311 struct address_space *mapping = bh->b_page->mapping; 276 struct address_space *mapping = bh->b_page->mapping;
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index c30973b07a7c..0d4c843b6f8e 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -56,9 +56,6 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno,
56int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh); 56int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh);
57struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create); 57struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create);
58 58
59void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
60 int meta);
61
62void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, 59void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
63 int meta); 60 int meta);
64 61
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 1fbd57eafa48..14dbf6d3cdc0 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -143,6 +143,21 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
143 sb_end_intwrite(sdp->sd_vfs); 143 sb_end_intwrite(sdp->sd_vfs);
144} 144}
145 145
146static struct gfs2_bufdata *gfs2_alloc_bufdata(struct gfs2_glock *gl,
147 struct buffer_head *bh,
148 const struct gfs2_log_operations *lops)
149{
150 struct gfs2_bufdata *bd;
151
152 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
153 bd->bd_bh = bh;
154 bd->bd_gl = gl;
155 bd->bd_ops = lops;
156 INIT_LIST_HEAD(&bd->bd_list);
157 bh->b_private = bd;
158 return bd;
159}
160
146/** 161/**
147 * databuf_lo_add - Add a databuf to the transaction. 162 * databuf_lo_add - Add a databuf to the transaction.
148 * 163 *
@@ -190,16 +205,15 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
190 lock_buffer(bh); 205 lock_buffer(bh);
191 gfs2_log_lock(sdp); 206 gfs2_log_lock(sdp);
192 bd = bh->b_private; 207 bd = bh->b_private;
193 if (bd) 208 if (bd == NULL) {
194 gfs2_assert(sdp, bd->bd_gl == gl);
195 else {
196 gfs2_log_unlock(sdp); 209 gfs2_log_unlock(sdp);
197 unlock_buffer(bh); 210 unlock_buffer(bh);
198 gfs2_attach_bufdata(gl, bh, 0); 211 if (bh->b_private == NULL)
199 bd = bh->b_private; 212 bd = gfs2_alloc_bufdata(gl, bh, &gfs2_databuf_lops);
200 lock_buffer(bh); 213 lock_buffer(bh);
201 gfs2_log_lock(sdp); 214 gfs2_log_lock(sdp);
202 } 215 }
216 gfs2_assert(sdp, bd->bd_gl == gl);
203 databuf_lo_add(sdp, bd); 217 databuf_lo_add(sdp, bd);
204 gfs2_log_unlock(sdp); 218 gfs2_log_unlock(sdp);
205 unlock_buffer(bh); 219 unlock_buffer(bh);
@@ -240,16 +254,17 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
240 lock_buffer(bh); 254 lock_buffer(bh);
241 gfs2_log_lock(sdp); 255 gfs2_log_lock(sdp);
242 bd = bh->b_private; 256 bd = bh->b_private;
243 if (bd) 257 if (bd == NULL) {
244 gfs2_assert(sdp, bd->bd_gl == gl);
245 else {
246 gfs2_log_unlock(sdp); 258 gfs2_log_unlock(sdp);
247 unlock_buffer(bh); 259 unlock_buffer(bh);
248 gfs2_attach_bufdata(gl, bh, 1); 260 lock_page(bh->b_page);
249 bd = bh->b_private; 261 if (bh->b_private == NULL)
262 bd = gfs2_alloc_bufdata(gl, bh, &gfs2_buf_lops);
263 unlock_page(bh->b_page);
250 lock_buffer(bh); 264 lock_buffer(bh);
251 gfs2_log_lock(sdp); 265 gfs2_log_lock(sdp);
252 } 266 }
267 gfs2_assert(sdp, bd->bd_gl == gl);
253 meta_lo_add(sdp, bd); 268 meta_lo_add(sdp, bd);
254 gfs2_log_unlock(sdp); 269 gfs2_log_unlock(sdp);
255 unlock_buffer(bh); 270 unlock_buffer(bh);
@@ -263,7 +278,7 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
263 BUG_ON(!list_empty(&bd->bd_list)); 278 BUG_ON(!list_empty(&bd->bd_list));
264 BUG_ON(!list_empty(&bd->bd_ail_st_list)); 279 BUG_ON(!list_empty(&bd->bd_ail_st_list));
265 BUG_ON(!list_empty(&bd->bd_ail_gl_list)); 280 BUG_ON(!list_empty(&bd->bd_ail_gl_list));
266 lops_init_le(bd, &gfs2_revoke_lops); 281 bd->bd_ops = &gfs2_revoke_lops;
267 tr->tr_touched = 1; 282 tr->tr_touched = 1;
268 tr->tr_num_revoke++; 283 tr->tr_num_revoke++;
269 sdp->sd_log_num_revoke++; 284 sdp->sd_log_num_revoke++;