Skip to content

Commit c76c4d9

Browse files
committed
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>
1 parent 767f433 commit c76c4d9

4 files changed

Lines changed: 26 additions & 56 deletions

File tree

‎fs/gfs2/lops.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,6 @@ static inline unsigned int databuf_limit(struct gfs2_sbd *sdp)
4747
return limit;
4848
}
4949

50-
static 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-
5750
static inline void lops_before_commit(struct gfs2_sbd *sdp)
5851
{
5952
int x;

‎fs/gfs2/meta_io.c‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -271,41 +271,6 @@ int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh)
271271
return 0;
272272
}
273273

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-
281-
void 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-
309274
void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta)
310275
{
311276
struct address_space *mapping = bh->b_page->mapping;

‎fs/gfs2/meta_io.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno,
5656
int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh);
5757
struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create);
5858

59-
void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
60-
int meta);
61-
6259
void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
6360
int meta);
6461

‎fs/gfs2/trans.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
143143
sb_end_intwrite(sdp->sd_vfs);
144144
}
145145

146+
static 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+
146161
/**
147162
* databuf_lo_add - Add a databuf to the transaction.
148163
*
@@ -190,16 +205,15 @@ void gfs2_trans_add_data(struct gfs2_glock *gl, struct buffer_head *bh)
190205
lock_buffer(bh);
191206
gfs2_log_lock(sdp);
192207
bd = bh->b_private;
193-
if (bd)
194-
gfs2_assert(sdp, bd->bd_gl == gl);
195-
else {
208+
if (bd == NULL) {
196209
gfs2_log_unlock(sdp);
197210
unlock_buffer(bh);
198-
gfs2_attach_bufdata(gl, bh, 0);
199-
bd = bh->b_private;
211+
if (bh->b_private == NULL)
212+
bd = gfs2_alloc_bufdata(gl, bh, &gfs2_databuf_lops);
200213
lock_buffer(bh);
201214
gfs2_log_lock(sdp);
202215
}
216+
gfs2_assert(sdp, bd->bd_gl == gl);
203217
databuf_lo_add(sdp, bd);
204218
gfs2_log_unlock(sdp);
205219
unlock_buffer(bh);
@@ -240,16 +254,17 @@ void gfs2_trans_add_meta(struct gfs2_glock *gl, struct buffer_head *bh)
240254
lock_buffer(bh);
241255
gfs2_log_lock(sdp);
242256
bd = bh->b_private;
243-
if (bd)
244-
gfs2_assert(sdp, bd->bd_gl == gl);
245-
else {
257+
if (bd == NULL) {
246258
gfs2_log_unlock(sdp);
247259
unlock_buffer(bh);
248-
gfs2_attach_bufdata(gl, bh, 1);
249-
bd = bh->b_private;
260+
lock_page(bh->b_page);
261+
if (bh->b_private == NULL)
262+
bd = gfs2_alloc_bufdata(gl, bh, &gfs2_buf_lops);
263+
unlock_page(bh->b_page);
250264
lock_buffer(bh);
251265
gfs2_log_lock(sdp);
252266
}
267+
gfs2_assert(sdp, bd->bd_gl == gl);
253268
meta_lo_add(sdp, bd);
254269
gfs2_log_unlock(sdp);
255270
unlock_buffer(bh);
@@ -263,7 +278,7 @@ void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd)
263278
BUG_ON(!list_empty(&bd->bd_list));
264279
BUG_ON(!list_empty(&bd->bd_ail_st_list));
265280
BUG_ON(!list_empty(&bd->bd_ail_gl_list));
266-
lops_init_le(bd, &gfs2_revoke_lops);
281+
bd->bd_ops = &gfs2_revoke_lops;
267282
tr->tr_touched = 1;
268283
tr->tr_num_revoke++;
269284
sdp->sd_log_num_revoke++;

0 commit comments

Comments
 (0)