@@ -228,83 +228,87 @@ static void gfs2_end_log_write(struct bio *bio)
228
228
}
229
229
230
230
/**
231
- * gfs2_log_flush_bio - Submit any pending log bio
232
- * @sdp: The superblock
231
+ * gfs2_log_submit_bio - Submit any pending log bio
232
+ * @biop: Address of the bio pointer
233
233
* @op: REQ_OP
234
234
* @op_flags: req_flag_bits
235
235
*
236
236
* Submit any pending part-built or full bio to the block device. If
237
237
* there is no pending bio, then this is a no-op.
238
238
*/
239
239
240
- void gfs2_log_flush_bio (struct gfs2_sbd * sdp , int op , int op_flags )
240
+ void gfs2_log_submit_bio (struct bio * * biop , int op , int op_flags )
241
241
{
242
- if (sdp -> sd_log_bio ) {
242
+ struct bio * bio = * biop ;
243
+ if (bio ) {
244
+ struct gfs2_sbd * sdp = bio -> bi_private ;
243
245
atomic_inc (& sdp -> sd_log_in_flight );
244
- bio_set_op_attrs (sdp -> sd_log_bio , op , op_flags );
245
- submit_bio (sdp -> sd_log_bio );
246
- sdp -> sd_log_bio = NULL ;
246
+ bio_set_op_attrs (bio , op , op_flags );
247
+ submit_bio (bio );
248
+ * biop = NULL ;
247
249
}
248
250
}
249
251
250
252
/**
251
- * gfs2_log_alloc_bio - Allocate a new bio for log writing
252
- * @sdp: The superblock
253
- * @blkno: The next device block number we want to write to
253
+ * gfs2_log_alloc_bio - Allocate a bio
254
+ * @sdp: The super block
255
+ * @blkno: The device block number we want to write to
256
+ * @end_io: The bi_end_io callback
254
257
*
255
- * This should never be called when there is a cached bio in the
256
- * super block. When it returns, there will be a cached bio in the
257
- * super block which will have as many bio_vecs as the device is
258
- * happy to handle.
258
+ * Allocate a new bio, initialize it with the given parameters and return it.
259
259
*
260
- * Returns: Newly allocated bio
260
+ * Returns: The newly allocated bio
261
261
*/
262
262
263
- static struct bio * gfs2_log_alloc_bio (struct gfs2_sbd * sdp , u64 blkno )
263
+ static struct bio * gfs2_log_alloc_bio (struct gfs2_sbd * sdp , u64 blkno ,
264
+ bio_end_io_t * end_io )
264
265
{
265
266
struct super_block * sb = sdp -> sd_vfs ;
266
- struct bio * bio ;
267
+ struct bio * bio = bio_alloc ( GFP_NOIO , BIO_MAX_PAGES ) ;
267
268
268
- BUG_ON (sdp -> sd_log_bio );
269
-
270
- bio = bio_alloc (GFP_NOIO , BIO_MAX_PAGES );
271
269
bio -> bi_iter .bi_sector = blkno * (sb -> s_blocksize >> 9 );
272
270
bio_set_dev (bio , sb -> s_bdev );
273
- bio -> bi_end_io = gfs2_end_log_write ;
271
+ bio -> bi_end_io = end_io ;
274
272
bio -> bi_private = sdp ;
275
273
276
- sdp -> sd_log_bio = bio ;
277
-
278
274
return bio ;
279
275
}
280
276
281
277
/**
282
278
* gfs2_log_get_bio - Get cached log bio, or allocate a new one
283
- * @sdp: The superblock
279
+ * @sdp: The super block
284
280
* @blkno: The device block number we want to write to
281
+ * @bio: The bio to get or allocate
282
+ * @op: REQ_OP
283
+ * @end_io: The bi_end_io callback
284
+ * @flush: Always flush the current bio and allocate a new one?
285
285
*
286
286
* If there is a cached bio, then if the next block number is sequential
287
287
* with the previous one, return it, otherwise flush the bio to the
288
- * device. If there is not a cached bio, or we just flushed it, then
288
+ * device. If there is no cached bio, or we just flushed it, then
289
289
* allocate a new one.
290
290
*
291
291
* Returns: The bio to use for log writes
292
292
*/
293
293
294
- static struct bio * gfs2_log_get_bio (struct gfs2_sbd * sdp , u64 blkno )
294
+ static struct bio * gfs2_log_get_bio (struct gfs2_sbd * sdp , u64 blkno ,
295
+ struct bio * * biop , int op ,
296
+ bio_end_io_t * end_io , bool flush )
295
297
{
296
- struct bio * bio = sdp -> sd_log_bio ;
297
- u64 nblk ;
298
+ struct bio * bio = * biop ;
298
299
299
300
if (bio ) {
301
+ u64 nblk ;
302
+
300
303
nblk = bio_end_sector (bio );
301
304
nblk >>= sdp -> sd_fsb2bb_shift ;
302
- if (blkno == nblk )
305
+ if (blkno == nblk && ! flush )
303
306
return bio ;
304
- gfs2_log_flush_bio ( sdp , REQ_OP_WRITE , 0 );
307
+ gfs2_log_submit_bio ( biop , op , 0 );
305
308
}
306
309
307
- return gfs2_log_alloc_bio (sdp , blkno );
310
+ * biop = gfs2_log_alloc_bio (sdp , blkno , end_io );
311
+ return * biop ;
308
312
}
309
313
310
314
/**
@@ -326,11 +330,12 @@ void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
326
330
struct bio * bio ;
327
331
int ret ;
328
332
329
- bio = gfs2_log_get_bio (sdp , blkno );
333
+ bio = gfs2_log_get_bio (sdp , blkno , & sdp -> sd_log_bio , REQ_OP_WRITE ,
334
+ gfs2_end_log_write , false);
330
335
ret = bio_add_page (bio , page , size , offset );
331
336
if (ret == 0 ) {
332
- gfs2_log_flush_bio (sdp , REQ_OP_WRITE , 0 );
333
- bio = gfs2_log_alloc_bio ( sdp , blkno );
337
+ bio = gfs2_log_get_bio (sdp , blkno , & sdp -> sd_log_bio ,
338
+ REQ_OP_WRITE , gfs2_end_log_write , true );
334
339
ret = bio_add_page (bio , page , size , offset );
335
340
WARN_ON (ret == 0 );
336
341
}
0 commit comments