ceph: size handling for the fscrypt
v7 cover ceph: size handling for the fscrypt
From: Xiubo Li <[email protected]>
Changed in V7:
- Use the u64 instead of object version struct.
Changed in V6:
- Fixed the file hole bug, also have updated the MDS side PR.
- Add add object version support for sync read in #8.
Xiubo Li (2):
ceph: add object version support for sync read
ceph: add truncate size handling support for fscrypt
fs/ceph/crypto.h | 21 +++++ fs/ceph/file.c | 8 +- fs/ceph/inode.c | 223 +++++++++++++++++++++++++++++++++++++++++++---- fs/ceph/super.h | 8 +- 4 files changed, 242 insertions(+), 18 deletions(-)
Signature · 1 line
2.27.0
PATCH v7 8/9 ceph: add object version support for sync read
From: Xiubo Li <[email protected]>
Always return the last object's version.
--- fs/ceph/file.c | 8 ++++++-- fs/ceph/super.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-)
fs/ceph/file.c +6 -2
@@ -883,7 +883,8 @@ enum {* only return a short read to the caller if we hit EOF. */ ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op) +struct iov_iter *to,int *retry_op, +u64 *last_objver) {struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);
@@ -950,6 +951,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); +if (last_objver) + *last_objver = req->r_version; +ceph_osdc_put_request (req); i_size =i_size_read (inode);
@@ -1020,7 +1024,7 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to, (unsigned )iov_iter_count (to), (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); -return __ceph_sync_read (inode, &iocb->ki_pos, to, retry_op); +return __ceph_sync_read (inode, &iocb->ki_pos, to, retry_op,NULL ); }struct ceph_aio_request {
fs/ceph/super.h +2 -1
@@ -1258,7 +1258,8 @@ extern int ceph_open(struct inode *inode, struct file *file);extern int ceph_atomic_open (struct inode *dir,struct dentry *dentry,struct file *file,unsigned flags,umode_t mode);extern ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op); +struct iov_iter *to,int *retry_op, +u64 *last_objver);extern int ceph_release (struct inode *inode,struct file *filp);extern void ceph_fill_inline_data (struct inode *inode,struct page *locked_page,char *data,size_t len);
Signature · 1 line
2.27.0
Re: [PATCH v7 8/9] ceph: add object version support for sync read
Quoted 25 lines · On Wed, 2021-12-08 at 20:45 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
Always return the last object's version.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 8 ++++++-- fs/ceph/super.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-)fs/ceph/file.c +2
-1@@ -883,7 +883,8 @@ enum {* only return a short read to the caller if we hit EOF. */ ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op) +struct iov_iter *to,int *retry_op, +u64 *last_objver) {struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);
fs/ceph/file.c ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · line 956
Quoted 6 lines
fs/ceph/file.c +3
-0@@ -950,6 +951,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); +if (last_objver) + *last_objver = req->r_version; +
Much better! That said, this might be unreliable if (say) the first OSD read was successful and then the second one failed on a long read that spans objects. We'd want to return a short read in that case, but the last_objver would end up being set to 0.
I think you shouldn't set last_objver unless the call is going to return
Quoted 1 line
0, and then you want to set it to the object version of the last
successful read in the series.
Quoted 26 lines
fs/ceph/file.c +1
-1ceph_osdc_put_request (req); i_size =i_size_read (inode);@@ -1020,7 +1024,7 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to, (unsigned )iov_iter_count (to), (file->f_flags & O_DIRECT) ? "O_DIRECT" : ""); -return __ceph_sync_read (inode, &iocb->ki_pos, to, retry_op); +return __ceph_sync_read (inode, &iocb->ki_pos, to, retry_op,NULL ); }struct ceph_aio_request {fs/ceph/super.h +2
-1@@ -1258,7 +1258,8 @@ extern int ceph_open(struct inode *inode, struct file *file);extern int ceph_atomic_open (struct inode *dir,struct dentry *dentry,struct file *file,unsigned flags,umode_t mode);extern ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op); +struct iov_iter *to,int *retry_op, +u64 *last_objver);extern int ceph_release (struct inode *inode,struct file *filp);extern void ceph_fill_inline_data (struct inode *inode,struct page *locked_page,char *data,size_t len);
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v7 8/9] ceph: add object version support for sync read
Quoted 38 lines · Jeff Layton
Quoted 25 lines · On Wed, 2021-12-08 at 20:45 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
Always return the last object's version.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 8 ++++++-- fs/ceph/super.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-)fs/ceph/file.c +2
-1@@ -883,7 +883,8 @@ enum {* only return a short read to the caller if we hit EOF. */ ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op) +struct iov_iter *to,int *retry_op, +u64 *last_objver) {struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);fs/ceph/file.c ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · line 956
Quoted 6 lines
fs/ceph/file.c +3
-0@@ -950,6 +951,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); +if (last_objver) + *last_objver = req->r_version; +Much better! That said, this might be unreliable if (say) the first OSD read was successful and then the second one failed on a long read that spans objects. We'd want to return a short read in that case, but the
last_objverwould end up being set to 0.
Quoted 5 lines
I think you shouldn't set
last_objverunless the call is going to returnQuoted 1 line
0, and then you want to set it to the object version of the last
successful read in the series.
Since this was a simple change, I went ahead and folded the patch below into this patch and updated wip-fscrypt-size. Let me know if you have any objections:
[PATCH] SQUASH: only set last_objver iff we're returning success
--- fs/ceph/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/ceph/file.c +5 -3
@@ -893,6 +893,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,u64 off = *ki_pos;u64 len =iov_iter_count (to);u64 i_size =i_size_read (inode); +u64 objver =0 ;dout ("sync_read on inode %p %llu~%u\n" , inode, *ki_pos, (unsigned )len);
@@ -951,9 +952,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); -if (last_objver) - *last_objver = req->r_version; - + objver = req->r_version;ceph_osdc_put_request (req); i_size =i_size_read (inode);
@@ -1010,6 +1009,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, } } +if (ret >0 ) + *last_objver = objver; +dout ("sync_read result %zd retry_op %d\n" , ret, *retry_op);return ret; }
Signature · 1 line
2.33.1
Re: [PATCH v7 8/9] ceph: add object version support for sync read
Quoted 38 lines · Jeff Layton
Quoted 37 lines · Jeff Layton
Quoted 25 lines · On Wed, 2021-12-08 at 20:45 +0800, [email protected] wrote:
From: Xiubo Li <[email protected]>
Always return the last object's version.
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 8 ++++++-- fs/ceph/super.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-)fs/ceph/file.c +2
-1@@ -883,7 +883,8 @@ enum {* only return a short read to the caller if we hit EOF. */ ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, -struct iov_iter *to,int *retry_op) +struct iov_iter *to,int *retry_op, +u64 *last_objver) {struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);fs/ceph/file.c ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · line 956
Quoted 6 lines
fs/ceph/file.c +3
-0@@ -950,6 +951,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); +if (last_objver) + *last_objver = req->r_version; +Much better! That said, this might be unreliable if (say) the first OSD read was successful and then the second one failed on a long read that spans objects. We'd want to return a short read in that case, but the
last_objverwould end up being set to 0.
Quoted 4 lines
Quoted 4 lines
I think you shouldn't set
last_objverunless the call is going to returnQuoted 1 line
0, and then you want to set it to the object version of the last
successful read in the series.
Make sense to me.
Quoted 35 lines
Since this was a simple change, I went ahead and folded the patch below into this patch and updated wip-fscrypt-size. Let me know if you have any objections:
[PATCH] SQUASH: only set
last_objveriff we're returning successSigned-off-by Jeff Layton <[email protected]>--- fs/ceph/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)fs/ceph/file.c +2
-3@@ -893,6 +893,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos,u64 off = *ki_pos;u64 len =iov_iter_count (to);u64 i_size =i_size_read (inode); +u64 objver =0 ;dout ("sync_read on inode %p %llu~%u\n" , inode, *ki_pos, (unsigned )len);@@ -951,9 +952,7 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); -if (last_objver) - *last_objver = req->r_version; - + objver = req->r_version;ceph_osdc_put_request (req); i_size =i_size_read (inode);
fs/ceph/file.c ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, · line 1017
Quoted 9 lines
fs/ceph/file.c +3
-0@@ -1010,6 +1009,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, } } +if (ret >0 ) + *last_objver = objver; +dout ("sync_read result %zd retry_op %d\n" , ret, *retry_op);return ret; }
This also looks good to me :-)
Thanks.
BRs
PATCH v7 9/9 ceph: add truncate size handling support for fscrypt
In reply to [email protected]From: Xiubo Li <[email protected]>
This will transfer the encrypted last block contents to the MDS along with the truncate request only when the new size is smaller and not aligned to the fscrypt BLOCK size. When the last block is located in the file hole, the truncate request will only contain the header.
The MDS could fail to do the truncate if there has another client or process has already updated the RADOS object which contains the last block, and will return -EAGAIN, then the kclient needs to retry it. The RMW will take around 50ms, and will let it retry 20 times for now.
--- fs/ceph/crypto.h | 21 +++++ fs/ceph/inode.c | 223 +++++++++++++++++++++++++++++++++++++++++++---- fs/ceph/super.h | 5 ++ 3 files changed, 234 insertions(+), 15 deletions(-)
fs/ceph/crypto.h +21 -0
@@ -25,6 +25,27 @@ struct ceph_fname {u32 ctext_len;// length of crypttext }; +/* +* Header for the crypted file when truncating the size, this +* will be sent to MDS, and the MDS will update the encrypted +* last block and then truncate the size. +*/ +struct ceph_fscrypt_truncate_size_header { +__u8 ver; +__u8 compat; + +/* +* It will be sizeof(assert_ver + file_offset + block_size) +* if the last block is empty when it's located in a file +* hole. Or the data_len will plus CEPH_FSCRYPT_BLOCK_SIZE. +*/ +__le32 data_len; + +__le64 assert_ver; +__le64 file_offset; +__le32 block_size; +} __packed; +struct ceph_fscrypt_auth {__le32 cfa_version;__le32 cfa_blob_len;
fs/ceph/inode.c +208 -15
319 lines not on this page · raw message
fs/ceph/super.h +5 -0
@@ -409,6 +409,11 @@ struct ceph_inode_info {u32 i_truncate_seq;/* last truncate to smaller size */ u64 i_truncate_size;/* and the size we last truncated down to */ int i_truncate_pending;/* still need to call vmtruncate */ +/* +* For none fscrypt case it equals to i_truncate_size or it will +* equals to fscrypt_file_size +*/ +u64 i_truncate_pagecache_size;u64 i_max_size;/* max file size authorized by mds */ u64 i_reported_size;/* (max_)size reported to or requested of mds */
Signature · 1 line
2.27.0
Hi Jeff,
Please replace the #8 and #9 patches on top of "wip-fscrypt-size" branch.
Thanks,
Quoted 21 lines · On 12/8/21 8:45 PM, [email protected] wrote:
From: Xiubo Li <[email protected]>
Changed in V7:
- Use the u64 instead of object version struct.Changed in V6:
- Fixed the file hole bug, also have updated the MDS side PR.
- Add add object version support for sync read in #8.Xiubo Li (2):
ceph: add object version support for sync read
ceph: add truncate size handling support for fscryptfs/ceph/crypto.h | 21 +++++ fs/ceph/file.c | 8 +- fs/ceph/inode.c | 223 +++++++++++++++++++++++++++++++++++++++++++---- fs/ceph/super.h | 8 +- 4 files changed, 242 insertions(+), 18 deletions(-)