ceph: size handling for the fscrypt
Subsystems (2)
v5 cover ceph: size handling for the fscrypt
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.
====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.
The MDS will use the filer.write_trunc(), which could update and truncate the file in one shot, instead of filer.truncate().
This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916
Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support in ceph_inode_info struct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.
Changed in V4:
- Retry the truncate request by 20 times before fail it with -EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.
Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.
Jeff Layton (5):
libceph: add CEPH_OSD_OP_ASSERT_VER support
ceph: size handling for encrypted inodes in cap updates
ceph: fscrypt_file field handling in MClientRequest messages
ceph: get file size from fscrypt_file when present in inode traces
ceph: handle fscrypt fields in cap messages from MDS
Xiubo Li (3):
ceph: add __ceph_get_caps helper support
ceph: add __ceph_sync_read helper support
ceph: add truncate size handling support for fscrypt
fs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-) create mode 100644 include/linux/ceph/crypto.h
Signature · 1 line
2.27.0
PATCH v5 1/8 libceph: add CEPH_OSD_OP_ASSERT_VER support
From: Jeff Layton <[email protected]>
...and record the user_version in the reply in a new field in ceph_osd_request, so we can populate the assert_ver appropriately. Shuffle the fields a bit too so that the new field fits in an existing hole on x86_64.
--- include/linux/ceph/osd_client.h | 6 +++++- include/linux/ceph/rados.h | 4 ++++ net/ceph/osd_client.c | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-)
include/linux/ceph/osd_client.h +5 -1
@@ -145,6 +145,9 @@ struct ceph_osd_req_op {u32 src_fadvise_flags;struct ceph_osd_data osd_data; } copy_from; +struct { +u64 ver; + } assert_ver; }; };
@@ -199,6 +202,7 @@ struct ceph_osd_request {struct ceph_osd_client *r_osdc;struct kref r_kref;bool r_mempool; +bool r_linger;/* don't resend on failure */ struct completion r_completion;/* private to osd_client.c */ ceph_osdc_callback_t r_callback;
@@ -211,9 +215,9 @@ struct ceph_osd_request {struct ceph_snap_context *r_snapc;/* for writes */ struct timespec64 r_mtime;/* ditto */ u64 r_data_offset;/* ditto */ -bool r_linger;/* don't resend on failure */ /* internal */ +u64 r_version;/* data version sent in reply */ unsigned long r_stamp;/* jiffies, send or check time */ unsigned long r_start_stamp;/* jiffies */ ktime_t r_start_latency;/* ktime_t */
include/linux/ceph/rados.h +4 -0
@@ -523,6 +523,10 @@ struct ceph_osd_op {struct {__le64 cookie; } __attribute__ ((packed)) notify; +struct { +__le64 unused; +__le64 ver; + } __attribute__ ((packed)) assert_ver;struct {__le64 offset, length;__le64 src_offset;
net/ceph/osd_client.c +5 -0
@@ -1038,6 +1038,10 @@ static u32 osd_req_encode_op(struct ceph_osd_op *dst, dst->copy_from.src_fadvise_flags =cpu_to_le32 (src->copy_from.src_fadvise_flags);break ; +case CEPH_OSD_OP_ASSERT_VER : + dst->assert_ver.unused =cpu_to_le64 (0 ); + dst->assert_ver.ver =cpu_to_le64 (src->assert_ver.ver); +break ;default :pr_err ("unsupported osd opcode %s\n" ,ceph_osd_op_name (src->op));
@@ -3763,6 +3767,7 @@ static void handle_reply(struct ceph_osd *osd, struct ceph_msg *msg)* one (type of) reply back. */ WARN_ON (!(m.flags &CEPH_OSD_FLAG_ONDISK )); + req->r_version = m.user_version; req->r_result = m.result ?: data_len;finish_request (req);mutex_unlock (&osd->lock);
Signature · 1 line
2.27.0
PATCH v5 2/8 ceph: size handling for encrypted inodes in cap updates
In reply to [email protected]From: Jeff Layton <[email protected]>
Transmit the rounded-up size as the normal size, and fill out the fscrypt_file field with the real file size.
--- fs/ceph/caps.c | 43 +++++++++++++++++++++++++------------------ fs/ceph/crypto.h | 4 ++++ 2 files changed, 29 insertions(+), 18 deletions(-)
fs/ceph/caps.c +25 -18
@@ -1215,10 +1215,9 @@ struct cap_msg_args {umode_t mode;bool inline_data;bool wake; +bool encrypted;u32 fscrypt_auth_len; -u32 fscrypt_file_len;u8 fscrypt_auth[sizeof (struct ceph_fscrypt_auth )];// for context -u8 fscrypt_file[sizeof (u64)];// for size };/* Marshal up the cap msg to the MDS */
@@ -1253,7 +1252,12 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg) fc->ino =cpu_to_le64 (arg->ino); fc->snap_follows =cpu_to_le64 (arg->follows); - fc->size =cpu_to_le64 (arg->size); +#if IS_ENABLED (CONFIG_FS_ENCRYPTION ) +if (arg->encrypted) + fc->size =cpu_to_le64 (round_up (arg->size,CEPH_FSCRYPT_BLOCK_SIZE )); + else +#endif + fc->size =cpu_to_le64 (arg->size); fc->max_size =cpu_to_le64 (arg->max_size);ceph_encode_timespec64 (&fc->mtime, &arg->mtime);ceph_encode_timespec64 (&fc->atime, &arg->atime);
@@ -1313,11 +1317,17 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg)ceph_encode_64 (&p,0 );#if IS_ENABLED (CONFIG_FS_ENCRYPTION ) -/* fscrypt_auth and fscrypt_file (version 12) */ +/* +* fscrypt_auth and fscrypt_file (version 12) +* +* fscrypt_auth holds the crypto context (if any). fscrypt_file +* tracks the real i_size as an __le64 field (and we use a rounded-up +* i_size in * the traditional size field). +*/ ceph_encode_32 (&p, arg->fscrypt_auth_len);ceph_encode_copy (&p, arg->fscrypt_auth, arg->fscrypt_auth_len); -ceph_encode_32 (&p, arg->fscrypt_file_len); -ceph_encode_copy (&p, arg->fscrypt_file, arg->fscrypt_file_len); +ceph_encode_32 (&p,sizeof (__le64)); +ceph_encode_64 (&p, arg->size);#else /* CONFIG_FS_ENCRYPTION */ ceph_encode_32 (&p,0 );ceph_encode_32 (&p,0 );
@@ -1389,7 +1399,6 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap, arg->follows = flushing ? ci->i_head_snapc->seq :0 ; arg->flush_tid = flush_tid; arg->oldest_flush_tid = oldest_flush_tid; - arg->size =i_size_read (inode); ci->i_reported_size = arg->size; arg->max_size = ci->i_wanted_max_size;
@@ -1443,6 +1452,7 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap, } } arg->flags = flags; + arg->encrypted =IS_ENCRYPTED (inode);#if IS_ENABLED (CONFIG_FS_ENCRYPTION )if (ci->fscrypt_auth_len &&WARN_ON_ONCE (ci->fscrypt_auth_len !=sizeof (struct ceph_fscrypt_auth ))) {
@@ -1453,21 +1463,21 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap,memcpy (arg->fscrypt_auth, ci->fscrypt_auth,min_t (size_t, ci->fscrypt_auth_len,sizeof (arg->fscrypt_auth))); } -/* FIXME: use this to track "real" size */ - arg->fscrypt_file_len =0 ;#endif /* CONFIG_FS_ENCRYPTION */ } +#if IS_ENABLED (CONFIG_FS_ENCRYPTION )#define CAP_MSG_FIXED_FIELDS (sizeof(struct ceph_mds_caps) + \ - 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4) + 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4 + 8) -#if IS_ENABLED (CONFIG_FS_ENCRYPTION )static inline int cap_msg_size (struct cap_msg_args *arg) { -return CAP_MSG_FIXED_FIELDS + arg->fscrypt_auth_len + - arg->fscrypt_file_len; +return CAP_MSG_FIXED_FIELDS + arg->fscrypt_auth_len; }#else +#define CAP_MSG_FIXED_FIELDS (sizeof(struct ceph_mds_caps) + \ + 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4) +static inline int cap_msg_size (struct cap_msg_args *arg) {return CAP_MSG_FIXED_FIELDS ;
@@ -1546,13 +1556,10 @@ static inline int __send_flush_snap(struct inode *inode, arg.inline_data = capsnap->inline_data; arg.flags =0 ; arg.wake = false; + arg.encrypted =IS_ENCRYPTED (inode); -/* -* No fscrypt_auth changes from a capsnap. It will need -* to update fscrypt_file on size changes (TODO). -*/ +/* No fscrypt_auth changes from a capsnap.*/ arg.fscrypt_auth_len =0 ; - arg.fscrypt_file_len =0 ; msg =ceph_msg_new (CEPH_MSG_CLIENT_CAPS ,cap_msg_size (&arg),GFP_NOFS , false);
fs/ceph/crypto.h +4 -0
@@ -9,6 +9,10 @@#include <crypto/sha2.h> #include <linux/fscrypt.h> +#define CEPH_FSCRYPT_BLOCK_SHIFT 12 +#define CEPH_FSCRYPT_BLOCK_SIZE (_AC(1,UL) << CEPH_FSCRYPT_BLOCK_SHIFT) +#define CEPH_FSCRYPT_BLOCK_MASK (~(CEPH_FSCRYPT_BLOCK_SIZE-1)) +struct ceph_fs_client ;struct ceph_acl_sec_ctx ;struct ceph_mds_request ;
Signature · 1 line
2.27.0
PATCH v5 3/8 ceph: fscrypt_file field handling in MClientRequest messages
In reply to [email protected]From: Jeff Layton <[email protected]>
For encrypted inodes, transmit a rounded-up size to the MDS as the normal file size and send the real inode size in fscrypt_file field.
Also, fix up creates and truncates to also transmit fscrypt_file.
--- fs/ceph/dir.c | 3 +++ fs/ceph/file.c | 2 ++ fs/ceph/inode.c | 18 ++++++++++++++++-- fs/ceph/mds_client.c | 9 ++++++++- fs/ceph/mds_client.h | 2 ++ 5 files changed, 31 insertions(+), 3 deletions(-)
fs/ceph/dir.c +3 -0
@@ -916,6 +916,9 @@ static int ceph_mknod(struct user_namespace *mnt_userns, struct inode *dir, goto out_req; } +if (S_ISREG (mode) &&IS_ENCRYPTED (dir)) +set_bit (CEPH_MDS_R_FSCRYPT_FILE , &req->r_req_flags); + req->r_dentry =dget (dentry); req->r_num_caps =2 ; req->r_parent = dir;
fs/ceph/file.c +2 -0
@@ -715,6 +715,8 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, req->r_args.open.mask =cpu_to_le32 (mask); req->r_parent = dir;ihold (dir); +if (IS_ENCRYPTED (dir)) +set_bit (CEPH_MDS_R_FSCRYPT_FILE , &req->r_req_flags);if (flags &O_CREAT ) {struct ceph_file_layout lo;
fs/ceph/inode.c +16 -2
@@ -2383,11 +2383,25 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr, struct ceph_iattr *c } }else if ((issued &CEPH_CAP_FILE_SHARED ) ==0 || attr->ia_size != isize) { - req->r_args.setattr.size =cpu_to_le64 (attr->ia_size); - req->r_args.setattr.old_size =cpu_to_le64 (isize); mask |=CEPH_SETATTR_SIZE ; release |=CEPH_CAP_FILE_SHARED |CEPH_CAP_FILE_EXCL |CEPH_CAP_FILE_RD |CEPH_CAP_FILE_WR ; +if (IS_ENCRYPTED (inode)) { +set_bit (CEPH_MDS_R_FSCRYPT_FILE , &req->r_req_flags); + mask |=CEPH_SETATTR_FSCRYPT_FILE ; + req->r_args.setattr.size = +cpu_to_le64 (round_up (attr->ia_size, +CEPH_FSCRYPT_BLOCK_SIZE )); + req->r_args.setattr.old_size = +cpu_to_le64 (round_up (isize, +CEPH_FSCRYPT_BLOCK_SIZE )); + req->r_fscrypt_file = attr->ia_size; +/* FIXME: client must zero out any partial blocks! */ + }else { + req->r_args.setattr.size =cpu_to_le64 (attr->ia_size); + req->r_args.setattr.old_size =cpu_to_le64 (isize); + req->r_fscrypt_file =0 ; + } } }if (ia_valid &ATTR_MTIME ) {
fs/ceph/mds_client.c +8 -1
@@ -2653,7 +2653,12 @@ static void encode_mclientrequest_tail(void **p, const struct ceph_mds_request * }else {ceph_encode_32 (p,0 ); } -ceph_encode_32 (p,0 );// fscrypt_file for now +if (test_bit (CEPH_MDS_R_FSCRYPT_FILE , &req->r_req_flags)) { +ceph_encode_32 (p,sizeof (__le64)); +ceph_encode_64 (p, req->r_fscrypt_file); + }else { +ceph_encode_32 (p,0 ); + } }/*
@@ -2739,6 +2744,8 @@ static struct ceph_msg *create_request_message(struct ceph_mds_session *session,/* fscrypt_file */ len +=sizeof (u32); +if (test_bit (CEPH_MDS_R_FSCRYPT_FILE , &req->r_req_flags)) + len +=sizeof (__le64); msg =ceph_msg_new2 (CEPH_MSG_CLIENT_REQUEST , len,1 ,GFP_NOFS , false);if (!msg) {
fs/ceph/mds_client.h +2 -0
@@ -276,6 +276,7 @@ struct ceph_mds_request {#define CEPH_MDS_R_DID_PREPOPULATE (6)/* prepopulated readdir */ #define CEPH_MDS_R_PARENT_LOCKED (7)/* is r_parent->i_rwsem wlocked? */ #define CEPH_MDS_R_ASYNC (8)/* async request */ +#define CEPH_MDS_R_FSCRYPT_FILE (9)/* must marshal fscrypt_file field */ unsigned long r_req_flags;struct mutex r_fill_mutex;
@@ -283,6 +284,7 @@ struct ceph_mds_request {union ceph_mds_request_args r_args;struct ceph_fscrypt_auth *r_fscrypt_auth; +__le64 r_fscrypt_file;u8 *r_altname;/* fscrypt binary crypttext for long filenames */ u32 r_altname_len;/* length of r_altname */
Signature · 1 line
2.27.0
PATCH v5 4/8 ceph: get file size from fscrypt_file when present in inode traces
In reply to [email protected]From: Jeff Layton <[email protected]>
--- fs/ceph/inode.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
fs/ceph/inode.c +19 -11
@@ -978,6 +978,16 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page, from_kgid(&init_user_ns, inode->i_gid));ceph_decode_timespec64 (&ci->i_btime, &iinfo->btime);ceph_decode_timespec64 (&ci->i_snap_btime, &iinfo->snap_btime); + +#ifdef CONFIG_FS_ENCRYPTION +if (iinfo->fscrypt_auth_len && !ci->fscrypt_auth) { + ci->fscrypt_auth_len = iinfo->fscrypt_auth_len; + ci->fscrypt_auth = iinfo->fscrypt_auth; + iinfo->fscrypt_auth =NULL ; + iinfo->fscrypt_auth_len =0 ; +inode_set_flags (inode,S_ENCRYPTED ,S_ENCRYPTED ); + } +#endif } if ((new_version || (new_issued & CEPH_CAP_LINK_SHARED)) &&
@@ -1001,6 +1011,7 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page,if (new_version || (new_issued & (CEPH_CAP_ANY_FILE_RD |CEPH_CAP_ANY_FILE_WR ))) { +u64 size = info->size;s64 old_pool = ci->i_layout.pool_id;struct ceph_string *old_ns;
@@ -1014,10 +1025,17 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page, pool_ns = old_ns; +if (IS_ENCRYPTED (inode) && size && + (iinfo->fscrypt_file_len ==sizeof (__le64))) { + size =__le64_to_cpu (*(__le64 *)iinfo->fscrypt_file); +if (info->size !=round_up (size,CEPH_FSCRYPT_BLOCK_SIZE )) +pr_warn ("size=%llu fscrypt_file=%llu\n" , info->size, size); + } + queue_trunc =ceph_fill_file_size (inode, issued,le32_to_cpu (info->truncate_seq),le64_to_cpu (info->truncate_size), -le64_to_cpu (info->size)); +le64_to_cpu (size));/* only update max_size on auth cap */ if ((info->cap.flags &CEPH_CAP_FLAG_AUTH ) && ci->i_max_size !=le64_to_cpu (info->max_size)) {
@@ -1057,16 +1075,6 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page, xattr_blob =NULL ; } -#ifdef CONFIG_FS_ENCRYPTION -if (iinfo->fscrypt_auth_len && !ci->fscrypt_auth) { - ci->fscrypt_auth_len = iinfo->fscrypt_auth_len; - ci->fscrypt_auth = iinfo->fscrypt_auth; - iinfo->fscrypt_auth =NULL ; - iinfo->fscrypt_auth_len =0 ; -inode_set_flags (inode,S_ENCRYPTED ,S_ENCRYPTED ); - } -#endif -/* finally update i_version */ if (le64_to_cpu (info->version) > ci->i_version) ci->i_version =le64_to_cpu (info->version);
Signature · 1 line
2.27.0
PATCH v5 5/8 ceph: handle fscrypt fields in cap messages from MDS
In reply to [email protected]From: Jeff Layton <[email protected]>
--- fs/ceph/caps.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-)
fs/ceph/caps.c +72 -2
@@ -3329,6 +3329,9 @@ struct cap_extra_info {/* currently issued */ int issued;struct timespec64 btime; +u8 *fscrypt_auth; +u32 fscrypt_auth_len; +u64 fscrypt_file_size; };/*
@@ -3361,6 +3364,14 @@ static void handle_cap_grant(struct inode *inode,bool deleted_inode = false;bool fill_inline = false; +/* +* If there is at least one crypto block then we'll trust fscrypt_file_size. +* If the real length of the file is 0, then ignore it (it has probably been +* truncated down to 0 by the MDS). +*/ +if (IS_ENCRYPTED (inode) && size) + size = extra_info->fscrypt_file_size; +dout ("handle_cap_grant inode %p cap %p mds%d seq %d %s\n" , inode, cap, session->s_mds, seq,ceph_cap_string (newcaps)); dout(" size %llu max_size %llu, i_size %llu\n", size, max_size,
@@ -3839,7 +3850,8 @@ static void handle_cap_flushsnap_ack(struct inode *inode, u64 flush_tid,*/ static bool handle_cap_trunc (struct inode *inode,struct ceph_mds_caps *trunc, -struct ceph_mds_session *session) +struct ceph_mds_session *session, +struct cap_extra_info *extra_info) {struct ceph_inode_info *ci =ceph_inode (inode);int mds = session->s_mds;
@@ -3856,6 +3868,14 @@ static bool handle_cap_trunc(struct inode *inode, issued |= implemented | dirty; +/* +* If there is at least one crypto block then we'll trust fscrypt_file_size. +* If the real length of the file is 0, then ignore it (it has probably been +* truncated down to 0 by the MDS). +*/ +if (IS_ENCRYPTED (inode) && size) + size = extra_info->fscrypt_file_size; +dout ("handle_cap_trunc inode %p mds%d seq %d to %lld seq %d\n" , inode, mds, seq, truncate_size, truncate_seq); queue_trunc = ceph_fill_file_size(inode, issued,
@@ -4074,6 +4094,48 @@ static void handle_cap_import(struct ceph_mds_client *mdsc, *target_cap = cap; } +#ifdef CONFIG_FS_ENCRYPTION +static int parse_fscrypt_fields (void **p,void *end,struct cap_extra_info *extra) +{ +u32 len; + +ceph_decode_32_safe (p, end, extra->fscrypt_auth_len, bad); +if (extra->fscrypt_auth_len) { +ceph_decode_need (p, end, extra->fscrypt_auth_len, bad); + extra->fscrypt_auth =kmalloc (extra->fscrypt_auth_len,GFP_KERNEL ); +if (!extra->fscrypt_auth) +return -ENOMEM ; +ceph_decode_copy_safe (p, end, extra->fscrypt_auth, + extra->fscrypt_auth_len, bad); + } + +ceph_decode_32_safe (p, end, len, bad); +if (len ==sizeof (u64)) +ceph_decode_64_safe (p, end, extra->fscrypt_file_size, bad); +else +ceph_decode_skip_n (p, end, len, bad); +return 0 ; +bad: +return -EIO ; +} +#else +static int parse_fscrypt_fields (void **p,void *end,struct cap_extra_info *extra) +{ +u32 len; + +/* Don't care about these fields unless we're encryption-capable */ +ceph_decode_32_safe (p, end, len, bad); +if (len) +ceph_decode_skip_n (p, end, len, bad); +ceph_decode_32_safe (p, end, len, bad); +if (len) +ceph_decode_skip_n (p, end, len, bad); +return 0 ; +bad: +return -EIO ; +} +#endif +/* * Handle a caps message from the MDS. *
@@ -4192,6 +4254,12 @@ void ceph_handle_caps(struct ceph_mds_session *session,ceph_decode_64_safe (&p, end, extra_info.nsubdirs, bad); } +if (msg_version >=12 ) { +int ret =parse_fscrypt_fields (&p, end, &extra_info); +if (ret) + goto bad; + } +/* lookup ino */ inode =ceph_find_inode (mdsc->fsc->sb, vino); ci =ceph_inode (inode);
@@ -4288,7 +4356,8 @@ void ceph_handle_caps(struct ceph_mds_session *session,break ;case CEPH_CAP_OP_TRUNC : - queue_trunc =handle_cap_trunc (inode, h, session); + queue_trunc =handle_cap_trunc (inode, h, session, + &extra_info);spin_unlock (&ci->i_ceph_lock);if (queue_trunc)ceph_queue_vmtruncate (inode);
@@ -4306,6 +4375,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,iput (inode); out:ceph_put_string (extra_info.pool_ns); +kfree (extra_info.fscrypt_auth);return ; flush_cap_releases:
Signature · 1 line
2.27.0
PATCH v5 6/8 ceph: add __ceph_get_caps helper support
In reply to [email protected]From: Xiubo Li <[email protected]>
--- fs/ceph/caps.c | 19 +++++++++++++------ fs/ceph/super.h | 2 ++ 2 files changed, 15 insertions(+), 6 deletions(-)
fs/ceph/caps.c +13 -6
@@ -2911,10 +2911,9 @@ int ceph_try_get_caps(struct inode *inode, int need, int want,* due to a small max_size, make sure we check_max_size (and possibly * ask the mds) so we don't get hung up indefinitely. */ -int ceph_get_caps (struct file *filp,int need,int want,loff_t endoff,int *got) +int __ceph_get_caps (struct inode *inode,struct ceph_file_info *fi,int need, +int want,loff_t endoff,int *got) { -struct ceph_file_info *fi = filp->private_data; -struct inode *inode =file_inode (filp);struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);int ret, _got, flags;
@@ -2923,7 +2922,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *gotif (ret <0 )return ret; -if ((fi->fmode &CEPH_FILE_MODE_WR ) && +if (fi && (fi->fmode &CEPH_FILE_MODE_WR ) && fi->filp_gen !=READ_ONCE (fsc->filp_gen))return -EBADF ;
@@ -2931,7 +2930,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *gotwhile (true) { flags &=CEPH_FILE_MODE_MASK ; -if (atomic_read (&fi->num_locks)) +if (fi &&atomic_read (&fi->num_locks)) flags |=CHECK_FILELOCK ; _got =0 ; ret = try_get_cap_refs(inode, need, want, endoff,
@@ -2976,7 +2975,7 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *gotcontinue ; } -if ((fi->fmode &CEPH_FILE_MODE_WR ) && +if (fi && (fi->fmode &CEPH_FILE_MODE_WR ) && fi->filp_gen !=READ_ONCE (fsc->filp_gen)) {if (ret >=0 && _got)ceph_put_cap_refs (ci, _got);
@@ -3039,6 +3038,14 @@ int ceph_get_caps(struct file *filp, int need, int want, loff_t endoff, int *gotreturn 0 ; } +int ceph_get_caps (struct file *filp,int need,int want,loff_t endoff,int *got) +{ +struct ceph_file_info *fi = filp->private_data; +struct inode *inode =file_inode (filp); + +return __ceph_get_caps (inode, fi, need, want, endoff, got); +} +/* * Take cap refs. Caller must already know we hold at least one ref * on the caps in question or we don't know this is safe.
fs/ceph/super.h +2 -0
@@ -1225,6 +1225,8 @@ extern int ceph_encode_dentry_release(void **p, struct dentry *dn,struct inode *dir, int mds, int drop, int unless); +extern int __ceph_get_caps (struct inode *inode,struct ceph_file_info *fi, +int need,int want,loff_t endoff,int *got);extern int ceph_get_caps (struct file *filp,int need,int want,loff_t endoff,int *got); extern int ceph_try_get_caps(struct inode *inode,
Signature · 1 line
2.27.0
PATCH v5 7/8 ceph: add __ceph_sync_read helper support
In reply to [email protected]From: Xiubo Li <[email protected]>
--- fs/ceph/file.c | 35 +++++++++++++++++++++++------------ fs/ceph/super.h | 2 ++ 2 files changed, 25 insertions(+), 12 deletions(-)
fs/ceph/file.c +23 -12
@@ -870,21 +870,18 @@ enum {* If we get a short result from the OSD, check against i_size; we need to * only return a short read to the caller if we hit EOF. */ -static ssize_t ceph_sync_read (struct kiocb *iocb,struct iov_iter *to, -int *retry_op) +ssize_t __ceph_sync_read (struct inode *inode,loff_t *ki_pos, +struct iov_iter *to,int *retry_op) { -struct file *file = iocb->ki_filp; -struct inode *inode =file_inode (file);struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);struct ceph_osd_client *osdc = &fsc->client->osdc;ssize_t ret; -u64 off = iocb->ki_pos; +u64 off = *ki_pos;u64 len =iov_iter_count (to);u64 i_size; -dout ("sync_read on file %p %llu~%u %s\n" , file, off, (unsigned )len, - (file->f_flags &O_DIRECT ) ?"O_DIRECT" :"" ); +dout ("sync_read on inode %p %llu~%u\n" , inode, *ki_pos, (unsigned )len);if (!len)return 0 ;
@@ -986,14 +983,14 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,break ; } -if (off > iocb->ki_pos) { +if (off > *ki_pos) {if (off >= i_size) { *retry_op =CHECK_EOF ; - ret = i_size - iocb->ki_pos; - iocb->ki_pos = i_size; + ret = i_size - *ki_pos; + *ki_pos = i_size; }else { - ret = off - iocb->ki_pos; - iocb->ki_pos = off; + ret = off - *ki_pos; + *ki_pos = off; } }
@@ -1001,6 +998,20 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to,return ret; } +static ssize_t ceph_sync_read (struct kiocb *iocb,struct iov_iter *to, +int *retry_op) +{ +struct file *file = iocb->ki_filp; +struct inode *inode =file_inode (file); + +dout ("sync_read on file %p %llu~%u %s\n" , file, iocb->ki_pos, + (unsigned )iov_iter_count (to), + (file->f_flags &O_DIRECT ) ?"O_DIRECT" :"" ); + +return __ceph_sync_read (inode, &iocb->ki_pos, to, retry_op); + +} +struct ceph_aio_request {struct kiocb *iocb;size_t total_len;
fs/ceph/super.h +2 -0
@@ -1253,6 +1253,8 @@ extern int ceph_renew_caps(struct inode *inode, int fmode);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);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
PATCH v5 8/8 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/file.c | 10 +- fs/ceph/inode.c | 198 ++++++++++++++++++++++++++++++++++-- fs/ceph/super.h | 8 +- include/linux/ceph/crypto.h | 28 +++++ 4 files changed, 230 insertions(+), 14 deletions(-) create mode 100644 include/linux/ceph/crypto.h
fs/ceph/file.c +8 -2
@@ -871,7 +871,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 *assert_ver) {struct ceph_inode_info *ci =ceph_inode (inode);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);
@@ -938,6 +939,9 @@ ssize_t __ceph_sync_read(struct inode *inode, loff_t *ki_pos, req->r_end_latency, len, ret); +/* Grab assert version. It must be non-zero. */ + *assert_ver = req->r_version; +WARN_ON_ONCE (assert_ver ==0 );ceph_osdc_put_request (req); i_size =i_size_read (inode);
@@ -1003,12 +1007,14 @@ static ssize_t ceph_sync_read(struct kiocb *iocb, struct iov_iter *to, {struct file *file = iocb->ki_filp;struct inode *inode =file_inode (file); +u64 assert_ver;dout ("sync_read on file %p %llu~%u %s\n" , file, iocb->ki_pos, (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, + &assert_ver); }
fs/ceph/inode.c +187 -11
284 lines not on this page · raw message
fs/ceph/super.h +7 -1
@@ -408,6 +408,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 */
@@ -1254,7 +1259,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 *assert_ver);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);
include/linux/ceph/crypto.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _FS_CEPH_CRYPTO_H +#define _FS_CEPH_CRYPTO_H + +#include <linux/types.h> + +/* +* 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; + +#endif
Signature · 1 line
2.27.0
Quoted 69 lines · On Wed, 2021-11-03 at 09:22 +0800, [email protected] wrote:
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.The MDS will use the
filer.write_trunc(), which could update and truncate the file in one shot, instead offiler.truncate().This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support inceph_inode_infostruct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.Changed in V4:
- Retry the truncate request by 20 times before fail it with-EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.Jeff Layton (5):
libceph: addCEPH_OSD_OP_ASSERT_VERsupport
ceph: size handling for encrypted inodes in cap updates
ceph:fscrypt_filefield handling in MClientRequest messages
ceph: get file size fromfscrypt_filewhen present in inode traces
ceph: handle fscrypt fields in cap messages from MDSXiubo Li (3):
ceph: add__ceph_get_capshelper support
ceph: add__ceph_sync_readhelper support
ceph: add truncate size handling support for fscrypt
Quoted 15 lines
fs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-) create mode 100644 include/linux/ceph/crypto.h
Thanks Xiubo,
This looks like a great start. I set up an environment vs. a cephadm cluster with your fscrypt changes, and started running xfstests against it with test_dummy_encryption enabled. It got to generic/014 and the test hung waiting on a SETATTR call to come back:
[root@client1 f3cf8b7a-38ec-11ec-a0e4-52540031ba78.client74208]# cat mdsc
89447 mds0 setattr #1000003b19c
Looking at the MDS that it was talking to, I see:
Nov 03 08:25:09 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 1 included below; oldest blocked for > 31.627241 secs
Nov 03 08:25:09 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : slow request 31.627240 seconds old, received at 2021-11-03T12:24:37.911553+0000: client_request(client.74208:89447 setattr size=102498304 #0x1000003b19c 2021-11-03T12:24:37.895292+0000 caller_uid=0, caller_gid=0{0,}) currently acquired locks
Nov 03 08:25:14 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 0 included below; oldest blocked for > 36.627323 secs
Nov 03 08:25:19 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 0 included below; oldest blocked for > 41.627389 secs...and it still hasn't resolved.
I'll keep looking around a bit more, but I think there are still some bugs in here. Let me know if you have thoughts as to what the issue is.
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 102 lines · Jeff Layton
Quoted 82 lines · On Wed, 2021-11-03 at 09:22 +0800, [email protected] wrote:
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.The MDS will use the
filer.write_trunc(), which could update and truncate the file in one shot, instead offiler.truncate().This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support inceph_inode_infostruct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.Changed in V4:
- Retry the truncate request by 20 times before fail it with-EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.Jeff Layton (5):
libceph: addCEPH_OSD_OP_ASSERT_VERsupport
ceph: size handling for encrypted inodes in cap updates
ceph:fscrypt_filefield handling in MClientRequest messages
ceph: get file size fromfscrypt_filewhen present in inode traces
ceph: handle fscrypt fields in cap messages from MDSXiubo Li (3):
ceph: add__ceph_get_capshelper support
ceph: add__ceph_sync_readhelper support
ceph: add truncate size handling support for fscryptfs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-)Quoted 2 lines
create mode 100644
include/linux/ceph/crypto.hThanks Xiubo,
This looks like a great start. I set up an environment vs. a cephadm cluster with your fscrypt changes, and started running xfstests against it with
test_dummy_encryptionenabled. It got to generic/014 and the test hung waiting on a SETATTR call to come back:[root@client1 f3cf8b7a-38ec-11ec-a0e4-52540031ba78.client74208]# cat mdsc
89447 mds0 setattr #1000003b19cLooking at the MDS that it was talking to, I see:
Nov 03 08:25:09 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 1 included below; oldest blocked for > 31.627241 secs Nov 03 08:25:09 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : slow request 31.627240 seconds old, received at 2021-11-03T12:24:37.911553+0000: client_request(client.74208:89447 setattr size=102498304 #0x1000003b19c 2021-11-03T12:24:37.895292+0000 caller_uid=0, caller_gid=0{0,}) currently acquired locks Nov 03 08:25:14 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 0 included below; oldest blocked for > 36.627323 secs Nov 03 08:25:19 cephadm2 ceph-mds[3133]: log_channel(cluster) log [WRN] : 1 slow requests, 0 included below; oldest blocked for > 41.627389 secs
Quoted 4 lines
...and it still hasn't resolved.
I'll keep looking around a bit more, but I think there are still some bugs in here. Let me know if you have thoughts as to what the issue is.
From MDS side log, it keeps retrying the truncate request:
2021-11-04T10:24:25.542+0800 149d48288700 1 -- v1:10.72.47.117:6814/424105754 <== osd.0 v1:10.72.47.117:6800/10035 249354 ==== osd_op_reply(358495 10000000ed7.00000016 [read 92872704~8] v0'0 uv0 ondisk = -2 ((2) No such file or directory)) v8 ==== 164+0+0 (unknown 4045992944 0 0) 0x55cd75169440 con 0x55cd7514dc00 2021-11-04T10:24:25.542+0800 149d46278700 10 MDSIOContextBase::complete: 24C_IO_MDC_ReadtruncFinish 2021-11-04T10:24:25.542+0800 149d46278700 10 MDSContext::complete: 24C_IO_MDC_ReadtruncFinish
It's a bug when hit a file hole. I will fix it soon.
Thanks.
BRs
Quoted 1 line
Thanks,
Quoted 69 lines · On Wed, 2021-11-03 at 09:22 +0800, [email protected] wrote:
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.The MDS will use the
filer.write_trunc(), which could update and truncate the file in one shot, instead offiler.truncate().This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support inceph_inode_infostruct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.Changed in V4:
- Retry the truncate request by 20 times before fail it with-EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.Jeff Layton (5):
libceph: addCEPH_OSD_OP_ASSERT_VERsupport
ceph: size handling for encrypted inodes in cap updates
ceph:fscrypt_filefield handling in MClientRequest messages
ceph: get file size fromfscrypt_filewhen present in inode traces
ceph: handle fscrypt fields in cap messages from MDSXiubo Li (3):
ceph: add__ceph_get_capshelper support
ceph: add__ceph_sync_readhelper support
ceph: add truncate size handling support for fscrypt
Quoted 15 lines
fs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-) create mode 100644 include/linux/ceph/crypto.h
Nice work, Xiubo. This looks good.
I've been testing it some today and it seems to work fine so far. I've got a bit more testing that I want to do tomorrow, but this should hopefully clear the way for us to finish the content encryption piece!
Many thanks!
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 85 lines · Jeff Layton
Quoted 82 lines · On Wed, 2021-11-03 at 09:22 +0800, [email protected] wrote:
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.The MDS will use the
filer.write_trunc(), which could update and truncate the file in one shot, instead offiler.truncate().This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support inceph_inode_infostruct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.Changed in V4:
- Retry the truncate request by 20 times before fail it with-EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.Jeff Layton (5):
libceph: addCEPH_OSD_OP_ASSERT_VERsupport
ceph: size handling for encrypted inodes in cap updates
ceph:fscrypt_filefield handling in MClientRequest messages
ceph: get file size fromfscrypt_filewhen present in inode traces
ceph: handle fscrypt fields in cap messages from MDSXiubo Li (3):
ceph: add__ceph_get_capshelper support
ceph: add__ceph_sync_readhelper support
ceph: add truncate size handling support for fscryptfs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-)Quoted 2 lines
create mode 100644
include/linux/ceph/crypto.h
Quoted 3 lines
Nice work, Xiubo. This looks good.
I've been testing it some today and it seems to work fine so far.
Cool.
Quoted 2 lines
I've
got a bit more testing that I want to do tomorrow,
At the same time I will test more.
Quoted 2 lines
but this should
hopefully clear the way for us to finish the content encryption piece!
Yeah, the experimental branch for the content encryption is not working well as the fname branch does, we may need more review and testing about it.
BRs
Xiubo
Quoted 1 line
Many thanks!
Quoted 96 lines · Xiubo Li
Quoted 85 lines · Jeff Layton
Quoted 82 lines · On Wed, 2021-11-03 at 09:22 +0800, [email protected] wrote:
From: Jeff Layton <[email protected]>
This patch series is based on the "wip-fscrypt-fnames" branch in repo https://github.com/ceph/ceph-client.git.
And I have picked up 5 patches from the "ceph-fscrypt-size-experimental" branch in repo
https://git.kernel.org/pub/scm/linux/kernel/git/jlayton/linux.git.====
This approach is based on the discussion from V1 and V2, which will pass the encrypted last block contents to MDS along with the truncate request.
This will send the encrypted last block contents to MDS along with the truncate request when truncating to a smaller size and at the same time new size does not align to BLOCK SIZE.
The MDS side patch is raised in PR
https://github.com/ceph/ceph/pull/43588, which is also based Jeff's previous great work in PR https://github.com/ceph/ceph/pull/41284.The MDS will use the
filer.write_trunc(), which could update and truncate the file in one shot, instead offiler.truncate().This just assume kclient won't support the inline data feature, which will be remove soon, more detail please see:
https://tracker.ceph.com/issues/52916Changed in V5:
- Rebase to "wip-fscrypt-fnames" branch in ceph-client.git repo.
- Pick up 5 patches from Jeff's "ceph-fscrypt-size-experimental" branch in linux.git repo.
- Add "i_truncate_pagecache_size" member support inceph_inode_infostruct, this will be used to truncate the pagecache only in kclient side, because the "i_truncate_size" will always be aligned to BLOCK SIZE. In fscrypt case we need to use the real size to truncate the pagecache.Changed in V4:
- Retry the truncate request by 20 times before fail it with-EAGAIN.
- Remove the "fill_last_block" label and move the code to else branch.
- Remove the #3 patch, which has already been sent out separately, in V3 series.
- Improve some comments in the code.Changed in V3:
- Fix possibly corrupting the file just before the MDS acquires the xlock for FILE lock, another client has updated it.
- Flush the pagecache buffer before reading the last block for the when filling the truncate request.
- Some other minore fixes.Jeff Layton (5):
libceph: addCEPH_OSD_OP_ASSERT_VERsupport
ceph: size handling for encrypted inodes in cap updates
ceph:fscrypt_filefield handling in MClientRequest messages
ceph: get file size fromfscrypt_filewhen present in inode traces
ceph: handle fscrypt fields in cap messages from MDSXiubo Li (3):
ceph: add__ceph_get_capshelper support
ceph: add__ceph_sync_readhelper support
ceph: add truncate size handling support for fscryptfs/ceph/caps.c | 136 ++++++++++++++---- fs/ceph/crypto.h | 4 + fs/ceph/dir.c | 3 + fs/ceph/file.c | 43 ++++-- fs/ceph/inode.c | 236 +++++++++++++++++++++++++++++--- fs/ceph/mds_client.c | 9 +- fs/ceph/mds_client.h | 2 + fs/ceph/super.h | 10 ++ include/linux/ceph/crypto.h | 28 ++++ include/linux/ceph/osd_client.h | 6 +- include/linux/ceph/rados.h | 4 + net/ceph/osd_client.c | 5 + 12 files changed, 427 insertions(+), 59 deletions(-)Quoted 2 lines
create mode 100644
include/linux/ceph/crypto.hQuoted 3 lines
Nice work, Xiubo. This looks good.
I've been testing it some today and it seems to work fine so far.
Cool.
Quoted 2 lines
I've
got a bit more testing that I want to do tomorrow,
Quoted 8 lines
At the same time I will test more.
Quoted 2 lines
but this should
hopefully clear the way for us to finish the content encryption piece!Yeah, the experimental branch for the content encryption is not working well as the fname branch does, we may need more review and testing about it.
Definitely. That work is not at all complete yet. We need to make sure the size handling is rock-solid before we add in content encryption though. If we get the size handling wrong then it will probably just manifest as data corruption once encryption is in play.
Heck, we may want to consider an fscrypt mode that just does no-op encryption for testing this sort of thing.
On another note...one interesting this with this patchset:
[jlayton@client1 scratch]$ ls -l /mnt/scratch/crypt total 12
-rw-r--r--. 1 jlayton jlayton 1025 Nov 5 06:55 1025 -rw-r--r--. 1 jlayton jlayton 1024 Nov 5 06:54 1k -rw-r--r--. 1 jlayton jlayton 2048 Nov 5 06:54 2k -rw-r--r--. 1 jlayton jlayton 7168 Nov 5 06:55 7k -rw-r--r--. 1 jlayton jlayton 4 Nov 5 06:54 foo
...but when the same client doesn't have the key, the real sizes are still presented:
[jlayton@client1 ~]$ ls -l /mnt/scratch/crypt
total 12
-rw-r--r--. 1 jlayton jlayton 4 Nov 5 06:54 mmyetGFDwaf_PPqhm2ofMkNOFxBPFyrYJc_uif1vXL8 -rw-r--r--. 1 jlayton jlayton 1024 Nov 5 06:54 OGkEeGaqqLj7YVceGN5SkCF80et25ZkPUwdrd9nqtsg -rw-r--r--. 1 jlayton jlayton 7168 Nov 5 06:55 RL6qlqBvpAkZEku3SKrTmGqTkJWkWjqM7KtPvYJBAf8 -rw-r--r--. 1 jlayton jlayton 1025 Nov 5 06:55 w1rCnxYQLJTbxHtZC2qtRnDdoIO9-vf_OlKjY0WcwH8 -rw-r--r--. 1 jlayton jlayton 2048 Nov 5 06:54 YcwUK3htDdBkSqJVMebaKgR5xLO6BXz-NpABPa-mUA
On a client that doesn't support fscrypt, the sizes show the rounded-up values (as expected):
[jlayton@client2 ~]$ ls -l /mnt/scratch/crypt/
total 24
-rw-r--r--. 1 jlayton jlayton 4096 Nov 5 06:54 mmyetGFDwaf_PPqhm2ofMkNOFxBPFyrYJc_uif1vXL8 -rw-r--r--. 1 jlayton jlayton 4096 Nov 5 06:54 OGkEeGaqqLj7YVceGN5SkCF80et25ZkPUwdrd9nqtsg -rw-r--r--. 1 jlayton jlayton 8192 Nov 5 06:55 RL6qlqBvpAkZEku3SKrTmGqTkJWkWjqM7KtPvYJBAf8 -rw-r--r--. 1 jlayton jlayton 4096 Nov 5 06:55 w1rCnxYQLJTbxHtZC2qtRnDdoIO9-vf_OlKjY0WcwH8 -rw-r--r--. 1 jlayton jlayton 4096 Nov 5 06:54 YcwUK3htDdBkSqJVMebaKgR5xLO6BXz-NpABPa-mUAU
Question: should we present the rounded-up sizes to applications on clients that support fscrypt but do not have the key?
I tend to think that that makes for better opsec, overall. Are there reasons not to hide the real size when the user doesn't have the key?
Signature · 1 line
Jeff Layton <[email protected]>