@@ -1217,10 +1217,9 @@ struct cap_msg_args {
12171217 umode_t mode ;
12181218 bool inline_data ;
12191219 bool wake ;
1220+ bool encrypted ;
12201221 u32 fscrypt_auth_len ;
1221- u32 fscrypt_file_len ;
12221222 u8 fscrypt_auth [sizeof (struct ceph_fscrypt_auth )]; // for context
1223- u8 fscrypt_file [sizeof (u64 )]; // for size
12241223};
12251224
12261225/* Marshal up the cap msg to the MDS */
@@ -1255,7 +1254,13 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg)
12551254 fc -> ino = cpu_to_le64 (arg -> ino );
12561255 fc -> snap_follows = cpu_to_le64 (arg -> follows );
12571256
1258- fc -> size = cpu_to_le64 (arg -> size );
1257+ #if IS_ENABLED (CONFIG_FS_ENCRYPTION )
1258+ if (arg -> encrypted )
1259+ fc -> size = cpu_to_le64 (round_up (arg -> size ,
1260+ CEPH_FSCRYPT_BLOCK_SIZE ));
1261+ else
1262+ #endif
1263+ fc -> size = cpu_to_le64 (arg -> size );
12591264 fc -> max_size = cpu_to_le64 (arg -> max_size );
12601265 ceph_encode_timespec64 (& fc -> mtime , & arg -> mtime );
12611266 ceph_encode_timespec64 (& fc -> atime , & arg -> atime );
@@ -1315,11 +1320,17 @@ static void encode_cap_msg(struct ceph_msg *msg, struct cap_msg_args *arg)
13151320 ceph_encode_64 (& p , 0 );
13161321
13171322#if IS_ENABLED (CONFIG_FS_ENCRYPTION )
1318- /* fscrypt_auth and fscrypt_file (version 12) */
1323+ /*
1324+ * fscrypt_auth and fscrypt_file (version 12)
1325+ *
1326+ * fscrypt_auth holds the crypto context (if any). fscrypt_file
1327+ * tracks the real i_size as an __le64 field (and we use a rounded-up
1328+ * i_size in the traditional size field).
1329+ */
13191330 ceph_encode_32 (& p , arg -> fscrypt_auth_len );
13201331 ceph_encode_copy (& p , arg -> fscrypt_auth , arg -> fscrypt_auth_len );
1321- ceph_encode_32 (& p , arg -> fscrypt_file_len );
1322- ceph_encode_copy (& p , arg -> fscrypt_file , arg -> fscrypt_file_len );
1332+ ceph_encode_32 (& p , sizeof ( __le64 ) );
1333+ ceph_encode_64 (& p , arg -> size );
13231334#else /* CONFIG_FS_ENCRYPTION */
13241335 ceph_encode_32 (& p , 0 );
13251336 ceph_encode_32 (& p , 0 );
@@ -1391,7 +1402,6 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap,
13911402 arg -> follows = flushing ? ci -> i_head_snapc -> seq : 0 ;
13921403 arg -> flush_tid = flush_tid ;
13931404 arg -> oldest_flush_tid = oldest_flush_tid ;
1394-
13951405 arg -> size = i_size_read (inode );
13961406 ci -> i_reported_size = arg -> size ;
13971407 arg -> max_size = ci -> i_wanted_max_size ;
@@ -1445,6 +1455,7 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap,
14451455 }
14461456 }
14471457 arg -> flags = flags ;
1458+ arg -> encrypted = IS_ENCRYPTED (inode );
14481459#if IS_ENABLED (CONFIG_FS_ENCRYPTION )
14491460 if (ci -> fscrypt_auth_len &&
14501461 WARN_ON_ONCE (ci -> fscrypt_auth_len > sizeof (struct ceph_fscrypt_auth ))) {
@@ -1456,21 +1467,21 @@ static void __prep_cap(struct cap_msg_args *arg, struct ceph_cap *cap,
14561467 min_t (size_t , ci -> fscrypt_auth_len ,
14571468 sizeof (arg -> fscrypt_auth )));
14581469 }
1459- /* FIXME: use this to track "real" size */
1460- arg -> fscrypt_file_len = 0 ;
14611470#endif /* CONFIG_FS_ENCRYPTION */
14621471}
14631472
1473+ #if IS_ENABLED (CONFIG_FS_ENCRYPTION )
14641474#define CAP_MSG_FIXED_FIELDS (sizeof(struct ceph_mds_caps) + \
1465- 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4)
1475+ 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4 + 8 )
14661476
1467- #if IS_ENABLED (CONFIG_FS_ENCRYPTION )
14681477static inline int cap_msg_size (struct cap_msg_args * arg )
14691478{
1470- return CAP_MSG_FIXED_FIELDS + arg -> fscrypt_auth_len +
1471- arg -> fscrypt_file_len ;
1479+ return CAP_MSG_FIXED_FIELDS + arg -> fscrypt_auth_len ;
14721480}
14731481#else
1482+ #define CAP_MSG_FIXED_FIELDS (sizeof(struct ceph_mds_caps) + \
1483+ 4 + 8 + 4 + 4 + 8 + 4 + 4 + 4 + 8 + 8 + 4 + 8 + 8 + 4 + 4)
1484+
14741485static inline int cap_msg_size (struct cap_msg_args * arg )
14751486{
14761487 return CAP_MSG_FIXED_FIELDS ;
@@ -1550,13 +1561,10 @@ static inline int __send_flush_snap(struct inode *inode,
15501561 arg .inline_data = capsnap -> inline_data ;
15511562 arg .flags = 0 ;
15521563 arg .wake = false;
1564+ arg .encrypted = IS_ENCRYPTED (inode );
15531565
1554- /*
1555- * No fscrypt_auth changes from a capsnap. It will need
1556- * to update fscrypt_file on size changes (TODO).
1557- */
1566+ /* No fscrypt_auth changes from a capsnap.*/
15581567 arg .fscrypt_auth_len = 0 ;
1559- arg .fscrypt_file_len = 0 ;
15601568
15611569 msg = ceph_msg_new (CEPH_MSG_CLIENT_CAPS , cap_msg_size (& arg ),
15621570 GFP_NOFS , false);
0 commit comments