diff options
author | Abhi Das <adas@redhat.com> | 2018-11-09 10:49:01 -0500 |
---|---|---|
committer | Andreas Gruenbacher <agruenba@redhat.com> | 2018-12-11 11:50:36 -0500 |
commit | 5b84609532d6e48a769a735d214e2cd705ed395e (patch) | |
tree | 977c0448c40b90f3193f64c300653c5af1673463 /fs/gfs2 | |
parent | 98583b3e87303e5941c30d4cf0c117cbfaa89116 (diff) |
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>
Diffstat (limited to 'fs/gfs2')
-rw-r--r-- | fs/gfs2/log.c | 4 | ||||
-rw-r--r-- | fs/gfs2/lops.c | 73 | ||||
-rw-r--r-- | fs/gfs2/lops.h | 2 |
3 files changed, 42 insertions, 37 deletions
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 99dd58694ba1..e7c6e9fc62b5 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c | |||
@@ -734,7 +734,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, | |||
734 | lh->lh_crc = cpu_to_be32(crc); | 734 | lh->lh_crc = cpu_to_be32(crc); |
735 | 735 | ||
736 | gfs2_log_write(sdp, page, sb->s_blocksize, 0, addr); | 736 | 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); |
738 | log_flush_wait(sdp); | 738 | log_flush_wait(sdp); |
739 | } | 739 | } |
740 | 740 | ||
@@ -811,7 +811,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) | |||
811 | 811 | ||
812 | gfs2_ordered_write(sdp); | 812 | gfs2_ordered_write(sdp); |
813 | lops_before_commit(sdp, tr); | 813 | 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); |
815 | 815 | ||
816 | if (sdp->sd_log_head != sdp->sd_log_flush_head) { | 816 | if (sdp->sd_log_head != sdp->sd_log_flush_head) { |
817 | log_flush_wait(sdp); | 817 | log_flush_wait(sdp); |
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c index 4c7069b8f3c1..2295042bc625 100644 --- a/fs/gfs2/lops.c +++ b/fs/gfs2/lops.c | |||
@@ -228,8 +228,8 @@ 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 | 231 | * gfs2_log_submit_bio - Submit any pending log bio |
232 | * @sdp: The superblock | 232 | * @biop: Address of the bio pointer |
233 | * @op: REQ_OP | 233 | * @op: REQ_OP |
234 | * @op_flags: req_flag_bits | 234 | * @op_flags: req_flag_bits |
235 | * | 235 | * |
@@ -237,74 +237,78 @@ static void gfs2_end_log_write(struct bio *bio) | |||
237 | * there is no pending bio, then this is a no-op. | 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 | atomic_inc(&sdp->sd_log_in_flight); | 245 | atomic_inc(&sdp->sd_log_in_flight); |
244 | bio_set_op_attrs(sdp->sd_log_bio, op, op_flags); | 246 | bio_set_op_attrs(bio, op, op_flags); |
245 | submit_bio(sdp->sd_log_bio); | 247 | submit_bio(bio); |
246 | sdp->sd_log_bio = NULL; | 248 | *biop = NULL; |
247 | } | 249 | } |
248 | } | 250 | } |
249 | 251 | ||
250 | /** | 252 | /** |
251 | * gfs2_log_alloc_bio - Allocate a new bio for log writing | 253 | * gfs2_log_alloc_bio - Allocate a bio |
252 | * @sdp: The superblock | 254 | * @sdp: The super block |
253 | * @blkno: The next device block number we want to write to | 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 | 258 | * Allocate a new bio, initialize it with the given parameters and return it. |
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. | ||
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 | struct super_block *sb = sdp->sd_vfs; | 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 | bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9); | 269 | bio->bi_iter.bi_sector = blkno * (sb->s_blocksize >> 9); |
272 | bio_set_dev(bio, sb->s_bdev); | 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 | bio->bi_private = sdp; | 272 | bio->bi_private = sdp; |
275 | 273 | ||
276 | sdp->sd_log_bio = bio; | ||
277 | |||
278 | return bio; | 274 | return bio; |
279 | } | 275 | } |
280 | 276 | ||
281 | /** | 277 | /** |
282 | * gfs2_log_get_bio - Get cached log bio, or allocate a new one | 278 | * gfs2_log_get_bio - Get cached log bio, or allocate a new one |
283 | * @sdp: The superblock | 279 | * @sdp: The super block |
284 | * @blkno: The device block number we want to write to | 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 | * If there is a cached bio, then if the next block number is sequential | 286 | * If there is a cached bio, then if the next block number is sequential |
287 | * with the previous one, return it, otherwise flush the bio to the | 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 | * allocate a new one. | 289 | * allocate a new one. |
290 | * | 290 | * |
291 | * Returns: The bio to use for log writes | 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; | 298 | struct bio *bio = *biop; |
297 | u64 nblk; | ||
298 | 299 | ||
299 | if (bio) { | 300 | if (bio) { |
301 | u64 nblk; | ||
302 | |||
300 | nblk = bio_end_sector(bio); | 303 | nblk = bio_end_sector(bio); |
301 | nblk >>= sdp->sd_fsb2bb_shift; | 304 | nblk >>= sdp->sd_fsb2bb_shift; |
302 | if (blkno == nblk) | 305 | if (blkno == nblk && !flush) |
303 | return bio; | 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 | struct bio *bio; | 330 | struct bio *bio; |
327 | int ret; | 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 | ret = bio_add_page(bio, page, size, offset); | 335 | ret = bio_add_page(bio, page, size, offset); |
331 | if (ret == 0) { | 336 | if (ret == 0) { |
332 | gfs2_log_flush_bio(sdp, REQ_OP_WRITE, 0); | 337 | bio = gfs2_log_get_bio(sdp, blkno, &sdp->sd_log_bio, |
333 | bio = gfs2_log_alloc_bio(sdp, blkno); | 338 | REQ_OP_WRITE, gfs2_end_log_write, true); |
334 | ret = bio_add_page(bio, page, size, offset); | 339 | ret = bio_add_page(bio, page, size, offset); |
335 | WARN_ON(ret == 0); | 340 | WARN_ON(ret == 0); |
336 | } | 341 | } |
diff --git a/fs/gfs2/lops.h b/fs/gfs2/lops.h index e4949394f054..711c4d89c063 100644 --- a/fs/gfs2/lops.h +++ b/fs/gfs2/lops.h | |||
@@ -30,7 +30,7 @@ extern u64 gfs2_log_bmap(struct gfs2_sbd *sdp); | |||
30 | extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page, | 30 | extern void gfs2_log_write(struct gfs2_sbd *sdp, struct page *page, |
31 | unsigned size, unsigned offset, u64 blkno); | 31 | unsigned size, unsigned offset, u64 blkno); |
32 | extern void gfs2_log_write_page(struct gfs2_sbd *sdp, struct page *page); | 32 | 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); |
34 | extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); | 34 | extern void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh); |
35 | 35 | ||
36 | static inline unsigned int buf_limit(struct gfs2_sbd *sdp) | 36 | static inline unsigned int buf_limit(struct gfs2_sbd *sdp) |