diff options
Diffstat (limited to 'fs/nilfs2/the_nilfs.c')
-rw-r--r-- | fs/nilfs2/the_nilfs.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 6241e1722efc..33871f7e4f01 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c | |||
@@ -386,7 +386,7 @@ static int nilfs_store_disk_layout(struct the_nilfs *nilfs, | |||
386 | 386 | ||
387 | nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); | 387 | nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment); |
388 | if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) { | 388 | if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) { |
389 | printk(KERN_ERR "NILFS: too short segment. \n"); | 389 | printk(KERN_ERR "NILFS: too short segment.\n"); |
390 | return -EINVAL; | 390 | return -EINVAL; |
391 | } | 391 | } |
392 | 392 | ||
@@ -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); |