mirror of
https://github.com/adulau/aha.git
synced 2024-12-29 04:06:22 +00:00
nilfs2: hide nilfs_write_info struct in segment buffer code
Hides nilfs_write_info struct and nilfs_segbuf_prepare_write function in segbuf.c to simplify the interface of nilfs_segbuf_write function. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
This commit is contained in:
parent
9284ad2a90
commit
9c965bac16
3 changed files with 49 additions and 49 deletions
|
@ -24,10 +24,22 @@
|
||||||
#include <linux/buffer_head.h>
|
#include <linux/buffer_head.h>
|
||||||
#include <linux/writeback.h>
|
#include <linux/writeback.h>
|
||||||
#include <linux/crc32.h>
|
#include <linux/crc32.h>
|
||||||
|
#include <linux/backing-dev.h>
|
||||||
#include "page.h"
|
#include "page.h"
|
||||||
#include "segbuf.h"
|
#include "segbuf.h"
|
||||||
|
|
||||||
|
|
||||||
|
struct nilfs_write_info {
|
||||||
|
struct the_nilfs *nilfs;
|
||||||
|
struct bio *bio;
|
||||||
|
int start, end; /* The region to be submitted */
|
||||||
|
int rest_blocks;
|
||||||
|
int max_pages;
|
||||||
|
int nr_vecs;
|
||||||
|
sector_t blocknr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct kmem_cache *nilfs_segbuf_cachep;
|
static struct kmem_cache *nilfs_segbuf_cachep;
|
||||||
|
|
||||||
static void nilfs_segbuf_init_once(void *obj)
|
static void nilfs_segbuf_init_once(void *obj)
|
||||||
|
@ -271,7 +283,7 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
|
||||||
struct bio *bio = wi->bio;
|
struct bio *bio = wi->bio;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->bdi)) {
|
if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->nilfs->ns_bdi)) {
|
||||||
wait_for_completion(&segbuf->sb_bio_event);
|
wait_for_completion(&segbuf->sb_bio_event);
|
||||||
segbuf->sb_nbio--;
|
segbuf->sb_nbio--;
|
||||||
if (unlikely(atomic_read(&segbuf->sb_err))) {
|
if (unlikely(atomic_read(&segbuf->sb_err))) {
|
||||||
|
@ -305,17 +317,15 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nilfs_alloc_seg_bio - allocate a bio for writing segment.
|
* nilfs_alloc_seg_bio - allocate a new bio for writing log
|
||||||
* @sb: super block
|
* @nilfs: nilfs object
|
||||||
* @start: beginning disk block number of this BIO.
|
* @start: start block number of the bio
|
||||||
* @nr_vecs: request size of page vector.
|
* @nr_vecs: request size of page vector.
|
||||||
*
|
*
|
||||||
* alloc_seg_bio() allocates a new BIO structure and initialize it.
|
|
||||||
*
|
|
||||||
* Return Value: On success, pointer to the struct bio is returned.
|
* Return Value: On success, pointer to the struct bio is returned.
|
||||||
* On error, NULL is returned.
|
* On error, NULL is returned.
|
||||||
*/
|
*/
|
||||||
static struct bio *nilfs_alloc_seg_bio(struct super_block *sb, sector_t start,
|
static struct bio *nilfs_alloc_seg_bio(struct the_nilfs *nilfs, sector_t start,
|
||||||
int nr_vecs)
|
int nr_vecs)
|
||||||
{
|
{
|
||||||
struct bio *bio;
|
struct bio *bio;
|
||||||
|
@ -326,18 +336,18 @@ static struct bio *nilfs_alloc_seg_bio(struct super_block *sb, sector_t start,
|
||||||
bio = bio_alloc(GFP_NOIO, nr_vecs);
|
bio = bio_alloc(GFP_NOIO, nr_vecs);
|
||||||
}
|
}
|
||||||
if (likely(bio)) {
|
if (likely(bio)) {
|
||||||
bio->bi_bdev = sb->s_bdev;
|
bio->bi_bdev = nilfs->ns_bdev;
|
||||||
bio->bi_sector = (sector_t)start << (sb->s_blocksize_bits - 9);
|
bio->bi_sector = start << (nilfs->ns_blocksize_bits - 9);
|
||||||
}
|
}
|
||||||
return bio;
|
return bio;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
|
static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
|
||||||
struct nilfs_write_info *wi)
|
struct nilfs_write_info *wi)
|
||||||
{
|
{
|
||||||
wi->bio = NULL;
|
wi->bio = NULL;
|
||||||
wi->rest_blocks = segbuf->sb_sum.nblocks;
|
wi->rest_blocks = segbuf->sb_sum.nblocks;
|
||||||
wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev);
|
wi->max_pages = bio_get_nr_vecs(wi->nilfs->ns_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->blocknr = segbuf->sb_pseg_start;
|
wi->blocknr = segbuf->sb_pseg_start;
|
||||||
|
@ -352,7 +362,7 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
|
||||||
BUG_ON(wi->nr_vecs <= 0);
|
BUG_ON(wi->nr_vecs <= 0);
|
||||||
repeat:
|
repeat:
|
||||||
if (!wi->bio) {
|
if (!wi->bio) {
|
||||||
wi->bio = nilfs_alloc_seg_bio(wi->sb, wi->blocknr + wi->end,
|
wi->bio = nilfs_alloc_seg_bio(wi->nilfs, wi->blocknr + wi->end,
|
||||||
wi->nr_vecs);
|
wi->nr_vecs);
|
||||||
if (unlikely(!wi->bio))
|
if (unlikely(!wi->bio))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -371,31 +381,47 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nilfs_segbuf_write - submit write requests of a log
|
||||||
|
* @segbuf: buffer storing a log to be written
|
||||||
|
* @nilfs: nilfs object
|
||||||
|
*
|
||||||
|
* Return Value: On Success, 0 is returned. On Error, one of the following
|
||||||
|
* negative error code is returned.
|
||||||
|
*
|
||||||
|
* %-EIO - I/O error
|
||||||
|
*
|
||||||
|
* %-ENOMEM - Insufficient memory available.
|
||||||
|
*/
|
||||||
int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
|
int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
|
||||||
struct nilfs_write_info *wi)
|
struct the_nilfs *nilfs)
|
||||||
{
|
{
|
||||||
|
struct nilfs_write_info wi;
|
||||||
struct buffer_head *bh;
|
struct buffer_head *bh;
|
||||||
int res = 0, rw = WRITE;
|
int res = 0, rw = WRITE;
|
||||||
|
|
||||||
|
wi.nilfs = nilfs;
|
||||||
|
nilfs_segbuf_prepare_write(segbuf, &wi);
|
||||||
|
|
||||||
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_segbuf_submit_bh(segbuf, 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_segbuf_submit_bh(segbuf, wi, bh, rw);
|
res = nilfs_segbuf_submit_bh(segbuf, &wi, bh, rw);
|
||||||
if (unlikely(res))
|
if (unlikely(res))
|
||||||
goto failed_bio;
|
goto failed_bio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wi->bio) {
|
if (wi.bio) {
|
||||||
/*
|
/*
|
||||||
* Last BIO is always sent through the following
|
* Last BIO is always sent through the following
|
||||||
* submission.
|
* submission.
|
||||||
*/
|
*/
|
||||||
rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
|
rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
|
||||||
res = nilfs_segbuf_submit_bio(segbuf, wi, rw);
|
res = nilfs_segbuf_submit_bio(segbuf, &wi, rw);
|
||||||
}
|
}
|
||||||
|
|
||||||
failed_bio:
|
failed_bio:
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <linux/buffer_head.h>
|
#include <linux/buffer_head.h>
|
||||||
#include <linux/bio.h>
|
#include <linux/bio.h>
|
||||||
#include <linux/completion.h>
|
#include <linux/completion.h>
|
||||||
#include <linux/backing-dev.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* struct nilfs_segsum_info - On-memory segment summary
|
* struct nilfs_segsum_info - On-memory segment summary
|
||||||
|
@ -173,27 +172,8 @@ static inline void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
|
||||||
nilfs_release_buffers(&segbuf->sb_payload_buffers);
|
nilfs_release_buffers(&segbuf->sb_payload_buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nilfs_write_info {
|
int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
|
||||||
struct bio *bio;
|
struct the_nilfs *nilfs);
|
||||||
int start, end; /* The region to be submitted */
|
|
||||||
int rest_blocks;
|
|
||||||
int max_pages;
|
|
||||||
int nr_vecs;
|
|
||||||
sector_t blocknr;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The following fields must be set explicitly
|
|
||||||
*/
|
|
||||||
struct super_block *sb;
|
|
||||||
struct backing_dev_info *bdi; /* backing dev info */
|
|
||||||
struct buffer_head *bh_sr;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *,
|
|
||||||
struct nilfs_write_info *);
|
|
||||||
int nilfs_segbuf_write(struct nilfs_segment_buffer *,
|
|
||||||
struct nilfs_write_info *);
|
|
||||||
int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
|
int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
|
||||||
|
|
||||||
#endif /* _NILFS_SEGBUF_H */
|
#endif /* _NILFS_SEGBUF_H */
|
||||||
|
|
|
@ -1784,19 +1784,13 @@ static int nilfs_segctor_prepare_write(struct nilfs_sc_info *sci,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nilfs_segctor_write(struct nilfs_sc_info *sci,
|
static int nilfs_segctor_write(struct nilfs_sc_info *sci,
|
||||||
struct backing_dev_info *bdi)
|
struct the_nilfs *nilfs)
|
||||||
{
|
{
|
||||||
struct nilfs_segment_buffer *segbuf;
|
struct nilfs_segment_buffer *segbuf;
|
||||||
struct nilfs_write_info wi;
|
|
||||||
int err, res;
|
int err, res;
|
||||||
|
|
||||||
wi.sb = sci->sc_super;
|
|
||||||
wi.bh_sr = sci->sc_super_root;
|
|
||||||
wi.bdi = bdi;
|
|
||||||
|
|
||||||
list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) {
|
list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) {
|
||||||
nilfs_segbuf_prepare_write(segbuf, &wi);
|
err = nilfs_segbuf_write(segbuf, nilfs);
|
||||||
err = nilfs_segbuf_write(segbuf, &wi);
|
|
||||||
|
|
||||||
res = nilfs_segbuf_wait(segbuf);
|
res = nilfs_segbuf_wait(segbuf);
|
||||||
err = err ? : res;
|
err = err ? : res;
|
||||||
|
@ -2170,7 +2164,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
|
||||||
|
|
||||||
nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed);
|
nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed);
|
||||||
|
|
||||||
err = nilfs_segctor_write(sci, nilfs->ns_bdi);
|
err = nilfs_segctor_write(sci, nilfs);
|
||||||
if (unlikely(err))
|
if (unlikely(err))
|
||||||
goto failed_to_write;
|
goto failed_to_write;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue