]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-client.git/commitdiff
ceph: fscrypt_file field handling in MClientRequest messages
authorJeff Layton <jlayton@kernel.org>
Thu, 25 Aug 2022 13:31:07 +0000 (09:31 -0400)
committerXiubo Li <xiubli@redhat.com>
Fri, 26 Aug 2022 23:58:54 +0000 (07:58 +0800)
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.

Reviewed-by: Xiubo Li <xiubli@redhat.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
fs/ceph/dir.c
fs/ceph/file.c
fs/ceph/inode.c
fs/ceph/mds_client.c
fs/ceph/mds_client.h

index b136fb923b7a08ba661564d4779c430ebf512ca7..59df878a4df785e5d4b676d7d2b9b074128dd1da 100644 (file)
@@ -914,6 +914,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;
index 86265713a743589b4692e0302c89d4ba44879e28..0dba7ec6744998781ff5dd7fc7c2c50397682b08 100644 (file)
@@ -785,6 +785,7 @@ retry:
        req->r_parent = dir;
        ihold(dir);
        if (IS_ENCRYPTED(dir)) {
+               set_bit(CEPH_MDS_R_FSCRYPT_FILE, &req->r_req_flags);
                if (!fscrypt_has_encryption_key(dir)) {
                        spin_lock(&dentry->d_lock);
                        dentry->d_flags |= DCACHE_NOKEY_NAME;
index 4db4394912e799d17fec4b7876a462a231b72e50..67a2421ed092bcf7892d8109cb95eba49c3d44b1 100644 (file)
@@ -2390,11 +2390,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) && attr->ia_size) {
+                               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) {
index e3683305445ce947996ffd63d04dd76142515450..9518ac8e407d7e78e99f99be54d4ed95cd59df85 100644 (file)
@@ -2830,7 +2830,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);
+       }
 }
 
 /*
@@ -2916,6 +2921,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) {
index 728b7d72bf7688ad68dacf94ead95234962c0ecd..81a1f9a4ac3bee3456d74565a24cf4a588631376 100644 (file)
@@ -282,6 +282,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;
@@ -289,6 +290,7 @@ struct ceph_mds_request {
        union ceph_mds_request_args r_args;
 
        struct ceph_fscrypt_auth *r_fscrypt_auth;
+       u64     r_fscrypt_file;
 
        u8 *r_altname;              /* fscrypt binary crypttext for long filenames */
        u32 r_altname_len;          /* length of r_altname */