aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-28 11:17:31 -0500
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2009-11-30 07:06:35 -0500
commit9c965bac169f786cc6cca8ff81d3b636e923c960 (patch)
tree71c05d6e981e2b2c5c3797cbcf8b8e619b48e966 /fs
parent9284ad2a9016ad631460caf8fd01fc21d84f118c (diff)
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/nilfs2/segbuf.c62
-rw-r--r--fs/nilfs2/segbuf.h24
-rw-r--r--fs/nilfs2/segment.c12
3 files changed, 49 insertions, 49 deletions
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index d86056ca9a27..636590c92c8b 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -24,10 +24,22 @@
24#include <linux/buffer_head.h> 24#include <linux/buffer_head.h>
25#include <linux/writeback.h> 25#include <linux/writeback.h>
26#include <linux/crc32.h> 26#include <linux/crc32.h>
27#include <linux/backing-dev.h>
27#include "page.h" 28#include "page.h"
28#include "segbuf.h" 29#include "segbuf.h"
29 30
30 31
32struct nilfs_write_info {
33 struct the_nilfs *nilfs;
34 struct bio *bio;
35 int start, end; /* The region to be submitted */
36 int rest_blocks;
37 int max_pages;
38 int nr_vecs;
39 sector_t blocknr;
40};
41
42
31static struct kmem_cache *nilfs_segbuf_cachep; 43static struct kmem_cache *nilfs_segbuf_cachep;
32 44
33static void nilfs_segbuf_init_once(void *obj) 45static void nilfs_segbuf_init_once(void *obj)
@@ -271,7 +283,7 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
271 struct bio *bio = wi->bio; 283 struct bio *bio = wi->bio;
272 int err; 284 int err;
273 285
274 if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->bdi)) { 286 if (segbuf->sb_nbio > 0 && bdi_write_congested(wi->nilfs->ns_bdi)) {
275 wait_for_completion(&segbuf->sb_bio_event); 287 wait_for_completion(&segbuf->sb_bio_event);
276 segbuf->sb_nbio--; 288 segbuf->sb_nbio--;
277 if (unlikely(atomic_read(&segbuf->sb_err))) { 289 if (unlikely(atomic_read(&segbuf->sb_err))) {
@@ -305,17 +317,15 @@ static int nilfs_segbuf_submit_bio(struct nilfs_segment_buffer *segbuf,
305} 317}
306 318
307/** 319/**
308 * nilfs_alloc_seg_bio - allocate a bio for writing segment. 320 * nilfs_alloc_seg_bio - allocate a new bio for writing log
309 * @sb: super block 321 * @nilfs: nilfs object
310 * @start: beginning disk block number of this BIO. 322 * @start: start block number of the bio
311 * @nr_vecs: request size of page vector. 323 * @nr_vecs: request size of page vector.
312 * 324 *
313 * alloc_seg_bio() allocates a new BIO structure and initialize it.
314 *
315 * Return Value: On success, pointer to the struct bio is returned. 325 * Return Value: On success, pointer to the struct bio is returned.
316 * On error, NULL is returned. 326 * On error, NULL is returned.
317 */ 327 */
318static struct bio *nilfs_alloc_seg_bio(struct super_block *sb, sector_t start, 328static struct bio *nilfs_alloc_seg_bio(struct the_nilfs *nilfs, sector_t start,
319 int nr_vecs) 329 int nr_vecs)
320{ 330{
321 struct bio *bio; 331 struct bio *bio;
@@ -326,18 +336,18 @@ static struct bio *nilfs_alloc_seg_bio(struct super_block *sb, sector_t start,
326 bio = bio_alloc(GFP_NOIO, nr_vecs); 336 bio = bio_alloc(GFP_NOIO, nr_vecs);
327 } 337 }
328 if (likely(bio)) { 338 if (likely(bio)) {
329 bio->bi_bdev = sb->s_bdev; 339 bio->bi_bdev = nilfs->ns_bdev;
330 bio->bi_sector = (sector_t)start << (sb->s_blocksize_bits - 9); 340 bio->bi_sector = start << (nilfs->ns_blocksize_bits - 9);
331 } 341 }
332 return bio; 342 return bio;
333} 343}
334 344
335void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf, 345static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
336 struct nilfs_write_info *wi) 346 struct nilfs_write_info *wi)
337{ 347{
338 wi->bio = NULL; 348 wi->bio = NULL;
339 wi->rest_blocks = segbuf->sb_sum.nblocks; 349 wi->rest_blocks = segbuf->sb_sum.nblocks;
340 wi->max_pages = bio_get_nr_vecs(wi->sb->s_bdev); 350 wi->max_pages = bio_get_nr_vecs(wi->nilfs->ns_bdev);
341 wi->nr_vecs = min(wi->max_pages, wi->rest_blocks); 351 wi->nr_vecs = min(wi->max_pages, wi->rest_blocks);
342 wi->start = wi->end = 0; 352 wi->start = wi->end = 0;
343 wi->blocknr = segbuf->sb_pseg_start; 353 wi->blocknr = segbuf->sb_pseg_start;
@@ -352,7 +362,7 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
352 BUG_ON(wi->nr_vecs <= 0); 362 BUG_ON(wi->nr_vecs <= 0);
353 repeat: 363 repeat:
354 if (!wi->bio) { 364 if (!wi->bio) {
355 wi->bio = nilfs_alloc_seg_bio(wi->sb, wi->blocknr + wi->end, 365 wi->bio = nilfs_alloc_seg_bio(wi->nilfs, wi->blocknr + wi->end,
356 wi->nr_vecs); 366 wi->nr_vecs);
357 if (unlikely(!wi->bio)) 367 if (unlikely(!wi->bio))
358 return -ENOMEM; 368 return -ENOMEM;
@@ -371,31 +381,47 @@ static int nilfs_segbuf_submit_bh(struct nilfs_segment_buffer *segbuf,
371 return err; 381 return err;
372} 382}
373 383
384/**
385 * nilfs_segbuf_write - submit write requests of a log
386 * @segbuf: buffer storing a log to be written
387 * @nilfs: nilfs object
388 *
389 * Return Value: On Success, 0 is returned. On Error, one of the following
390 * negative error code is returned.
391 *
392 * %-EIO - I/O error
393 *
394 * %-ENOMEM - Insufficient memory available.
395 */
374int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, 396int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
375 struct nilfs_write_info *wi) 397 struct the_nilfs *nilfs)
376{ 398{
399 struct nilfs_write_info wi;
377 struct buffer_head *bh; 400 struct buffer_head *bh;
378 int res = 0, rw = WRITE; 401 int res = 0, rw = WRITE;
379 402
403 wi.nilfs = nilfs;
404 nilfs_segbuf_prepare_write(segbuf, &wi);
405
380 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) { 406 list_for_each_entry(bh, &segbuf->sb_segsum_buffers, b_assoc_buffers) {
381 res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw); 407 res = nilfs_segbuf_submit_bh(segbuf, &wi, bh, rw);
382 if (unlikely(res)) 408 if (unlikely(res))
383 goto failed_bio; 409 goto failed_bio;
384 } 410 }
385 411
386 list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { 412 list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) {
387 res = nilfs_segbuf_submit_bh(segbuf, wi, bh, rw); 413 res = nilfs_segbuf_submit_bh(segbuf, &wi, bh, rw);
388 if (unlikely(res)) 414 if (unlikely(res))
389 goto failed_bio; 415 goto failed_bio;
390 } 416 }
391 417
392 if (wi->bio) { 418 if (wi.bio) {
393 /* 419 /*
394 * Last BIO is always sent through the following 420 * Last BIO is always sent through the following
395 * submission. 421 * submission.
396 */ 422 */
397 rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG); 423 rw |= (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
398 res = nilfs_segbuf_submit_bio(segbuf, wi, rw); 424 res = nilfs_segbuf_submit_bio(segbuf, &wi, rw);
399 } 425 }
400 426
401 failed_bio: 427 failed_bio:
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index bd076cca37a8..241a00dc4988 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -27,7 +27,6 @@
27#include <linux/buffer_head.h> 27#include <linux/buffer_head.h>
28#include <linux/bio.h> 28#include <linux/bio.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
30#include <linux/backing-dev.h>
31 30
32/** 31/**
33 * struct nilfs_segsum_info - On-memory segment summary 32 * struct nilfs_segsum_info - On-memory segment summary
@@ -173,27 +172,8 @@ static inline void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
173 nilfs_release_buffers(&segbuf->sb_payload_buffers); 172 nilfs_release_buffers(&segbuf->sb_payload_buffers);
174} 173}
175 174
176struct nilfs_write_info { 175int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
177 struct bio *bio; 176 struct the_nilfs *nilfs);
178 int start, end; /* The region to be submitted */
179 int rest_blocks;
180 int max_pages;
181 int nr_vecs;
182 sector_t blocknr;
183
184 /*
185 * The following fields must be set explicitly
186 */
187 struct super_block *sb;
188 struct backing_dev_info *bdi; /* backing dev info */
189 struct buffer_head *bh_sr;
190};
191
192
193void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *,
194 struct nilfs_write_info *);
195int nilfs_segbuf_write(struct nilfs_segment_buffer *,
196 struct nilfs_write_info *);
197int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); 177int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
198 178
199#endif /* _NILFS_SEGBUF_H */ 179#endif /* _NILFS_SEGBUF_H */
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index cb004ebe7895..4422cdae112a 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -1784,19 +1784,13 @@ static int nilfs_segctor_prepare_write(struct nilfs_sc_info *sci,
1784} 1784}
1785 1785
1786static int nilfs_segctor_write(struct nilfs_sc_info *sci, 1786static int nilfs_segctor_write(struct nilfs_sc_info *sci,
1787 struct backing_dev_info *bdi) 1787 struct the_nilfs *nilfs)
1788{ 1788{
1789 struct nilfs_segment_buffer *segbuf; 1789 struct nilfs_segment_buffer *segbuf;
1790 struct nilfs_write_info wi;
1791 int err, res; 1790 int err, res;
1792 1791
1793 wi.sb = sci->sc_super;
1794 wi.bh_sr = sci->sc_super_root;
1795 wi.bdi = bdi;
1796
1797 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { 1792 list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) {
1798 nilfs_segbuf_prepare_write(segbuf, &wi); 1793 err = nilfs_segbuf_write(segbuf, nilfs);
1799 err = nilfs_segbuf_write(segbuf, &wi);
1800 1794
1801 res = nilfs_segbuf_wait(segbuf); 1795 res = nilfs_segbuf_wait(segbuf);
1802 err = err ? : res; 1796 err = err ? : res;
@@ -2170,7 +2164,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2170 2164
2171 nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed); 2165 nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed);
2172 2166
2173 err = nilfs_segctor_write(sci, nilfs->ns_bdi); 2167 err = nilfs_segctor_write(sci, nilfs);
2174 if (unlikely(err)) 2168 if (unlikely(err))
2175 goto failed_to_write; 2169 goto failed_to_write;
2176 2170