Commit 9284ad2a authored by Ryusuke Konishi's avatar Ryusuke Konishi

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: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent 5f1586d0
...@@ -63,6 +63,11 @@ struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb) ...@@ -63,6 +63,11 @@ struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb)
INIT_LIST_HEAD(&segbuf->sb_list); INIT_LIST_HEAD(&segbuf->sb_list);
INIT_LIST_HEAD(&segbuf->sb_segsum_buffers); INIT_LIST_HEAD(&segbuf->sb_segsum_buffers);
INIT_LIST_HEAD(&segbuf->sb_payload_buffers); INIT_LIST_HEAD(&segbuf->sb_payload_buffers);
init_completion(&segbuf->sb_bio_event);
atomic_set(&segbuf->sb_err, 0);
segbuf->sb_nbio = 0;
return segbuf; return segbuf;
} }
...@@ -132,8 +137,6 @@ int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned flags, ...@@ -132,8 +137,6 @@ int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned flags,
segbuf->sb_sum.sumbytes = sizeof(struct nilfs_segment_summary); segbuf->sb_sum.sumbytes = sizeof(struct nilfs_segment_summary);
segbuf->sb_sum.nfinfo = segbuf->sb_sum.nfileblk = 0; segbuf->sb_sum.nfinfo = segbuf->sb_sum.nfileblk = 0;
segbuf->sb_sum.ctime = ctime; segbuf->sb_sum.ctime = ctime;
segbuf->sb_io_error = 0;
return 0; return 0;
} }
...@@ -247,7 +250,7 @@ void nilfs_release_buffers(struct list_head *list) ...@@ -247,7 +250,7 @@ void nilfs_release_buffers(struct list_head *list)
static void nilfs_end_bio_write(struct bio *bio, int err) static void nilfs_end_bio_write(struct bio *bio, int err)
{ {
const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
struct nilfs_write_info *wi = bio->bi_private; struct nilfs_segment_buffer *segbuf = bio->bi_private;
if (err == -EOPNOTSUPP) { if (err == -EOPNOTSUPP) {
set_bit(BIO_EOPNOTSUPP, &bio->bi_flags); set_bit(BIO_EOPNOTSUPP, &bio->bi_flags);
...@@ -256,21 +259,22 @@ static void nilfs_end_bio_write(struct bio *bio, int err) ...@@ -256,21 +259,22 @@ static void nilfs_end_bio_write(struct bio *bio, int err)
} }
if (!uptodate) if (!uptodate)
atomic_inc(&wi->err); atomic_inc(&segbuf->sb_err);
bio_put(bio); bio_put(bio);
complete(&wi->bio_event); complete(&segbuf->sb_bio_event);
} }
static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
struct nilfs_write_info *wi, int mode)
{ {
struct bio *bio = wi->bio; struct bio *bio = wi->bio;
int err; int err;
if (wi->nbio > 0 && bdi_write_congested(wi->bdi)) { if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->bdi)) {
wait_for_completion(&wi->bio_event); wait_for_completion(&segbuf->sb_bio_event);
wi->nbio--; segbuf->sb_nbio--;
if (unlikely(atomic_read(&wi->err))) { if (unlikely(atomic_read(&segbuf->sb_err))) {
bio_put(bio); bio_put(bio);
err = -EIO; err = -EIO;
goto failed; goto failed;
...@@ -278,7 +282,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) ...@@ -278,7 +282,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode)
} }
bio->bi_end_io = nilfs_end_bio_write; bio->bi_end_io = nilfs_end_bio_write;
bio->bi_private = wi; bio->bi_private = segbuf;
bio_get(bio); bio_get(bio);
submit_bio(mode, bio); submit_bio(mode, bio);
if (bio_flagged(bio, BIO_EOPNOTSUPP)) { if (bio_flagged(bio, BIO_EOPNOTSUPP)) {
...@@ -286,7 +290,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode) ...@@ -286,7 +290,7 @@ static int nilfs_submit_seg_bio(struct nilfs_write_info *wi, int mode)
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
goto failed; goto failed;
} }
wi->nbio++; segbuf->sb_nbio++;
bio_put(bio); bio_put(bio);
wi->bio = NULL; wi->bio = NULL;
...@@ -336,15 +340,12 @@ void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf, ...@@ -336,15 +340,12 @@ void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev); wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev);
wi->nr_vecs = min(wi->max_pages, wi->rest_blocks); wi->nr_vecs = min(wi->max_pages, wi->rest_blocks);
wi->start = wi->end = 0; wi->start = wi->end = 0;
wi->nbio = 0;
wi->blocknr = segbuf->sb_pseg_start; wi->blocknr = segbuf->sb_pseg_start;
atomic_set(&wi->err, 0);
init_completion(&wi->bio_event);
} }
static int nilfs_submit_bh(struct nilfs_write_info *wi, struct buffer_head *bh, static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
int mode) struct nilfs_write_info *wi,
struct buffer_head *bh, int mode)
{ {
int len, err; int len, err;
...@@ -363,7 +364,7 @@ static int nilfs_submit_bh(struct nilfs_write_info *wi, struct buffer_head *bh, ...@@ -363,7 +364,7 @@ static int nilfs_submit_bh(struct nilfs_write_info *wi, struct buffer_head *bh,
return 0; return 0;
} }
/* bio is FULL */ /* bio is FULL */
err = nilfs_submit_seg_bio(wi, mode); err = nilfs_segbuf_submit_bio(segbuf, wi, mode);
/* never submit current bh */ /* never submit current bh */
if (likely(!err)) if (likely(!err))
goto repeat; goto repeat;
...@@ -377,13 +378,13 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, ...@@ -377,13 +378,13 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
int res = 0, rw = WRITE; int res = 0, rw = WRITE;
list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) { list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) {
res = nilfs_submit_bh(wi, bh, rw); res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw);
if (unlikely(res)) if (unlikely(res))
goto failed_bio; goto failed_bio;
} }
list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) {
res = nilfs_submit_bh(wi, bh, rw); res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw);
if (unlikely(res)) if (unlikely(res))
goto failed_bio; goto failed_bio;
} }
...@@ -394,7 +395,7 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, ...@@ -394,7 +395,7 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
* submission. * submission.
*/ */
rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
res = nilfs_submit_seg_bio(wi, rw); res = nilfs_segbuf_submit_bio(segbuf, wi, rw);
} }
failed_bio: failed_bio:
...@@ -403,29 +404,27 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, ...@@ -403,29 +404,27 @@ int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
/** /**
* nilfs_segbuf_wait - wait for completion of requested BIOs * nilfs_segbuf_wait - wait for completion of requested BIOs
* @wi: nilfs_write_info * @segbuf: segment buffer
* *
* Return Value: On Success, 0 is returned. On Error, one of the following * Return Value: On Success, 0 is returned. On Error, one of the following
* negative error code is returned. * negative error code is returned.
* *
* %-EIO - I/O error * %-EIO - I/O error
*/ */
int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf, int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf)
struct nilfs_write_info *wi)
{ {
int err = 0; int err = 0;
if (!wi->nbio) if (!segbuf->sb_nbio)
return 0; return 0;
do { do {
wait_for_completion(&wi->bio_event); wait_for_completion(&segbuf->sb_bio_event);
} while (--wi->nbio > 0); } while (--segbuf->sb_nbio > 0);
if (unlikely(atomic_read(&wi->err) > 0)) { if (unlikely(atomic_read(&segbuf->sb_err) > 0)) {
printk(KERN_ERR "NILFS: IO error writing segment\n"); printk(KERN_ERR "NILFS: IO error writing segment\n");
err = -EIO; err = -EIO;
segbuf->sb_io_error = 1;
} }
return err; return err;
} }
...@@ -77,7 +77,9 @@ struct nilfs_segsum_info { ...@@ -77,7 +77,9 @@ struct nilfs_segsum_info {
* @sb_rest_blocks: Number of residual blocks in the current segment * @sb_rest_blocks: Number of residual blocks in the current segment
* @sb_segsum_buffers: List of buffers for segment summaries * @sb_segsum_buffers: List of buffers for segment summaries
* @sb_payload_buffers: List of buffers for segment payload * @sb_payload_buffers: List of buffers for segment payload
* @sb_io_error: I/O error status * @sb_nbio: Number of flying bio requests
* @sb_err: I/O error status
* @sb_bio_event: Completion event of log writing
*/ */
struct nilfs_segment_buffer { struct nilfs_segment_buffer {
struct super_block *sb_super; struct super_block *sb_super;
...@@ -96,7 +98,9 @@ struct nilfs_segment_buffer { ...@@ -96,7 +98,9 @@ struct nilfs_segment_buffer {
struct list_head sb_payload_buffers; /* including super root */ struct list_head sb_payload_buffers; /* including super root */
/* io status */ /* io status */
int sb_io_error; int sb_nbio;
atomic_t sb_err;
struct completion sb_bio_event;
}; };
#define NILFS_LIST_SEGBUF(head) \ #define NILFS_LIST_SEGBUF(head) \
...@@ -177,11 +181,6 @@ struct nilfs_write_info { ...@@ -177,11 +181,6 @@ struct nilfs_write_info {
int nr_vecs; int nr_vecs;
sector_t blocknr; sector_t blocknr;
int nbio;
atomic_t err;
struct completion bio_event;
/* completion event of segment write */
/* /*
* The following fields must be set explicitly * The following fields must be set explicitly
*/ */
...@@ -195,7 +194,6 @@ void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *, ...@@ -195,7 +194,6 @@ void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *,
struct nilfs_write_info *); struct nilfs_write_info *);
int nilfs_segbuf_write(struct nilfs_segment_buffer *, int nilfs_segbuf_write(struct nilfs_segment_buffer *,
struct nilfs_write_info *); struct nilfs_write_info *);
int nilfs_segbuf_wait(struct nilfs_segment_buffer *, int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
struct nilfs_write_info *);
#endif /* _NILFS_SEGBUF_H */ #endif /* _NILFS_SEGBUF_H */
...@@ -1382,14 +1382,14 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci, ...@@ -1382,14 +1382,14 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci,
struct the_nilfs *nilfs) struct the_nilfs *nilfs)
{ {
struct nilfs_segment_buffer *segbuf; struct nilfs_segment_buffer *segbuf;
int ret, done = 0; int ret;
segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs);
if (nilfs->ns_nextnum != segbuf->sb_nextnum) { if (nilfs->ns_nextnum != segbuf->sb_nextnum) {
ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum);
WARN_ON(ret); /* never fails */ WARN_ON(ret); /* never fails */
} }
if (segbuf->sb_io_error) { if (atomic_read(&segbuf->sb_err)) {
/* Case 1: The first segment failed */ /* Case 1: The first segment failed */
if (segbuf->sb_pseg_start != segbuf->sb_fseg_start) if (segbuf->sb_pseg_start != segbuf->sb_fseg_start)
/* Case 1a: Partial segment appended into an existing /* Case 1a: Partial segment appended into an existing
...@@ -1398,19 +1398,16 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci, ...@@ -1398,19 +1398,16 @@ static void nilfs_segctor_free_incomplete_segments(struct nilfs_sc_info *sci,
segbuf->sb_fseg_end); segbuf->sb_fseg_end);
else /* Case 1b: New full segment */ else /* Case 1b: New full segment */
set_nilfs_discontinued(nilfs); set_nilfs_discontinued(nilfs);
done++;
} }
list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) { list_for_each_entry_continue(segbuf, &sci->sc_segbufs, sb_list) {
ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum); ret = nilfs_sufile_free(nilfs->ns_sufile, segbuf->sb_nextnum);
WARN_ON(ret); /* never fails */ WARN_ON(ret); /* never fails */
if (!done && segbuf->sb_io_error) { if (atomic_read(&segbuf->sb_err) &&
if (segbuf->sb_segnum != nilfs->ns_nextnum) segbuf->sb_segnum != nilfs->ns_nextnum)
/* Case 2: extended segment (!= next) failed */ /* Case 2: extended segment (!= next) failed */
nilfs_sufile_set_error(nilfs->ns_sufile, nilfs_sufile_set_error(nilfs->ns_sufile,
segbuf->sb_segnum); segbuf->sb_segnum);
done++;
}
} }
} }
...@@ -1801,7 +1798,7 @@ static int nilfs_segctor_write(struct nilfs_sc_info *sci, ...@@ -1801,7 +1798,7 @@ static int nilfs_segctor_write(struct nilfs_sc_info *sci,
nilfs_segbuf_prepare_write(segbuf, &wi); nilfs_segbuf_prepare_write(segbuf, &wi);
err = nilfs_segbuf_write(segbuf, &wi); err = nilfs_segbuf_write(segbuf, &wi);
res = nilfs_segbuf_wait(segbuf, &wi); res = nilfs_segbuf_wait(segbuf);
err = err ? : res; err = err ? : res;
if (err) if (err)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment