diff options
author | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2009-11-24 11:04:21 -0500 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2009-11-30 07:05:57 -0500 |
commit | 9284ad2a9016ad631460caf8fd01fc21d84f118c (patch) | |
tree | 6ef77d51ca75017a1632bf215703ed9ee12feade /fs/nilfs2/segbuf.c | |
parent | 5f1586d0dd8f6eeecf6c0d35cbca6291afd6f1cc (diff) |
nilfs2: relocate io status variables to segment buffer
This moves io status variables in nilfs_write_info struct to
nilfs_segment_buffer struct.
This is a preparation to hide nilfs_write_info in segment buffer code.
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/segbuf.c')
-rw-r--r-- | fs/nilfs2/segbuf.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c index c71b689bdbce..d86056ca9a27 100644 --- a/fs/nilfs2/segbuf.c +++ b/fs/nilfs2/segbuf.c | |||
@@ -63,6 +63,11 @@ struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb) | |||
63 | INIT_LIST_HEAD(&segbuf->sb_list); | 63 | INIT_LIST_HEAD(&segbuf->sb_list); |
64 | INIT_LIST_HEAD(&segbuf->sb_segsum_buffers); | 64 | INIT_LIST_HEAD(&segbuf->sb_segsum_buffers); |
65 | INIT_LIST_HEAD(&segbuf->sb_payload_buffers); | 65 | INIT_LIST_HEAD(&segbuf->sb_payload_buffers); |
66 | |||
67 | init_completion(&segbuf->sb_bio_event); | ||
68 | atomic_set(&segbuf->sb_err, 0); | ||
69 | segbuf->sb_nbio = 0; | ||
70 | |||
66 | return segbuf; | 71 | return segbuf; |
67 | } | 72 | } |
68 | 73 | ||
@@ -132,8 +137,6 @@ int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned flags, | |||
132 | segbuf->sb_sum.sumbytes = sizeof(struct nilfs_segment_summary); | 137 | segbuf->sb_sum.sumbytes = sizeof(struct nilfs_segment_summary); |
133 | segbuf->sb_sum.nfinfo = segbuf->sb_sum.nfileblk = 0; | 138 | segbuf->sb_sum.nfinfo = segbuf->sb_sum.nfileblk = 0; |
134 | segbuf->sb_sum.ctime = ctime; | 139 | segbuf->sb_sum.ctime = ctime; |
135 | |||
136 | segbuf->sb_io_error = 0; | ||
137 | return 0; | 140 | return 0; |
138 | } | 141 | } |
139 | 142 | ||
@@ -247,7 +250,7 @@ void nilfs_release_buffers(struct list_head *list) | |||
247 | static void nilfs_end_bio_write(struct bio *bio, int err) | 250 | static void nilfs_end_bio_write(struct bio *bio, int err) |
248 | { | 251 | { |
249 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); | 252 | const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); |
250 | struct nilfs_write_info *wi = bio->bi_private; | 253 | struct nilfs_segment_buffer *segbuf = bio->bi_private; |
251 | 254 | ||
252 | if (err == -EOPNOTSUPP) { | 255 | if (err == -EOPNOTSUPP) { |
253 | set_bit(BIO_EOPNOTSUPP, &bio->bi_flags); | 256 | set_bit(BIO_EOPNOTSUPP, &bio->bi_flags); |
@@ -256,21 +259,22 @@ static void nilfs_end_bio_write(struct bio *bio, int err) | |||
256 | } | 259 | } |
257 | 260 | ||
258 | if (!uptodate) | 261 | if (!uptodate) |
259 | atomic_inc(&wi->err); | 262 | atomic_inc(&segbuf->sb_err); |
260 | 263 | ||
261 | bio_put(bio); | 264 | bio_put(bio); |
262 | complete(&wi->bio_event); | 265 | complete(&segbuf->sb_bio_event); |
263 | } | 266 | } |
264 | 267 | ||
265 | static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) | 268 | static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf, |
269 | struct nilfs_write_info *wi, int mode) | ||
266 | { | 270 | { |
267 | struct bio *bio = wi->bio; | 271 | struct bio *bio = wi->bio; |
268 | int err; | 272 | int err; |
269 | 273 | ||
270 | if (wi->nbio > 0 && bdi_write_congested(wi->bdi)) { | 274 | if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->bdi)) { |
271 | wait_for_completion(&wi->bio_event); | 275 | wait_for_completion(&segbuf->sb_bio_event); |
272 | wi->nbio--; | 276 | segbuf->sb_nbio--; |
273 | if (unlikely(atomic_read(&wi->err))) { | 277 | if (unlikely(atomic_read(&segbuf->sb_err))) { |
274 | bio_put(bio); | 278 | bio_put(bio); |
275 | err = -EIO; | 279 | err = -EIO; |
276 | goto failed; | 280 | goto failed; |
@@ -278,7 +282,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) | |||
278 | } | 282 | } |
279 | 283 | ||
280 | bio->bi_end_io = nilfs_end_bio_write; | 284 | bio->bi_end_io = nilfs_end_bio_write; |
281 | bio->bi_private = wi; | 285 | bio->bi_private = segbuf; |
282 | bio_get(bio); | 286 | bio_get(bio); |
283 | submit_bio(mode, bio); | 287 | submit_bio(mode, bio); |
284 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { | 288 | if (bio_flagged(bio, BIO_EOPNOTSUPP)) { |
@@ -286,7 +290,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) | |||
286 | err = -EOPNOTSUPP; | 290 | err = -EOPNOTSUPP; |
287 | goto failed; | 291 | goto failed; |
288 | } | 292 | } |
289 | wi->nbio++; | 293 | segbuf->sb_nbio++; |
290 | bio_put(bio); | 294 | bio_put(bio); |
291 | 295 | ||
292 | wi->bio = NULL; | 296 | wi->bio = NULL; |
@@ -336,15 +340,12 @@ void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf, | |||
336 | wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev); | 340 | wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev); |
337 | wi->nr_vecs = min(wi->max_pages, wi->rest_blocks); | 341 | wi->nr_vecs = min(wi->max_pages, wi->rest_blocks); |
338 | wi->start = wi->end = 0; | 342 | wi->start = wi->end = 0; |
339 | wi->nbio = 0; | ||
340 | wi->blocknr = segbuf->sb_pseg_start; | 343 | wi->blocknr = segbuf->sb_pseg_start; |
341 | |||
342 | atomic_set(&wi->err, 0); | ||
343 | init_completion(&wi->bio_event); | ||
344 | } | 344 | } |
345 | 345 | ||
346 | static int nilfs_submit_bh(struct nilfs_write_info *wi, struct buffer_head *bh, | 346 | static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf, |
347 | int mode) | 347 | struct nilfs_write_info *wi, |
348 | struct buffer_head *bh, int mode) | ||
348 | { | 349 | { |
349 | int len, err; | 350 | int len, err; |
350 | 351 | ||
@@ -363,7 +364,7 @@ static int nilfs_submit_bh(struct nilfs_write_info *wi, struct buffer_head *bh, | |||
363 | return 0; | 364 | return 0; |
364 | } | 365 | } |
365 | /* bio is FULL */ | 366 | /* bio is FULL */ |
366 | err = nilfs_submit_seg_bio(wi, mode); | 367 | err = nilfs_segbuf_submit_bio(segbuf, wi, mode); |
367 | /* never submit current bh */ | 368 | /* never submit current bh */ |
368 | if (likely(!err)) | 369 | if (likely(!err)) |
369 | goto repeat; | 370 | goto repeat; |
@@ -377,13 +378,13 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, | |||
377 | int res = 0, rw = WRITE; | 378 | int res = 0, rw = WRITE; |
378 | 379 | ||
379 | list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) { | 380 | list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) { |
380 | res = nilfs_submit_bh(wi, bh, rw); | 381 | res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw); |
381 | if (unlikely(res)) | 382 | if (unlikely(res)) |
382 | goto failed_bio; | 383 | goto failed_bio; |
383 | } | 384 | } |
384 | 385 | ||
385 | list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { | 386 | list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { |
386 | res = nilfs_submit_bh(wi, bh, rw); | 387 | res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw); |
387 | if (unlikely(res)) | 388 | if (unlikely(res)) |
388 | goto failed_bio; | 389 | goto failed_bio; |
389 | } | 390 | } |
@@ -394,7 +395,7 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, | |||
394 | * submission. | 395 | * submission. |
395 | */ | 396 | */ |
396 | rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); | 397 | rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); |
397 | res = nilfs_submit_seg_bio(wi, rw); | 398 | res = nilfs_segbuf_submit_bio(segbuf, wi, rw); |
398 | } | 399 | } |
399 | 400 | ||
400 | failed_bio: | 401 | failed_bio: |
@@ -403,29 +404,27 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, | |||
403 | 404 | ||
404 | /** | 405 | /** |
405 | * nilfs_segbuf_wait - wait for completion of requested BIOs | 406 | * nilfs_segbuf_wait - wait for completion of requested BIOs |
406 | * @wi: nilfs_write_info | 407 | * @segbuf: segment buffer |
407 | * | 408 | * |
408 | * Return Value: On Success, 0 is returned. On Error, one of the following | 409 | * Return Value: On Success, 0 is returned. On Error, one of the following |
409 | * negative error code is returned. | 410 | * negative error code is returned. |
410 | * | 411 | * |
411 | * %-EIO - I/O error | 412 | * %-EIO - I/O error |
412 | */ | 413 | */ |
413 | int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf, | 414 | int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf) |
414 | struct nilfs_write_info *wi) | ||
415 | { | 415 | { |
416 | int err = 0; | 416 | int err = 0; |
417 | 417 | ||
418 | if (!wi->nbio) | 418 | if (!segbuf->sb_nbio) |
419 | return 0; | 419 | return 0; |
420 | 420 | ||
421 | do { | 421 | do { |
422 | wait_for_completion(&wi->bio_event); | 422 | wait_for_completion(&segbuf->sb_bio_event); |
423 | } while (--wi->nbio > 0); | 423 | } while (--segbuf->sb_nbio > 0); |
424 | 424 | ||
425 | if (unlikely(atomic_read(&wi->err) > 0)) { | 425 | if (unlikely(atomic_read(&segbuf->sb_err) > 0)) { |
426 | printk(KERN_ERR "NILFS: IO error writing segment\n"); | 426 | printk(KERN_ERR "NILFS: IO error writing segment\n"); |
427 | err = -EIO; | 427 | err = -EIO; |
428 | segbuf->sb_io_error = 1; | ||
429 | } | 428 | } |
430 | return err; | 429 | return err; |
431 | } | 430 | } |