From: Xiubo Li <xiubli@xxxxxxxxxx> When hit a file hole, will keep the header.assert_ver as 0, and in MDS side it will check it to decide whether should it do a RMW. And always set the header.block_size to CEPH_FSCRYPT_BLOCK_SIZE, because even in the hole case, the MDS will need to use this to do the filer.truncate(). Signed-off-by: Xiubo Li <xiubli@xxxxxxxxxx> --- Hi Jeff, Please squash this patch to the previous "ceph: add truncate size handling support for fscrypt" commit in ceph-client/wip-fscrypt-size branch. And also please sync the ceph PR, I have updated it too. fs/ceph/inode.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index 53b8e2ff3678..b4f7a4b4f15c 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -2312,6 +2312,12 @@ static int fill_fscrypt_truncate(struct inode *inode, header.ver = 1; header.compat = 1; + /* + * Always set the block_size to CEPH_FSCRYPT_BLOCK_SIZE, + * because in MDS it may need this to do the truncate. + */ + header.block_size = cpu_to_le32(CEPH_FSCRYPT_BLOCK_SIZE); + /* * If we hit a hole here, we should just skip filling * the fscrypt for the request, because once the fscrypt @@ -2327,15 +2333,19 @@ static int fill_fscrypt_truncate(struct inode *inode, pos, i_size); header.data_len = cpu_to_le32(8 + 8 + 4); + + /* + * If the "assert_ver" is 0 means hitting a hole, and + * the MDS will use the it to check whether hitting a + * hole or not. + */ header.assert_ver = 0; header.file_offset = 0; - header.block_size = 0; ret = 0; } else { header.data_len = cpu_to_le32(8 + 8 + 4 + CEPH_FSCRYPT_BLOCK_SIZE); header.assert_ver = cpu_to_le64(objvers.objvers[0].objver); header.file_offset = cpu_to_le64(orig_pos); - header.block_size = cpu_to_le32(CEPH_FSCRYPT_BLOCK_SIZE); /* truncate and zero out the extra contents for the last block */ memset(iov.iov_base + boff, 0, PAGE_SIZE - boff); -- 2.27.0