Skip to content

Commit 5b84609

Browse files
Abhi DasAndreas Gruenbacher
authored andcommitted
gfs2: changes to gfs2_log_XXX_bio
Change gfs2_log_XXX_bio family of functions so they can be used with different bios, not just sdp->sd_log_bio. This patch also contains some clean up suggested by Andreas. Signed-off-by: Abhi Das <adas@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Bob Peterson <rpeterso@redhat.com>
1 parent 98583b3 commit 5b84609

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

fs/gfs2/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
734734
lh->lh_crc = cpu_to_be32(crc);
735735

736736
gfs2_log_write(sdp, page, sb->s_blocksize, 0, addr);
737-
gfs2_log_flush_bio(sdp, REQ_OP_WRITE, op_flags);
737+
gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, op_flags);
738738
log_flush_wait(sdp);
739739
}
740740

@@ -811,7 +811,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags)
811811

812812
gfs2_ordered_write(sdp);
813813
lops_before_commit(sdp, tr);
814-
gfs2_log_flush_bio(sdp, REQ_OP_WRITE, 0);
814+
gfs2_log_submit_bio(&sdp->sd_log_bio, REQ_OP_WRITE, 0);
815815

816816
if (sdp->sd_log_head != sdp->sd_log_flush_head) {
817817
log_flush_wait(sdp);

fs/gfs2/lops.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -228,83 +228,87 @@ static void gfs2_end_log_write(struct bio *bio)
228228
}
229229

230230
/**
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
233233
* @op: REQ_OP
234234
* @op_flags: req_flag_bits
235235
*
236236
* Submit any pending part-built or full bio to the block device. If
237237
* there is no pending bio, then this is a no-op.
238238
*/
239239

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)
241241
{
242-
if (sdp->sd_log_bio) {
242+
struct bio *bio = *biop;
243+
if (bio) {
244+
struct gfs2_sbd *sdp = bio->bi_private;
243245
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;
247249
}
248250
}
249251

250252
/**
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
254257
*
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.
259259
*
260-
* Returns: Newly allocated bio
260+
* Returns: The newly allocated bio
261261
*/
262262

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)
264265
{
265266
struct super_block *sb = sdp->sd_vfs;
266-
struct bio *bio;
267+
struct bio *bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
267268

268-
BUG_ON(sdp->sd_log_bio);
269-
270-
bio = bio_alloc(GFP_NOIO, BIO_MAX_PAGES);
271269
bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9);
272270
bio_set_dev(bio, sb->s_bdev);
273-
bio->bi_end_io = gfs2_end_log_write;
271+
bio->bi_end_io = end_io;
274272
bio->bi_private = sdp;
275273

276-
sdp->sd_log_bio = bio;
277-
278274
return bio;
279275
}
280276

281277
/**
282278
* gfs2_log_get_bio - Get cached log bio, or allocate a new one
283-
* @sdp: The superblock
279+
* @sdp: The super block
284280
* @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?
285285
*
286286
* If there is a cached bio, then if the next block number is sequential
287287
* 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
289289
* allocate a new one.
290290
*
291291
* Returns: The bio to use for log writes
292292
*/
293293

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)
295297
{
296-
struct bio *bio = sdp->sd_log_bio;
297-
u64 nblk;
298+
struct bio *bio = *biop;
298299

299300
if (bio) {
301+
u64 nblk;
302+
300303
nblk = bio_end_sector(bio);
301304
nblk >>= sdp->sd_fsb2bb_shift;
302-
if (blkno == nblk)
305+
if (blkno == nblk && !flush)
303306
return bio;
304-
gfs2_log_flush_bio(sdp, REQ_OP_WRITE, 0);
307+
gfs2_log_submit_bio(biop, op, 0);
305308
}
306309

307-
return gfs2_log_alloc_bio(sdp, blkno);
310+
*biop = gfs2_log_alloc_bio(sdp, blkno, end_io);
311+
return *biop;
308312
}
309313

310314
/**
@@ -326,11 +330,12 @@ void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
326330
struct bio *bio;
327331
int ret;
328332

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);
330335
ret = bio_add_page(bio, page, size, offset);
331336
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);
334339
ret = bio_add_page(bio, page, size, offset);
335340
WARN_ON(ret == 0);
336341
}

fs/gfs2/lops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp);
3030
extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page,
3131
unsigned size, unsigned offset, u64 blkno);
3232
extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page);
33-
extern void gfs2_log_flush_bio(struct gfs2_sbd *sdp, int op, int op_flags);
33+
extern void gfs2_log_submit_bio(struct bio **biop, int op, int op_flags);
3434
extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
3535

3636
static inline unsigned int buf_limit(struct gfs2_sbd *sdp)

0 commit comments

Comments
 (0)