diff options
author | Jiro SEKIBA <jir@unicus.jp> | 2010-01-30 04:06:35 -0500 |
---|---|---|
committer | Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> | 2010-02-12 22:26:02 -0500 |
commit | e902ec9906e844f4613fa6190c6fa65f162dc86e (patch) | |
tree | ee0ea829ae04a30fb01c119f050a3967304e55ba /fs/nilfs2/the_nilfs.c | |
parent | 724e6d3fe8003c3f60bf404bf22e4e331327c596 (diff) |
nilfs2: issue discard request after cleaning segments
This adds a function to send discard requests for given array of
segment numbers, and calls the function when garbage collection
succeeded.
Signed-off-by: Jiro SEKIBA <jir@unicus.jp>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Diffstat (limited to 'fs/nilfs2/the_nilfs.c')
-rw-r--r-- | fs/nilfs2/the_nilfs.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 6241e1722efc..92733d5651d2 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -646,6 +646,44 @@ int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data) | |||
646 | goto out; | 646 | goto out; |
647 | } | 647 | } |
648 | 648 | ||
649 | int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump, | ||
650 | size_t nsegs) | ||
651 | { | ||
652 | sector_t seg_start, seg_end; | ||
653 | sector_t start = 0, nblocks = 0; | ||
654 | unsigned int sects_per_block; | ||
655 | __u64 *sn; | ||
656 | int ret = 0; | ||
657 | |||
658 | sects_per_block = (1 << nilfs->ns_blocksize_bits) / | ||
659 | bdev_logical_block_size(nilfs->ns_bdev); | ||
660 | for (sn = segnump; sn < segnump + nsegs; sn++) { | ||
661 | nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end); | ||
662 | |||
663 | if (!nblocks) { | ||
664 | start = seg_start; | ||
665 | nblocks = seg_end - seg_start + 1; | ||
666 | } else if (start + nblocks == seg_start) { | ||
667 | nblocks += seg_end - seg_start + 1; | ||
668 | } else { | ||
669 | ret = blkdev_issue_discard(nilfs->ns_bdev, | ||
670 | start * sects_per_block, | ||
671 | nblocks * sects_per_block, | ||
672 | GFP_NOFS, | ||
673 | DISCARD_FL_BARRIER); | ||
674 | if (ret < 0) | ||
675 | return ret; | ||
676 | nblocks = 0; | ||
677 | } | ||
678 | } | ||
679 | if (nblocks) | ||
680 | ret = blkdev_issue_discard(nilfs->ns_bdev, | ||
681 | start * sects_per_block, | ||
682 | nblocks * sects_per_block, | ||
683 | GFP_NOFS, DISCARD_FL_BARRIER); | ||
684 | return ret; | ||
685 | } | ||
686 | |||
649 | int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) | 687 | int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks) |
650 | { | 688 | { |
651 | struct inode *dat = nilfs_dat_inode(nilfs); | 689 | struct inode *dat = nilfs_dat_inode(nilfs); |