diff options
author | Chao Yu <yuchao0@huawei.com> | 2020-03-30 11:13:29 +0200 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2020-05-08 15:55:57 +0200 |
commit | c1c633878662341eb0c502b3cab6e8c5cc83f44c (patch) | |
tree | 0a7cdd54a7d71127f93f8bdcf14f90e0b8493b0b /fs/f2fs/data.c | |
parent | f2fs: support fiemap on compressed inode (diff) | |
download | linux-c1c633878662341eb0c502b3cab6e8c5cc83f44c.tar.xz linux-c1c633878662341eb0c502b3cab6e8c5cc83f44c.zip |
f2fs: introduce f2fs_bmap_compress()
to support bmap() on compressed inode: if queried block locates in
non-compressed cluster, return its physical block address.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs/f2fs/data.c')
-rw-r--r-- | fs/f2fs/data.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b79d643470d6..ff8a92df8d99 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3666,6 +3666,37 @@ static int f2fs_set_data_page_dirty(struct page *page) return 0; } + +static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block) +{ +#ifdef CONFIG_F2FS_FS_COMPRESSION + struct dnode_of_data dn; + sector_t start_idx, blknr = 0; + int ret; + + start_idx = round_down(block, F2FS_I(inode)->i_cluster_size); + + set_new_dnode(&dn, inode, NULL, NULL, 0); + ret = f2fs_get_dnode_of_data(&dn, start_idx, LOOKUP_NODE); + if (ret) + return 0; + + if (dn.data_blkaddr != COMPRESS_ADDR) { + dn.ofs_in_node += block - start_idx; + blknr = f2fs_data_blkaddr(&dn); + if (!__is_valid_data_blkaddr(blknr)) + blknr = 0; + } + + f2fs_put_dnode(&dn); + + return blknr; +#else + return -EOPNOTSUPP; +#endif +} + + static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode = mapping->host; @@ -3677,6 +3708,9 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) filemap_write_and_wait(mapping); + if (f2fs_compressed_file(inode)) + return f2fs_bmap_compress(inode, block); + return generic_block_bmap(mapping, block, get_data_block_bmap); } |