Commit c76c4d96bdd89027306cebc80eb3397286d8da66

Authored by Steven Whitehouse
1 parent 767f433f34

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>

Showing 4 changed files with 26 additions and 56 deletions Side-by-side Diff

... ... @@ -47,13 +47,6 @@
47 47 return limit;
48 48 }
49 49  
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   -
57 50 static inline void lops_before_commit(struct gfs2_sbd *sdp)
58 51 {
59 52 int x;
... ... @@ -271,41 +271,6 @@
271 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   -
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   -
309 274 void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int meta)
310 275 {
311 276 struct address_space *mapping = bh->b_page->mapping;
... ... @@ -56,9 +56,6 @@
56 56 int gfs2_meta_wait(struct gfs2_sbd *sdp, struct buffer_head *bh);
57 57 struct buffer_head *gfs2_getbuf(struct gfs2_glock *gl, u64 blkno, int create);
58 58  
59   -void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
60   - int meta);
61   -
62 59 void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
63 60 int meta);
64 61  
... ... @@ -143,6 +143,21 @@
143 143 sb_end_intwrite(sdp->sd_vfs);
144 144 }
145 145  
  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 +
146 161 /**
147 162 * databuf_lo_add - Add a databuf to the transaction.
148 163 *
149 164  
150 165  
... ... @@ -190,16 +205,15 @@
190 205 lock_buffer(bh);
191 206 gfs2_log_lock(sdp);
192 207 bd = bh->b_private;
193   - if (bd)
194   - gfs2_assert(sdp, bd->bd_gl == gl);
195   - else {
  208 + if (bd == NULL) {
196 209 gfs2_log_unlock(sdp);
197 210 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);
200 213 lock_buffer(bh);
201 214 gfs2_log_lock(sdp);
202 215 }
  216 + gfs2_assert(sdp, bd->bd_gl == gl);
203 217 databuf_lo_add(sdp, bd);
204 218 gfs2_log_unlock(sdp);
205 219 unlock_buffer(bh);
206 220  
207 221  
... ... @@ -240,16 +254,17 @@
240 254 lock_buffer(bh);
241 255 gfs2_log_lock(sdp);
242 256 bd = bh->b_private;
243   - if (bd)
244   - gfs2_assert(sdp, bd->bd_gl == gl);
245   - else {
  257 + if (bd == NULL) {
246 258 gfs2_log_unlock(sdp);
247 259 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);
250 264 lock_buffer(bh);
251 265 gfs2_log_lock(sdp);
252 266 }
  267 + gfs2_assert(sdp, bd->bd_gl == gl);
253 268 meta_lo_add(sdp, bd);
254 269 gfs2_log_unlock(sdp);
255 270 unlock_buffer(bh);
... ... @@ -263,7 +278,7 @@
263 278 BUG_ON(!list_empty(&bd->bd_list));
264 279 BUG_ON(!list_empty(&bd->bd_ail_st_list));
265 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 282 tr->tr_touched = 1;
268 283 tr->tr_num_revoke++;
269 284 sdp->sd_log_num_revoke++;