UPSTREAM: f2fs: support SEEK_DATA and SEEK_HOLE for compression files

Fix to support SEEK_DATA and SEEK_HOLE for compression files

Bug: 325092012
Signed-off-by: Daeho Jeong <daehojeong@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
(cherry picked from commit a94c7fded76bfd1a061deae7be80fedbfa26774e)
(cherry picked from https://android-review.googlesource.com/q/commit:268f1fed504a7bc9cfba291fe994ad767eda7a70)
Merged-In: Iba62c53e634682205f84c8dc3566ab8df9079158
Change-Id: Iba62c53e634682205f84c8dc3566ab8df9079158
This commit is contained in:
Daeho Jeong 2024-02-15 12:16:33 -08:00 committed by Android Build Cherrypicker Worker
parent 894861d67a
commit a8339e7fd0

View File

@ -382,9 +382,20 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
return f2fs_do_sync_file(file, start, end, datasync, false);
}
static bool __found_offset(struct address_space *mapping, block_t blkaddr,
pgoff_t index, int whence)
static bool __found_offset(struct address_space *mapping,
struct dnode_of_data *dn, pgoff_t index, int whence)
{
block_t blkaddr = f2fs_data_blkaddr(dn);
struct inode *inode = mapping->host;
bool compressed_cluster = false;
if (f2fs_compressed_file(inode)) {
block_t first_blkaddr = data_blkaddr(dn->inode, dn->node_page,
ALIGN_DOWN(dn->ofs_in_node, F2FS_I(inode)->i_cluster_size));
compressed_cluster = first_blkaddr == COMPRESS_ADDR;
}
switch (whence) {
case SEEK_DATA:
if (__is_valid_data_blkaddr(blkaddr))
@ -392,8 +403,12 @@ static bool __found_offset(struct address_space *mapping, block_t blkaddr,
if (blkaddr == NEW_ADDR &&
xa_get_mark(&mapping->i_pages, index, PAGECACHE_TAG_DIRTY))
return true;
if (compressed_cluster)
return true;
break;
case SEEK_HOLE:
if (compressed_cluster)
return false;
if (blkaddr == NULL_ADDR)
return true;
break;
@ -462,7 +477,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence)
goto fail;
}
if (__found_offset(file->f_mapping, blkaddr,
if (__found_offset(file->f_mapping, &dn,
pgofs, whence)) {
f2fs_put_dnode(&dn);
goto found;